Most beautiful programming language feature | Chris Lattner and Lex Fridman

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
there you go this is a question uh to ask what is the most beautiful feature in a programming language before i ask you let me say like with python i remember i saw list comprehensions okay it was like when i like really took it in yeah it i don't know i just loved it it was like fun to do like it was fun to do that kind of um uh it was something about it to be able to filter through a list and to create a new list all in a single line was elegant i could all get into my head and it just made me um fall in love with the language so is there let me ask you a question uh is there what to use the most beautiful feature in uh in a programming languages that you've ever encountered in swift maybe and then outside of swift i think the thing that i like the most from a programming language so so i think the thing you have to think about with the programming language again what is the goal you're trying to get people to get things done quickly and so you need libraries you need high quality libraries and then you need a user base around them that can assemble them and do cool things with them right and so to me the question is what enables high quality libraries okay yeah and there's a huge divide in the world between libraries who enable high quality libraries versus um the ones that put special stuff in the language so programming languages that enable high quality quality libraries got it so so and what i mean by that is expressive libraries that then feel like a natural integrated part of the language itself so um an example this in swift is the int and float and also rain string things like this these are all part of the library like int is not hard coded into swift and so what that means is that because int is just a library thing defined in the standard library along with strings and arrays and all the other things that come with standard library well hopefully you do like int but anything that any language features that you needed to define int you can also use in your own types so if you wanted to find a uh quaternion or something like this right um well it doesn't come the standard library um there's a very special set of people that care a lot about this but those people are also important it's not it's not about classism right it's not about the people who care about instant floats are more important than the people who care about quaternions and so to me the beautiful things about programming languages is when you allow those communities to build high quality libraries that feel native they feel like they're built into the built into the compiler without having to be what does it mean for the int to be part of not hardcoded in so is it like how so what isn't what is an int okay is just a integer in this case it's like a you know like a 64-bit integer or something like this but so like the 64-bit is hard-coded or no no none of that's hard-coded so ins if you go look at how it's implemented it's just a struct and swift and so it's a struct and then how do you add two structs well you define plus and so you can define plus on int well you can define plus on your thing too you can define uh int has like an is odd method or something like that on it and so yeah you can add methods onto things yeah uh so you can you can define operators like how it behaves yeah that's you is beautiful when there there's something about the language which enables others to create libraries which are um not hacky yeah they feel they feel native and so one of the best examples of this is lisp right because in lisp like all the libraries are basically part of the language right you write term rewrite systems and things like this and so can you as a counter example provide what makes it difficult to write a library that's native is it the python c well so well so one example i'll give you two examples um java and c plus plus or java and c um they both allow you to find your own types but int is hardcoded in the language okay well why well in in java for example coming back to this whole reference semantic value semantic thing um int gets passed around by value yeah but if you if you make if you make like a pair or two something like that a complex number right it's a it's a class in java and now it gets passed around by reference by pointer and so now you lose value semantics right you lost math okay well that's not great right if you if you can do something within why can't i do with my type yeah right so that's that's the the negative side of the thing i find beautiful is when you can solve that when you can have full expressivity where you as a user of the language have as much or almost as much power as the people who implemented all the standard built-in stuff because what that enables is that enables truly beautiful libraries you know it's kind of weird because i've gotten used to that uh that's one i guess other aspect of programming language design you have to think you know the old first principles thinking like why are we doing it this way by the way i mean i remember because i was thinking about the wallers operator and i'll ask you about it later but it hit me that like the equal sign for assignment yeah like why are we using the equal sign assignment and that's that's not the only solution right so if you look at pascal they use colon equals or assignment and equals for um for equality and they use like less than greater than instead of the not equal yeah like there are other answers here so but like and yeah i'd like us ask you all but but how do you then decide uh to break convention to say you know what everybody's doing it wrong we're gonna do it right yep so so it's like an roi like return on investment trade-off right so if you do something weird let's just say like not like colon equal instead of equal for assignment that would be weird with today's aesthetic right and so you'd say cool this is theoretically better but is it better in which ways like what do i get out of that do i define a way class of bugs well one of the class of bugs that c has is that you can use like you know if x equals without equals equals f x equals y yeah right well turns out you can solve that problem in lots of ways clang for example gcc all these compilers will detect that as a as they likely bug produce a warning do they yeah i feel like they didn't or clang does gcc didn't and it's like one of the important things about programming language design is like you're literally creating suffering in the world okay like like i feel like i mean one way to see it is the bicycle for the mind but the other way is to like minimizing suffering well you have to decide if it's worth it right and so let's come back to that okay but um but if you if you look at this and again this is where there's a lot of detail that goes into each of these things um uh equal and c returns a value yep that's messed up that allows you say x equals y equals z like that works in c yeah um is it messed up you know well so that most people think it's messed up i think it is very by messed up what i mean is it is very rarely used for good and it's often used for bugs yeah right and so that's that's a good definition yeah you could use you know it's a in hindsight this was not such a great idea right now one of the things with swift that is really powerful and one of the reasons it's actually good um versus it being full of good ideas is that um when when we launched swift one we announced that it was public people could use it people could build apps but it was going to change and break okay when swift 2 came out we said hey it's open source and there's this open process which people can help evolve and direct the language so the community at large like swift users can now help shape the language as it is and what happened is that part as part of that process is a lot of really bad mistakes got taken out so for example swift used to have the c style plus plus and minus minus operators like what does it mean when you put it before versus after right well that got cargo culted from c into swift early what's the cargo cult cargo colton means uh brought forward without really considering considering it okay um this may be not the most pc term but uh look it up an urban dictionary yeah so it got pulled it got pulled into c without or it got pulled into swift without very good consideration and we went through this process and one of the first things got ripped out was plus plus and minus minus because they lead to confusion they have very little value over saying you know x plus equals one and x plus equals one is way more clear and so when you're optimizing for teachability and clarity and bugs and this multi-dimensional space that you're looking at things like that really matter and so being first principles on where you're coming from and what you're trying to achieve and being anchored on the objective is really important you
Info
Channel: Lex Clips
Views: 43,886
Rating: undefined out of 5
Keywords: chris lattner, lex fridman podcast, artificial intelligence, ai, ai podcast, artificial intelligence podcast, lex clips, lex fridman, lex friedman, joe rogan, elon musk, lex podcast, lex mit, lex ai, mit ai, ai podcast clips, ai clips, deep learning, machine learning, computer science, engineering, physics, science, tech, technology, tech podcast, physics podcast, mathematics, math, math podcast, friedman, consciousness, philosophy, turing, einstein
Id: t5CcNJx5qtM
Channel Id: undefined
Length: 9min 47sec (587 seconds)
Published: Thu Oct 22 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.