Learn Rust Together Finale: Review of Book and Language

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right what is up rust family we're here tonight with another episode of the learn rust live stream we're just coming off finishing the book yep we did it it took a while but we did it every single chapter 1 through 20 we built the web server we're going to be adding to the web server probably next week but tonight i want to do something a little different take maybe a little break from doing the book and kind of do like a review of the journey so far talk about what we did what chapters i'm going to talk about what chapters i liked obviously it's all going to be subjective but what chapters i enjoyed what i like so far about rust compared to other languages that i've used what i think we can do going forward we'll talk about the book we'll talk about the wrestling's exercise we did we'll talk about the potential future things we can do like one of them is exorcism.io we might do we're going to be adding to that web server and probably following some of the cues that they left at the end of the book for us to try out trying out some crates is going to be a big one right we've learned about crates so we're going to try to pull in some other ones and then building some small projects we've got some awesome comments in the chat on youtube requesting some projects so probably maybe we'll start there but if you do have any ideas for other things we can build with rust feel free to put them in the comments section below if you're on youtube or toss them in the chat if you're watching live on twitch um it's been really really fun and yeah so today's gonna be mostly just chatting we're gonna chat about the book i'll talk about you know like i said what i enjoyed some of the chapters i needed some of the things i'm looking forward to doing with rust i'll compare it to some of the languages i've been using and we'll talk about what's coming up next for the stream right we're going to keep going we're going to keep doing rust maybe we'll pull in some other language stuff as many of you may know i i work with other languages day to day javascript elixir python so maybe we'll do some more of that but don't worry there's definitely more rust in store so let's jump in and let's do a quick recap of where we've been so if you missed any of it you know it's all up on youtube so you can see this is where we started we started out with chapter one whoo look at that young tom no it's only a few months ago we started out in chapter one we made it all the way through we did a little one-off from running on docker i'll probably continue with that um we did the wrestling's exercises so we'll go over those in a second we'll talk about the fun exercises that we did we did it all every single chapter of the book and we ended it two weeks ago we took a week off last week but two weeks ago we did the finale it was a longer episode uh i think it was like three hours so we did a three hour stream we built a web server and rust a multi-threaded web server we followed along there and there's some cues at the end of it or some prompts i should say some prompts at the end of it for suggestions on what we can add to that so we'll definitely be picking that up probably next week but again today i'm just going to kind of recap we're going to go through some of the chapters of the book that i enjoyed we'll talk about some of the topics some of the things so far that i've been liking uh in rust i'm excited again follow on twitter for updates when you go live uh of when i go live maybe you go live but follow that on twitter there again the repo for the code that we've been writing is all here so you have the learn rest live you can see we put chapter 20 up there it's all here go here you can follow you can start whatever you want you can just use it as a reference you could have your own repo but whatever you want it's all here and we'll probably be looking at this today and the book of course this is the book we finished right so i always give a shout out before these episodes shout out to steve klobnick and carol nichols the authors of the book and anyone from the rust community who contributed got to give a shout out excuse me sorry a little water you got to give that shout out so we've had an amazing time or i've had an amazing time hope you have going through the book and it's been super helpful and today that's what we're going to be reviewing right we're going to talk about what we liked rustlings we did so we'll cover that in a minute another shout out i want to thank everyone on youtube who's been subscribing and liking the videos we've reached over 500 subs may not be a lot in general youtube standards but for myself for someone who's just doing this once a week and just posting their stream up there it's been awesome to see how many subscribers and how many people are interested in these videos the views have been going up which has been great so if you like what you see again like and subscribe recommend some comment some content what'd i say comment recommend some content put some comments in the chat tell me what you'd like to see i'm happy to hear some requests well definitely like i said be doing more of us we'll probably revisit that web server pull down some crates and try doing stuff with that um other languages anything uh folks are interested in otherwise what i'm gonna do is just code right every week i'll do something fun and different that i want to mess around with i'll live stream it then i'll post it up on youtube but you have to shout it out thank you so much it's been awesome 505 subscribers look at that small small in youtube standards but big for me right i wasn't even planning on getting more than five five close friends that i have all five of them no these aren't i don't know most of these people personally i will i will get to know all of you through your comments so thank you for that that's been awesome all right so let's talk about russ let's talk about the journey so far so we started this book and the cool thing we did in the beginning right was they jumped us right in we did the installation whatever but they jumped us right into the hello world and right off the bat it seemed pretty straightforward right print nothing too fancy and then we started getting a little more into the the environment like the build tool and cargo so i want to talk about cargo for a minute so i'm going to pull that up because that's that's uh well not just cargo but rust apparently it's a post apocalyptic movie that's awesome cargo rust ooh we talk about here we talk about crates but anyway what i love about cargo let me just look at it here what i love about cargo is it's awesome to have build tooling around your language so i'm coming from having a lot of experience in java right maybe some experience in not a lot of experience javascript i have some experience in java very little a lot of experience in javascript a lot of experience kind of a good amount of experience in um python done some python done a bunch of elixir recently you've heard me talk about that a lot i'll probably talk about that more because i'm really really enjoying that language i've done languages like elm i've written very little c what else have i written a few other things but basically most of my experience is in javascript in the javascript ecosystem and in javascript we now have npm for managing packages but we don't have anything for scaffolding out new applications of course there's third-party things right there's create react native app for creating react native apps and there's cli tools for things like angular and vue but having it built into the language and having it be a set thing has been really cool so cargo has been awesome and we use cargo we used it a bunch so every time let me see if i can pull this up every time we created a new repo right or every time we created a new let me pull this up here a new project or any time i did a new chapter i used cargo and what was great about cargo and what i really liked about it is it gives you everything you need so here's like an example just cargo project that we built out so you have your source folder there's a binary crate or library crate so we had our main like source file we had our tomml which kind of describes our dependencies that was super cool the lock file but it was just awesome and it gives you all the tooling and it also is what lets us build and what lets us run and what lets us test so that was super cool coming from something like javascript right um to do that i have to pull in libraries and so some may say oh it's nice not you know you don't get everything on the box you have to pull in things but i really enjoy cargo because it's built for the language it's built for the language it has the compiler it has the checker it leverages everything for you and so um that's something i really really enjoyed with rust was just using cargo it's super easy super intuitive so that was really fantastic next we actually did the guessing game so the guessing game was cool because i like when books dive right in show a bunch of concepts and then kind of like elaborate on them later and i think the book did a great job of just jumping in and having us use the guessing game here's why i really liked the guessing game so if you've ever done a hello world for any other language um it's usually something similar right you're reading input from the user sometimes they have you just jump right in and read it from a file like in node i know if you know tutorials have used the file system api but it was super cool jumping in taking user input and building something kind of fun right the guessing game was pretty fun and they did in some really great steps so we had processing a line showing an x an exception and we did things the long way and then we saw later how to make them better right and we learned about things as we went along so we learned about basically reading input and then one of my favorite parts about rust which we're going to talk about in a second the result type so here we can talk about handling failure with the result type so i really love this this is one of the things i love about rust i actually like this about a lot of strongly typed languages if you've heard me mention elm elm is a language that i work with a lot elixir mostly for side projects nothing professional but what i love about elements it almost something similar and why i like the result type is it's a way to indicate that something can fail without like it being something throws or throws and catches in javascript it's a way to wrap something in the in a potential that you know it may or may not work and why i like that right the reason i like that is it forces you as a developer to handle both scenarios often and you know i think we're all probably guilty of this i'm sure most people you know handle this appropriately but i am guilty of this at least in javascript for example when i make a request to a server or i do something that may fail i usually just handle the happy path right i'll do a try with an async await i'll make a request you know obviously in real production apps i do handle theirs but like generally when i'm just messing around i'll often just code the happy path first and the problem is sometimes i'll forget to go back and do that error path right i'll forget to handle that other part of it and with the result type you have to right your code won't compile if you don't handle both scenarios so it kind of forces you to think in a way of like creating a safety harness around that result type and making sure that everything's handled it is a little more work up front but the benefits are that you're guaranteeing you're thinking about both situations and i find when you think about both of those situations up front you tend to write better code because your code reflects both scenarios that are possible instead of just reflecting the happy path and making the error path an afterthought you're really coding with the expectation that hey this can go right or this can go wrong and we even learned about you know instead of using um we can use like the question mark right so if it proceeds we continue with line otherwise we panic so we learned how to use the result type to our to our basically best interest right we can figure out to our advantage so we can figure out do we want a continuous program do we want to panic or do we want to handle the error maybe it's an error that we're okay with right so the result type was something i was super super interested in so i'm going to pull up some code and we'll take a look at some of the places we used it so i'll put the guessing game and we'll see some examples here we also remember we adjusted our guessing game we broke things out that was kind of cool so we had our main program and we delegated out to some library functions so let's take a look at one of our result types so here we had trimming of the guess so we took input from the reader it was their guess it was their number and we trimmed it and again that could pass or that could fail and so we handle that and in this case we didn't just use the question mark and move on to the next line if it was good we actually did something that was useful for the user in their case so in our okay case you know we we processed it um we we had our value i returned our value if there was an error right if there's an error parsing the guess right we printed it so we did something useful with the error and the result type let us do that it gives us both scenarios and lets us write our code up front thinking about this so this kind of thing is what i really like in typed languages is that notion of a like a maybe type right something similar to this is the option type which is the next thing i want to talk about that i really like so let me see if i can find an instance where we're using an option there's a bunch of places we use it all over uh let's look for an early chapter let's see not that one let's try to find a more basic one favorite color here so favorite color this thing example the option type so the option type like the result type kind of encapsulates two types within it right um you can think of it as almost like a struct right the struct that has two two values so the value of option can either be the thing right some type in this case a string slice so some string slice or none and so the option again this is another situation where it makes you handle the two different code paths there's the code path where there is a value present in that option and there's the code path where there's no value present and so it lets you kind of model things in a way that i often wish i had in javascript to give you an example if any of you have ever written react or done javascript one of the things we do with our components and components receive properties and they also have state that they manipulate right and a lot of times you start out you have something that has to fetch from a server right it has to go to a server to get some data let's say it goes to a server to get a list of users well you initially start out with no users right so you have to go get those users and so you have to make a decision how do i want to model that do i want to start with the initial value being an empty array of no users or do i want to start out with null and null is always weird in in javascript because if you try to model that with the type with typescript your type would then be a list of users let's just say it's strings you would say our list of users is a is an array of strings or no so it's like it could be this thing or this thing so it's almost like you can model an option but it's it's a little awkward and the other reason it's awkward is if you decide to go with an empty array then you have to figure out well how do i know when i'm in a situation where i haven't yet fetched my users versus a situation where i have and there really were no users so i get an empty array and then you end up introducing a third thing like is fetching or is loading to indicate that you haven't tried yet with option what's really nice is you can say hey this value is either something it's either an array of strings or none right and it's one or the other and it's a nice way to model it and any time this is the key thing anytime you use that value or deal with that value you're going to have to check do i have something here or do i not versus javascript where you could try to manipulate that list of users if it was an array and if it is in fact null well you can't call map on it you can't call your array functions on it so you have to have a check there and your code won't tell you that at compile time right unless you're using something like typescript where you're actually enforcing these things you won't catch that with russ though with the option type and similar to the result type you catch those earlier on at compile time and it forces you to handle them but really i really like the way it lets you model data so that's really cool so that's definitely something i like about rust for sure um let's go back let's see what else we talked about excuse me so the other things we did we learned about printing the debugger how to print how to format strings general stuff like that we also pulled in a crate we pulled in a random crate and i want to talk about this a bit because the crates i find super cool so i'm familiar with pulling in dependencies in javascript we have npm right in python we have pip in elixir we have mix and our mix dependencies that we put in our hex file right so we import dependencies there so a lot of languages have this so it's not like a rare thing but it's very easy to do in in rust and for a lot of the other languages it took a while to get there but rust comes right out of the box with a really great package system so it's cargo and we have crates and we see that we have our cargo tamil file and that's where we're specifying let me put up a cargo tunnel for example let's go in the guessing game you have your dependencies and you're random also while we're here might as well touch on the fact that cargo went with tommel right he went with tommel for for a uh its dependency file right it's like package descriptor other languages have json right we have our package.json in javascript we have for like serverless we have like serverless yaml files so often you'll see yaml used um yeah i would say yaml and json are probably the most common but tamil was introduced to us by rust i had never seen it before maybe you had but tamil is tom's obvious markup language tom's obvious minimal language so this is really cool it's a i think it's you know we could probably it doesn't have to just be rust you can use this anywhere anywhere you'd use a yaml or a json you could probably switch this out if you're writing something to use those file types but it's pretty cool um it's very easy to read right you have your header and you have your values and what i like about it is it's key value key equals value so it's very straightforward and the nesting is is pretty straightforward as well and then lists are just lists right arrays what we're used to i know yaml we have indent and then dash json you know json it's curly's it looks like more like a javascript object and they talk about other other different traits right json yeah well they talk about that here and they compare it so this was super cool first time i'd use tommel and uh i like it i mean i think it's really cool very straightforward and easy to use so that was awesome um so yeah i really liked cargo i think what it does with the crates um it makes it really easy for packages i know that with npm in javascript it's not as you know you don't have cargo or crates you're you're dealing with in the javascript world you're like do i use yarn do i use npm and a lot of it's subject to the author of that package or whatever but in russ it seems like we've settled down a single package manager cargo in this case and it works really well same thing in python right python we have pip which is pretty standard right now i think and then other languages ruby right you have your gem files so it's nice to have dependencies be able to declare them so that was cool we got to see how that worked another thing we did in the guessing game um let's see we did some oh comparison so this is when we started to use traits right and we also learned how to import things so one thing the import syntax is easy enough but it's it's not as in my mind friendly looking as something like i would see in python or javascript i like the import blank from blank because you kind of know where it's come from whereas here they've simplified it right so it's just used this and you know that ordering comes from standard compare but it's the shorthand that sometimes can be a little confusing right like standard compare i know that this means standard compare because we talked about it but if you don't know these off the top of your head you do have to look them up which is fine but it's uh this was a little bit weird to see at first and they even mentioned like you won't know what functions to use you just sometimes have to look it up like what's in the standard library so i think once we learn once we mess with rust more we'll figure out what's in the standard library what's a crate but yeah this was a little odd and also the the way that we can specify multiple packages from the same source that syntax was a little bit confusing at first i'm sure it gets easier as you write more code just like anything right javascript's confusing too you have your default export versus your your regular exports python you can do similar things i think python has one of the easier import syntaxes but yeah that was something that was interesting to me uh what else did we do so the the i o for reading was super easy love that oh this is an obvious one we have to talk about like mutability right so one thing that rust has that not every language has right because they're all different obviously but there's some some languages just let you mutate things right and some just don't let you mutate things by default so for example in javascript everything is mutable right even when you declare constant you technically can change it but your usually your bundler or your compiler will warn you against it if you're using typescript or something like that but you can still modify it right and so there's no notion of mutable and immutability you have to kind of create that notion yourself and so often we do that in javascript we'll use a library like immutable.js or we'll be consistent and whenever we manipulate something we'll create a new version of it or we'll use functions like map filter and reduce that always do return a new value and don't mutate the original list but in rust you need to be upfront right so let me look at our code let's take a look at our guessing game again let's look at our library uh we didn't use the library okay guessing game so let's look at the beginning here so we declared secret number it's not mutable right so that's not going to change but here we have something that's mutable we have our guess right and we need to declare that it's readable so the compiler knows how to handle memory for it which makes sense right we're dealing with a lower level systems program programming language so it makes sense that we need to know that it's mutable so this is a little more effort right than something like a scripting language but that's to be expected because we're going to get the benefits of the compiler and we're not going to you don't get that with a weakly typed scripting language like javascript or python they've all of their pros and cons right and they all have their correct use cases you have to figure out what's the right tool for the job but if we're just talking about rust it's a little more overhead to do this but it gives you the benefit of that compiler so another thing that we talked about which is different if you've never used a memory managing type programming language like this is going to again lower level programming languages systems programming you want to deal with memory management why because you can make your programs you have more control over the memory they take and the speed then you get more performance out of them right this is going to be faster than something like python because it allows you at lower level and really deal with how you're working with memory so we had the sense of passing by reference right so you can pass a reference to something and then you can also pass something and you have the borrowing notion so we're going to kind of get into the next part but really quick so you have immutability immutability it has to be declared and we had this ability to pass references to things and de-reference things which gets me into my next topic which i actually really like um it's a little bit confusing up front but i really liked it and that's borrowing right understanding ownership this concept was something completely different from anything i've seen in javascript python elixir like i've mentioned the languages many times i don't need to anymore other languages i've used right and if you're new to programming this might be a little bit weird but don't worry if you're new to programming it's just as weird for someone who's not into programming because it's a new concept and so ownership was was a little bit interesting for me to like initially start with but then once i got it i really understood it and i kind of related it a little bit to javascript javascript has this notion of context and where things are their scope right where things were created and where their life is and what their scope is and that we call that context and creating closures you can manipulate context to create closures and things like that but with rust the reason we have this ownership and borrowing is so that we know when a thing is being used and when we can free up its memory and this is a really cool concept because i think about it like a book or something right if i have a book that i'm reading i could clone it if it's something simple and that's like the copy trait right if you have something small you can copy it but with the book if i need to pass it to somebody i would let them borrow it and that means they have ownership over it at that moment in time i may ultimately own the book but now they've borrowed it and they have it and i don't have it anymore but i want to at some point get it back right and so there was this notion of being able to pass a reference to the book right passing a reference and this way you still take ownership whereas if you give the full book right then they take ownership and that's where we saw it passing a reference verse not a reference so if we i want to go down here a little bit where we can see some of these examples actually i'll just pull it up i have ownership as a yeah a file here so we have this string we create a string we call take ownership why does it take ownership it takes ownership because we're not passing a reference we're passing the full thing so we're actually saying here we're giving it to that person it's like giving the book to that person and so what's what it means is once you've given ownership you no longer have it in this main scope and that means i can no longer use it here right so i'm not able to use s after this take ownership point and if i try to it will complain so that's pretty cool that's a way to pass ownership and why is that useful well if this function is done with it i can safely pass it away it doesn't matter if my function is done just if i'm done with this thing i can pass it to something else let them use it and i know that i don't have to worry about cleaning up its memory whoever has ownership will either worry about cleaning up its memory or when that function ends if it hasn't passed somewhere else it will be cleaned up automatically so it's a very nice way to handle almost like there's no garbage collection right but it's a nice way to kind of not think about the life cycle of that thing once we're done with it so but the at the caveat that we can no longer use it so that was giving ownership now we talked about some of the types of variables that are copied what does that mean it means the simple ones like integers right and characters are copy they have the copy trait so they when you pass that around uh you don't actually end up giving up ownership it gets copied and so we can still use x we see that here we can call make a copy it just takes an integer we know the integers implement the copy trait strings do not and so i can still use x then we talk about here we call it gives ownership s1 so what s1 does is this is calling a function that then gives us something back and it gives us that thing back with ownership what do i mean by that well we have the gives ownership some string we create a string and we pass it here we're passing it at the value so gives ownership is giving up that ownership passing it back to our s1 and now we can use that value so what do i like about ownership well what i like about it is once you see it it's pretty easy to understand once you've done it and i think this file kind of illustrates that i'm definitely going to go back to this file a bunch because it has those examples but i really like the concept of having control over when you take ownership when you give it up what else do i love about it the compiler the compiler is going to tell me hey you no longer have access to this and it's going to tell me what i need to use and when and the guarantees are what i really like i guarantee that i'm handling memory in an efficient way things are going to get cleaned up as i need them to and when things go out of scope they're destroyed right and so i need i only need to think about what's in scope and what i care about so i thought this concept was it's a complicated concept but it's simpler than having to kind of understand how this all works yourself and managing yourself they introduce this borrow thing to give you control but to make it easy and to make it more difficult to cause problems in other languages in c for example i always struggled with ownership references and pointers and passing them and dereferencing them i remember just adding an asterisk to get to get values out vortex manipulator in the chat hi tom glad i can catch a stream but it's incredibly we'll be able to catch this on youtube vortex absolutely and do not worry if it's late i just appreciate you stopping by awesome to see you and yes it will definitely be up on youtube uh so check it out there and thanks again for stopping by also if any of you else if anyone else watch on youtube hop in the stream it's fun vortex showed up but uh streams 9 p.m to 11 p.m eastern time today's gonna be a short one we'll do like a shorter review but usually until 10 pm eastern time and we'll see maybe we'll switch it up but hop in it's fun vortex did it you can do it too it's cool all right so um it makes it gives you that power without being too hard i remember just popping asterisks on like i said to to dereference because i didn't know what i was doing with c i was also a very beginner programmer i was in school i was partying a little bit it's college it was college but i had trouble with c i did like c almost turned me off of of programming all together in fact java almost did too but then i found a little language called javascript which was crazy and wild but allowed me to do crazy things and that's exactly what i needed at that time vortex sweet have a great stream and good night good night to you too vortex thank you for stopping by so yeah so this this took a very difficult in my mind what's a very difficult concept and made it a lot easier and if this is your first programming language right if you're learning rust for the first time or not rust any program like if this is literally your intro to programming this is something you get from systems programming level languages right lower level and that's why they're so performant is these kinds of things if you don't need that if you don't need that speed right if you don't need that safety if you don't need a language that can create a binary that can run on any operating system without the language needing to be installed maybe you don't need rust right and i do want to emphasize that like every language has a use and there's a few things to consider when you're thinking about a language there's step one is it fun to use right that i i i mean it's not the best step right the best stuff is is it the right part but like really like if we're coding this all the time is it fun to use is it enjoyable syntax is the syntax easy is it simple is the tooling great is the experience great that's an important one the next one is what is the problem i'm trying to solve and does this solve it can i solve it with this and can i solve with this in an easy way basically what i mean by that is if you're if all you're trying to do is make a request to a web page and spit out the response and you just want to run it it doesn't require to be really safe it doesn't need cross-operating system capabilities just going to run on your machine randomly on a script you could build in rust for fun be cool but you don't need it right you could use something like python or javascript and that's why python is very popular but that's not to say don't learn rust it is also very important in my mind to learn rust because it has a different job right and that's why i'm here that's why i'm learning i already know a bunch of other languages that i've tried and i have some idea of what they're good for but i didn't have that systems programming language i told you i tried c and it just wasn't for me so the lowest level language i have would probably be i mean like nothing that runs on the binary level maybe the the closest i would get is something like that's really fast maybe like erlang or something i don't know i don't really actually have any none of the languages i can think of are going to create binaries that can run on any machine like this i've done some bash scripting that's good for cross machines but like i didn't have a good systems program knowledge what do i mean by that systems program meaning low level coding for systems um with the ability to run a bind create a binary right and that binary can be run on mac it could be run on uh windows it can be run on linux and so that's a cool benefit right so what can you do with rust for example that you couldn't do with python with rust you can write a script let's say you write a script that deletes some files right from file system you can write that in rust create a binary and run it on windows it'll work and run it on mac it'll work i'm sure there's some caveats right to the file systems but otherwise if you wanted to do that you'd have to write a specific windows script maybe a bash script for mac and then maybe a powershell script for windows and you have to use some custom apis to do that i'm sure there's other scripting languages that obviously work across but whatever but it's going to allow you to do that but the key thing with rust is going to allow you to do that in a safe performant way right that's the thing that compiler gives you that safety so i know we're rambling a little bit here but again it's all coming back to if this is your first programming language and it's a little difficult they're not all like this and the difficulty is because you're getting something returned you're going to get that safety meaning you're you're going to put less bugs into production right because your compiler is going to catch a ton and you get that speed and performance if those aren't as important to you then you have other languages for that like javascript or python right and then you could augment javascript with typescript to get a little more safety right so something cool to think about basically if this was tough don't be deterred um it's tough for a reason but keep in mind that it's it's much easier than doing it manually and so borrowing can be a little tough to figure out once you get it and it's it actually is really nice way uh to kind of handhold you through that memory management process so back to the borrowing we talked about taking and giving back so you give something right you give a value ownership to this take and give back function and it simply returns that thing back so it gives it ownership you can't use it while that thing has ownership but as soon as it gets back you can use it again this is another great thing i love about rust it's a minor thing but oh my gosh is it an awesome thing to have in a language and when you don't have it it's really a pain and that is implicit returns what do i mean by that it means the last line the last line of the function is the return statement it's what get gets returned it is very annoying when you don't have this so for javascript you have to have a return statement return at the end return at the end it's really nice to have this because it means if everything is an expression you can end your function in expression and the result of that expression will be returned i don't know how many times i've written code in javascript where i've had a array comprehension or i'm doing a map or reduce or filter and i forget to like return the and reduce forget to return the accumulator or i forget to return something from my my function and i'm like oh what's happening and i forget because i left off that return implicit returns are fantastic and with remember with um rust you do it by just making it the last line and leaving off that semicolon right so it's not it actually will return that value because we have even if conditionals in roster expressions i love that it makes it so easy to do stuff we also talked about [Music] a reference so passing of reference so here we're giving a reference to calculate length with reference that means it's not going to take ownership and that's why i'm still able to print len of s4 here and i can print s4 both will print because i don't give ownership so i pass it to this calculate length with reference and you'll see that that is going to have to take the length and call len on it so we're passing it s4 gets that there oh and you'll see here see it's a reference and we do s.len if we needed the value out of it so like let's say for example we got a um some other structure and we wanted the value then we'd have to de-reference it right we'd have to use the asterisk and that's the draft rate so i really think the borrowing is pretty pretty cool it's pretty intuitive uh i definitely like it let's talk about some more stuff let's talk about structure structures are great i think pretty normal to have something like this in a language um the cool thing about structures though is they're typed right so they're they're typed and they're enforced so you can create some really cool stuff and you can model data in a really awesome way i like these better than classes i don't really am not really a fan of object-oriented programming don't get me wrong like i said there's a right tool for a job and it definitely has its use cases i just tend to lean more towards functional languages i find them easier to work with so i like that we didn't go with classes here and that we instead have structures that just describe what something looks like and then you can create um instances of them but we're not dealing with like inheritance and we talked about that in the object oriented section we're not dealing with inheritance in that sense you can still get those benefits without directly using those because i think those concepts can be kind of confusing and can get kind of messy it's hard to figure out i think best practices when you have that kind of stuff so i like structures it makes it really nice to model your code what do i mean by that when you have some data that you want to um like model or like structure right that's what a struct is for it creates some structure it not only makes it easier to think about stuff it makes your code more readable and this is a key thing as engineers as anyone developing code if you're developing code you're an engineer i don't know if you know it but you are right if you're developing code um a lot of time when you're working professionally with software or even when you're working on code yourself or fixing bugs you spend more time reading code than writing code and so structures besides the benefits that they give you when you're writing your code they make your code really readable so i know here that i'm dealing with a user right it's just right there it's in my face and the compiler is also going to say hey you're dealing with the user you need to include these properties right because that's what the user should have and you can declare okay this property should be there if something does need to be there you can say this property is an option right it's either some value or none so structures are super super great for modeling data and then the other thing that i kind of let me see if we can find it oh so the tuple is like this is great i love this it's just easy to model data it really is it makes it so great um so this is a very powerful thing i want to talk about the implementation block here's an example program using structs pretty straightforward let's see if i can find the part where we did an implementation block method syntax this i wasn't a huge fan of and i'm still a little iffy on it i get it i like it it's it's pretty pretty good but i'm not in love with it what i mean by that to me it feels weird that the implementation block is outside the struct if that makes sense i know it's it has a reason and it totally makes sense and i think the main reason is that your struct can remain clean and you can see what it is and then you can see separately the kind of functions that it has what's weird about it though for me is like the syntax i don't know i think it just looks a little odd you have your struct rectangle your implementation rectangle and actually let me see if i can pull this up let me see if i if we have this in our code i know we have it somewhere um it's probably under structs okay so here we have double strokes build user let's see oh yeah so here's our user so do we have functions now let's see methods do we not have uh a thing on methods interesting structs hmm let's see what chapter is this five we didn't start doing that yet all right so let's just look for this what is this one impl there we go it's under rectangles anyway so yeah like the the syntax here was a little bit weird for me having it be separate like your implementation block but it is kind of like now they think about it it's not maybe a strange like it's it's nice like you have your structure and then you have the code but what is weird is you could you could put this anywhere right i could put this down at the bottom like it doesn't need to be attached maybe that's on purpose i'm sure it is but that was a little weird for me and the reason it's a little weird because i tend to think about stuff especially with structs like i think about it as like a type um or something like that even though it's slightly different right um and having functions on it it starts to to me to start it makes me think of a class right because we have that we generally have like a new function for instantiating one um a can hold and you have like yourself notion so i start thinking about a class in javascript and then i think about how it's usually all grouped together right um but i guess the benefit of separating it out is you can define it everywhere and i'm excited to see when i look at other projects how the code is structured and how they where they put structs destructs usually get their own file i'm excited to see that that's the kind of stuff you don't maybe we don't really get to see in the book it's something that we like i see all the time in other languages you slowly figure out as you use it what's the best pat practice for file structure where should stuff go i'm excited to see when i look at other projects like how do they structure their code where do you put the structs are they in the file are you just importing them so that's pretty cool and that'll be interesting to see but yeah this is a little weird for me again just a little bit different the other thing i struggled with for sure and also by the way with any of this stuff put some comments if you totally disagree and you're like tom you're wrong put it down there that's awesome that's exactly what i want here like i want to hear everyone's opinions and feedback because i'd love to hear why people like different stuff maybe i'm not thinking about the right way or if you agree maybe you're like oh yeah i also am confused by the mutable self in the method put in there all right let's chat about i think it's fun uh we're all learning so area so yeah so like the fact that you get this reference to self this makes sense to me this is pretty pretty clear it's very similar to python right on python class methods you get self as the first argument so not not too um foreign to me but then there was like other cases let me see like where you get mutable self and that's when you want to mutate something so i like the implementation box i like that you can encapsulate functionality dealing with a rectangle but yeah this was a little strange and i'm still probably going to be taking taking a little time to get used to it now let's go more in depth here so pattern matching [Music] rust fam come on i love pattern matching if you didn't know this if you didn't pick this up if you didn't google elm or elixir when i was talking about those i was like oh yeah i like this language called elixir huh this is fantastic oh yeah if you use dome it's pretty cool i'm not just name dropping i am just name dropping let's lie i'm just name dropping but the reason i happen to love those two languages pattern matching where do i start pattern matching oh pattern matching where do i begin but really i love pattern matching why you're probably thinking why why do you look bad at magic so much well because it makes writing branch code or arm code in this so easy and so readable now i've worked with javascript for a while i've worked with python you have if statements you have switch statements switch statements are great when you start getting a lot of stuff but they're not as powerful you're just checking the value of something or checking a conditional and then doing something with pattern matching you can express things in the pattern let's talk let's go more into it and we've been through the chapter so you've seen it but let's talk about it more because i want to talk about in the context of other languages and why i really love it because i'm pretty stoked on this feature and this is why i was so interested in rust when i found out rust had pattern matching all right let's take a look so what is pattern matching so we talked about this ip address thing let me put up my code pattern matching okay why is this cool so with pattern matching it's like a conditional over a value right so let's look at the very basic example match x we've declared x is one so you literally use the value here we're not saying it's a string we're not doing if x equals one you can leave off that crux and that extra boilerplate it's just match on x if x is one this arm executes plain and simple if it's two execute this if it's anything else execute this so this is equivalent to an if x equals equals one else if x equals equals two else this but this just reads it's simpler but this is we're not even touching the surface right of why i love this but this is one reason right it makes it simpler to write this stuff reason number two this right here this is like a beautiful thing here we're matching over an option right so if you look here why is my rust my rust analyzer is it not not showing up here what's going on let's see let's see let's see i know why because i'm not in the actual folder that's why all right so let me see if i can do that yeah let me just go into this folder i'll open it separately this way we get our analyzer because it's going to be useful so we'll do 3d projects chapter we talked about in chapter 18 but we talked about it earlier in that too but chapter 18 we really got to see some examples pattern syntax chapter 18 was very recently right but we've been using pattern matching throughout the whole book okay let's download the latest version of rust analyzer also by the way early in the book we didn't use rust analyzer the chat was like yo tom you're a clown you need to get on rust analyzer right now and i did and i pulled out the theme uh greyjack in the chat had his own theme which it really i think it plays really nicely with rust analyzer so that's the theme we're using here okay so you're seeing this that's because i'm not using it so we're getting the the compiler is actually compiling as we code which is fantastic this is another let's get here and say we'll talk about rust analyzer in a second let's focus on pattern matching we'll come back because this is low-key one of the best things about ross okay so here we have an option integer 32 and what i like about this is this is that case right where you have some or none and it makes you handle all of them if you do a match expression you have to handle all the arms it's going to look at the type of the thing you're matching over and say hey you haven't handled this so what i like about this is we have some and look at this it's a very it's like a if else but much more readable we're saying if the if there is a value when that value is 50 print got 50. otherwise if there is a value and it's not 50 if it's anything else print this otherwise if there's no value print this so this what would this look like this would look like if x equals equals 50 print this else if x doesn't equal 50 print this else print this but the beauty here is the variable capture right we are capturing here we're actually using like look at how we're doing this here we have x is some 5 y is 10. so we're actually able to use y here so let's let's print this out let's just show this one because this one's kind of cool matching named variables let's run this change the color to whatever that's that one matched y equals 5. so what happened here so we have we've declared y is 10. but here we're re-populating y with the value from x let me show what that looks like so let me show you in a different way if i were to change this to z right and we say z equals comma z equals that and let's do y equals and we'll print y as well now let's run that same code you can see z equals 5 y equals 10. so y is not modified in this case y still takes the value of 10. but here i was actually able to we were actually able to change y right we were able to change the value of y which is is cool it's letting us not only match on something but capture that value that's the cool thing about it you can't get that out of an if statement it's not going to capture the value in the if statement but here we can actually capture the the value in a variable and then use it we don't need to do it in our arm here and say like for example if we said you know something else like let's do x we wouldn't have to say uh y equals x right and then print it so it lets us create variables or in this case we're shadowing um why are we shadowing because we're we're changing the value of y here right we have let y here and here we're just changing it but that's awesome right it gives you the ability to use those okay let's look at another example here is another example one or two so this is again this like if x equals one or x equals two print this otherwise this so again this could be mod as an lsat but it looks a lot nicer this is another sick one a range of values right you could match on a range of values so if if it's one through five print this otherwise print this so it's a it's very nice easy way to express what you're looking for here's another range but what i'm more interested in is the stuff down here this is again this is another simple thing it's pretty cool though you can map a range really cool stuff but let's look at when it gets more cool and useful and this is when you're dealing with structs and data and i talk about elixir a lot because elixir does an amazing job of this because elixir can actually pattern match in function arguments which is really powerful so you get the same ability there and i'll probably do a video on elixir just because i've been really really enjoying it lately um i've also been enjoying rust but it's what i've been coding more in so i'll probably do something on that but for now i want to talk about this so destructuring um structs here so we have a structure right and i love this because our structure has two things right it doesn't have to have two integers in this case we do um and we have our point and we've created this point p right um p equals point zero seven and then we've destructured the point so we've captured x and y from the point so x will be zero y will be seven right and then we assert that that's the case so we we show that our destruction works and this is actually pattern matching um destructuring is using pattern matching it's basically saying the first thing in the tuple at the value x goes here the second goes here so that's destructuring is kind of similar right okay but here's where it gets cool we can actually map on different values so here we're saying we don't really care about the value of x we just care that y is 0. if y is 0 do this here we're saying we don't care about the value of y but if x is zero do this and here we don't care about either so this is like a more complicated would be a much more complicated if statement right you have to say if y equals zero do this else if x equals zero uh do this otherwise do this so i mean it's not too complicated but it really lets us model things nicely also we can use those those values right in here which is nice another one was down here where we have this one is really cool this is using a cool like complex structure right or in this case we're using an enum and we're using enum to represent possible things that we can do right possible messages and this is really cool to model your applications and model what users could do right and so this is a cool like powerful use case of the feature so let's take a look at what we're doing here because again i know this is review and recap but i love pattern matching so i want to chat about because it's definitely my favorite things about rust okay so we have our color we have our message and so our message has these different values so we have quit move and move has to be supplied a point it looks like basically right and right has to be supplied a string and change color and change color has to be supplied to color and the colors are reflected up here color can be rgb or hsv so first we create a message called message change color and we create that with a color zero 160 255 that's the rgb values right actually for hsv i'm not totally sure what hsv uh it's something hue saturation and hue saturation and value i don't know anyway this look at this we're mapping on that message so look at how cool these this looks right so if our message matches this if it's a quit message we do this if it's a move message we pull out x and y we can use them right we can use them right here and we can use them that's great if it's right it's going to have a string we're we're not only checking if it's right but we're pulling out the string storing it in a variable and then being able to use it we're doing all that pulling out and storing it and checking in this one little statement this one little match same thing here check this out we are matching on change color and then we're pulling out the rgb values and storing them in rg and b for use within our function so our match not only does the check it does the destructuring so it's super cool which makes writing the code look a lot better in my opinion other stuff like this yeah anyway i can go on for days about pattern matching but you can see how powerful it can be just like match guards you can add guards extra conditionals so some x if you don't want to say you know if you don't want to do if you don't look for a specific number you can even add a conditional there but again you're still getting the benefit of pulling that value out and storing it in x just a really nice guard clauses are super powerful too they're really great because they make it sometimes regard causes make it a little more readable um here's another example message other message hello here we're doing hello we're pulling out the id look at this arrange right super cool so yeah so pattern matching anyway to sum it up i've already said it pattern matching is a huge thing that i love and it just makes programming a lot easier in my opinion especially when you pair with stuff like enums like they have here like our ip address if you look i remember our ip address we can look at the end because i know we became pretty cool uh i think it happened over here oh coin coin was a cool one right we talked about the type we matched on that control flow with if let this was cool if that was a little weird for me at first um because it was like combining a conditional with creating a variable it's almost like a pattern match outside of a match right so like if let's sum three equals some value so it's like here it's doing if sum three equals some value print three it takes a pattern an expression separated by an equal sign it works the same way as match where the expression is given to the match and the pattern is its first arm so yeah so if it's three it's gonna store that value right so that was it's it's strange i think there's a better example down here yeah if like coin quarter state equal coin so if um basically it's saying coin quarter state equal coin if this pattern matches we're going to be able to use state right we're going to have access to state so it's it's like pulling that pattern outside of a match so super powerful really cool we talked about packages don't want to get too much into that we've already talked about that a bit um the other thing i want to talk about the collections are pretty good the vector macro there's a lot of things like i need to be looking up a lot like especially like the syntax and and the functions and that's to be expected if you're finding yourself do that too i think that's totally to be expected like the difference between a string slice and the string for me was really confusing um and then you had like the string from versus the two string and they both kind of the same thing that was a little bit um tough for me at first the error handling i really liked i already talked about this i love the result i like the error handling i think that's awesome i loved that we could use the question mark to decide if it should panic unwrap right was another great what use case where we actually just tried to do something we unwrapped it and i think down here we leveraged um panic yeah i think the error handling is great there's a lot of different ways to do things and that's like where i'm gonna have to try to figure out what the best practices but that's any language and you figure that out as you go this was hard i'm not gonna lie traits generic types this is always tough for me um but if anyone else found this tough uh i think it's it's kind of normal that this was difficult because it might not be something you've dealt with but i have a lot of trouble with the syntax around traits that's one of the things i'm definitely struggling with what do i mean by that generic data types i understand and i understand the use case if you don't and you're new to programming it's very hard to know what generics are useful until you've needed them to give the most basic example i always tell people generics are useful this isn't the only example at all right they're extremely useful but this is the simplest example i can always give people imagine you're a library author and you write a function that takes in a value and converts that value to a string and returns it how does it do that you just call tostring on it you need generics if you're the author of that because you want to write your function and you want to express that hey my function will take any argument that has a tostring and it will call to string and return it so you are taking a generic type as long as that generic type implements two string and that's where traits come in right so it's it's like um traits are gonna express they handle that second part that second part that's like as long as it implements blank as long as it has a blank function that's what the trait is doing for us the generic is the part that's saying hey this will take any type right any type and return some other type but that trait the trade parts filling in that as long as it has this function or as long as it has this property as long as it can do this thing right and so traits are really important because we saw the copy trade but they they let us really use generics in full power so the syntax around this was kind of rough for me uh to be honest like here um let me see if i can pull up let me just pull up our own file here what chatter chapter was this 10 i think at this point i started keeping track of the chapters so let's take a look chapter 10. yeah so yeah so some of this was just it was a little rough not gonna lie so we started out pretty basic uh this takes a list of integer 32 largest largest character so we start out we said okay let's write a largest function that works on an integer and a character let's do one individually write them both and then let's do one that can handle either right and so we went from largest integer largest character to a generic largest and so the this is where we have the we need the trait and the generic to just kind of explain what our function does so largest operates on an integer and what it's going to do is it's going to loop over that integer list right and it's going to find which integer is the largest how does it do that it's going to com it's going to basically keep track of the largest thing it's seen and if it gets something larger than the largest it makes that the new largest so if you have let me see what i have around my desk uh books books books books okay so i have three books in a list let's say this is the order what largest is gonna do is it's gonna take a look at each book i'm gonna try to put them in the order so this one's the largest we're talking about height i'm going to do height based on height so this book it looks at this first it says hey this is the largest book i've seen because i haven't looked at these yet so this gets marked as largest then looks the second it says oh that's bigger now that book is the largest cool book by the way and then it's going to look at the next book and see if it's larger than that other book if it's not this one still remains the largest and that's what's returned so i got to show off some of my bookshelf and explain that function all right i'm back so that's what that's doing now we have the same function that operates over character list and it does the exact same thing right it checks the size however the size is a little bit different when you're dealing with characters but the thing that works on both is you can compare right we can do partial order comparison so basically we could write a largest function we did this a largest function that takes something as long as that thing is comparable right it's size is comparable we can return the largest so how do we express that with a generic and a trait right and i'm actually i'm actually learning a little bit more as i do this with all of you like as i read through it again this is actually a really good recap and it's becoming a little less confusing for me so this is kind of cool so how do we do that how do we reflect that with a generic and a trait so generic t you'll see this a lot this is just capital t the reason this is used for generic is it's usually used to say a generic type right of some type t of some type t you'll hear people say that so we take a generic type t as long as it implements the trait partial order how did we know to use this the book told us no but yeah i mean that is why but we also got partial order from the prelude so we didn't have to bring it in but let's look it up if we look up we can probably find more about it so let's look up rust partial order trade for values that can be compared for a sort order the comparison must satisfy for all a b and c asymmetry transit transitivity so the transitivity transitive property and asymmetrical right you can pull it in we didn't need to do that i think it says something about it being the prelude partial order only requires limitation of partial compare method what the others generated for the default limitations so this is how we can read about partial order um but yes we have our partial order and we're saying it just needs some partial order and then our argument list was is a bit different and that's also different let's look so up here okay let me just copy one of these down here so we don't keep scrolling all right let me just move this up right it doesn't need to be here let me move this up a bit okay so here the difference here we had a reference to a car list right here we have a reference to a list of type t of generics when we return we return a reference to a character the largest character here the largest center here the largest of type t we don't know right and then everything else in the function is the same with one caveat this here so at the end here we're returning a reference to largest right um the other thing is here i forget why we're starting at negative one that's the end of the list we're starting at the end of the list in this case which i don't know why we did that but regardless um here's the function and you can see it lets us do the same function with a generic type as long as that type implements partial order so pretty cool right it's going to do a comparison so like which number is bigger right which string is bigger which character is bigger right and we can do that so again we're able to specify that by saying we support something of that type t as long as it has implements or can do trait partial order type t partial order that's the combination for writing a function right that does these kinds of things so that was pretty cool what i did have more trouble with though was not necessarily that but it's actually when we started getting into this complexity stuff the implementation block this syntax was weird for me um because you have implementation block and then you say generic type i understand this to you two different types but then you say complex point and then you have these types again this just seems super verbose and um i don't know it was tough this was a little tough for me um to kind of figure out why we need it both i'll have to probably read more and see why we needed this but i definitely struggled a little bit with this um aspect of it because yeah it's still a little weird like you have the even in this case let's look at this simple example implement t point t so you have you're implementing something for point t i guess this year that's this point but why why do you need this yeah so that this syntax was a little odd for me um to see it was a little complicated i definitely struggled with that a bit um in the beginning i still do right i still struggle with that so that's one of the things i'm not as yeah i guess like one of the things i'm not as fond of is the syntax it's just not as intuitive to me coming from the languages i'm coming from maybe if it's your first language it's easier or maybe it's like unbelievably hard like i'm not sure but it's as i use it more again with any language as you use it more it just makes more sense but there's just some stuff i think generally this like here is another it looks just craziness right to you function mix up you also have to specified here point other here again you're specifying it so i think generally one of my not frustrations but one of the difficulties i'm having with rust is how much more verbose it is than a scripted language it's obviously going to be scripting languages are simple by nature but even compared to something like elixir or python it's definitely more to type it can be a little more confusing i'm definitely struggling with remembering the syntax i have to reference my code a lot which is totally fine i think i'm not worried i'm not holding it against myself but the syntax can be nuts me like 2d in the chat said russ has a crazy syntax yeah for sure and coming from python elixir which has a ruby-like syntax python has its own syntax elixir has a ruby like syntax javascript has well javascript's had many different syntax over the years um with the different ecmascript standards but yeah rust it's it's definitely tough for me to i can't type it from my head i can't just go in and write a function i have to reference my old code a lot to see how that works there's some stuff that's really basic function definitions are easy um like when their basic function structures are pretty straightforward but yeah i often forget that syntax me like 2d in the chat thank you for stopping by so that's one of the things i've definitely been struggling with um this chapter was really cool i liked it because it was like talking about how to um have like a workspace that was awesome separating modules super good because generally when you learn a language they don't teach you the patterns on how to like structure things and then you go and you work on a project in at a company or your side project or project with a buddy or an open source project and the first thing to figure out is what is the file structure how do they navigate around how is it structured and i like that they presented that in the book because some like i said some languages just don't touch upon that subject and it can be very intimidating and very important i remember back when i was learning a javascript framework at the time angular one of the biggest issues from going from codebase to codebase was how the folders were structured they could be significantly different based on you know what team you were jumping to or where you were writing that code and so eventually style guides kind of came about to say hey it should be structured this way and files should go here and these functions should go here but it took a long time to get there and it was extremely intimidating to try to figure that out um especially when everyone was doing things differently so it's nice that the book kind of recommends that and russ kind of naturally they mention this too pushes you in a certain way uh to handle stuff so that's great um so yes we talked we started talking about this generic traits and lifetimes this was rough too um for me i think lifetimes at first was tough the syntax was weird again this is another syntax thing like i understand here let's go to the let's see if i can find the part about uh let me see if i can find it here like when you have that this thing no not that yeah this this was weird for me at first i was like what am i looking at but then when you when the book broke it down they broke it down really well it's definitely something where like i'm going to mess up and not and not include it and then forget but what it does is it noted it's really cool and it's something that i wouldn't think of from another language but like here in this case let's look at this content content is going to take um a post and return the content from a post so here what this is saying so we're returning a string slice right the lifetime is marking that the string slice will come from the post that's passed in so we have to say if we're actually taking a piece of a slice of something in the argument list we need to specify that so they know not to get rid of that argument and that that argument's lifetime is tied to the lifetime of this because it's a reference let me break that down for you because i'm help it's helping me by bringing it down the lifetime basically says okay let's say let me let me see what do i have around me that i can use as an example you know i like using physical objects okay okay i got my lego reinhardt let's use lego reinhardt if anyone ever played overwatch we got a little lego reinhardt here all right so reinhardt has his hammer right hammer down that's the move let's say my function takes a reinhardt and returns a hammer in the signature with the lifetime you actually specify that it takes a reinhardt and returns a hammer and you also specify with that a the hammer is actually part of that reinhardt so that argument that's coming in i'm actually going to take a part of that and that's going to be the hammer i return and so why is that important it knows that as long as this hammer is in is being passed around because slice it has to keep reinhardt around because reinhardt is the owner of that hanger that hammer right that hammer's part of him so as long as i'm referencing and using that hanger and dragging that around i'm dragging reinhardt around with me so that's kind of what that denotes right it says this slice is going to be sliced from this post so you better keep that post around otherwise the slice will no longer reference anything meaningful and so it's a way to tell the compiler that right there you go so it's actually pretty cool but the syntax like i wouldn't know looking at that right and so that's something that i'll have to figure out so that's one of my things where i'm not as good with it structs clear whatever those are pretty straightforward we talked about that i don't we don't need to talk about that anymore pattern match we talked about packages and crates uh i want to just go back actually because chapter 10 was the craziest so i just want to see what else we covered in here generic data types that was pretty straightforward um we talked about points yep we did that that was kind of cool i'm definitely going to cover this more traits defining traits ah yes this okay so this this actually wasn't that bad like once you're past the implementation block i think declaring you know summary for newsletter the thing that is is a little rough for me is i'm not good at like remembering the inner part so like here let me go down here let me show where they show some more code here uh here let's put up on our end traits let's see where do we have that's chapter 10 yeah so chapter 10 traits all right so we have summary um it's a trait and summary says that you have to implement if you if you have the trait summary you have to implement summarize author and summarize summarize author returns a string summarize returns a string how does it do that it calls format so here it's like here we're defining a function that just takes self and returns a string and here we're actually saying summarize and it's actually a function this is the default so that's pretty pretty great mike me like 2d in the chat said russ is such a powerful language but i'm an object-oriented pleb so i have a hard time learning other languages classes equals good language 10 10. that's hilarious because we like 2d i was just saying how i'm the complete opposite i'm a functional programming club so for me on my classes but i totally get it because classes i think functional object orient was what i first learned it was much easier because our world is made up of objects right cup so it's easy for like i think initially to understand programs in that sense um coming from javascript and kotlin yeah so javascript og javascript you had prototypical inheritance you had prototypes then you had classes now javascript with some of the frameworks is leaning functional but yeah it's definitely like it makes sense our world is made up of objects and it makes sense to think that way i know in video game programming that's a huge way to think about stuff i've been more recently enjoying the functional programming side of things and what's cool about rust is there is even a chapter right rust has a little bit of both so you have your object oriented chapter right and then we also had our functional chapter which was where was that object oriented where was that there is a functional chapter i promise well it's somewhere but yeah they did a functional concepts chapter and we had the object-oriented so it's got a little bit of both uh while it doesn't directly have like inheritance and objects classes you can kind of make them with structs so here we have this is kind of like that right this is kind of like inheritance so he says i can understand the syntax i can understand the syntax at all but i just have a hard time structuring things yeah me too for sure um it's definitely tough so here we have the this is kind of like object oriented um so we have summarize we have the default but then here we're actually saying newsletter and we're going to implement summary for newsletter and we're going to change it so that the summarize does something a little different so this part's pretty easy to understand um and i think just like they said in the chat just like me like said in the chat it's like the structuring things yeah sometimes it can be hard to kind of structure the stuff so they made a good point there in the chat um all right so here we like this part i think is it makes sense right um to have summary for tweet like you're saying what it's for and you're implementing it but since i just i just forget the syntax and then even here um trait bouncing this was the one this was the one i was very confused about trait bounce index i knew there was one thing i couldn't see i couldn't even think about what it was the trait bound syntax was confusing for me because you have notify your generic type summary i don't know maybe it's simpler now i'm seeing it but it was very complicated oh here look function returns implementation summary this stuff this stuff was tough for me for sure returns summarizable it returns an implementation block yeah summary yeah this is a little weird for me this implements so here again we have this crazy syntax where we're saying t has to have these two traits display plus partial order this is again an implementation block with a generic that's why it looks like this but it's just yeah it can be a little confusing for sure also this like if you're coming from other languages this is like verbose right having to do string from but again we've learned why that's the case and that's because we're not dealing with like regular strings right we have strings when string slices so um yeah this was you know a little bit more verbose but again you could use a string slice it's just whether you're declaring on the stack or the heap right which we also learned about that's another cool concept so there's a lot of things flying around um but as i use it more i will definitely get um a little better with it but i like how the book has presented it all they present it in a nice flowing way okay another topic um i love the way they've done tests i must say let me see if i can show it here let's go to our chapter 11 chapter 11 we're filing for chapter 11. now so i love that test just go in the file what i don't love like straight up like this isn't like i'm sure i really don't love this stuff it's super confusing to me um i get what it does but like it's not intuitive to me i don't remember these i always forget them i had to reference them i don't know what this is called like if this thing has a name i forget if it's like an annotation or what i don't love this also like this i get this but yeah i feel like there's a little bit of ceremony that i just don't get i could probably someone probably knows put in the comments or point me in the right direction maybe we did read it and i forgot but like this stuff i always forget like the derive like that syntax kind of wacky to me um but i love add two and two like this just i just love that it can go right in the same file and it's just like using a straight up assertion it's very easy nothing nothing to hide there um i just like that you just put tests right here it makes it easier it makes me want to be able to test also we learned about like skipping tests and things like that you can run them on compile like it's just very very nice that they're just right in the file i love that and you could break it up in a different file but i just like how easy that is you don't need to import another library if you're using javascript so me like 2d said that they use javascript in kotlin i know for javascript if you're testing you're probably pulling in some other testing library like jest jess is real poppy right now maybe you pulled in mocha or jasmine or q in it we got doze boy in the chat with the hype welcome does boy we're reviewing the book today talking about what we like and don't like about rust um so welcome so yeah so like i love it testing is super easy you don't have to pull in any libraries you can literally just put it in your main file super easy and it's great when testing is easy when languages make testing easy people write tests which we all love right it could be it could take a lot of times it takes longer to write the test in the code right and debugging isn't that bad yeah we haven't gotten into like much debugging like we haven't done any kind of debugging where we're actually stepping through the code i do kind of want to see what that's like me like 2d said i don't even do testing i don't see a point in doing it so yeah i feel like with rust the compiler probably catches a lot right um i think it's more for like the business logic that i would test i would say i would write tests for functions that do some complicated business logic that i wouldn't want messed up like maybe calculating the tax or that's always the example i use but generally what's nice is because the compiler catches so much you don't need to test things like types or stuff like that you can actually test business logic which is kind of cool um but yeah i think that's fantastic i really like the testing story that that rust has what else do we learn about so we did the command line program that was super cool um graph mini graph mini grip was fun that was another thing so the cool thing is like the book like had an intermission where it had us do a mini grip and that was super cool we actually built like a little grep utility that's actually really useful and not only that they told us hey this utility is cool but it's for play like if you want to actually have a real good crepe utility you can actually pull in one from a crate but this was super cool too like we just i like the way it was structured we took a little break we wrote a program to flex those muscles um and that was awesome so that was great we talked oh here we go so this is um me like 2d this is what i was talking about there's the functional chapter that we went over talk about the functional concepts we talked about the object oriented concepts smart pointers this got a little crazy for me i knew we were going to get here because this is one of the ones i want to talk about this was tough for me um it's a difficult concept i think it was a little bit hard for me to get again i'm not none of this stuff is like i'm never gonna like i'm loving rust i'm gonna continue using it but this one tripped me up a bit um mainly because i get why it was used like it's very useful i'm just worried that i'm gonna forget when to use it and i'm hoping the compiler will tell me but i want to make sure i use it effectively specifically the rest cell the ref cell was like the box i kind of get like the box that makes indirection it makes sense ref cell was a little bit tough for me and i'm definitely going to spend more time on this and as i go through stuff spend more time because this the syntax starts getting wacky like wild um super verbose like just looking at this out of context it just looks absurd i know what it's doing because we've done it but like this if i were to just be handed this i wouldn't be able to read it like if most of the time when i'm looking at another language i can kind of figure out what it is even if i don't know that language just from my experience going from language to language but if i saw this without reading the book i would have no idea no idea so i think this was very difficult and this is the part of rust i'm like a little nervous about getting into and like i could see this being if you're is this your first program language i could see this being intimidating but again all this stuff eases up as you use the language but for sure this was scary concurrency it makes concurrency very easy with spying threads i thought that was very easy until it started introducing until we started looking at like um well sorry i skipped where where'd it go currency come back currency here it introduced threads really nicely so definitely really liked that it got a little crazy when we started doing shared state concurrency because then we started pulling in smart pointers it got a little crazy right with the mutex but again these are very hard concepts generally that said there's other languages that like elixir deals with processes i think in my favorite way so i definitely prefer the way they handle it just makes it really easy to deal with processes but or processes but um rust does a good job with it it's definitely a hard concept and the the thing though is yeah there might be more coating up front and more to understand up front but you're getting that safety harness that you wouldn't get in something like java where you can have locking threads and it's preventing you from doing that stuff which it's okay to pay that upfront cost to get that those guarantees because the last thing you want is to write a multi-threaded program that's going to lock up in production right so that's something we're going to revisit but yeah definitely intimidating um the web server was really cool it started out great the single thread was super easy and then it got crazy complicated i think that was kind of interesting like it started out very straightforward easy then as soon as we started going to multi-threading we started pulling in reference counters creating thread pools like this it got a little crazy it definitely got a little crazy um not as simple as i thought it was going to be i thought it was going to be like look how easy this makeable it definitely wasn't um rusted in a nutshell yeah so exactly you're paying up front but you'll get that added benefit so overall i think the book did a fantastic job of walking through the concepts then introducing an exercise then some more concepts than an exercise there was definitely some times when it got pretty crazy the syntax got crazy i think for me what i'm going to need to spend more time is on just coding it more like building stuff with it referencing code looking stuff up leaning on the compiler i've talked about that a lot leaning on the compiler it's gonna give you that benefit right so do it lean on it and uh yeah i'm gonna i mean i the book was great i think i'm very happy and you've heard me say this before if you've watched the stream or you're watching on youtube i'm very happy i went through the book most of the time i dive right into a language and then learn as i go i was recommended by friends and colleagues that oh with rust it's got a lot of complicated concepts especially coming from javascript or python so you have to uh read the book like they recommended reading the book first because it's got so many concepts and i get why that was recommended because i would have been lost and you saw when we did rustlings if you were here from when we did wrestlings here we were able to do most of it but we had to go back to the book and we got totally caught up on the thread part but wrestling's was really fun so overall i'd say the book was awesome some crazy concepts russ makes some of them very simple the syntax i would say on a scale of rating on the languages i've used it's one of the more difficult syntaxes i think um but with the added benefit of getting that safety that you do not get in python you don't get in javascript not even something like elixir maybe when you're using like very strict typescript you get some of that but not even close to what you get in rust elm is the next closest thing i can think of with in terms of compiler catching stuff but with all that the compiler gives you it's worth that upfront cost again if you need that type of safety with any language you pick there's like i said do you enjoy using it does it have a good developer experience is it the right tool for the job is it overkill or does it what gets you to solve your problem quickly because ultimately we're writing code to either have fun with it which is the fun experience developer experience or to solve a problem and so you got to always ask will this make you know is this overkill will it solve my problem um and in some cases if you need typesafe code if you need a binary that works on mac and um mac and linux windows rust is great it's going to be safe writing low level performance stuff it's going to be safe and i feel like eventually after we start to use it because the syntax isn't that bad right it's not i would think it's i think it's better than some languages um but it is a little rough at first but i'm sure i'll get to the point where i'm writing some scripts in it for my computer or writing some binaries i'm hoping to employ it at work a little bit um where i can currently i'm using maybe some windows powershell scripts and some mac scripts maybe i can write some rust binaries instead so i'm definitely looking forward to that but yeah i think i would say syntax is tough the resources are excellent that's the thing right the book rustlings uh we might try the rust exorcism but there's so many um rust resources that learning it and they're free right this book was free so again shout out thank you to steve klopnick carol nichols anyone from russ community the resources are great learning resources are great the community has been great so that's a huge plus performance the compiler is fantastic the compiler messages are best in class the only one i'd say it basically is maybe could be better could be equal would be the elm compiler the own compiler if anyone has ever seen it or heard me talk about the l compiler is far and away my favorite but this is right there and i think they took a lot of um hints from that and vice versa i think they both kind of maybe took influence each other so i love the compiler loving that so basically my overall impression after going through the book i really enjoy rust i think for a systems programming language it's extremely accessible would it be my first language to learn as a programmer no i would say definitely not if it is your first language don't be deterred by me saying that it's just having done other languages and coming from them it's more difficult for me it's kind of like when i started with snowboarding and then i tried skiing skiing was hard but i've heard from everybody else skiing's easier to learn might be like that but i would say if you're just a very new programmer i would think a more accessible language like python would be the right choice i personally love javascript so i always like to push for javascript because it's very accessible it's in the browser so that's always my first choice for languages this would not be my first choice but for a systems programming language again that's an important i think distinction to make you have your scripting languages for writing quick scripts you can write servers things like that and then you have your systems programming languages faster more performant you can still write the other stuff like web servers and things like that but um there have like a different use case rust would be the one i would use i would use rust over c for sure i've struggled with c um i'm trying to think of some other systems program i just have used no that's really it just c yeah i don't i know there's uh some other ones like crystal crystal's a i think crystal is a newer language that is c like with ruby s syntax i believe crystal syntax heavenly spyware ruby yep so this is another like well maybe we'll take a look at this one there that'd be kind of cool um but yeah for assistance programming language this is the one i would learn the community's great cargo is fantastic the tooling the tooling is tremendous so once i get past that syntax which comes with just doing more code i'm excited so that's kind of my take so far on rust i've been really enjoying it again i'm going to continue with it sorry i'm like clicking around i'm going to continue with it but my overall review to sum it all up amazing developer tooling amazing compiler amazing learning resources super fun to go through the book and the exercises i love how simple it makes memory management and the compiler catches everything the testing is super easy very low lift no no libraries needed to be included you just have it all built in cargo handles everything for you out of the box we even talk about my one of my favorite parts rust analyzer is incredible the what you get from rust analyzer where it compiles the code is your typing you get the messages in line you can see the types rust analyzer is absolutely awesome so the developer tooling is amazing performance is amazing what i still struggle with with the language is some of the concepts are a little bit more difficult because we're thinking about memory we're thinking about ownership while it does make some of that easier than other systems programming languages coming from scripting languages or other languages like python javascript elixir it makes it's a little more difficult but it's i'm getting there i'm learning it and then my other thing would be the syntax can be difficult to look at and read initially coming from other languages i'm hoping that gets a better over time but sometimes the syntax can be very verbose especially as you start to add indirection and smart pointers reference counters boxes those kinds of things it can get kind of wild but again with great power sometimes comes intense syntax no that's not that's not a saying but love rust i'm gonna keep going with it um i hope you enjoyed this review i know we kind of took a break from the code but i kind of wanted to get my thoughts out i know i've been talking throughout the book but i wanted to get kind of like a overall summary of the experience so far but i'd love to hear what your experience has been so feel free to put comments in the chat if you're here on twitch if not put some comments down below on the youtube video if you're watching that i really want to hear feedback from all of you what you've liked about rust if you've been learning it along with me love to see those comments if it's your first language um i'd love to hear what your experience has been there if you're coming from other languages again any kind of experience you've had would love to hear it put in the comments or put in the chat um just been like really great going through it and i'm happy to be able to sum it all up at least my experience but again we're going to keep going with it build some more stuff and we might do some other stuff we got kiwi gamer romania in the chat hello what up we are coming to the end close here but don't worry if you missed it all this gets posted up on youtube above which brings me to the wrap up so here again everything's posted here put some comments tell me what you think what you thought about russ i want to hear what else what they thought if you following the journey leave comments we've been getting some great comments you can follow it all here but yes so that's it for tonight that's my summary of going to the rust book that's what i enjoyed kind of my review i hope you all enjoyed it and we're going to keep going we're going to keep going with rust me we'll do some other stuff you've heard me talk about elixir and python javascript we'll do more of that as well i think probably as a channel we'll do more general programming we've been rust focused for a while and we'll continue doing rust but um as a generalist programmer uh we'll be doing a bunch of different stuff so i hope you stick around uh we'll be back next week with some new stuff but yeah that's it for tonight again check out the youtube and twitter for these videos if you're watching on youtube subscribe and like and you'll get notified for when we post more videos but that's it for tonight again i'm tom mcgirl i hope you enjoyed the learn russ live stream and i hope you enjoyed my take on rust again if you said put some stuff in the comments but tom you're wrong about this you're right about this whatever i want to hear it but that's all thanks for stopping by and have a good night later does boy
Info
Channel: Tom McGurl
Views: 521
Rating: 5 out of 5
Keywords: Rustlang, Tutorial, beginner, Systems Programming, Live coding, Learn Rust, Rustlang Tutorial, Rust Tutorial, Rust Programming Language, Review, Recap, Book Review, Likes and dislikes
Id: zWLhgDnhqCk
Channel Id: undefined
Length: 104min 24sec (6264 seconds)
Published: Mon Apr 05 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.