An Overview of the Rust Programming Language

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Havn't till the end yet but it looks like a really nice overview I must say

๐Ÿ‘๏ธŽ︎ 9 ๐Ÿ‘ค๏ธŽ︎ u/lsmod1 ๐Ÿ“…๏ธŽ︎ Mar 29 2021 ๐Ÿ—ซ︎ replies

Great introduction!

Update: All the tools and src are at the end of the prez ๐Ÿ˜‚

What are you using to build and manage you presentation?

The notes looks like a vim integration (1) with some kind of MD presentation (0).

Is it sharable?

๐Ÿ‘๏ธŽ︎ 4 ๐Ÿ‘ค๏ธŽ︎ u/syepes ๐Ÿ“…๏ธŽ︎ Mar 30 2021 ๐Ÿ—ซ︎ replies

Sorry for that typo src got changed for the other word ๐Ÿ˜‚

๐Ÿ‘๏ธŽ︎ 2 ๐Ÿ‘ค๏ธŽ︎ u/syepes ๐Ÿ“…๏ธŽ︎ Mar 30 2021 ๐Ÿ—ซ︎ replies

Thank you! I will share it with my friends! Also, what software do you use for showing the document in the presentation? Seems like a great tool, it shows time and shell and other info Edit: I saw that other people asked about the tools too. Thank you

