I would like to say that Rust is unlike other languages where you can learn as you go/while experimenting. I'd really recommend reading through the resources people mentioned before jumping in (steep learning curve).
I recently tried to learn emacs lisp with experimenting. First exercise was to calculate if a year is a leap year. I was just sitting there, staring at the screen. I knew how to do it, but I had no clue about how to do it in emacs lisps syntax. :D
Rust has a great documentation that is even available offline when you install it, and in the documentation there is the rust book which explains all its concepts with practical examples. I think it's a must to go through it because it's quite different than typical languages I think (although I only really know C and python).
@@UnicycleSoul Quite the opposite case for me. Cargo makes including dependencies as easy as it can be. Literally just the name and version of the library you wanna use, and boom it's done.
Great Timing! I've been thinking for a while to learn Rust (I already know C and a little C++). The video was very clear, fast and efficient. Loved it. Will be eagerly waiting for next lecture Professor!
I really like your explanation of String vs str. Not a complete definition but I think very good when you're hearing "rust has 2 string types" for the first time.
You're showing some fantastic breadth on this vid, Gary. I'm, foremost, a programming nerd and I've been following you for your hardware coverage and have been delighted with it for its accessibility. But I, myself, with a degree in computer science, am just beginning with Rust and I love it. They've run with the C++ community's long refined practice of RIAA memory semantics and have turned an art to a science with their fundamental build of a programming language atop it. It's amazing. The Rust-lang book is my homepage as I plod through it all. The borrowing tricks are very clever and to be completely honest, I wish there was a garbage collected version of the language so as to relax the learning curve so that the final jump to rust could be just laser focused on the borrowing and ownership stuff. It is real crazy and cool. I like garbage collection less and less as I reason through how graph algorithms absolutely destroy the CPU cache with frequent invalidations. And the CPU cache isn't just a nice-to-have on the side. Good performance can't be had without it.
I am about a year into learning and using Rust, about as old as this video is. Now I can really appreciate why Rust has been the most loved language in SO surveys for 6 years running. On a management level, projects leaders like it because the compiler catches so many bugs, which means they can put more trust on every of their programmers (junior and senior) to produce reliable, bug-free code. On an individual level, programmers like it because of all the modern ergonomics Rust brings to the table - type inference, Python-like string templating, iterators, message channels, official build tool, world-class documentation, and so much more. And of course to tie it all together, the programs that come out is hella fast - nearly as performant as well-optimised C and Cpp, and leagues above interpreted languages such as Python. It's a language so good it only existed in people's dreams, right up until it actually happened.
@8:07 i tried to replace those with strings and i noticed rust cares about what type of quotes i use, which is kinda wild. cause what if i need to make a template string on the web? i suppose i'll have to store it in those "" quotes as a string. looked more into it, its like bash where you can escape characters you need inside a string so thats good
I know its not the niche of your channel, but can we please get a full Rust course 🙏🙏 This explanation was fantastic! The little things you mentioned on the side were actually very helpful in clearing many misconceptions I would have assumed initially. Please give us all of Rust you know 🙏🙏
Excellent video! I've just started learning Rust, and I learnt a lot from this video. One minor suggestion: I found myself needing to seek back-and-forth a bit from the resulting output back to the code that produced it. It would have been nice to have both on screen at once. I know there's limited space when using big fonts for videos, but you could crop out the run/debug/stable buttons along the top, and it would create enough space for a few lines of output at the bottom. This (needing to seek back-and-forth) is one of the things where article/books are often better than videos (much quicker to seek by just moving your eyeballs than fiddling with the seekbar), so this would help get closer to that efficiency. You could still hide the output before you're ready to show it, but just leave the code on screen too when showing the output. Having a different background color for code vs output would be nice too. Alternatively doing something like quokka where you show the output as a comment on the same line as the code means that the viewer doesn't need to try to mentally match things up.
Nice overview! I would really love a video on how to make code more... Rusty. I often still feel like I'm writing very iterative code, and would love some "instead of X, try using a more idiomatic pattern like Y" examples. Also something along the lines of "How not to panic!() when you see angled brackets". Memory safety and borrowing can be confusing for a bit -- But I found that the real brainteasers start when you encounter generics, traits, boundaries and macros -- and that's usually pretty quickly because Iterators, From/Into conversion and Result/Optional are so prevalent in other people's crates.
Great intro video. I'm going to be using rust at work in the next few weeks and this is helping me to get a basic understanding. I was educated in C++ and so far, they are very similar!
Every minute of this video is valuable ... I have just started learning Rust this week; and I only know python (2 years experience)... and this video helped me a lot... please do more Rust programming stuff.
As a programmer that knows more than 10 programming languages including Rust, C and C++, i think Rust is pretty exagerated. You know, when i was learning C, i thought to myself: why does this language not have classes or at least libraries for the basic things like hash tables, or even maybe a way to check for memory violation at compile time. Then i read the libc (c standard libraries) and indeed C has many libraries, just that they are not classified as standard. This really troubled me, but with time, i realized why C is so, why a C compiler exists almost every hardware out there. C knows its place and it is as a mediator between hardware and human, a nice assembler. C11 included generics, but barely anyone uses them, it even added the bound checking option for developper, which people criticised. This leads to my complain about your points at 0:43: C and C++ are very popular and a lot of people use these languages without actually knowing what they are doing. Funny is the fact that the Rust community is filled with good C and C++ developpers. An example is what i keep seeing in C++: People using C style programming in C++ and calling themselves C++ devs. Instead of creating a raw array of raw pointers, rather use C++ std::array or std::vector coupled with std::unique_ptr.
Actually most are not. The reason good c/cpp programmers are looking at rust is precisly because they understand the deficiencies of using those languages to write safe systems. The legacy of cpp is that it was written to allow most of C to be acceptable. This has lead to many people writing c in cpp, like you say. Some places c is good, but in many places rust is just better. As someone who's been programming for 40 years, I used think language X was great, until I realised what language Y was better for.
I doubt you know very much about rust at all, as you really have completely missed the point of it as language. it prevents you from making almost all of the bugs which c and c++ programs are riddled with - null pointers, dangling pointers, use after free, data races and so on. As for utter nonsense like barely anyone uses generics.... at this point I strongly suspect you're merely trolling.
I'm fairly certain you have at most surface level knowledge in 10 different languages. Someone who's actually been around should know the weak points of C and C++ and should recognize that Rust (succesfully) tries fixing them
Interesting stuff, but I'd like some more information on what is going on under the hood. For example, when you say let (w, x, y, z) = tup, are w, x, y and z references to tup values that become invalidated if tup is deallocated, or are they copies? I'm guessing in a memory-safe-to-point-of-madness language like Rust, they are copies, so the operation is more expensive than just referencing tup.0, tup.1, etc. Also, yes, do that UTF-8 video. :D
This is a great style of video! I'm curiously prodding around the outsides of Rust to see what it's like and this is a terrific introduction to core concepts and features without being overly verbose or lengthy
I was wondering about cloud computing. Like run my java app in cloud foundry, in aws cloud, azure, ali cloud. How much effort is running a complex rust app in different cloud environments, using the same code base.
2 books, get only one or both: a) The Complete Software Developer's Career Guide, b) The Self-Taught Programmer: The Definitive Guide to Programming Professionally
If you intend to make a carreer out of it, learn C. Not because you will end being a C developer, but because you will learn how the computer works and how to think like a software engineer.
i think some of the main differences are that Go is garbage collected and Rust uses a borrow checker instead, Go does not have generics but Rust does, error handling in Rust is different than in Go and many other languages, i.e. a function can return a result that is Ok(value) or an Error, which can be matched, unwrapped, etc. Rust variables are immutable by default
Liad Sagi Rust is a Systems Language and has (almost) no runtime, while Golang has a runtime for n:m threading and garbage collection. Thats why rust is much more powerful but on the other hand exposes much more low level stuff to you than golang. Compared to C or C++ though the compiler really tries to ensure with stuff like the borrowchecker that the code you write behaves like you expect it to (no undefined behavior, dangling pointers or data races in safe rust). You can develop an operating system in Rust or develop for embedded systems using rust. Theres also a popular crate (library) which contains a runtime for async io and n:m threading like golang does called Tokio, which even exceeds golangs performance for server applications, but its not „baked into the language“ like with go. So to conclude rust is potentially much faster, safer and more versatile than go. whats the downside you may ask? the downside is that rust is a much harder language to get productive with than go. Its similar to writing modern idiomatic C++ with more syntactic sugar, better enums, pattern matching etc. and safety guarantees though, so its easy to get started using it for everyone who knows modern idiomatic C++, but everyone else probably really has to wrap his head around this. this not like learning java or c#.
I would learn C first as it's a very easy language that teaches you how the low level world works. Writing efficient code has a lot to do with knowing what's actually happening on the instruction level
Start with something the learner is already familiar with, for example, a simplified order entry system, or a simplified person book inventory system, or a car maintenence scheduler system. A competent teacher can start at any point to accommodate the experiences that the learner brings to the table.
I tought .len counted the length of the string not the number of bytes of a utf-8 encoding. :( Is there a method to count the actual string length? edit: 1. Found it. see my comment bellow. 2. I understand now why the default is bytes. String length could still be easier :/
@@31redorange08 that's a bit complicated to explain. The stackoverflow Q&A that I've linked before, probably does a better job, but I'll try. First of all, the easy part: UTF-8 bytes != number of characters. The euro-sign € is 1 character, but is encoded as 3 bytes in UTF-8 (en.wikipedia.org/wiki/UTF-8#Examples) The more complicated part char is sometimes different of characters. Char is usually a unicode scalar value, which usually referes to a single charater (hence the name) but some characters can constructed from multiple unicode scalar values, like ´ and e to form the character é (en.wikipedia.org/wiki/Precomposed_character)
If another coder can re-declare your variable without throwing an error, what’s to prevent that accidentally happening? (Expecting the next coder to be careful doesn’t count.)
I can tell you from experience that accidental shadowing really doesn't happen. How often do you accidentally overwrite a local variable? Because it's effectively the exact same thing
does it have a lot of libraries/imports .. so you get a bunch of stuff for free? I try to write as few lines of code as possible. i don't like to re-invent the wheel. i care more about pre-built libraries (that are available "for free"), versus language syntax. :)
9:40 lol, that's amazing. Why would they allow shadow variables ? That seems like not a smart idea. Expressions seems really dumb, for example why not have return ? And then I realized, this forces the return to be at the end of the function. That was not as stupid as it seems at all ! Tip: with loop and while use a < > or instead of equal, so you know it will never end up in an endless loop in case you change some of the other code/calculations.
Sólo le veo dos cosas interesantes: las tuplas (que no dejan de ser estructuras) y que los tipos de datos tienen definido el tamaño de bits. Para todo lo demás me gusta más C.
It's a technicality, but Rust DOES have an intermediate language, it's just not usually what gets delivered and it's a part of the compiler. Rust is getting compiled to LLVM (low-level virtual machine) code, and other than the name suggests that is (in this instance at least, and AFAIK) used to compile further to Machine Code. The LLVM layer is what allows Rust to run on multiple platforms without requiring a runtime - like I. E. Java (and other languages with the typical 'intermediate language') or Python (and other interpreted languages) do. The only reason C(++) is able to run on so many platforms is because these platform holders or others put in a lot of work to make the compiler work, because in the end you need a language to Programm systems, and C(++) is what's used for these most of the time to this day. Rust doesn't have that luxory, but by using LLVM they can just port the LLVM Instruction Set and they're good to go. LLVM is also used by the C Compiler Clang and there's other languages that can be compiled to machine code using it btw. Coming back to Rust, they (probably, not an expert) loose a bit performance by using LLVM, but Rust makes up for it with other features that reduce runtime overhead (lots of zero cost abstractions) and you win a lot of other really nice to have things like I. E. The type-managed memory safety etc that improve code quality as well as ease development. I haven't really used Rust yet for lack of a good project to do on it, but what I have heard is quite amazing and right down my lane. Maybe you will give me a good project for it, or I'll get back to the neural network book with code I read and try and port the essentials from Python to Rust. Eventually...
Samuel Maier rust often ends up faster than C or C++ code given time and effort constraints. This is because, with C and C++, you may waste performance in pursuit of safety. Rust’s built-in memory guardrails allow a programmer to optimize with reckless abandon without worrying about memory issues. This, combined with Rust’s built-in support of forced simd opcodes via std::arch and crates that wrap this for ease of use like faster (which offers simd-capable versions of map-reduce, iter, and special data types for them), it’s much easier to optimize rust than C or C++.
The one last thing I think rust really needs to have a decisive all-around win over C and C++ for most use cases is a more generic logical proof system beyond just the memory stuff. That, using a security-focused RTOS like SEL4 for FOSS or INTEGRITY for compliance, could allow for potentially hack-proof, “mathematically perfect” software.
@@romannasuti25 Yeah I was expecting an effect like you describe. And yeah, I think I've read about the SIMD prepared functions but forgot about it, that's a really nice time safer too, though technically you can create them in C++ too if u recall correctly. You just have to implement them yourself/use an implementation by another person. A number of the comfort features of Rust are technically a thing in C++, it's just that because they're an afterthought it's hard to use them, setting up all of them is bound to come with a shitton of experimentation. Rust gives them to you for free.
This is a good video and well-explained, which I appreciate greatly. But Woooo! I'm old school. I started programming in APL, Z-80 and 8080 assembly in 1978. I went on to design two programming languages myself: R-code and LIM. From my perspective, an immutable variable is a CONSTANT. It's RIDICULOUS to default all variables to constants. Additionally, The format for displaying a line of text is needlessly complicated and makes it harder to read and debug. For one thing, it shouldn't need a macro. Jeezy Joe! Trust me on this, as I have read and debugged code in several languages. Rust would have made me get up and walk out. Python is crazy too, with the rigorous white space, but it's not as crazy as Rust, and actually is pretty useful when coding for the Pi. Therefore there is nothing on planet earth that would induce me to code in Rust. Anyone who likes Rust, please reply and tell me why you do. Maybe I'm missing something. All good wishes.
According to Wiktionary both are used/correct. The etymology of the words however suggest that “tooples” is more correct, since it originates from terms like quadruple, quintuple, sextuple, septuple, octuple, being generalized to 𝑛-tuple in mathematics where 𝑛 is a positive integer, and all those (quadruple, quintuple, etc..) are pronounced like “...toople”.
I'm starting to learn Rust, but I'm wondering if the memory flaws in MODERN C++ are vastly overstated. For most projects it's a non-issue. How is anyone going to do a memory exploit of some silly game I develop, for example? Most systems programming is done in C rather than C++ anyway, So how can anyone say that C++ is vulnerable when it's not used that much in systems programming? It seems that someone has said that C is unsafe, and then thrown the baby out with the bathwater.
Because C++ has pointers, just like C, it is just as susceptible to memory bugs. As for you silly game the problem is a) the libraries you link against, b) exploits involving any network activity including web stuff, c) anything that increases the attack surface of a computer... Finally, it depends on how popular your silly game becomes.
@@GaryExplains Well, why don't I just not use pointers in C++; pass references to objects instead, const if necessary? Also, if I don't have the program connect to the web, then I have no network vulnerabilities. Simples. :Like I say, I think Rust oversells the whole memory safety thing.
@@zetaconvex1987 You see what you did there was take C++ and change it, now it isn't C++. Many companies have development policies about how a language can be used to minimize the attack surface. Also what you have done is admit that you need to limit what types of programs you can write using C++ for it to be safe.
what is the point of making a variable immutable if you can still let any variable be changed at anytime using Let, not only that, but you can also change its type? all its doing is making it a bit more long winded to do by having to type Let in front of it each time or am i missing something? I thought Rust was meant to be safe... how is that more safe than what you can do in any other language like D or Go etc?
Rust is statically typed not dynamically typed. Rebinding an owned variable to mutable is ok since you are the sole owner of that address and it does not change any non mutable references internally. So if you are borrowing imitable data it stays imitable. Its a bit to much to get into in one comment but since Rust not only tracks owners but borrows you cannot run into a lot of memory errors you can in other languages.
If you go back to mathematics, where the term actually comes from, it makes sense again: consider a function of one argument, e.g. f(x) = x * x. The variable `x` is not mutated, but represent different (hence "variable") values, as different argument values can be passed to `f`.
Hi David, an immutable variable is computed at runtime. Or it is created at runtime. (Eg. You can assign a mutable variable to immutable variable) A constant is prepared/computed at compile time. That is, a constant is just an alias for a literal.
Maybe I'm just old school but a "variable" that is immutable is better known as a constant. I really don't understand the point of this language pattern in rust, it's ridiculous.
I've lost count over the years of the number of trendy niche languages that were going to replace C or even C++. Anyone remember D? Didn't think so. C and C++ will always remain the standard languages for embedded software. There may be a case for using Rust in place of C as raw pointers and arrays are tricky for programmers to handle. C++ avoids many of these pitfalls by providing deterministic destructors for cleanup (RAII), smart pointers, bounds checked vectors etc. Modern C++(11/../20) also provides move semantics to distinguish between copying and exchanging data, as well as a whole host of other modern language goodies such as type inference, lambda expressions, direct iteration over collections, initializer expressions, etc, etc. If you want to learn a better C, learn modern C++!
No, C++ is not the answer. It's horribly broken and probably can't be fixed. Rust is the first successor to C to actually figure out real memory safety without sacrificing performance. It's definitely here to stay
UTF-8 can also encode all 24 something bit Unicode codepoints require. It's actually by far the most widely used encoding nowadays! In fact this very comment is UTF-8 encoded
LOVE RUST! Been doing my senior project for my CS degree in Rust to help me really learn it. Been an absolute blast!
Can i ask what a type of project ?next year i will do my senior project also
Yes please tell what type of a project
I would like to say that Rust is unlike other languages where you can learn as you go/while experimenting. I'd really recommend reading through the resources people mentioned before jumping in (steep learning curve).
I recently tried to learn emacs lisp with experimenting. First exercise was to calculate if a year is a leap year. I was just sitting there, staring at the screen. I knew how to do it, but I had no clue about how to do it in emacs lisps syntax. :D
TOC: 4:06
println! : 4:25
mut : 10:19
shadow variables : 11:40
constants : 13:49
types : 15:03
Strings : 17:05
tuples : 20:08
arrays : 22:35
expressions and statements : 24:01
functions : 26:38
loop and while : 31:32
for : 33:13
closing statements : 35:06
Thanks for the time indexes, but you do realise that I had included that in the description already?
Upper case separated but underscores is called "SCREAMING_SNAKE_CASE"
Video on utf-8 would be nice!
Agree! That would be interesting.
Here’s an amazing video on Unicode / utf 8: ua-cam.com/video/MijmeoH9LT4/v-deo.html
@Axton Aarav if you download other people's code meant to "hack" things this channel is not for you XD
There's that one on computerphile by Tom Scott. It's a nice one.
Rust has a great documentation that is even available offline when you install it, and in the documentation there is the rust book which explains all its concepts with practical examples. I think it's a must to go through it because it's quite different than typical languages I think (although I only really know C and python).
I quite like their documentation but I find it that using crates and wiring them together is a general nightmare.
@@UnicycleSoul Quite the opposite case for me. Cargo makes including dependencies as easy as it can be. Literally just the name and version of the library you wanna use, and boom it's done.
Great Timing! I've been thinking for a while to learn Rust (I already know C and a little C++). The video was very clear, fast and efficient. Loved it. Will be eagerly waiting for next lecture Professor!
Quickest, most consise Rust introduction I've see yet. Kudos!
I really like your explanation of String vs str. Not a complete definition but I think very good when you're hearing "rust has 2 string types" for the first time.
You're showing some fantastic breadth on this vid, Gary. I'm, foremost, a programming nerd and I've been following you for your hardware coverage and have been delighted with it for its accessibility. But I, myself, with a degree in computer science, am just beginning with Rust and I love it. They've run with the C++ community's long refined practice of RIAA memory semantics and have turned an art to a science with their fundamental build of a programming language atop it. It's amazing. The Rust-lang book is my homepage as I plod through it all. The borrowing tricks are very clever and to be completely honest, I wish there was a garbage collected version of the language so as to relax the learning curve so that the final jump to rust could be just laser focused on the borrowing and ownership stuff. It is real crazy and cool. I like garbage collection less and less as I reason through how graph algorithms absolutely destroy the CPU cache with frequent invalidations. And the CPU cache isn't just a nice-to-have on the side. Good performance can't be had without it.
At 14:07 I guess you wanted to say that constants are always imutable (instead of mutable).
This is a great introduction to the Rust language. Gary really does explain and in a clear concise manner.
Great introduction to Rust. I am looking forward to the next instalment in this series. I would also be interested in your presentation of UTF-8.
I am about a year into learning and using Rust, about as old as this video is. Now I can really appreciate why Rust has been the most loved language in SO surveys for 6 years running.
On a management level, projects leaders like it because the compiler catches so many bugs, which means they can put more trust on every of their programmers (junior and senior) to produce reliable, bug-free code.
On an individual level, programmers like it because of all the modern ergonomics Rust brings to the table - type inference, Python-like string templating, iterators, message channels, official build tool, world-class documentation, and so much more.
And of course to tie it all together, the programs that come out is hella fast - nearly as performant as well-optimised C and Cpp, and leagues above interpreted languages such as Python. It's a language so good it only existed in people's dreams, right up until it actually happened.
@8:07 i tried to replace those with strings and i noticed rust cares about what type of quotes i use, which is kinda wild. cause what if i need to make a template string on the web? i suppose i'll have to store it in those "" quotes as a string. looked more into it, its like bash where you can escape characters you need inside a string so thats good
I know its not the niche of your channel, but can we please get a full Rust course 🙏🙏 This explanation was fantastic! The little things you mentioned on the side were actually very helpful in clearing many misconceptions I would have assumed initially. Please give us all of Rust you know 🙏🙏
Excellent video! I've just started learning Rust, and I learnt a lot from this video.
One minor suggestion: I found myself needing to seek back-and-forth a bit from the resulting output back to the code that produced it. It would have been nice to have both on screen at once. I know there's limited space when using big fonts for videos, but you could crop out the run/debug/stable buttons along the top, and it would create enough space for a few lines of output at the bottom. This (needing to seek back-and-forth) is one of the things where article/books are often better than videos (much quicker to seek by just moving your eyeballs than fiddling with the seekbar), so this would help get closer to that efficiency. You could still hide the output before you're ready to show it, but just leave the code on screen too when showing the output. Having a different background color for code vs output would be nice too.
Alternatively doing something like quokka where you show the output as a comment on the same line as the code means that the viewer doesn't need to try to mentally match things up.
I am also learning rust☺, I have just finished ownership chapter and started next topic i.e about structuring data using struct keyword.
Nice overview!
I would really love a video on how to make code more... Rusty.
I often still feel like I'm writing very iterative code, and would love some "instead of X, try using a more idiomatic pattern like Y" examples.
Also something along the lines of "How not to panic!() when you see angled brackets".
Memory safety and borrowing can be confusing for a bit -- But I found that the real brainteasers start when you encounter generics, traits, boundaries and macros -- and that's usually pretty quickly because Iterators, From/Into conversion and Result/Optional are so prevalent in other people's crates.
hmm .. at 24:05 inside y block x is muted does mut needed as it comes under shadowing ?
x is not a shadow variable in the loop because it doesn't use "let"
I would pay for a full course on rust explained by you, This is really very clear and straightforward.
Great intro video. I'm going to be using rust at work in the next few weeks and this is helping me to get a basic understanding. I was educated in C++ and so far, they are very similar!
Hey Gary, I'm late to the party but I want to dive into rust programming and this video gave me an excellent introduction. Thanks a lot!!
Wow, Gary. You did sooo much work here. 👏🏽👏🏽👏🏽
The Professor keeps on professing!
I like it. Thanks for the intro. Something to do while in lock down. Learn a new language.
For the function `is_odd` at 28:17, the logic holds in a single line: (x & 1) != 0.
Thank you so much, I was just wondering about this language and wasn't quite sure where to begin. Hats off to you Gary
Nice one. It would be nice if you do a video on Haskell too.
Every minute of this video is valuable ... I have just started learning Rust this week; and I only know python (2 years experience)... and this video helped me a lot... please do more Rust programming stuff.
Is tulle the equivalent of JavaScript object? Why does rust not use curly brackets instead of paren?
Brilliant way of explaining things! Well Done!
As a programmer that knows more than 10 programming languages including Rust, C and C++, i think Rust is pretty exagerated.
You know, when i was learning C, i thought to myself: why does this language not have classes or at least libraries for the basic things like hash tables, or even maybe a way to check for memory violation at compile time. Then i read the libc (c standard libraries) and indeed C has many libraries, just that they are not classified as standard. This really troubled me, but with time, i realized why C is so, why a C compiler exists almost every hardware out there. C knows its place and it is as a mediator between hardware and human, a nice assembler. C11 included generics, but barely anyone uses them, it even added the bound checking option for developper, which people criticised.
This leads to my complain about your points at 0:43: C and C++ are very popular and a lot of people use these languages without actually knowing what they are doing. Funny is the fact that the Rust community is filled with good C and C++ developpers.
An example is what i keep seeing in C++: People using C style programming in C++ and calling themselves C++ devs. Instead of creating a raw array of raw pointers, rather use C++ std::array or std::vector coupled with std::unique_ptr.
Actually most are not. The reason good c/cpp programmers are looking at rust is precisly because they understand the deficiencies of using those languages to write safe systems. The legacy of cpp is that it was written to allow most of C to be acceptable. This has lead to many people writing c in cpp, like you say. Some places c is good, but in many places rust is just better. As someone who's been programming for 40 years, I used think language X was great, until I realised what language Y was better for.
I doubt you know very much about rust at all, as you really have completely missed the point of it as language. it prevents you from making almost all of the bugs which c and c++ programs are riddled with - null pointers, dangling pointers, use after free, data races and so on. As for utter nonsense like barely anyone uses generics.... at this point I strongly suspect you're merely trolling.
What’s your point?
I'm fairly certain you have at most surface level knowledge in 10 different languages. Someone who's actually been around should know the weak points of C and C++ and should recognize that Rust (succesfully) tries fixing them
Thanks for the video I started rust this year and I found it fascinating
Interesting stuff, but I'd like some more information on what is going on under the hood. For example, when you say let (w, x, y, z) = tup, are w, x, y and z references to tup values that become invalidated if tup is deallocated, or are they copies? I'm guessing in a memory-safe-to-point-of-madness language like Rust, they are copies, so the operation is more expensive than just referencing tup.0, tup.1, etc. Also, yes, do that UTF-8 video. :D
This is a great style of video! I'm curiously prodding around the outsides of Rust to see what it's like and this is a terrific introduction to core concepts and features without being overly verbose or lengthy
I was wondering about cloud computing. Like run my java app in cloud foundry, in aws cloud, azure, ali cloud. How much effort is running a complex rust app in different cloud environments, using the same code base.
looking forward to seeing the sequel to this on memory, ownership and borrowing
He did do this one: Dynamic Memory Allocation in C - malloc, free, and buffer overflows
Will there be followup to this?
Yes
Thank you for our Lesson Uncle Gary. It was very clear and informative.
I'm so glad to see you cover this
Very clearly explained, you've got another subscriber!
You should make a video on Go
Thanks Gary. You convinced me to learn Rust in this nice video
UTF8 lesson? Yes, please!
Excellent and elegant introduction to rustlang. Thank you for the video !
Thanks -- revisiting after seeing the Google "go" language vid to compare the differences (many).
Nice video bro!
Glad you liked it
Fantastic video!
damn this is so good i was having hard time gettin rust ur video is gem.
I am glad it was helpful. 👍
Thank you professor
Best intro to rust
Hello and thank you for the tut it’s really helpful fr, but am a beginner and I wanna learn rust how’s that possible?
Seems interesting language and quite powerful, how far it has been adapted ?
Here is a list of companies that are using it:
www.rust-lang.org/production/users
*BOOOOM* Let makes so much more sense !
How fast it is ? Any benchmarking test ?
Hey sir im 22 and i wana learn coding where should i start by which language and where can we get a good idea about the language on the net
2 books, get only one or both:
a) The Complete Software Developer's Career Guide, b) The Self-Taught Programmer: The Definitive Guide to Programming Professionally
If you intend to make a carreer out of it, learn C. Not because you will end being a C developer, but because you will learn how the computer works and how to think like a software engineer.
How Rust compare to go (golang) ?
i think some of the main differences are that Go is garbage collected and Rust uses a borrow checker instead, Go does not have generics but Rust does, error handling in Rust is different than in Go and many other languages, i.e. a function can return a result that is Ok(value) or an Error, which can be matched, unwrapped, etc. Rust variables are immutable by default
@@Myrkvi_ I meant different in purpose not syntax. (And go functions can return an error too , idk rust syntax for that so it might be different)
Liad Sagi Rust is a Systems Language and has (almost) no runtime, while Golang has a runtime for n:m threading and garbage collection. Thats why rust is much more powerful but on the other hand exposes much more low level stuff to you than golang. Compared to C or C++ though the compiler really tries to ensure with stuff like the borrowchecker that the code you write behaves like you expect it to (no undefined behavior, dangling pointers or data races in safe rust). You can develop an operating system in Rust or develop for embedded systems using rust. Theres also a popular crate (library) which contains a runtime for async io and n:m threading like golang does called Tokio, which even exceeds golangs performance for server applications, but its not „baked into the language“ like with go. So to conclude rust is potentially much faster, safer and more versatile than go. whats the downside you may ask? the downside is that rust is a much harder language to get productive with than go. Its similar to writing modern idiomatic C++ with more syntactic sugar, better enums, pattern matching etc. and safety guarantees though, so its easy to get started using it for everyone who knows modern idiomatic C++, but everyone else probably really has to wrap his head around this. this not like learning java or c#.
Rust prevents data races at compile time, whereas Go doesn't give such guarantee.
Can I go straight into Rust or would it be better to learn something like C first?
I learn Rust as my first low-level language and do try learning C from time to time. I'd say I have a much harder time learning C than Rust.
Rust is easier too learn than c
I would learn C first as it's a very easy language that teaches you how the low level world works. Writing efficient code has a lot to do with knowing what's actually happening on the instruction level
@@TheMrKeksLp Telling somebody to learn C as a first language because it's "easy". What a mad man.
a little guide on UTF-8 would be nice :)
I would like to learn a timezone language.
Start with something the learner is already familiar with, for example, a simplified order entry system, or a simplified person book inventory system, or a car maintenence scheduler system. A competent teacher can start at any point to accommodate the experiences that the learner brings to the table.
And how do I know the level of experience you have?
UTF-8 DO VIDEO PLEASE
I have been programming in rust since 2 years ago and I wasn't aware about the named variables in the println macro 😂.
Looking forward to the second video, but I'll throw in a vote for UTF8 as well!
Thanks man rust is quite easy and you explained it clearly
Gary, what a great intro. Thanks
Glad you like it
Very instructive, thanks !
A variable thet's not mutable? Wouldn't that be a constant??
o.k. I was to quick with that one...
I guessed that it was an ancient video so I can explore the whole tutorial but this video is 0 day old :'(
Excellent video! Thanks!
Thank you. This helped a lot :)
Interesting intro
Thanks for sharing :-)
what I also love in Rust is, that Microcontrollers are first class citizens. The Whole Rust Ecosystem supports Cortex-M out of the box
That was the first question on my mind.... what about microcrontrollers?
Thanks for this
I tought .len counted the length of the string not the number of bytes of a utf-8 encoding. :(
Is there a method to count the actual string length?
edit:
1. Found it. see my comment bellow.
2. I understand now why the default is bytes. String length could still be easier :/
Found it. stackoverflow.com/a/46290728/86845
It's actually a bit complicated...
println!("{}", "é".graphemes(true).count()); // 1
tmnt9001 That’s dreadful.
What is the actual string length?
@@31redorange08 that's a bit complicated to explain.
The stackoverflow Q&A that I've linked before, probably does a better job, but I'll try.
First of all, the easy part: UTF-8 bytes != number of characters.
The euro-sign € is 1 character, but is encoded as 3 bytes in UTF-8 (en.wikipedia.org/wiki/UTF-8#Examples)
The more complicated part char is sometimes different of characters. Char is usually a unicode scalar value, which usually referes to a single charater (hence the name) but some characters can constructed from multiple unicode scalar values, like ´ and e to form the character é (en.wikipedia.org/wiki/Precomposed_character)
@@tmnt9001 I know that it's complicated. I just wanted to state that it depends on what you want to count. There's bytes, codepoints, graphemes…
Awesome video, please do a video on UTF-8, I am subscribing to this channel for that reason only. Thanks again :)
Can you swishy-wishy?
x, y = y, x
(a, b, c) = (c, b, a)?
If another coder can re-declare your variable without throwing an error, what’s to prevent that accidentally happening? (Expecting the next coder to be careful doesn’t count.)
I can tell you from experience that accidental shadowing really doesn't happen. How often do you accidentally overwrite a local variable? Because it's effectively the exact same thing
does it have a lot of libraries/imports .. so you get a bunch of stuff for free? I try to write as few lines of code as possible. i don't like to re-invent the wheel. i care more about pre-built libraries (that are available "for free"), versus language syntax. :)
Yes it does. As well as the standard libraries there are "crates" which are part of the Cargo build system. See crates.io for details.
Good work. Thanks.
*GARY!!!*
*Good Morning Professor!*
*Good Morning Fellow Classmates!*
Stay Safe Out There Everyone!
MARK!!!
Where's that UTF8 video Gary? 😫
Not many people asked for it. I am not sure it would be popular.
@@GaryExplains Well if you get board hook a brother up. 😷
9:40 lol, that's amazing.
Why would they allow shadow variables ? That seems like not a smart idea.
Expressions seems really dumb, for example why not have return ? And then I realized, this forces the return to be at the end of the function. That was not as stupid as it seems at all !
Tip: with loop and while use a < > or instead of equal, so you know it will never end up in an endless loop in case you change some of the other code/calculations.
Shadowing is really more so a convenience but I can imagine situations in which you might accidentally shadow an immutable variable.
Sólo le veo dos cosas interesantes: las tuplas (que no dejan de ser estructuras) y que los tipos de datos tienen definido el tamaño de bits. Para todo lo demás me gusta más C.
excellent! Thanks
It's a technicality, but Rust DOES have an intermediate language, it's just not usually what gets delivered and it's a part of the compiler.
Rust is getting compiled to LLVM (low-level virtual machine) code, and other than the name suggests that is (in this instance at least, and AFAIK) used to compile further to Machine Code.
The LLVM layer is what allows Rust to run on multiple platforms without requiring a runtime - like I. E. Java (and other languages with the typical 'intermediate language') or Python (and other interpreted languages) do.
The only reason C(++) is able to run on so many platforms is because these platform holders or others put in a lot of work to make the compiler work, because in the end you need a language to Programm systems, and C(++) is what's used for these most of the time to this day.
Rust doesn't have that luxory, but by using LLVM they can just port the LLVM Instruction Set and they're good to go.
LLVM is also used by the C Compiler Clang and there's other languages that can be compiled to machine code using it btw.
Coming back to Rust, they (probably, not an expert) loose a bit performance by using LLVM, but Rust makes up for it with other features that reduce runtime overhead (lots of zero cost abstractions) and you win a lot of other really nice to have things like I. E. The type-managed memory safety etc that improve code quality as well as ease development.
I haven't really used Rust yet for lack of a good project to do on it, but what I have heard is quite amazing and right down my lane. Maybe you will give me a good project for it, or I'll get back to the neural network book with code I read and try and port the essentials from Python to Rust. Eventually...
Samuel Maier rust often ends up faster than C or C++ code given time and effort constraints. This is because, with C and C++, you may waste performance in pursuit of safety. Rust’s built-in memory guardrails allow a programmer to optimize with reckless abandon without worrying about memory issues. This, combined with Rust’s built-in support of forced simd opcodes via std::arch and crates that wrap this for ease of use like faster (which offers simd-capable versions of map-reduce, iter, and special data types for them), it’s much easier to optimize rust than C or C++.
The one last thing I think rust really needs to have a decisive all-around win over C and C++ for most use cases is a more generic logical proof system beyond just the memory stuff. That, using a security-focused RTOS like SEL4 for FOSS or INTEGRITY for compliance, could allow for potentially hack-proof, “mathematically perfect” software.
@@romannasuti25 Yeah I was expecting an effect like you describe.
And yeah, I think I've read about the SIMD prepared functions but forgot about it, that's a really nice time safer too, though technically you can create them in C++ too if u recall correctly. You just have to implement them yourself/use an implementation by another person.
A number of the comfort features of Rust are technically a thing in C++, it's just that because they're an afterthought it's hard to use them, setting up all of them is bound to come with a shitton of experimentation. Rust gives them to you for free.
Rust actually uses two intermediate bytecodes. LLVM IR and MIR, and there are plans to maybe even add a more high level HIR aswell
Thanks👍
This is a good video and well-explained, which I appreciate greatly. But Woooo! I'm old school. I started programming in APL, Z-80 and 8080 assembly in 1978. I went on to design two programming languages myself: R-code and LIM. From my perspective, an immutable variable is a CONSTANT. It's RIDICULOUS to default all variables to constants. Additionally, The format for displaying a line of text is needlessly complicated and makes it harder to read and debug. For one thing, it shouldn't need a macro. Jeezy Joe! Trust me on this, as I have read and debugged code in several languages. Rust would have made me get up and walk out. Python is crazy too, with the rigorous white space, but it's not as crazy as Rust, and actually is pretty useful when coding for the Pi. Therefore there is nothing on planet earth that would induce me to code in Rust. Anyone who likes Rust, please reply and tell me why you do. Maybe I'm missing something. All good wishes.
@4:12. For years I thought it was pronounced as “tooples” not “tuh-ples” 😆
According to Wiktionary both are used/correct. The etymology of the words however suggest that “tooples” is more correct, since it originates from terms like quadruple, quintuple, sextuple, septuple, octuple, being generalized to 𝑛-tuple in mathematics where 𝑛 is a positive integer, and all those (quadruple, quintuple, etc..) are pronounced like “...toople”.
I'm starting to learn Rust, but I'm wondering if the memory flaws in MODERN C++ are vastly overstated. For most projects it's a non-issue. How is anyone going to do a memory exploit of some silly game I develop, for example?
Most systems programming is done in C rather than C++ anyway, So how can anyone say that C++ is vulnerable when it's not used that much in systems programming? It seems that someone has said that C is unsafe, and then thrown the baby out with the bathwater.
Because C++ has pointers, just like C, it is just as susceptible to memory bugs. As for you silly game the problem is a) the libraries you link against, b) exploits involving any network activity including web stuff, c) anything that increases the attack surface of a computer... Finally, it depends on how popular your silly game becomes.
@@GaryExplains Well, why don't I just not use pointers in C++; pass references to objects instead, const if necessary? Also, if I don't have the program connect to the web, then I have no network vulnerabilities. Simples.
:Like I say, I think Rust oversells the whole memory safety thing.
@@zetaconvex1987 You see what you did there was take C++ and change it, now it isn't C++. Many companies have development policies about how a language can be used to minimize the attack surface. Also what you have done is admit that you need to limit what types of programs you can write using C++ for it to be safe.
what is the point of making a variable immutable if you can still let any variable be changed at anytime using Let, not only that, but you can also change its type? all its doing is making it a bit more long winded to do by having to type Let in front of it each time or am i missing something? I thought Rust was meant to be safe... how is that more safe than what you can do in any other language like D or Go etc?
Rust is statically typed not dynamically typed. Rebinding an owned variable to mutable is ok since you are the sole owner of that address and it does not change any non mutable references internally. So if you are borrowing imitable data it stays imitable. Its a bit to much to get into in one comment but since Rust not only tracks owners but borrows you cannot run into a lot of memory errors you can in other languages.
hey Gary -have you ever worked in any software firm??
Yes, of course, I was a professorial software developer for 10 years. I worked for several companies including Digital Equipment Corp and Reuters.
@Daniel Johnson 😂😂👍
a Variable that is immutable then it is not a Variable, it is a constant!
If you go back to mathematics, where the term actually comes from, it makes sense again: consider a function of one argument, e.g. f(x) = x * x. The variable `x` is not mutated, but represent different (hence "variable") values, as different argument values can be passed to `f`.
Hi David, an immutable variable is computed at runtime. Or it is created at runtime. (Eg. You can assign a mutable variable to immutable variable)
A constant is prepared/computed at compile time. That is, a constant is just an alias for a literal.
Trank you!
Got news that Linux kernel would support Rust to some extent like for writing modules. Came straight up here out of curiosity to know Rust 😂
Maybe I'm just old school but a "variable" that is immutable is better known as a constant. I really don't understand the point of this language pattern in rust, it's ridiculous.
I've lost count over the years of the number of trendy niche languages that were going to replace C or even C++. Anyone remember D? Didn't think so. C and C++ will always remain the standard languages for embedded software. There may be a case for using Rust in place of C as raw pointers and arrays are tricky for programmers to handle. C++ avoids many of these pitfalls by providing deterministic destructors for cleanup (RAII), smart pointers, bounds checked vectors etc. Modern C++(11/../20) also provides move semantics to distinguish between copying and exchanging data, as well as a whole host of other modern language goodies such as type inference, lambda expressions, direct iteration over collections, initializer expressions, etc, etc.
If you want to learn a better C, learn modern C++!
No, C++ is not the answer. It's horribly broken and probably can't be fixed. Rust is the first successor to C to actually figure out real memory safety without sacrificing performance. It's definitely here to stay
good video
Glad you enjoyed
did you say String:: is a class? As far as I know Rust has no classes, but traits instead
I don't get how UTF-8 is able to do fancy characters and even emoji's? Isn't that UTF-16's party?
UTF-8 can also encode all 24 something bit Unicode codepoints require. It's actually by far the most widely used encoding nowadays! In fact this very comment is UTF-8 encoded
👍
yo gary this is a rust crash course IMO