100 seconds of RUST by non other than the GOAT himself, Fireship! GO SUB!! / @fireship Recorded live on twitch, GET IN / theprimeagen MY MAIN YT CHANNEL: Has well edited engineering videos / theprimeagen Discord / discord
3:21 never understood the "Hello world" thing. I swear I struggled learning coding because I didn't understand what people meant by "Hello world" and why would every damn developer in the world use the same damn sentence. Please do like Jeff and use "Hi mom!" which makes more sense. Thank you! Btw, still waiting for the LegalEagle to weigh in on the Rust copyright bomb.
It's hard to overstate how much I appreciate cargo, having worked with St. Dennis Ritchie's blessed language and Bjarne Stroustrup's monstrosity for years. Having a single, unified build tool and package manager (that the entire community actually uses) had me thinking that there had to be a catch.
Abso-f'in-lutely. Not only is it the default tool for managing and building Rust projects, it is also very well made, even for manual build scripts. And the fact that you can easily extend it with user-land modules is the cherry on top. I've always dreaded having to install 10 different tools in order to configure, setup a project, targets and build pipelines when working with C and C++ code. Not to mention having to read, understand and modify someone's special syntax in each of those DSLs.
Making something 'mut' does not automatically put it on the heap. In the example "let mut hello = "hi mom"; the string literal would be stored in the data segment of the binary and the size of the reference to it (hello) is known at compile time and can be stored on the stack.
@@frydac ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-APfS3vgV9pU.html > "However, *mutable values* or objects with an unknown size at compile time are stored in the heap memory." ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-5C_HPTJg5ek.html - Original video, and people in the comments point out that the statement is incorrect.
But he makes the Windows people scared. 😂 I hopes keeps a sharp eye at the unsubscribe count. 🤣 Actually I noticed Rust on Windows is pretty cool too! I started learning it on Arch Linux by the way, but on the Windows side there's a lot going as well, like the windows-rs projects that basically makes all old API stuff available to the programming language for which people formerly needed Visual C++. I really don't expect see Rust replace any DotNet stuff, but all the native stuff has definitely a serious chance. Would be great to see Rust and C# both dominate the future on the operating system.
@@jongeduarddoes this mean I can compile Rust on windows now without having to download and install gigabytes of random C++ dependencies? I loved that it Just Werks® on a raspberry pi but not on windows.
As far as C goes - since it was among the first languages I learned, the memory allocation just felt relatively natural... You just learn how to manage memory.
I wish C was the first language I learned. I started with Java, from there memory allocation was a bit hard to understand when you've been coding with a garbage collector for almost a year.
Nah you shouldn't look it as just free and malloc. It's really that everything on the heap is tied to a stack variable, so the heap just falls off the stack like stack variables in C. How you keep it alive is returning the stack variables (part of the reason it's so darn functional despite being system lang).
yeah, this is a "more" correct view of it, which makes it super dooper, but its all about how much lying you do to learn. you start off by learning with max lies, then you slowly peel the onion
Technically a lot can be compared to C++ and not just C. For everything that uses the heap, the Drop trait is implemented in Rust. This compares a lot to C++ classes and their destructors. It's basically the RAII code pattern, a concept also used by smart pointers, which both languages know as well. The idea is that you hang the memory management of the heap behind a stack based connection of a variable, which internally frees itself by going out of scope. In C++ you can also directly use new and delete, or even the good old malloc and free, and you can do tons of things wrong, even worse than in C, but as a good habit you follow the above the above code pattern as much as possible to avoid most problems.
A lot of profesional C devs who think they know C, know relatively little of the actual language. I’ve met people who have been working as C devs for a decade, and have not read the C standard. They had no idea of what UB was, and a lot of times they’d blame the compiler for being buggy, when they’re the ones writing incorrect C and turning up optimizations hard. Heck, the people writing the standards are still learning how a lot of stuff works, things like pointer provenance are still in active development on C.
I’ve read the C99 standard as it was necessary to be able to do my job at the time (devops) but when other engineers find out that I’ve read it, they treat me like a lunatic with deviant interests. It’s really not that long.
"However, mutable values, objects with an unknown size at compile time are stored in the heap memory" Incredible, every word of what you just said, was wrong
@@ThePrimeTimeagen I mean, there are instances of objects with unknown size at comptime, but the only example I can think of are trait objects, which is a fairly advanced topic. Neither mutability nor general heap allocation implies unknown sizes.
2:30 one thing that seriously impressed me about manual memory management with free and malloc is just how many useful things can be done with destructors as you can predict exactly when they will be called and in which order. ...which also has the side effect of encouraging some programmers to put things there just because they could, even though they absolutely shouldn't.
Once you start doing RU-vid, you understand how hard it is what you and fireship do. It's unbelievably hard to communicate clearly and to explain to everyone in an easy manner.
I'm a Go engineer who's been trying to learn Rust as of a couple of days ago. I feel like even if I don't ever work in Rust, it should at least make me a better developer.
Hey guys. my work has been really busy so I haven't really spent much more time on it. I bought two books on Amazon and have a project I've been working on to help me learn Rust. Maybe this next weekend I'll put some more hours in. I do have to say, I really like Rust but Go still is my "Go"to... heh and I'm hoping at some point to change that.
Wait a minute. malloc and free are far from simple to work with. Sure in the simple case that you malloc at the top of a short scope, do something with it then free it at the end of the scope it's easy to see what is going on. But: 1)When malloced objects are passed into or returned from functions it is not clear who is responsible for freeing them. That needs to be documented and the documentation needs to be read. 2) When malloced objects can live on outside the scope in which they are created and then perhaps passed around to other parts of the program it can be difficult to keep track of who is responsible for freeing them. Leading to memory leaks. 3) Like 2) but with threads thrown into the mix. But this is all tied up with use of pointers... 1) Perhaps one forgets to malloc an object, perhaps thinking it was done elsewhere in the program, then we have dereferencing a null or uninitialised pointer. 2) Perhaps one forgets an object has been freed, then we have use after free errors. One has to do a lot of bookkeeping, busy work, to keep track of all this in ones head. Or worse still the heads of a large team. Rust of course does all that tedious checking for you. What is not to like about that?
Primagen: "Who uses rustc" Me who's only used Rust for a few months: "Right? I literally only used rustc once in my life, Cargo is always a lot more practical."
I work with a guy like this, while presenting he continuously nods his head to show that he's pleased with your message, then you say the smallest thing that displeases him and he explodes into a 5 minute rant about the dumbest shit you could imagine. For example, the pronunciation of "mut". 😂
The biggest advantage and hurdle of Rust in my opinion. Advantage: Cargo exists.... and is already way better than python's PIP in my opinion. Like you need to manually create a virtual enviroment for your python projects and initialize it every time you work on it, meanwhile in Rust, all you need to do is type cargo new (Project name) and boom, you have a project folder with a virtual enviroment to which you can install the crates, AND a local repository all set up kinda automatically. (Also I never had any problems with cargo, but I did have a few with PIP) Disadvantage: Well, I know this is a beginner issue, and I am a beginner, so I'm sorry for this vent but LOOK AT THE INSANE AMOUNT OF SYNTAX THIS LANGUAGE HAVE, NOTHING MAKES SENSE WHAT THE HELL IS A LIFETIME? WHAT IS REALITY? WHAT IS GOING ON? (Still better than JavaScript tho, judging by my small experience with it, at least when I declare a float 32, I know it will always quack like a float freaking 32, and that the language won't try to add a string number to a float number.)
lifetimes are only hard until you learn more. It is a quit moment. The only way to learn why they exist is to learn why they exist. It is painful. It is development.
I think the dark reader bug has something to with your os or browser color scheme, try switching off or just setting it to any color scheme. Then try switching it in dark reader.
Rust really only works if you understand how the lower level C stuff. Like, I find it easier to understand borrow checker errors by asking myself “How would I implement this in assembly?”
writing a berkley socket, non blocking etc.. in C yeah it is involved.. ONCE. then you have you network module and it just works. same for associative array. I have my hash module that provide half a dozen of variants, which covers all usual and unusual cases. People keep talking about C as if you had to start from scratch every time
2:15 I use C++ so I am familiar with new and delete, I have no problem with these functions after many years of trying, and learning, I kind of figure it out how to write very stable code that can run for decades.
i learned C way back in late 2000s in high school and from what i remember you initialize everything at the start. which makes more sense to me in terms of organizing a document. like python i can use i for iterations an infinite amount of times as long as it's in a different loop but i can also write the same program structured 1000 different ways while C might only have a few reflections that'd work
hey guys i am a java developer and i want to learn rust which books do you guys recommend. Also what can we build using rust like rest APIs? microservices?