๐Ÿ‘๏ธŽ︎ 1 ๐Ÿ‘ค๏ธŽ︎ u/IAmHereComrade ๐Ÿ“…๏ธŽ︎ Apr 01 2021 ๐Ÿ—ซ︎ replies
Captions
hey everyone uh so recently i really started to get into the rust programming language and i think that's gonna become really popular so i just wanted to make a video of just over of just highlighting some important uh points about rus and what it is i do want to know that this presentation was originally made for high school students uh so there are some memes but i just wanna i i think that it's really well made so i just wanted to share it out to you guys uh i also do want to highlight the fact that i used some um examples from articles and i did source them at the end of the last slide so i just um so before we begin i just want to point out why russ was made and the history of how it came to be because i think it's important to recognize um its history to determine why it was it why even exist so russ was a personal project that basically began in 2006 by an employee called uh grading horror and before that he was working with t plus plus in mozilla but the thing is if you ever played with c plus plus you would know that it's kind of difficult to manage your memory um um like if you're just an average person like me and it's really difficult it's just easy to make memory mistakes just errors and especially when you're handling concurrent code so greenhorn kind of recognized this and he said hey let's just make a language that's specifically made for system safety and in 2009 matilda began to sponsor a project um and finally in 2016 we finally got the first official release of russ so like i said russ is a systems language and specifically is a statically typed multi-paradigm language and i'm going to break them down if in case you don't know what that means statically type means that basically you annotate your variables with the type um and then multi-paradigm language means basically means that incorporates a lot of features or a lot of ideas from other programming languages um it is also really focused on performance reliability and productivity which is one of the reasons why stack overflows most love language for five years and before we even like even see rustcode i do want to highlight more about system sandwiches specifically i do want to go over what a garbage collector is and undefined behavior uh basically garbage collector is a feature in many programming languages like java or python that automatically frees memory on that is not used in runtime and undefined behavior is basically what it's self-explanatory but it's basically what a program runs unexpectedly when you as a programmer write some code and doesn't really work out the way you expected um i also do want to highlight the fact that in case you don't know uh there are two different kinds of memory in your i guess in a computer which is the stack and the heap and you can think of like an easy way to think of it is like the stack should just carry um values like um primitives like inks doubles um or chars and from java and the heap should carry mostly more abstract ideas like arrays on objects this way we can keep on using them even when it's this their i guess their scope goes out of balance so let's just start getting let's look let's start looking at some rust um just basics um as you can see here there's some um some types here i don't want to really cover them but i do want to highlight one of them which is a char and i do want to highlight this because as you can see i i see as you can see here i wrote that it uses gtf8 um which means that it uses four bytes for every char um and this is very important to highlight because in other systems languages if you're familiar with like c or c plus you basically just get like some ascii notation or enough for an ascii character um and this is because russ really likes to handle like wants to handle everything including strings so because of this we can get some like out of the box support with um with russ as you can see we can write i guess unicode or utf-8 characters and it's all valid in rus um and this is basically an example of how you write variables in rust it's also um nice to say but basically um i did say that russ was a statically type language but in most cases it can actually guess the type of what um your variable is or yeah and but you could also kind of notate it like i said um in case you don't know russ has top two poles and also has arrays that are with uh known compile with known sizes at compile times and if you're from java it also has like an arraylist but they are known more as vectors and let's just start getting into like more complex things those are just kind of guess primitives that you need to know and these are more functions so as you can see here this is how we write a function function name a function in the parameters and then the type but i do want to highlight i guess the switch case or what other languages might known switch case or in this case a match case and this was one of the features where russ comes in it's very hint uh i guess uh helpful and it's it's expression matching as you can see here we just write zero one uh to return like the fib like the first fibonacci numbers but then we here have we have like this underscore and this is supposed to like i guess match whatever n is if it's not zero one and then we'll just return this um i think this is very powerful and it just like matches your expression so you don't really have to keep on writing down or handle other cases and with this you can just make sure that your i guess your program if you don't really know what's gonna happen you can just um say in the match case hey there might be an error and we can just and with the this match case you can handle it and here's another implementation of our implementation implementation of fitzbus and if you don't know what fistbust is basically it uh takes the number zero two hundred or one two hundred and if it's if a number is a mult um a multiple of 15 5 or 3 it will uh print out some special characters or else it would just print out the number and and i just wanted to highlight here that uh we can just like um assign this result variable to a i guess loop or an if an if else chain and whatever it results we're just gonna automatically um assign it to a result and it's part of just this expression um brush has and i think it's really one of the yeah it's a really helpful feature uh finally i just wanted to highlight some more complex com i guess ideas and or not complex but more i guess if you're more familiar with object oriented programming um rust kind of has stuff too it's not really an object object oriented programming language but there are some ideas you can use it to um i guess stimulate the idea so we have here structs um instructs you can think of structs like classes where they have like variable type a variable name and then their type you can see here we're i guess making a card struct with some fields and then we have some enums and enums are really powerful and rust i suggest you use them when possible and the reason for this as i said russ it's really um a language made for systems safety so one of the things is that one of the special things about enums is that it prevents data entry errors so in case a um in case you ever make an enum fuel type and then you don't assign it to one of these i guess few types then it will the compiler will complain and it will tell you hey you need to make sure that it's one of these types or one of these data fields finally you also have i guess methods for i guess the structs and um as you can see here we use a keyword implement and then we just implement whatever methods or functions we want for our struct um and if you're familiar with java or python we have like this um we can create like this new cons our constructor for a struct and we can just assign whatever field um fuels you want to or parameters we want to and the last thing i wanted to note is traits um and you can think of traits as some uh something like java's interfaces or c declaration headers but it's more familiar to like java's interfaces because it gives the ability to use polymorphism and as you can see here we're just like i guess making some uh function signatures hermetic signatures and we're going to just like assign the type we're going to get in turn and then later on when we want to implement the trait for um for whatever shock we are uh we can actually implement these functions uh for instruct car and traits are really powerful because well polymorphism you can just make a trade and then have a class a struct um implement whatever that trait is and you can just get different behaviors for different structs with the same i guess a trait so now that we just had some basic building blocks up for us we can finally start just emphasizing more points and just get into the more complex or the fun features which i think are important to highlight so as i said writing good code is hard but writing safe code it's harder you want to like make sure that whoever is using your code or whoever is running your program is going to get the result you want exactly and that is why you need to handle a lot of cases which it means that your safe code has to be almost like perfect um and finally working with save with memory it's even dangerous because you might get some unexpected errors um so i just want so i think in order for us to understand why ruts is so powerful uh we kind of need to look at c and this is basically a very bad implementation of vectors it or dynamic array and c and this i guess uh just code block has a lot of errors here and i'm just going to go over some errors i this uh example has for example um here we have like this function called vec new and it's supposed to represent like a constructor but this constructor is stack allocated we never um allocated to heap which means that basically when this function ends we're gonna get nothing where the we're just gonna get a pointer that is not um that's not that does not point to the data we want and that is obviously an issue since we're we want to use this vector um in other functions um finally we also we also have like the fact that we assign um uh the field capacity to zero which means that i mean uh which means that whenever we try to i guess allocate more memory for this vector to hold more uh values we are going to get an error and specifically right here uh whenever we multiply by 2 it's always going to equal zero and that it's not good we're just gonna get some unexpected behavior right there we also have this vec free um function which incorrectly i guess orders around the freeze obviously we free the vector here but then we then we try to look into the data field of the vector but that's not going to exist because we already freed the vector um so as you can see here uh this might be like an example some person who is new to c might come up with two but it's gonna obviously have a lot of um i guess errors and this is where russ kind of comes into uh russ ceases and like she's hey this is actually really hard you know you know programmers should be dealing with implementing more or implementing higher programs we shouldn't really be dealing with um taking care of just like making sure our um making sure we're not gonna get a we're not gonna get an error with our implementation so as i said brush and memory safety those are the two things you want to want to highlight um and basically russ is a language that you can that allows you to check for errors before run time and this means that basically if you get a rust program to compile you can be like basically 100 sure that it's going to run the way you want it or the way you wrote it doesn't mean that's necessarily going to be the like the answer you want but as a programmer it's going to be like how you wrote your code exactly um which means that one of the like features that it has is that everything is immutable by default and if you don't know what immutable means is that basically um you really can't change the data of a variable um by default and as such we are kind of forced to handle errors when we when we write our code and there's the fact that and the way that this kind of works is by using by two features in rus called ownership and borrow checking finally there's this pie i really want to highlight uh because i said there's a lot of errors in a lot of um languages so this is i guess the the linux kernels um just overview and how what kind of bugs it gets so as you can see here like most of the bugs here are actually memory related and this is not that great because as i said we don't really want to be able to we want to just implement more features for the links kernel but when we get errors like this we don't know how that's going to affect our other our our chord base so let's get started um so two of the main features i said are is ownership and borrow checking and basically ownership is um it's the idea that russ implemented where every variable has a thing called an owner and there can only be one owner at the same time but multiple references we're gonna get into that later um and basically when the um when it's when the value or the owner goes out of scope the value will be dropped uh which means that basically which um whenever um the variable just goes out of uh like when a while loop is done we're going to automatically free that data uh due to this ownership system and the ownership system kind of works with the borrow checker system and they're just more specifications that says we really can't use um you really can't move the value um of a variable twice because that will go against the ownership system and these two kind of work really uh tightly together to make sure that you can only uh use a variable uh or you can really change their variables data once so you can imagine by using this system we can uh get rid of data races and if in case you don't know what a data race is basically when uh two concurrent threads or try to change the same um i guess uh value twice but if it changes the same value twice you're gonna get some at the same time you're gonna get some um errors right there so this is an example of just um what the i guess ownership system might look like where we're assigning a global struct a and then we're going to assign it to this variable a but and after using a we're also going to assign a b um so that means that b now owns i guess struck a but we're also assigning it's um the variable c a but the thing is the rust compiler is gonna scream at us it's gonna tell us this is no good because this goes against ownership system we hop here um and it exactly tells us here uh uh move occurs um a because has type a and then we move the value here which means that b now owns uh a but it also tells us hey we have about we don't a doesn't have anything because uh b noun stroke uh b now oh struck a so it's obvious gonna uh error out and you might think that this is annoying at first and i guess the example i gave is not the greatest but um as you can imagine with my data arrays example a rust will make sure that um you are only going to change the value of a variable once and i think that when you're writing i guess drivers this might be um very beneficial because you know that everything you're gonna end up writing is correct so let's move on as i said russ is very keen on error handling and which means that it has some special i guess syntax sugar to deal with uh errors so this is an example of just me creating a an image um like a graphic image a a ppm image in rus um and we can see here that we're trying to write to a file um and we're trying to like uh just write some thing to a file but we here have a question mark and basically um whenever you write to a file you might think that you might think of any um well there might be some uh errors that you can uh have when you're trying to write to a file such as the files already being um written in or the file doesn't exist and by using this question mark you're telling the um you're telling russ that you already know and you're gonna handle it um and here as you can see here um we're also using unwrap here because sometimes you might not have permission to create files but by using a wrapper we're basically telling us yeah we we know where there might be errors but we're going to handle it again um as you can see here and we just have like these functions or i guess syntax triggers just to handle these errors and we're gonna whenever you write a program uh in rus we have to be mindful that there might be errors but as a programmer we know that we're gonna handle it and that's the main thing i wanna i want you guys to take um on and finally there's also the fact that russ is has zero cost subtractions not everything is zero cost but most of things are and but basically what zero cost subtractions uh basically means is that whenever we have like very complex things like uh i guess um uh like calling another function or in a function uh russ is basically gonna optimize those calls and it's gonna allow us to have cool features but not at the expense of i guess uh speed so these are just three um examples i gathered uh just to show how um this kind of works so this is a simple implementation um where we're just basically taking uh at any number one to n one and then we're summing them together and this is something you can really write uh in any language um and when we kind of want can we kind of see the output of what the assembly looks like we can see that it's very simple it's not not complex like we're compiling this to this assembly and there's really not that many loops or there is isn't any loops um and but like i said this is generic this is something you might write in any programming language but it's not really rus um it's not really with the rus not the russ way so these are two rus i guess uh two examples of the same function uh written in the rest way and here i'm not going to explain what this means but we basically as you can see here we're creating this um we're using we're using a lot of rust methods to be able to do the same thing and it's certainly i guess more complex more abstractions but the thing is whenever um sorry let me get into it the thing is whenever we um if we we also use the same thing um and then we compile it to um assembly as well we can see that even though we're using more abstract um methods or like more abstractions that are are provided by russ it's gonna compile to the same assembly and the same thing goes with um with the third example so the point is that even if we have like really cool features with like um really cool features and more complex um abstractions russ is gonna take care of that and it's gonna optimize it the way we'd expect it so our code it it's gonna run just as fast as um something like c sometimes um finally i do want to highlight that russ has really cool macros um and what if you don't know what macros are they basically are are part of meta programming and i basically says that it's basically code that writes other code and the cool thing about macros and russ is that there really isn't um runtime there isn't a runtime cost so whenever you make like a macro um it's gonna just come just gonna apply to your binary size and that means that you are not gonna have like a any any uh guess downsides whenever you're running your program so there are two types of macros in rus there are declarative and prodigious well there isn't actually any types but these are just kind of the ideas we have currently um and in the future i think the rust team is trying to uh just make them more to make them into like i guess one type but for now we do have two types and so let's just take a little take a look at declarative and declarative you use basically um just sent like i guess the syntax macro rules and then define your macro so for example we're defining this at and then um so in rus i'm sorry i didn't explain this before but in rus um you whenever you use macro you're always going to see this exclamation mark which represents that this thing is macro so here we're kind of uh saying that we're using this macro as and we're providing these parameters to this macro and basically we're like i said this is gonna um this is gonna compile two this is gonna compile to other code we're gonna this macro is gonna write other code so basically um the parameters we have here are gonna be um substituted to this to right here and it's gonna just add them together like as the function sets um and this might not be a good example but as you can see here uh you can create a lot of cool stuff uh just by using macros um i for example the rust team um uses the vect macro to automatically uh create a new vector and then push all the elements you want into this vector and then finally it will return uh the vector so as you can as you can see here instead of like running this whole creating like this like a vector yourself and then making it like a while looper a for loop of how many elements you want uh this is just automatically gonna run and it's efficient there's also procedural macros and procedural macros are kind of a bit different because they are applied to a struct or they are applied to as like attributes so in russ we have these things called attributes and they kind of um manipulate whatever is below them so in this case um we are using the attribute derive getters and that's going to manipulate uh this truck called newsfeed and basically it can um just create getters for this for all the fields in this struct and it would just do it to the it was just when it compiles we will actually be getting this result um yeah um so yeah sorry and then these are just derived macros um and you can see you can see like there's a lot of um i know that a lot of libraries use these attributes or these procedural macros to create more complex things like i know that one library calls a macro to basically serialize your data to to a different for a different language to use and basically this is a really nice way for you as a programmer to just call it and just not have to worry about implementing this because you know that the macro is going to do itself finally i do want to highlight the point that compiler messages are amazing russ it's one of the best thing in russ because even though there are going to be like a lot of things for you to handle the uh the rust developers know that and one of the way they made one of the ways they made it uh they made rust better but having amazing compiler messages so as you can see here we just have this struct uh color and it has rgb something you would expect for pixel but whenever we're i guess constructing this new a new struct we made a mistake here instead of b we wrote d and when we compile it and run this code you see that we are the compiler is going to tell us hey there's actually a field you actually made an error here uh it doesn't really exist but there's a similar field called b you might want to check that out and exactly as you can see here it's very helpful because it's basically just telling you what error you made and how to fix it and then you can see here we also have the ability to um just learn more about the error and and the more you use brush the more you're going to appreciate this that it's just going to give you a lot of suggestions on how to fix your code it's i would say the rust compiler it's more as a teacher you should work with because it's teaching you how to work your or how to make your code better finally i want to go over the fact that the rus 2 chain is pretty amazing basically there's one tool a lot of people use and that is cargo i think most people actually use it i might be wrong about that i don't know i'm pretty sure like 100 use it but again i'm sorry i might be wrong about that and basically cargo is your build system which means um it's going to build your project and it but it can also do a lot of more things for example in um if you ever work with javascript you know that there's thing called node and um an npm now yeah and npm is used more for i guess um uploading and then downloading more uh i guess libraries you want to install and we're using cargo um and then in cargo in this case um we are using the same thing to build our system but also upload and install crates and if you don't know what crates are i don't think i mentioned this but crates are just um rust terms for libraries um there's also the fact that cargo it's really it can be used for unit tests so if you worked at python you know there's a thing called pie test but it's also like a different thick you have to install but with cargo we can automatically just just use the same thing to test our programs there's also the fact that we can benchmark our code and i think a really good thing is create documentation so uh here sorry so in russ um we have two types of comments there's the uh the comments where we just do let me just try example here where we just use two four slashes and this is something you would normally see in a lot of programming languages but if we added third slash that is basically going to indicate that this is a documentation comment and basically whenever we doc generate documentation with these documents and then add some documentation comments to our code is automatically kind of parts for those and it's going to create a um like an html document that you can just upload to the web and basically you're going to end up with the system that your code is self documentating um and it's just very nice because you know that if someone writes a library you can at least see their api at a superficial level at the very minimum cargo also has clipper and it's basically a better linter um because it's gonna give us it gives you more suggestions um and it's gonna tell you like hey there might be some things you can do here that's actually better and it's going to optimize your code finally we have like rust up rust up is the program used in store rust and other components there's also rust formatter um and all these things you can just install by using rust up um and then rest up in rust formatter it's just basically it formats your code automatically so you don't really have to use a like you don't have to like if you're using javascript you know that there's a lot of tools you can use to format your code set like this way and i know that python has a lot of like formatters but with just use by like having its own supplied a 2 chain rust can make sure that everyone's running the same tools unlike other languages i the final thing i want to highlight is the rust on analyzer which is a very amazing language server um and this is a language server it's just a thing that basically gives you your auto complete your intelligence and snippets and it's very amazing because it helps you so much and i recommend using it over something called rls if you are not using it and so yeah overall very great tool chain for us finally the last thing i actually want to highlight is its libraries what like there's a lot of high performance libraries out there in rus and when you use like rust you can like i guess when you use these libraries are made for us you can meet like kind of sure that these languages like these libraries are highly performance and um very well written one of the things i want to mention is uh the regex library the regular expression library because it's one of the best regular expression libraries in any programming language um and here's a cold snipper where i used it um you know i just use the regex um library which and for if you don't know having of code is just this really cool i guess christmas thing where a tournament kind of competitive for competitive programming kind of thing where you just solve problems for puzzles to give out and i use brush for on for that whole contest and basically we just um create this i guess the regular expression we want and then we can just even through this we can just i guess create the capture groups we want and then use them the the way we want them and i wanted to point out that the rus the the russ regex library was made was used to make this tool called rip grep which is a very great tool and i would suggest for uh like i would suggest for people to look it up in case you don't use their ready um because it's basically i think a better grab in a in a lot in some cases it's more uh it's faster than um grip and these are other libraries i won't mention them because um i don't really want to explain what they are or what they do but they are great like one of the things i do want to highlight it's the wason pack which integration with a web assembly and it's really popular right now so but and russ has one of the best integration with webs assembly so i just want to highlight that and yeah it's just great libraries overall so we're ending the near the end of presentation and so like i i said a lot i spoke a lot and i gave like some overview but what can you actually use russ for uh obviously you can use it for writing system software like drivers like operating systems i know there's an operating system actively uh being uh i guess made in rust called redux i think sorry if i don't know that one um there are a lot of web projects like dropbox uh discord that use russ as at least one of their components they use rust to write one of their components um they're especially um also due to the lack of uh garbage collector um and rust so i think i mentioned this but rust doesn't have a garbage collector you have to i guess deal it deal with it yourself it's i guess it's optimal for game use um because some things like for example like the game minecraft it's written java but sometimes you're you're gonna get a bit of lag and the reason because like the reason of that like the reason because you get those flag spikes is because um basically java is trying to get rid of objects you don't need in the in your game and since the garbage collector is running in the background you can't get you're not gonna like your game is not gonna perform as well that's not happening in the background but because russ is a a non-garbage collector name which um it doesn't really have that downside um and as you can see that if something for like an fps you might really want that um so also networking it's very huge um like if you're making a web server if you have to like have to make a lot of transactions russ you need to make sure that's secure and reliable and russ is the perfect lane for that um machine learning um i did write this down and there are some things now but i just i guess this is clip bait because it's not there yet but it's also um it's it's really but they will be at one point there because basically there's a lot of performance and it's kind of uh great for like the machine machine learning i guess the implementation part finally finally why shouldn't use russ like i've been talking a lot about russ and what it is but there are some downsides of course and i need to highlight this because i think it's fair for a person to know what these downsides are before they're actually used for us for a project and basically due to like the many features russ has the compiler it's a tad slow i'm not gonna lie it's very slow compared to like something like gcc um well not that slow compare well not like it's usable but it's still very slow and the fact that russ is very slow uh a very new it was made like it was the first official release was in 2015 were in 2021 and it's only been six years you know um companies are just starting to adopt this language uh more and more but it's still overall new and that's kind of concerned uh because like some of the apis might change or especially in libraries like new libraries um and also the fact that we don't really have like every language every library written for it like java has like so many libraries you can use and russ is still not at that point i think i believe um there's also the fact that the language is kind of difficult for people coming from more high language uh high-level languages like python it's a systems language of course but the fact that you have to deal with ownership you have to deal with like all these new concepts it's kind of difficult um and also russ is a lit i guess a lot harder to learn than c or c plus plus initially due to the fact that you're just gonna have to like look at documentation for what ownership and um and like the compiler messages and whereas in c and c plus plus you can just like basically look at the tutorial run like i guess i guess very simple uh programmed uh i guess like a program on your like first day i feel like in russ you're probably gonna have to look at the documentation for your first day and that makes it i guess harder to learn so that's it and you know i there are some resources i just wanted to point out this this repo i'm like this this whole presentation is basically a markdown file so if you just ever want to look at it you can do so um these are a lot of more resources finally there i know that people want to be hired so there are like i said companies are starting to adapt and more more and more companies are looking at russ i know that amazon has their own rust team um especially just for like working with russ like i guess that's kind of cool and i said i do have some sources um and if if you want to know how i made this presentation i use this program called look at me it's very nice and i recommend it um so anyway thank you for watching and bye
Info
Channel: SeniorMars
Views: 1,265
Rating: 4.9200001 out of 5
Keywords: rust, lookatme, garbage collector, terminal, programming, code, SeniorMars
Id: aBHCTHeLjD0
Channel Id: undefined
Length: 42min 40sec (2560 seconds)
Published: Mon Mar 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.