ERRATA 3:51 I line 3 in the second code snippet is supposed to be `b = "newname"` (thanks VVill!) 1:02 Go is not object oriented, my mistake (I suppose I saw 'interfaces' and extrapolated from there) I'm delighted
"object-oriented" means different things to different people. Newer languages tend to be ones which meet some peoples' definitions of object-oriented and not others'. Personally, I am very strongly attached to what I understand to be more classical understandings of OO -- from before C++ got popular. That older notion focuses on encapsulation inheritance of behavior, and that aligns very strongly with Go's interfaces and Rust's traits. Java, C#, etc are based on a kind of reimagining of OO, which was popularized by C and C++ and which creates a lot of the common problems people now associated with the phrase "object-oriented"
@@klikkolee "which was popularized by C and C++" Wdym C ? C is purely procedural. Also I think you are tried to imply 'abstraction' there. I think inheritance was always the most error and headache inducing, despised feature of OO besides abstraction and by a long shot, encapsulation. I was surprised to find that rust supported inheritance with traits, that's one OO feature that I didn't want in rust but yeah.
taking from another perspective, you can only crash a supercar one time, and if you live, you learn a lesson, the same cannot be said about C, if the stress of crashing hundreds of times doesn't kill you, you may eventually learn a lesson
"Rust has an algebraic type system, and if you know what that is, you already know you want it in your language." no statement exists that is more perfect
@@NoBoilerplate Absolutely. I honestly wonder why it isn't more common. Actually, I wondered that before I even knew there were languages they had them. This was my immediate thought when I heard about enums for the first time...
Even if you do like dynamic language’s ability to just set something without specifying the type, Rust also lets you do that through type inference, which is pretty much having a cake (being able to define stuff without worrying much about specifics) and eating it too (it’s still static typing and you get all its benefits)
Even more important is the fact that Rust has enums and traits. There genuinely are cases where the type should be "dynamic" at runtime, be it from a set of known variants (enum) or generic based on common interface (generics + traits). The problem with dynamic types ala python/ruby is that they go too far.
also because of .into() you often dont have to worry about choosing a convert function. Honestly Every staticly language should have something like the From trait.
Type inference is not the same as dynamic typing in languages like Javascript. Sure Rust can guess a type from how you use that thing later in your code. But the type is known and fixed at compile time. By contrast in a dynamically typed language the type of a named thing can be changed as the program runs. Which might seem convenient sometimes but can also make it hard to figure out what is happening at run time and does a good job of buggering up performance.
@@heater5979 You are right, of course. But I don't see where you disagree with kat 🙂 You mention two characteristics of dynamic types: no type signatures needed, and mandatory RTTI (runtime type information). kat was simply saying they liked having the first one without the inconvenience of the last one. I agree with both of you on that... Rust has RTTI as well in a couple different ways, dyn traits being one of them. It is just not mandatory. Imho, idiomatic rust only has types signatures as part of function signatures, inferring the entire function body, which it is really good at.
To anyone starting out with rust: dont let the immature ecosystem scare you from using it . Unless you’re writing extremly critical enterprise software, the most popular library for the thing you want to do will have everything you will ever need
@@parlor3115 by that i meant that if you want to write enterprise software purely with rust, the most popular library might not suit your needs and you would need to make the functionality yourself. But if you have the resources to do it or just want to use rust here and there, use it
I'd hesitate to even call it 'immature' at this point! There are the same number of packages on crates.io as there were in npm in 2013 - I was a web developer then and we sure thought it was mature and the de-facto standard! XD
Unfortunately where I would need it most (for web3 stuff), there isn't a good crate with full functionality and responsive contributors at the moment. That's why I'm still using Go even though I sacrifice some performance. EDIT: found ethers-rs which comes close, need to look into it.
My reply keeps getting deleted :( I am going to mis-spell things to get around the filter. Sorry for the stroke: It's a better s0ptify analysis tool. Gives you more ifno than exitsing onez by uzing files from GDPR data request. Can get all podcats/snoggs you've listend to for lifetime of acct and a lot more cool listning data. If I type more I am afraid this comment will get hidden
@@2raddude ive ran into the problem of replies getting like, shadow removed a few times as well. It might be that your comment contains some blacklisted word, or that youtube thinks youre a bot or something because you didnt watch any of the video before commenting (clearly youtube's comment bot prevention is still very bad though)
Thank you. Go, Rust, and Zig are not enemies. They are friends! Its interesting that you see Go as a replacment for C++. While it was designed as one, I tend to use Go where 10 years ago people would have used scripting languages: simple CLI apps, webservers, small tools. I also lean towards it for prototyping or 'throw-away' code, because the Go compiler's incredible speed makes iteration faster there. I use Rust where I need performance or safety and can afford to write from scratch. When I write Rust code, I'm confident that it's correct. In general, it's my preferred language for hobby projects. Rust also has best-in-class documentation, dependency management, and publication tooling. It's my personal favorite, so that's a tiebreaker. I don't use Zig (much, yet!), but when I do, it's where the pre-existing infrastructure expects C and C's conventions (i.e, in the world of device drivers, syscalls, and OS internals). Zig is still a bit immature, but the project is rapidly improving. Like it or not, the world we live in is built on 50 years of C, and not everything can or should be rewritten in Rust. Zig helps bridge that gap. The Zig community is incredibly generous w/ their time and expertise, too. They've helped both the Go & Rust projects, despite being significantly smaller.
You're right, I shouldn't have pitted these languages against each other, especially as I am not expert in them. I hoped to make it clear that I too love them all! (but I REALLY like writing correct code, so Rust is my fav!)
🙂 "Excuse me !" I thought, GC not GC they do not play in the same field regardless. However I would not write a microservice in C++ perhaps. Compare C++ to Carbon maybe 🙂 but great content nonetheless
Imo Zig and Rust are very philosophically distinct. Zig wants small language approach, where the code is as upfront as possible about what it does, with as little unintuitiveness as possible, whereas Rust wants a big language approach, where the code is adorned with high level abstractions and powerful expression and clear function contracts are valued over immediate clarity of the underlying workings.
I wouldn't say that Go wants to be a better C++. It's type system is very different, it's way of working is extremely different. I think of Go as a simple-to-reason-about pragmatic fast compiled language. It's interface system is basically a simplified, prettier (sue me) version of Rust's, with less options. Go tries to be simple in everything. For instance, things such as map functions etc. are not in the standard library. Indeed, Go does not even have a set. I think Go is it's own beast. I've seen people compare Go to Python, and get extremely confused. I've seen people compare it to Rust, and call it ugly. I've seen people compare it to C++, and call it incomplete. It's none of them. I think Go's main strength lies in it's simplicity of composition: the simple interfaces really allow for things such as hexagonal architecture within your application.
@@sohn7767 yeah I agree. Mind you I'm in the camp that a required GC precludes being a systems language (an optional one like D is fine since it gives choices)
I've been told that Java was sold as a better C++ at the beginning, so maybe not too far from the truth. But you're right in that GC really does separate languages fundamentally
I used to be primarily a C programmer, a little bit of x86 ASM, and C++. I remember seeing videos like this and "C turned 50 today, so I decided to learn Rust" by Low Level Programming, and wondering what all the fuss was about. I eventually decided to give it a try, and it quickly became my favorite programming language. To me, it feels like what C++ should have always been. I know you made another video about this, but it really feels like in Rust I can focus on actually solving a problem instead of remembering to check for nullptr and use copy methods, all without introducing any runtime overhead. I write some code, cargo check, cargo build, then move on to the next problem. I don't need to study a method for an hour to make sure I didn't just implement RCE.
@@nicktreleaven4119 Hi Nick, that a Cornish name? I'm from Cornwall! Anyway, you're right that Rc/Arc add a small amount of overhead, but most of the time we don't use them, Rust's normal ownership semantics works great 99% of the time. However, even when we have to use them (shared mutable state for example) Rust is SO FAST that honestly unless you're comparing it to manual memory management in C++, Rust will still be faster. By the way, you can still pass around a raw pointer in Rust, just like in C++, and it's just as unsafe ;-) On pure mathematical benchmarks, its something like: C - 1x Rust - 1.1x Go - 2x Java - 4x Javascript 4x (yes I know, a trillion dollars of optimisation has made js as fast as java I was surprised too) Ruby - 20x Python - 80x So if you're comparing Rust to, say, Python, that ~77x speed bump covers a lot of sins! XD
@@NoBoilerplate yes Cornish but I'm from London. Yes rust is fast and it's probably great for when you only need unique ownership. I just think reference counting is slow because accessing memory is slow. But it's still a good option. Decent Garbage Collection is typically faster but tends to use a lot more memory for efficient collections. Last I heard rust didn't support tracing GC. But it is a great language, I hope they can improve it even more (e.g. for generic async functions).
@@nicktreleaven4119 Amazing, I'm Cornish but living in London! What a small world. Yeah, Rc is slow, if you use it. Rust's ownership has zero cost, ie nothing happens at runtime, the compiler's proved you've never used a reference after it has been freed etc etc. Best of both worlds, with no, as you say, heavy GC. Makes it trivial to run Rust on embedded devices or low ram environments (such as in-browser). Have you seen my other videos? Not having a GC is a very unusual thing, and the way Rust solved memory safety accidentally gave it superpowers, here's the video where I explain this: th-cam.com/video/0rJ94rbdteE/w-d-xo.html
I love this stuff. I'm retired, now, but I used C back in the day, close to the metal, for physics experiments. Before that it was assembler and sometimes machine code. But C does give you serious foot wounds on occasion. Rust has proper ideas to stop that while you still have real control over the runtime. (In my case, small computers/microcontrollers , networked, doing monitoring stuff). Great series, keep it up.
I wish I could learn low level programming with some guidance... Do you have any learning resources recommendations, or know anyone who teaches this sort of stuff?
@@avidrucker How low level we talking? If it's "to the metal", look at the documentation (if there is any) and make a table for all the registers for the prototype program _after_ you have a high-level idea of how the program's logic should work. Sometimes, the fastest way to get an answer is to have a table with the answer already calculated for you...
@@avidrucker Raspberry pi's are not a bad bet; you can get general purpose machines, to little pi zeros (still capable) or to microcontrollers. There's also a thriving community, with many projects you can get a feeling for. You can cross-compile using rust, or C or java (those are the ones I've done. Java won't go on a microcontroller. But it will work on a pi zero. Slowly, but it'll run a website. Ish)
Hi! There are 2 things in Rust that I personally like very much as well: First of all literally any compound statement is actually just another expression, returning the result from a final expression inside it when that subexpression is not followed by a semicolon. And even if it hasn't such an expression, it still returns a value, namely the Unit type, which is an empty tuple. There's no void return type. This is non-typical for C family programming languages, and comes from functional language influence. It's something that I really mis in C# for example, which is also a very great programming language by the way (I work with it for 20 years already). Second thing that I like is that Rust's object oriented way of programming chooses composition over inheritance strategies, which is good, because inheritance causes many problems.
Wow. This guy’s talking so well about a compiled language that I feel he’s a script writer! So many statements that would be great chapter names ! Subscribed.
9:30 if anyone else is confused, I looked it up and Rust has implicit returns, so the last line would be equivalent with `return Order(tris)`, which would leak memory outside the function scope.
I'm a frontend dev, so basically as far away from C as a dev can get. But I've been looking into Rust for my bachelor thesis project, I was originally gonna use C++, (cause I need the kind of speed that makes JS just not an option) but the memories from first year classes are painful. I think you pushed me over the edge, so I am installing Rust today, and giving it a spin to see how I like it.
@@hermes6910 Yea. it has really cool potential to it. Right now, I don't have the time to really dive into WASM at all, but it's definitely something I need to try someday.
4:37 - This is a _very_ useful way to think about the transfer of ownership, at least for us old dogs (who were rather mature programmers when C came out) learning new tricks.
I've always said, statically typed languages make reading code much easier, because I can be sure, that the things I see will always be that way. Dynamically typed languages make writing code much easier, because you can get things done without thinking too hard about the "what if's". Experience tells us that programmers spend much more time reading code, than writing code.
As a python developer, typing every variable is very difficult work. But every line written in Rust, I think that it is very beautiful language. I love Rust and Rust love me.
As a python developer myself, I sympathise! Mypy is great, but it's SO MUCH WORK. However, you're wrong: In Rust, type inference means that you only typically type a function signature, eg, fn send_email(recipient: EmailAddress, client: EmailClientConnection) -> Result {} What wonderful documentation! I bet you can already imagine how to write the function body :-D
well done! And do check out Rustlings and Rust By Example - if you need any help, ask in #newbie-advice on my discord server (links in the description!) GOOD LUCK
What do you mean Go is a better C++? Go has a Garbage collector. I would say Go is more of a better faster Python/Javscript thing, because it's still slower than C++.
Better code design, not faster. I have no clue if it is actually better design, never used Go and I've only watched a stream of someone using it, but that's how I interpreted it.
Go is more likely in the class of Java, C# and the likes, it's not a (dynamically typed) script language like Python/Javascript though etc. I would consider Go to be even lower level than Java and C#, not a real system language like C,C++ or Rust, but close to it. The Garbage Collector is compiled into the binary, so it has a rather large runtime, but it can run on its own. Rust does also have a (much smaller) runtime, it's all the syntax sugar magic, that the compiler miraculously translates into the binary.
Depends on how you define speed. For someone like me with extensive knowledge of Python and very little C++ experience, who just wanted to write some CUDA, C++ is infinitely frustrating. It keeps breaking in weird ways and it's impossible to find good resources that aren't horrifically out of date. And given the history of C++ it makes a lot of sense that it turned out this way. Mistakes were made initially and they've been trying to paper over them ever since. C++17 already filled 1400 pages and C++20 grew to 1800! Who is supposed to read, understand every minute detail, and memorize all of it? So for someone like me, who's ripping his hair out googling obtuse compiler errors and valgrinding for hours to find memory errors/leaks, Go is infinitely faster. I get to actually finish my project and it really doesn't matter that it spends 0.05% of its CPU cycles on GC.
@@jfolz You are talking 'faster to write', while they are talking 'faster running'. Totally different. And at a professional level, they are all pretty close in how fast it is to write it. All you've actually said is that you are not a professional C++ dev.
@@jursamaj above was a discussion that go being a better c++ was referring to the language design rather than the performance, and i think riDDimann had a point
I think one major selling point with Rust is scalability within it's codebase. The Ruby team for example, chose to write the new JIT compiler (YJIT) in Rust because the code became too unreadable and complex.
@@theroboman727 But the rust html rending also failed, it's just the css engine and that is something that they could have done also in C++. Servo was expected to be much much more.l
Very nice, what I missed, the rust traits which allows to put features on existing and new types, for me a key feature, think about the iterator trait, once implemented for your type you can use all the iterator functionality implemented with rust. That is an extreme form of re-using code, …
I am absolutely in love with Rust, and agree broadly on the thesis of this video, but having programmed in C most of my programming career, when you said "Is that all you want? A better C?" I almost dropped to my knees crying. It is all I want, I would love that very much
I think what would convince me more is some going through a significant project, Handmade Hero style, on TH-cam, showing how they think through the code while they write it. I have a lot of little problems with Rust while I write it, sometimes the docs generated by cargo make my eyes bleed, and I don't really have a good IDE to help guide me through the syntax, so I would get more use out of a practical hands-on video at this point. If you have one to recommend I'd really like that.
I would definitely follow a rust tutorial series from beginner to advanced that explains why we do things. Your voice is so calm:) Rn it is just watching tutorials, and then watch these videos for more in depth topics
Thank you so much! My next video (eta thursday) will be more of a tutorial. If you would like a scifi story narrated in my voice, I have great news! th-cam.com/video/p3bDE9kszMc/w-d-xo.html
I just like listening to you speak about rust. I haven't picked rust back up in months. I'm still sitting here with my typescript enjoying myself but whenever you post.... makes me wanna drop everything. Might be your soothing voice. Might be that you're talking about Rust. Hard to know.
6:23 In Python if you write name: str = 13, the program will run but any linter like Pylance will tell you that there is type mismatch. So you know what type variable should have.
your segment about lifetimes was great. and the order / account example really helps to understand it. would be great to hear more about ownership, borrow checker and lifetimes
@@NoBoilerplate cant wait. i have read some rust books. i feel like i get it, but i still dont really use it in my rust code. only for a &str in a struct. but i usually end up using String and getting rid of the reference. The order / account example showed me a new way to see lifetimes :-)
Is it deliberate or accidental that the unsafe code snipped presented around 10:35 actually has undefined behavior? (Hint: Run it with “miri”, it’s available to install on nightly via rustup, or you can also find it in the playground under “Tools”.)
Just now discovering more of your illuminating 10 minute videos. Usually I listen to coding vids at 1.5 or 1.75 speed...while doing something else. Not so with your stuff...I'm pausing, going back...yet at the same time, relaxing! Love your style, feels like you may have been a philosopher in a past or future lifetime 😶🌫
Thank you so much! Yes I find that many coding videos have great content, but are too slow. I assume my audience is smart, and also knows where the pause button is!
I am starting to like Rust. I still want to build a project from start to finish it with, but from what I see so far it is pretty good. It is funny that concepts that I apply for C and C++ regarding memory management are enforced with Rust. And finally a compiler that is smart and tells you the error in a human-understandable way. I am a bit scared about integration with C libraries / C++ libraries, I hope I do not need to create wrappers and converters for it
It is remarkable how consistent you sound across your different works of media (at least this and the Lost Terminal Broadcast). The voice, the patterns of speech, the precision of the expressions. Very recognizable. I like it.
You do me an enormous complement, I've always been impressed by musicians that sound IDENTICAL on stage as they do on the album. Two bands come to mind here: Rage against The Machine and the Darkness. Both surprised me by sounding SO similar that I initially thought they were lip-syncing! But they weren't: I was looking at thousands of hours of practice. The album wasn't a fluke: They could do it again and again. I practice a lot, it's only polite when you are giving your time to listen to me! Thank you again.
There are also a new generation of proof oriented programming languages which bring another area to explore in the programming languages landscape: Coq, Lean, F*, Agda, Idris, ATS, HOL, Curry, Mercury.
My interest in Rust is DIRECTLY inspired from learning about formal systems (we did B and Z) at university. I've been trying to find a popular language I can do real work in that I can formally prove. I thought Haskell might get me close, but it's not quite popular enough. Rust of course isn't a formal language, but it has enough of what I liked from Haskell, and is popular enough, that I'm ALL IN!
Thanks for all of your rust videos. You've just came in time for me to choose a language for a new project. And I'm looking forward to use rust and become a part of rust community as well :)
Fantastic! Welcome! The best place to get started is the official book, and also Rust by Example. I also came across this today, which is a great overview learning-rust.github.io/docs/a1.why_rust.html Have fun! And do join the discord if you want tips or advice.
I'm not entirely sure that the whole "reference vs value" problem of remembering which types follow which rules is fully gone: in Rust, you have to remember which types are Copy and which types are not. It's definitely not as big of a problem as remembering if something is a reference type or a value type (especially thanks to trait bounds) but it is worth noting.
Wait, what?? Can't you choose whether you want an argument to be copied or referenced? In C++, f(T& arg) is a pass-by-reference function. f(T arg) is a pass-by-value function.
@@nothingtoospecial777 Rust lets you do that too, using similar syntax (`T`, `&T`, `&mut T`). However, references aren't magic, they act just like any other value: they're pointers but with compiler-enforced lifetime annotations: you have to annotate when you're passing by reference and when you're changing the value pointed to rather than changing where the reference points to.
@@nothingtoospecial777 It's not "copied or referenced" in Rust, usually - it's "moved or referenced". Once a function takes ownership of a parameter (the parameter is moved into the function), it is no longer usable from outside the function. You can control whether a variable is passed by value (moved) or by reference in Rust. Here's what I'm talking about: There is an exception to the rule about moving: types that have the Copy trait are copied, not moved, when passed by value, meaning that the original variable is still usable outside the function (since the function only owns a copy). You cannot directly control whether a type is moved or copied. If the type derives Copy, it is always implicitly copied, and otherwise, it is never implicitly copied. You can make functions that require their arguments to be implicitly copied, or you can (probably) manually copy bits from one variable to another, but it is still sometimes necessary to know if something will be implicitly copied or not.
@@Sean-of9rs But types that are Copy just have the "bonus" of sticking around after being moved. And if you read code that uses a variable after its been moved then you automatically know it's Copy. You don't often have to think about whether a type is Copy or not when reading code
@@olestrohm Fair point! It's mainly when writing code (and specifically functions) that it becomes relevant, but even then it can be learned relatively quickly.
The thing about Rust's ownership system is that it makes the *compiler* do what you would have to do anyway. Data ownership and lifetimes do not just go away and stop mattering because your compiler allows you to get it wrong. That's why Rust is so neat: For a newbie, the borrow checker provides training wheels that keep you from falling over, and once you internalize the rules of programming and gain expertise, it'll fade into the background but will still be there to catch you when your caffeine levels dip too low.
Rust's syntax looks very scary to me as a beginner but I really want to start learning it, I don't know if rust is a good pick for a first language, I have some experience with programming but never decided to try and get into the nitty grittys of a language. your content is very inspiring and I hope you well, thanks for showing us rust!
As someone who started with C(++), java, and javascript and has recently learned rust, rust is definitely going to be the hardest to learn. That said, as long as you have a good editor that can feed you rust_analyzer (language server) hints/warnings/errors without having to go back and forth to a terminal shell, I'll say that rust can be a great first language. The language server will give you lots of directed help at how to write better or more idiomatic code and fix errors. Dynamically typed languages leave too much freedom for a beginner to build bad habits and avoid learning important concepts IMO. C/C++ (moreso cpp) are the default first languages in uni for good reasons: learning about memory, data structures, and algorithms. I think rust strikes a great niche of being low level AND modern without the baggage of C++'s long history (you have 10 different ways to do a thing right and many more ways to do it wrong lol).
Nick has the right of it. If you get vscode set up with the rust_analyzer extension, you'll have a rich coding experience that holds your hand. Try the Rust Book for starters, and keep at it, and ask for questions when you get stuck (maybe on my discord!) doc.rust-lang.org/stable/book/
Whatever was said about Java/JavaScript being 3-4x slower than C while Go being 2x is not true. In most benchmarks you will see C# /Java / Go very close to each other, with most edges being given to C#. The JavaScript part is correct.
My apologies, I tried to be as vague as possible, as benchmarks differ SO much - I didn't include C# because though it's popular, it's not on my linux radar - I'll include it next time!
@@NoBoilerplate No need to apologize, you are doing great work here. You should try C# on linux. I exclusively use it on macOS is it's actually amazing. Have a wonderful day.
I started a c# job recently and I'm exclusively on Linux. .NET is fully cross platform now, and a combination of dotnet CLI and vscode makes visual studio totally unnecessary for me. I'm currently learning how to configure neovim with Lua to take vscode out of the picture too (your video on the rust lightsaber pointed me towards AstroNvim, from which i found LunarNvim, whose creator has a video tutorial series on building basically that from scratch)
Thanks for the videos about rust :) Rust is like accouting! You need it to run a smooth business, it is a hassel, but it is there for a reason. A rust program is like business unit, the programmer is responsible for following the "accounting rules" of the borrowchecker and the linter, no illigal transactions, no horsing around and if the "budget" of the program is correct, all is kosher! Rust + Rust analyzer is the coolest programming experience I've had, it almost feels like the code is writing itself (except when I fail to grasp what's going on, but then Shepmaster's answers on stackoverflow is always one google away) and I do love implementing strucks, enums and traits :) 🦀
10:00 C++ (not C) has templates but there are also constexpr, consteval & constinit that are just normal code and I think it's very unjust to not properly display such crucial points. Generally, your videos give a sense of prejudice sometimes, like you first think of what you want to say and then you try to somehow reason around your pre-determined opinion, ignoring everything that may invalidate the statement. I'm not saying you're purposely doing that, but sometimes your arguments feel very forced and it's a bit disappointing to have great explanations and essays mixed with this unnecessary litter. I, as a C/C++ enthusiast, believe in the power of Rust and I actually think it's great and in many ways better than other languages I know. I got inspired to really get into Rust (partially by you and I'm very grateful for that) and I've found it to be one of the best, if not the best, experience I've ever had with a new language. There's absolutely no reason to artificially present Rust as better when there's actually stuff to talk about and come to that conclusion. But please once in a while revise your scripts from the perspective of another language's user and think about how their view might be affected by unfair treatment towards their favorite "toy", which sometimes boils down to easily fixable things like poor research on fundamental concepts of languages (eg. Go isn't OO) or choice of words. I'm sorry for being so direct in this comment, but this is a thing that's annoyed me in many videos already and I hope you can incorporate my criticism into upcoming videos. I'm thrilled to see more from you, keep up the mostly good work and also I like your approach to error-correcting your videos, which I've found brilliant! No hard feelings
Totally agree. Rust is a great language, and he definitely has many valid points, but to praise Rust without giving other languages a valid or comprehensive explanation is just not cool .. i do enjoy the languages honestly, but i also believe different languages serve different purposes, it should be okay for someone to enjoy using languages A, language B or language C at the same time.
Really really loved this video. I had stopped watching programming videos on TH-cam for couple years now since all these channels have became repeating the same thing and also I don't like their general view on programming. I'm glad this one popped up on my recommendations. Coming from a JavaScript/TypeScript world, I've always wanted to take a look into Rust and see how it works and compares to its other related languages, now I actually I think I'm inspired to start from somewhere with your content and even start learning Rust.
I'm so pleased! I too noticed a lack of this kind of careful video. I'm doing the best I can, and learning each week! Do let me know what you think of the fest of the series, there's 11 videos so far, all in this exact format. th-cam.com/video/Q3AhzHq8ogs/w-d-xo.html
@@NoBoilerplate I've already watched all of them, they're great! I like how every comment under the videos are so informative, it's like everyone here are learning together.
8:07 In the game osu!, the GitHub issues page specifically has a bulletin for performance issues caused by the garbage collector-it's written in C#. Sometimes people experience lag spikes in the middle of gameplay because the GC just _decided_ to clean some stuff up, taking way longer than a frame to do so. Nasty stuff.
8:16 as a random side note, Nim actually has a GC that works fairly well in (as far as my personal experience goes) at least a few embedded devices, e.g. the ESP32
C does not have a templating system. It has macros (as does also C++) which are, as you point out, a text substitution system. When you say about templates being "nightmare to use" it's partially true, but they have nothing to do with macros or just text substitution. I get you like Rust but there's no need to skew the facts to make it artificially look nicer. I think it's quite nice on it's own.
Never ascribe to malice that which is adequately explained by incompetence! Thank you for the clarification, I'm new to C and C++. I now see the difference between C's macro system and C++'s template system. However, I think I'm right about them being text manipulation, though, right? You can't execute arbitrary code at compile time and use the results of those executions to build new syntax like you can in Rust?
@@NoBoilerplate No. The c preprocessor (macros) is a legacy text manipulation facility with a number of inherent caveats and limitations and is present in both c and c++. C++ templates are a whole different beast and can be used as essentially a type system for types (i.e. to create code parameterized on types) and in that role is far more powerful and flexible than any "generics" system I've seen in other languages, by far. It also can be used for heavy metaprogramming and compile-time code execution. The former used to require quite a lot of boilerplate but it's much more terse these days syntax-wise, and you can do the latter without using templates at all. EDIT: grammar
"we have to know, through convention and experience "!! I've been saying this for years when teaching beginners about types. It's the reason I don't think it's wise to teach languages with runtime types to beginners.
Agreed. It's far better to teach them a strict system first, then once they become a bit more comfortable it's fine to use runtime types. That's one of the reasons why I think Java is a good language for a beginner. Because of the highly explicit syntax, you're telling the system everything it needs to know. For that reason it is highly educational. Because the things you wouldn't think of in a language such as JavaScript or Python, you have to think about in Java. This is despite those very things being just as important in other languages.
@@CottidaeSEA I started with python, the moved to java. Head first java taught me more about programming then multipule python books and courses. Now I'm moving to rust
A course I tutor at my university (aimed at people with 6 months or so of programming experience) teaches people JS then moves them to TS whilst explaining why the weak typing of JS was risky in terms of code safety.
@@miguelguthridge I think Rust would be a great language to teach at university. Imagine the subjects this single language can be used to teach: - Bare-metal robotics - Reactive webgl websites - Database apis - REST apis - Web programming the list goes on! This is one of the reasons I'm most excited about Rust: I might never need another language for 20 years!
I kinda want Rust's memory management in a Python interpreter. To me, that is the most compelling feature and the only major improvement that could be added to Python other than optional strict, static typing. (To simulate the latter, I use assert preconditions.)
@@NoBoilerplate it might be, but it doesn't turn my stomach sour like JavaScript. I'm unconvinced that I can use Rust to do all the things I do with Python, for example having a multiplatform contract that commits to a single piece of code by its content hash.
@@k98killer That seems like a pretty normal thing to do in most programming general-purpose languages, why can you only do that in Python? Here's some concrete things: - Python can't compile to webassembly, - nor run natively on bare metal chips (micro/circuitpython isn't python, ask pip!), - It runs 72x slower than rust in single process benchmarks and HUNDREDS of times slower in multiprocessing. - and I guarantee there are bugs in your code that you'll only find in production, or maybe NEVER. They'll just be a lingering feeling that something is hidden under the waterline, waiting to bite you. Have a look at th-cam.com/video/Q3AhzHq8ogs/w-d-xo.html where I dig in deep, and even give examples where Python falls short.
@@NoBoilerplate I'll check out that video. On the code/contract commitment topic, you could commit to the source code with Rust, but then you would have to recompile before running every single time to ensure you are running the code in the commitment. Of course, there is an implicit security assumption with implementing this in Python that the interpreters will be compatible, so it isn't that different. The secure distribution of software is still technically unsolved. I suppose that the largest issue preventing my use of Rust is that I haven't been using it, so I lack the confidence to build things with it. Do you have any resources for Rust TDD that you would recommend to a Rust noob? Edit for side note: I wish Python had an immutable/frozen dict type. It really does not make sense that it does not.
I'd heard about Rust before these videos, but actually started learning it after these came out, and now I'm rewriting old Python projects in Rust. On another note, I love the attention to detail here, and the fact that the errata comment even exists shows the quality of this channel!
Congrats on the enthusiasm, but I'm surprised that you would write something in python and then move it to Rust. Python is slow, but it's a great scripting language, therefore, it's being primarily used to ease of use of actual performant code (as in, write a lib in Rust, control it's API through Python).
@@GonziHere For context, I'm not actually working as a developer or anything, I'm a bored teen learning Rust. Rewriting old programs gives me an end goal in mind, so I find it easier to learn the language that way (and can visually see my growth!). Also, because I have to handle errors instead writing something that "just works", I think I become a better programmer.
@@GonziHere Oh and do you have any resources for learning how to control Rust libs in Python? I didn't actually know you could do that, that sounds really cool
@@camerontaylor8709 Oh, I see, as an excercise, it's a great idea! I cannot point you to a specific resource, but it should be googleable because that's really typical use for python.
1:48 "But a fast-executing language that crashes all the time, is like a supercar... that crashes all the time." Richard Hammond (and James May in "A Scandi Flick"): _nervous glancing_
I'm an ameteur programmer. I really only know java basics but have been looking for a language i can do basically anything i want with. Your vids have sold me on Rust, gonna make my Lightsaber as soon as i can.
Your lifetimes order_example() doesn’t compile. The tris Account variable has to be created outside that function. You can create it in main and then pass it into order_example but it won’t compile if it’s owned by that function.
~ 7:00 I would argue, that the memory safetey of a language is independent of garbage collection? To me memory safety means no dangling pointers or references. On the other hand, garbage collector or not, one can always have memory leaks. One could even argue, that a garbage collector may help detecting lost / no longer accessible memory by analysing the object graph.
I see what you mean, but to me memory safety = a human doesn't get involved with memory management. Either you free up memory when it's not used, or the garbage collector does. Either method can cause memory unsafely, it's just that the garbage collector has perfect knowledge and doesn't make mistakes. (it can have bugs that cause problems, of course) By the strict definition of systems languages, memory leaks aren't a safety problem, they're an operator problem. In GC languages, they represent a bug in the GC.
I wouldn't call Go object oriented when comparing it to C++. It does OO very differently. While calling it OO is technically true, it kinda implies inheritance, which it very much does not have.
4:45 That's not pass by reference. It's pass by "move", which does shallow copy after compilation* (copies the address of the vectors data, its capacity and length), where as pass by reference "copies" only a single value: the reference to the triple (address of vectors data, capacity, length). *) compiler might optiomize to use variable a onward instead of moving the contents to a new variable.
Thank you very much for explaining this to me. Now that I see there's even more detail I didn't know, I'm convinced that Rust's ownership is wise in its clarify :-D
@@NoBoilerplate Yes it can be complicated and the compiler auto-inserting references where it needs them makes it harder to understand what is going on under the hood.
@@karelhrkal8753 Right, yeah. You can understand why languages like Zig have been deigned to have NO HIDDEN CONTROL FLOW. I think Zig takes it to unusual extremes, obviously I prefer Rust. I'm happy for things to happen behind the scenes if they're complex, and not complicated.
That's not necessarily what I meant, the Go team thought about what they would do if they could design C++ with a clean slate, today, based on all we know. They chose: - Buillt-in GC - Static compilation by default - Batteries included standard library - Simple concurrency - simplified syntax with one obvious way to do things. - etc. And it's really paid off!
Currently going through The book - at chap 8th and am learning a ton, especially since im coming from Python and am not an experienced programmer. Great video!
0:40 No. I might agree, that Rust is not just a better C++ (honestly I think, it is), but Go is definitely not a better C++. Rust and C++ have these in common, which go doesn't: - generics (newest go has) - no GC - no reflection (runtime type information) - focus on zero cost abstractions - RAII - low level programming abilities (pointer math, etc.) Rust basically takes all the general ideas of C++ and implements them in a cleaner and safe way.
Also, Rust *does* have runtime - you almost always end up using tokio (or unfortunately less popular async-std). In addition, GC does *not* introduce indirection by itself. You can think of it as just another allocator implementation with tracing collection in places where it's impossible to directly infer where Rust-analog of .drop() is called.
Sure, I mean like a full mandatory heavyweight dynamic language runtime. Tokio has no std options I believe! A GC's indirection is due to lack of control over memory, it seems to me.
I’m not sure about the rocket analogy. That implies C or C++ is on average slower than Rust. Which is definitely not the case. Instead, Rust is the car that doesn’t allow you to ride it if you plan on ever breaking road laws. Sure, the guy who isn’t bound by road laws will arrive at the destination 10% faster. But he also has a risk of dying in a car crash. The Rust car makes it impossible for you to get into an accident at a small speed cost.
That's a great analogy. I wasn't thinking of a rocket being faster than a car, but an entirely different kind of vehicle with different principles and operating modes.
"Rust has an Algebraic Type System, and if you know what that is you already know you want it in your language" Somebody out there may know what it is and not want it, but I haven't met them.
How does Rust handle the RC (reference counter) type without a garbage collector? Isn’t that what a garbage collector does? Keep track of how many times data is referenced until it can be safely dropped?
You can think of a RC type as a single garbage collected value. This is how things work in Rust: Everything's supported, you just import and use a-la-carte!
The language I use depends on the environment and problem I am solving at the time. All languages have macros, it is just that the macro part is not built in : ) I regularly run code through a macro processor before running / compiling. I started running Pascal through gpm because at 300 baud it was far to verbose : ) For many problems you can define a model to solve the problem, a virtual machine to implement a programming language to solve the problem.
Peter! I spotted your spectrum in your profile picture and blasted through a bunch of your chiptune videos - fantastic! I don't disagree with your sentiment, one should always chose the right language. HOWEVER I beg you to feel out Rust so you can make that decision, you might be surprised at what you can do! Here's my showcase video on loads of Rust's features that you can't really find in one place elsewhere th-cam.com/video/0rJ94rbdteE/w-d-xo.html I'd love to know what you think!
You left out the most important feature of Rust: screaming at you every other line of code for something weird and hard to debug. At least this is how I felt on my first week learning Rust 😅. The more I keep pushing through the more I enjoy it (I'm probably becoming a masochist 🤣). Anyhow, great video!
The classic Rust road: Beginner: "Why the fuck does this code not compile!? It's obviously correct! Borrow checker you pedantic idiot!" Intermediate: "Wow thanks borrow checker for saving my ass again! I totally missed this weird edge case!" Expert: ""Why the fuck does this code even compile?! It's obviously wrong! Borrow checker you sloppy idiot!"
ive started learning Rust semi recently and like I write code and get a bunch of errors and i look at one and its like "why the fuck would this not work? this is how i would code it in any other language" ... thinking ... "oh frick that would totally have a major bug in this edge case"
"No Garbage Collector" is not necessary a feature. It is just one of the options to manage memory. And it can act better than ref-counts because you do not intermix your work with increments/decrements/conditions. And can sometimes act better than explicit management since it may improve some locality of accessed memory by batching frees and it can be tuned for system it is starting on. Stack allocation, "Never free", and hierarchical - yet another options. They have their own compromises. Rust, indeed, helps to reduce surface where those are usually expose themselves. But it is not zero. Don't forget that call to free() function is not free. P.S. I expect Rust, modern C++ and Zig to have means to pluggin in GC too.
Thank you for your wisdom here, but perhaps my point wasn't clear enough: If you have a garbage collector, you're now blocked from: - Embedded development where constraints mean you can't run a GC - Webassembly - where the browser brings its own GC, you will have to disable yours (can you do so? Go can't, you must use an experimental alternate compiler, for example) - Real time applications where there must be STRICLY NO GC pauses. This is what I mean when I say "No GC is a feature".
@@NoBoilerplate I guess, I got where that "feature" stems from. Maybe in this case "having choice to be free from GC" - that's the feature 🙂 P.S. Sorry if my previous comment sounded arrogant (hope that's the right word).
@@virkony I didn't think you sounded arrogant, I thought you sounded knowledgable. Thank you very much for talking about these concepts with me, I'm learning much!
I guess the million dollar question is, should GC be an "opt out" feature or an "opt in" feature. In Rust, it's an opt in feature. There are crates that provide "smart pointers" with batched destructors and free. As well as custom allocators, that can do something similar. It's fairly rare that you need a full blown global garbage collector.
@@KohuGaly A great question, and I'm certainly not smart enough to know the answer. HOWEVER, here's my feeling: If GC is default, removing it is difficult as it breaks a lot of assumptions. If GC isn't default, adding one is easy. My source for this is the Nim language, which is trying to go from GC -> Arc, and it's been a lot of work. In Rust, Arc's just a type we can use if we fancy it, on a case by case basis.
How a developer starts interacting with rust. - Look at the code once, gets confused by a lot of unique features. - Start studying the book. Gets even more confused by all the technical details. - Start writing a few projects. Gets a lot of errors, start hating the language and all the time spent trying to making the compiler work. - Finish writing the project. Start testing and debugging. Realize it takes a few minutes to debug and test the ENTIRE project. - Finds out how fast the project runs. - Realize that all frameworks in rust are written in a similar way. No need to re-learn every time like in javascript. - Start loving Rust.
I used to wonder why it ranks so high each year in SO's surveys for being the most loved. That is until I tried it. Yep, definitely feels like a cult devoted to worshipping Rust.
been learning rust for about 1 month now and I actually understand what is going on at 10:57 :). First watched this video about 2 weeks ago and I had no clue what any of that meant
I'm unconvinced by the "no garbage collector" part. AAA games use a bunch of hand picked allocators to handle millions of entities without any lag. Low-end Embedded devices will often use static allocations for fine grain control over memory layout. Wasm doesn't come with an allocator, so producing nice wasm requires the programmer to think about memory management. The (safe) rust solution is to just let the borrow checker spam malloc and free calls. I do believe you can write rust code that's as fast or faster than C, but the performance critical parts of the code *will* end up looking at lot like C code.
The borrow checker shouldn't be spamming malloc and free calls. Memory should only be allocated on the heap if you use a Box, Rc or RefCell (or their parallel friendly cousins), and should only be freed if one of those objects goes out of scope.
@@taragnor Don't forget the probably most used Vec. There are a few other data structures from standard libary that are heap allocated. But the language (without std lib) itself doesn't magically use allocators. If it would, it wouldn't be a system language I'd say. You have the same power as C and C++ (although it requires sometimes unsafe Rust)
@@khaared Yeah, Vec and the other data structure classes too. Still have no idea where he's saying that the borrow checker is spamming malloc and free calls. At worst that might happen on a growing Vec, but you can set it to reserve a set amount of space when you create it if you want to avoid it resizing a bunch of time as you grow a big one.
I don't think you understand how the borrow checker works, but maybe I'm reading this wrong. It's a compile-time feature. Static allocations are possible. This isn't an issue really. Wasm is a virtual instruction set. Instruction sets don't come with allocators, OSes and standard libraries do. The one thing that Rust can't do that you mentioned is usage of various custom allocators for various scenarios. Rust currently can use only one custom allocator globally, per crate (library). From my experience, it's not the best language for tasks that require very fine-grained memory management (altough some people wrote entire kernels in Rust), but it works very well for a lot of performance-critical code .
5:46 No runtime types - does this mean it's impossible to interrogate the type of a variable at runtime? If so, how does the cat/dog example know which type is being passed in?
Yes. You can't check the type of a variable at runtime because you don't need to: you already know. In the cat/dog example the type of pet is stated in the function signature; `pet: Animal`
In statically typed languages, there is nothing to interrogate at runtime - the value could only be exactly of one type, otherwise the code would not compile. The cat/dog example works, because rust enum is a tagged union. It has a hidden discriminator field, that is used by the "match" statement to branch the code for the different variants of the enum. Rust also has a dyn modifier for pointers, that allow you to do dynamic dispatch (the pointer can store any type that implements a given interface, but there's no way to get the concrete type out of it). And then there's also the Any trait, which in combination with dyn let's you do downcasting to concrete types. But that's rarely used, as it is mostly pointless and unergonomic in statically typed language.
Imagine it this way: The cpu doesn't understand types, it only knows about bytes and a few operations. Runtime types are an elaborate fiction that stops us being confident in what we're doing!
The compiler checks type on assignment, it can therefore never be anything else as it throws a compiler exception. You can get the type at runtime, but unless you're using unsafe, there's really no point in doing so as it can never be anything else outside of it. Check std::any::type_name if you want to see how you can get the name of the type. It also takes into account whether or not the value is a reference or not.
6:55, interestingly, if you really hate explicitly naming types(I personally don’t mind that much) there are languages like ML that can do essentially all type inference for you( and display it to you) without any explicit annotation. This comes with it’s trade offs , but there you go
I started hearing a lot about Rust recently, so I decided to read up about it before trying it. I decided not to use it and without mincing words, I just don't trust a language with that foundation list.
@@ONIscrooge Ah! Mozilla, Google, AWS, Microsoft, and Huawei. Yeah. I don't really know about Google and Huawei's plans for Rust, other than they are happy to pay to help development. But Mozilla, AWS, and Microsoft are building and hiring with Rust HUGELY: Microsoft ported all of the windows api to rust: crates.io/crates/windows AWS are porting all of the aws cloud api to Rust: github.com/awslabs/aws-sdk-rust And Mozilla, well they've lost their way a little at the moment haven't they. I hope they can find their way back. At least they're still putting huge amounts of money into Rust, so I won't write them off just yet! What's the 'trust' part here? What don't you trust them to do, vis Rust? I'll take TH-cam's advertising money to do good Rust education, even though I don't trust them!
@@NoBoilerplate I don't trust them to make good decisions long term in Rust's development. I can't really give specifics, because anything under the sun is a possibility with their track record.
I completely disagree with your statement on how rust is not a better c++ and that go is. First of all, c++ no does not rely on object orientation and its type system is way more complex than go, the only part of c++ standard library that relies on classical object oriented with dynamic dispatch are streams and exceptions, all other parts relies primarily on meta-programming and secondly on functional programming. Think of std::string for instance, std::string is an alias for the template std::basic_string. If you want a new string type using another allocator, you just change the allocator, creating a whole new type in the process. Giving this template a new allocator is actually giving him something that holds a set of functions to call when needed, this is an approach of functional programming. From this simple and overused class example, you can see directly where the traits in rust came. Same for all collections, iterators, same for the whole and libraries, meta-programming and functional programming, C++20 with concepts is giving us an alternative to rust traits (concepts were planned on c++11 at first), C++20 new library is directly based on functional programming, C++20 is integrating the fmt library in the standard which rust took almost as it was. Secondly, C is not the fastest between C, C++ and rust. C could be the fastest if the programmer is actually taking a lot of time to adapt its code to the compiler translation in assembly that could not be portable to another architecture and/or could change with a compiler update. Most of the time C++ is faster because the compiler is free to make way more optimizations on code and rely a lot more on compilation-time calculation Rust is almost at the same level of c++ in term of performance and have way less delta between two runs. Rust is taking the whole philosophy of c++ on zero cost abstraction. The sum type is not rust-specific, rust almost literally took it from functional languages, especially Ocaml. You can do sum types in c with an union and an enum, you can do sum types in c++ with std::variant or std::optional. For the "data ownership" and "garbage collector" sections, this is relying yet on another C++ mechanic that is the core of this language and as Bjarne Stroustrup said, it would be the first thing he would do if he was asked to rewrite C++ today : RAII (Resource Acquisition Is Initialization), Go didn’t get this and preferred a Garbage collector. C++ is memory safe as long as you don’t use c functions and no longer use operator new and operator delete. Rely on smart pointers like std::unique_ptr, look at std::box::Box and see how things seems similar. Rust is taking this safety and ensure you do it the right way. These are all the reasons why rust, for me, is a better c++. Rust is actually a C++ if we give up the C code compatible constraint, everything that rust do better than C++, it can because rust designers didn’t care about C retro-compatibility (except for exceptions). Const correctness is really important for C++ for instance, C retrofitted the keyword because it was helpful but C++ did it before C. But because C++ had to be retro-compatible, a value declaration could never be const by default, thus const has to be written, rust is not bonded to be C retrocompatible, thus all values are const by default, only mut values are variables. Same for move semantic. I think you missed an important point on rust : its very name. Rust has been named like that because it does not invent many things; it uses things that has been experienced throughout the decades of programming, taking the best of everywhere and making it better. Rust is a better C++, taking its whole philosophy, the same goals on performance, the same use, the same goals on how to make things on many things. It’s just making it way simpler, giving up C retrocompatibility that makes no sense now, taking years of experiences and tests in C++ without having to prevent to break compatibility with existing code and taking whole parts of functional programming language in the process to make it better. Go is nowhere near that, RAII has been abandoned, performances too, compile time operation and meta programming as well. In many ways, go is way closer to python than C++, making a language as simple as possible, really easy to learn, provided with lots and lots of modules, used a lot for scripts and to be used online primarily. Go for me is like Python and Java having a baby, the performances and garbage collector approach of Java, the learning simplicity coming with batteries of Python.
A kind driving instructor! "Now over there, that's a runaway truck, we're just going to ease into the next lane and let it pass... that's right... a little faster..."
ERRATA
3:51 I line 3 in the second code snippet is supposed to be `b = "newname"` (thanks VVill!)
1:02 Go is not object oriented, my mistake (I suppose I saw 'interfaces' and extrapolated from there) I'm delighted
you should pin this
Pin errata
"object-oriented" means different things to different people. Newer languages tend to be ones which meet some peoples' definitions of object-oriented and not others'. Personally, I am very strongly attached to what I understand to be more classical understandings of OO -- from before C++ got popular. That older notion focuses on encapsulation inheritance of behavior, and that aligns very strongly with Go's interfaces and Rust's traits.
Java, C#, etc are based on a kind of reimagining of OO, which was popularized by C and C++ and which creates a lot of the common problems people now associated with the phrase "object-oriented"
@@sohn7767 Thank you for the reminder - youtube removes the pin when I edit it!
@@klikkolee "which was popularized by C and C++"
Wdym C ? C is purely procedural. Also I think you are tried to imply 'abstraction' there. I think inheritance was always the most error and headache inducing, despised feature of OO besides abstraction and by a long shot, encapsulation. I was surprised to find that rust supported inheritance with traits, that's one OO feature that I didn't want in rust but yeah.
Alright that's it, I'm learning Rust. That's the first time I've ever felt happy reading a compiler error.
YES! I'm excited for you! Start here, check the whole playlist th-cam.com/video/2hXNd6x9sZs/w-d-xo.html
Is your Hello World! compiled or are you still waiting for the compiler to finnish?
“A fast executing language that crashes all the time is like a supercar… that crashes all the time” -0atman 2022
taking from another perspective, you can only crash a supercar one time, and if you live, you learn a lesson, the same cannot be said about C, if the stress of crashing hundreds of times doesn't kill you, you may eventually learn a lesson
Tattoo right there
this is my favourite quote from any of his videos, hands down
@@ataraxianAscendant I totally agree!
@@ataraxianAscendant so happy with , I hope my mum likes my new tattoo /s
"Rust has an algebraic type system, and if you know what that is, you already know you want it in your language." no statement exists that is more perfect
Mandatory feature.
@@NoBoilerplate Absolutely. I honestly wonder why it isn't more common.
Actually, I wondered that before I even knew there were languages they had them. This was my immediate thought when I heard about enums for the first time...
I don't understand this!?
@@Yotanido IMO I suspect it's because of the fashion for OOP. You THINK you don't need enums if you have inheritance.
@@shreyasjejurkar1233 The statement or algebraic type systems? Re-watch my video for an explanation of Sum and Product types
Even if you do like dynamic language’s ability to just set something without specifying the type, Rust also lets you do that through type inference, which is pretty much having a cake (being able to define stuff without worrying much about specifics) and eating it too (it’s still static typing and you get all its benefits)
Even more important is the fact that Rust has enums and traits. There genuinely are cases where the type should be "dynamic" at runtime, be it from a set of known variants (enum) or generic based on common interface (generics + traits). The problem with dynamic types ala python/ruby is that they go too far.
And you can even do Dyn stuff if you want!
also because of .into() you often dont have to worry about choosing a convert function.
Honestly Every staticly language should have something like the From trait.
Type inference is not the same as dynamic typing in languages like Javascript. Sure Rust can guess a type from how you use that thing later in your code. But the type is known and fixed at compile time. By contrast in a dynamically typed language the type of a named thing can be changed as the program runs. Which might seem convenient sometimes but can also make it hard to figure out what is happening at run time and does a good job of buggering up performance.
@@heater5979 You are right, of course. But I don't see where you disagree with kat 🙂 You mention two characteristics of dynamic types: no type signatures needed, and mandatory RTTI (runtime type information). kat was simply saying they liked having the first one without the inconvenience of the last one. I agree with both of you on that...
Rust has RTTI as well in a couple different ways, dyn traits being one of them. It is just not mandatory.
Imho, idiomatic rust only has types signatures as part of function signatures, inferring the entire function body, which it is really good at.
To anyone starting out with rust: dont let the immature ecosystem scare you from using it . Unless you’re writing extremly critical enterprise software, the most popular library for the thing you want to do will have everything you will ever need
Meanwhile Amazon, Facebook and Microsoft are all using Rust in there enterprise software...
@@parlor3115 by that i meant that if you want to write enterprise software purely with rust, the most popular library might not suit your needs and you would need to make the functionality yourself. But if you have the resources to do it or just want to use rust here and there, use it
I'd hesitate to even call it 'immature' at this point! There are the same number of packages on crates.io as there were in npm in 2013 - I was a web developer then and we sure thought it was mature and the de-facto standard! XD
The quality of serde and tokio have blown my mind
Unfortunately where I would need it most (for web3 stuff), there isn't a good crate with full functionality and responsive contributors at the moment. That's why I'm still using Go even though I sacrifice some performance. EDIT: found ethers-rs which comes close, need to look into it.
I've started my first project in Rust because of you! Thanks for spreading the word about Rust
I am so glad to hear it, this is my goal!
What’s the project?
My reply keeps getting deleted :( I am going to mis-spell things to get around the filter. Sorry for the stroke:
It's a better s0ptify analysis tool. Gives you more ifno than exitsing onez by uzing files from GDPR data request. Can get all podcats/snoggs you've listend to for lifetime of acct and a lot more cool listning data. If I type more I am afraid this comment will get hidden
TH-cam won't let me post a reply about this. @No Boilerplate can you see the hidden comments?
@@2raddude ive ran into the problem of replies getting like, shadow removed a few times as well. It might be that your comment contains some blacklisted word, or that youtube thinks youre a bot or something because you didnt watch any of the video before commenting (clearly youtube's comment bot prevention is still very bad though)
Thank you. Go, Rust, and Zig are not enemies. They are friends!
Its interesting that you see Go as a replacment for C++. While it was designed as one, I tend to use Go where 10 years ago people would have used scripting languages: simple CLI apps, webservers, small tools. I also lean towards it for prototyping or 'throw-away' code, because the Go compiler's incredible speed makes iteration faster there.
I use Rust where I need performance or safety and can afford to write from scratch. When I write Rust code, I'm confident that it's correct. In general, it's my preferred language for hobby projects. Rust also has best-in-class documentation, dependency management, and publication tooling. It's my personal favorite, so that's a tiebreaker.
I don't use Zig (much, yet!), but when I do, it's where the pre-existing infrastructure expects C and C's conventions (i.e, in the world of device drivers, syscalls, and OS internals). Zig is still a bit immature, but the project is rapidly improving. Like it or not, the world we live in is built on 50 years of C, and not everything can or should be rewritten in Rust. Zig helps bridge that gap. The Zig community is incredibly generous w/ their time and expertise, too. They've helped both the Go & Rust projects, despite being significantly smaller.
You're right, I shouldn't have pitted these languages against each other, especially as I am not expert in them. I hoped to make it clear that I too love them all! (but I REALLY like writing correct code, so Rust is my fav!)
🙂 "Excuse me !" I thought, GC not GC they do not play in the same field regardless. However I would not write a microservice in C++ perhaps. Compare C++ to Carbon maybe 🙂 but great content nonetheless
Imo Zig and Rust are very philosophically distinct. Zig wants small language approach, where the code is as upfront as possible about what it does, with as little unintuitiveness as possible, whereas Rust wants a big language approach, where the code is adorned with high level abstractions and powerful expression and clear function contracts are valued over immediate clarity of the underlying workings.
I wouldn't say that Go wants to be a better C++. It's type system is very different, it's way of working is extremely different.
I think of Go as a simple-to-reason-about pragmatic fast compiled language. It's interface system is basically a simplified, prettier (sue me) version of Rust's, with less options. Go tries to be simple in everything. For instance, things such as map functions etc. are not in the standard library.
Indeed, Go does not even have a set.
I think Go is it's own beast. I've seen people compare Go to Python, and get extremely confused. I've seen people compare it to Rust, and call it ugly. I've seen people compare it to C++, and call it incomplete. It's none of them.
I think Go's main strength lies in it's simplicity of composition: the simple interfaces really allow for things such as hexagonal architecture within your application.
Thank you so much for creating easy to understand, digestible and clear videos on Rust. Much respect.
You're very kind, as I learn more, I'll produce more!
Go cannot be a better c++, a language with a GC is fundementally solving different problems. Otherwise you could argue Java or c# is a better c++.
Go isn’t even primarily a systems programming language. Sure it can do some of that, but it’s most useful for web backend
@@sohn7767 yeah I agree. Mind you I'm in the camp that a required GC precludes being a systems language (an optional one like D is fine since it gives choices)
Yeah, I was thinking "yeah sure" when he called Zig a better C, but... Go being a better C++... ehhh
I've been told that Java was sold as a better C++ at the beginning, so maybe not too far from the truth. But you're right in that GC really does separate languages fundamentally
I'd say Go's biggest feature has to be its ability to replace node.js severs (abominations) without being much slower
I used to be primarily a C programmer, a little bit of x86 ASM, and C++. I remember seeing videos like this and "C turned 50 today, so I decided to learn Rust" by Low Level Programming, and wondering what all the fuss was about. I eventually decided to give it a try, and it quickly became my favorite programming language. To me, it feels like what C++ should have always been. I know you made another video about this, but it really feels like in Rust I can focus on actually solving a problem instead of remembering to check for nullptr and use copy methods, all without introducing any runtime overhead. I write some code, cargo check, cargo build, then move on to the next problem. I don't need to study a method for an hour to make sure I didn't just implement RCE.
Isn't it lovely! I'm having such a great time programming again :-)
If you use the reference counting types then there is runtime overhead. Probably other things too.
@@nicktreleaven4119 Hi Nick, that a Cornish name? I'm from Cornwall!
Anyway, you're right that Rc/Arc add a small amount of overhead, but most of the time we don't use them, Rust's normal ownership semantics works great 99% of the time.
However, even when we have to use them (shared mutable state for example) Rust is SO FAST that honestly unless you're comparing it to manual memory management in C++, Rust will still be faster.
By the way, you can still pass around a raw pointer in Rust, just like in C++, and it's just as unsafe ;-)
On pure mathematical benchmarks, its something like:
C - 1x
Rust - 1.1x
Go - 2x
Java - 4x
Javascript 4x (yes I know, a trillion dollars of optimisation has made js as fast as java I was surprised too)
Ruby - 20x
Python - 80x
So if you're comparing Rust to, say, Python, that ~77x speed bump covers a lot of sins! XD
@@NoBoilerplate yes Cornish but I'm from London. Yes rust is fast and it's probably great for when you only need unique ownership. I just think reference counting is slow because accessing memory is slow. But it's still a good option. Decent Garbage Collection is typically faster but tends to use a lot more memory for efficient collections. Last I heard rust didn't support tracing GC. But it is a great language, I hope they can improve it even more (e.g. for generic async functions).
@@nicktreleaven4119 Amazing, I'm Cornish but living in London! What a small world.
Yeah, Rc is slow, if you use it. Rust's ownership has zero cost, ie nothing happens at runtime, the compiler's proved you've never used a reference after it has been freed etc etc. Best of both worlds, with no, as you say, heavy GC. Makes it trivial to run Rust on embedded devices or low ram environments (such as in-browser).
Have you seen my other videos? Not having a GC is a very unusual thing, and the way Rust solved memory safety accidentally gave it superpowers, here's the video where I explain this:
th-cam.com/video/0rJ94rbdteE/w-d-xo.html
I love this stuff. I'm retired, now, but I used C back in the day, close to the metal, for physics experiments. Before that it was assembler and sometimes machine code.
But C does give you serious foot wounds on occasion.
Rust has proper ideas to stop that while you still have real control over the runtime.
(In my case, small computers/microcontrollers , networked, doing monitoring stuff).
Great series, keep it up.
I wish I could learn low level programming with some guidance... Do you have any learning resources recommendations, or know anyone who teaches this sort of stuff?
@@avidrucker How low level we talking? If it's "to the metal", look at the documentation (if there is any) and make a table for all the registers for the prototype program _after_ you have a high-level idea of how the program's logic should work. Sometimes, the fastest way to get an answer is to have a table with the answer already calculated for you...
@@avidrucker Raspberry pi's are not a bad bet; you can get general purpose machines, to little pi zeros (still capable) or to microcontrollers.
There's also a thriving community, with many projects you can get a feeling for.
You can cross-compile using rust, or C or java (those are the ones I've done. Java won't go on a microcontroller. But it will work on a pi zero. Slowly, but it'll run a website. Ish)
My friend, you should learn Rust, it's the same level as C! Try the rust book
I hear raspberry pi pico is a strong rust compile target!
_"Rust might not be the language you wanted, but it might be the language you need"_ ~ Great Explanation
Thank you!
Rust community is very lucky to have people like you. Keep up the good work!
Thank you! I'll try to use my powers for good
@@NoBoilerplate use them for evil! It's fun! >:3
“A fast executing language that crashes all the time is like a supercar driven by Richard Hammond” -Jeremy Clarkson
"Hammond you blithering idiot"
Hi! There are 2 things in Rust that I personally like very much as well:
First of all literally any compound statement is actually just another expression, returning the result from a final expression inside it when that subexpression is not followed by a semicolon. And even if it hasn't such an expression, it still returns a value, namely the Unit type, which is an empty tuple. There's no void return type.
This is non-typical for C family programming languages, and comes from functional language influence.
It's something that I really mis in C# for example, which is also a very great programming language by the way (I work with it for 20 years already).
Second thing that I like is that Rust's object oriented way of programming chooses composition over inheritance strategies, which is good, because inheritance causes many problems.
Really great design decisions, aren't they!
Wow. This guy’s talking so well about a compiled language that I feel he’s a script writer!
So many statements that would be great chapter names !
Subscribed.
Thank you!
Oh I see what you did there! :D
9:30 if anyone else is confused, I looked it up and Rust has implicit returns, so the last line would be equivalent with `return Order(tris)`, which would leak memory outside the function scope.
I'm a frontend dev, so basically as far away from C as a dev can get.
But I've been looking into Rust for my bachelor thesis project, I was originally gonna use C++, (cause I need the kind of speed that makes JS just not an option) but the memories from first year classes are painful.
I think you pushed me over the edge, so I am installing Rust today, and giving it a spin to see how I like it.
Fantastic! Check out my other videos on rust for more features you're gonna love!
@@hermes6910 Yea. it has really cool potential to it. Right now, I don't have the time to really dive into WASM at all, but it's definitely something I need to try someday.
4:37 - This is a _very_ useful way to think about the transfer of ownership, at least for us old dogs (who were rather mature programmers when C came out) learning new tricks.
I'm glad to help! It's not too bad, just unfamiliar, I think :-)
I've always said, statically typed languages make reading code much easier, because I can be sure, that the things I see will always be that way.
Dynamically typed languages make writing code much easier, because you can get things done without thinking too hard about the "what if's".
Experience tells us that programmers spend much more time reading code, than writing code.
absolutely, a huge reason why I love Rust
As a python developer, typing every variable is very difficult work. But every line written in Rust, I think that it is very beautiful language. I love Rust and Rust love me.
As a python developer myself, I sympathise! Mypy is great, but it's SO MUCH WORK.
However, you're wrong: In Rust, type inference means that you only typically type a function signature, eg,
fn send_email(recipient: EmailAddress, client: EmailClientConnection) -> Result {}
What wonderful documentation! I bet you can already imagine how to write the function body :-D
I'll have you know, I'm reading through the Rust documentation and it's your voice in my head that I'm hearing. Good stuff.
well done! And do check out Rustlings and Rust By Example - if you need any help, ask in #newbie-advice on my discord server (links in the description!) GOOD LUCK
What do you mean Go is a better C++? Go has a Garbage collector. I would say Go is more of a better faster Python/Javscript thing, because it's still slower than C++.
Better code design, not faster. I have no clue if it is actually better design, never used Go and I've only watched a stream of someone using it, but that's how I interpreted it.
Go is more likely in the class of Java, C# and the likes, it's not a (dynamically typed) script language like Python/Javascript though etc.
I would consider Go to be even lower level than Java and C#, not a real system language like C,C++ or Rust, but close to it. The Garbage Collector is compiled into the binary, so it has a rather large runtime, but it can run on its own. Rust does also have a (much smaller) runtime, it's all the syntax sugar magic, that the compiler miraculously translates into the binary.
Depends on how you define speed. For someone like me with extensive knowledge of Python and very little C++ experience, who just wanted to write some CUDA, C++ is infinitely frustrating. It keeps breaking in weird ways and it's impossible to find good resources that aren't horrifically out of date.
And given the history of C++ it makes a lot of sense that it turned out this way. Mistakes were made initially and they've been trying to paper over them ever since. C++17 already filled 1400 pages and C++20 grew to 1800! Who is supposed to read, understand every minute detail, and memorize all of it?
So for someone like me, who's ripping his hair out googling obtuse compiler errors and valgrinding for hours to find memory errors/leaks, Go is infinitely faster. I get to actually finish my project and it really doesn't matter that it spends 0.05% of its CPU cycles on GC.
@@jfolz You are talking 'faster to write', while they are talking 'faster running'. Totally different. And at a professional level, they are all pretty close in how fast it is to write it. All you've actually said is that you are not a professional C++ dev.
@@jursamaj above was a discussion that go being a better c++ was referring to the language design rather than the performance, and i think riDDimann had a point
"Rust might not be the language you wanted but Rust might be the language you need" --Tris
I think one major selling point with Rust is scalability within it's codebase. The Ruby team for example, chose to write the new JIT compiler (YJIT) in Rust because the code became too unreadable and complex.
And parts of NPM infra, are written in Rust!
@@NoBoilerplate CSS rendering engine in firefox was attempted to be rewritten from c++ to c++ twice but they failed. Its written in rust now.
@@theroboman727 mozilla also own firefox and rust, so there might have has being another incentive to use it
@@till8413 yes, but all attempts were serious regardless
@@theroboman727 But the rust html rending also failed, it's just the css engine and that is something that they could have done also in C++. Servo was expected to be much much more.l
Very nice, what I missed, the rust traits which allows to put features on existing and new types, for me a key feature, think about the iterator trait, once implemented for your type you can use all the iterator functionality implemented with rust. That is an extreme form of re-using code, …
That's a really great feature, you're right I should talk about traits more!
I am absolutely in love with Rust, and agree broadly on the thesis of this video, but having programmed in C most of my programming career, when you said "Is that all you want? A better C?" I almost dropped to my knees crying. It is all I want, I would love that very much
I think what would convince me more is some going through a significant project, Handmade Hero style, on TH-cam, showing how they think through the code while they write it. I have a lot of little problems with Rust while I write it, sometimes the docs generated by cargo make my eyes bleed, and I don't really have a good IDE to help guide me through the syntax, so I would get more use out of a practical hands-on video at this point. If you have one to recommend I'd really like that.
You are in luck, this is LITERALLY my next video :-)
As for IDE, watch my previous "lightsaber" video, or just use vscode!
It's not on youtube, but I can reccomend togglebit on twitch. Really nice guy, great personality and streams his work on his own rust projects.
@@iamhardliner Thank you, I found him on twitch, that was a great recommendation.
I would definitely follow a rust tutorial series from beginner to advanced that explains why we do things. Your voice is so calm:)
Rn it is just watching tutorials, and then watch these videos for more in depth topics
Thank you so much! My next video (eta thursday) will be more of a tutorial.
If you would like a scifi story narrated in my voice, I have great news! th-cam.com/video/p3bDE9kszMc/w-d-xo.html
@@NoBoilerplate just watched the tutorial on the space craft, very cool:)
Thanks!
@@job4753 amazing!
Thanks again for another great and inspirational video, this platform needs more people with presentation skills like yours!
Thank you so much, I practice a LOT!
I just like listening to you speak about rust. I haven't picked rust back up in months. I'm still sitting here with my typescript enjoying myself but whenever you post.... makes me wanna drop everything.
Might be your soothing voice. Might be that you're talking about Rust. Hard to know.
If you want more of my voice (thank you!) I produce a scifi podcast th-cam.com/video/p3bDE9kszMc/w-d-xo.html
If you want more Rust, stay tuned :-)
6:23 In Python if you write name: str = 13, the program will run but any linter like Pylance will tell you that there is type mismatch. So you know what type variable should have.
Linters are essential, absolutely. The Rust linter is called 'clippy'
Kiitos!
That cat joke was brutal.
I feel a bit bad about it XD
your segment about lifetimes was great. and the order / account example really helps to understand it. would be great to hear more about ownership, borrow checker and lifetimes
I'd like to learn more about it too! I'll make a video when I learn more :-)
@@NoBoilerplate cant wait. i have read some rust books. i feel like i get it, but i still dont really use it in my rust code. only for a &str in a struct. but i usually end up using String and getting rid of the reference. The order / account example showed me a new way to see lifetimes :-)
@@andredasilva6807 No shame in writing bad rust that works, while you get the hang of it: Copy everything! `String`s everywhere! ALL INTS ARE i32!
Is it deliberate or accidental that the unsafe code snipped presented around 10:35 actually has undefined behavior?
(Hint: Run it with “miri”, it’s available to install on nightly via rustup, or you can also find it in the playground under “Tools”.)
Oh interesting… that example is apparently from the book!
Apparently there’s already an issue open on this point :-) I would include a link, but f-ing TH-cam silently auto-deletes my comment in that case.
Amazing! Thank you for telling me this. I stay away from unsafe in my normal code!
Just now discovering more of your illuminating 10 minute videos. Usually I listen to coding vids at 1.5 or 1.75 speed...while doing something else. Not so with your stuff...I'm pausing, going back...yet at the same time, relaxing! Love your style, feels like you may have been a philosopher in a past or future lifetime 😶🌫
Thank you so much! Yes I find that many coding videos have great content, but are too slow. I assume my audience is smart, and also knows where the pause button is!
I am starting to like Rust. I still want to build a project from start to finish it with, but from what I see so far it is pretty good. It is funny that concepts that I apply for C and C++ regarding memory management are enforced with Rust. And finally a compiler that is smart and tells you the error in a human-understandable way. I am a bit scared about integration with C libraries / C++ libraries, I hope I do not need to create wrappers and converters for it
Very easy extern c wrappers are available in Rust - check the book!
It is remarkable how consistent you sound across your different works of media (at least this and the Lost Terminal Broadcast). The voice, the patterns of speech, the precision of the expressions. Very recognizable. I like it.
You do me an enormous complement, I've always been impressed by musicians that sound IDENTICAL on stage as they do on the album. Two bands come to mind here: Rage against The Machine and the Darkness. Both surprised me by sounding SO similar that I initially thought they were lip-syncing! But they weren't: I was looking at thousands of hours of practice.
The album wasn't a fluke: They could do it again and again.
I practice a lot, it's only polite when you are giving your time to listen to me! Thank you again.
Keep the good work up! Loving these.
Thanks, will do!
I love how this videos background matches with the youtubes, making a nice blend.
:-D
There are also a new generation of proof oriented programming languages which bring another area to explore in the programming languages landscape:
Coq, Lean, F*, Agda, Idris, ATS, HOL, Curry, Mercury.
My interest in Rust is DIRECTLY inspired from learning about formal systems (we did B and Z) at university. I've been trying to find a popular language I can do real work in that I can formally prove. I thought Haskell might get me close, but it's not quite popular enough.
Rust of course isn't a formal language, but it has enough of what I liked from Haskell, and is popular enough, that I'm ALL IN!
Thanks for all of your rust videos. You've just came in time for me to choose a language for a new project. And I'm looking forward to use rust and become a part of rust community as well :)
Fantastic! Welcome! The best place to get started is the official book, and also Rust by Example.
I also came across this today, which is a great overview learning-rust.github.io/docs/a1.why_rust.html
Have fun! And do join the discord if you want tips or advice.
I'm not entirely sure that the whole "reference vs value" problem of remembering which types follow which rules is fully gone: in Rust, you have to remember which types are Copy and which types are not. It's definitely not as big of a problem as remembering if something is a reference type or a value type (especially thanks to trait bounds) but it is worth noting.
Wait, what?? Can't you choose whether you want an argument to be copied or referenced? In C++, f(T& arg) is a pass-by-reference function. f(T arg) is a pass-by-value function.
@@nothingtoospecial777 Rust lets you do that too, using similar syntax (`T`, `&T`, `&mut T`). However, references aren't magic, they act just like any other value: they're pointers but with compiler-enforced lifetime annotations: you have to annotate when you're passing by reference and when you're changing the value pointed to rather than changing where the reference points to.
@@nothingtoospecial777 It's not "copied or referenced" in Rust, usually - it's "moved or referenced". Once a function takes ownership of a parameter (the parameter is moved into the function), it is no longer usable from outside the function. You can control whether a variable is passed by value (moved) or by reference in Rust.
Here's what I'm talking about:
There is an exception to the rule about moving: types that have the Copy trait are copied, not moved, when passed by value, meaning that the original variable is still usable outside the function (since the function only owns a copy).
You cannot directly control whether a type is moved or copied. If the type derives Copy, it is always implicitly copied, and otherwise, it is never implicitly copied. You can make functions that require their arguments to be implicitly copied, or you can (probably) manually copy bits from one variable to another, but it is still sometimes necessary to know if something will be implicitly copied or not.
@@Sean-of9rs But types that are Copy just have the "bonus" of sticking around after being moved. And if you read code that uses a variable after its been moved then you automatically know it's Copy. You don't often have to think about whether a type is Copy or not when reading code
@@olestrohm Fair point! It's mainly when writing code (and specifically functions) that it becomes relevant, but even then it can be learned relatively quickly.
The thing about Rust's ownership system is that it makes the *compiler* do what you would have to do anyway. Data ownership and lifetimes do not just go away and stop mattering because your compiler allows you to get it wrong.
That's why Rust is so neat: For a newbie, the borrow checker provides training wheels that keep you from falling over, and once you internalize the rules of programming and gain expertise, it'll fade into the background but will still be there to catch you when your caffeine levels dip too low.
Exactly! I now write Python thinking about ownership, and my code is better for it!
Rust's syntax looks very scary to me as a beginner but I really want to start learning it, I don't know if rust is a good pick for a first language, I have some experience with programming but never decided to try and get into the nitty grittys of a language.
your content is very inspiring and I hope you well, thanks for showing us rust!
As someone who started with C(++), java, and javascript and has recently learned rust, rust is definitely going to be the hardest to learn. That said, as long as you have a good editor that can feed you rust_analyzer (language server) hints/warnings/errors without having to go back and forth to a terminal shell, I'll say that rust can be a great first language. The language server will give you lots of directed help at how to write better or more idiomatic code and fix errors.
Dynamically typed languages leave too much freedom for a beginner to build bad habits and avoid learning important concepts IMO. C/C++ (moreso cpp) are the default first languages in uni for good reasons: learning about memory, data structures, and algorithms. I think rust strikes a great niche of being low level AND modern without the baggage of C++'s long history (you have 10 different ways to do a thing right and many more ways to do it wrong lol).
Nick has the right of it. If you get vscode set up with the rust_analyzer extension, you'll have a rich coding experience that holds your hand.
Try the Rust Book for starters, and keep at it, and ask for questions when you get stuck (maybe on my discord!) doc.rust-lang.org/stable/book/
I just found your videos a few days ago.
Thank you very much.
I look forward to your next video.
Thank you very much, I hope they're helpful!
Whatever was said about Java/JavaScript being 3-4x slower than C while Go being 2x is not true. In most benchmarks you will see C# /Java / Go very close to each other, with most edges being given to C#. The JavaScript part is correct.
My apologies, I tried to be as vague as possible, as benchmarks differ SO much - I didn't include C# because though it's popular, it's not on my linux radar - I'll include it next time!
@@NoBoilerplate No need to apologize, you are doing great work here. You should try C# on linux. I exclusively use it on macOS is it's actually amazing. Have a wonderful day.
@@metaltyphoon Incredible!
I started a c# job recently and I'm exclusively on Linux. .NET is fully cross platform now, and a combination of dotnet CLI and vscode makes visual studio totally unnecessary for me. I'm currently learning how to configure neovim with Lua to take vscode out of the picture too (your video on the rust lightsaber pointed me towards AstroNvim, from which i found LunarNvim, whose creator has a video tutorial series on building basically that from scratch)
@@Klayperson what a world!
Thanks for the videos about rust :)
Rust is like accouting! You need it to run a smooth business, it is a hassel, but it is there for a reason. A rust program is like business unit, the programmer is responsible for following the "accounting rules" of the borrowchecker and the linter, no illigal transactions, no horsing around and if the "budget" of the program is correct, all is kosher!
Rust + Rust analyzer is the coolest programming experience I've had, it almost feels like the code is writing itself (except when I fail to grasp what's going on, but then Shepmaster's answers on stackoverflow is always one google away) and I do love implementing strucks, enums and traits :)
🦀
It's such a relaxing dev experience!
10:00 C++ (not C) has templates but there are also constexpr, consteval & constinit that are just normal code and I think it's very unjust to not properly display such crucial points. Generally, your videos give a sense of prejudice sometimes, like you first think of what you want to say and then you try to somehow reason around your pre-determined opinion, ignoring everything that may invalidate the statement. I'm not saying you're purposely doing that, but sometimes your arguments feel very forced and it's a bit disappointing to have great explanations and essays mixed with this unnecessary litter. I, as a C/C++ enthusiast, believe in the power of Rust and I actually think it's great and in many ways better than other languages I know. I got inspired to really get into Rust (partially by you and I'm very grateful for that) and I've found it to be one of the best, if not the best, experience I've ever had with a new language. There's absolutely no reason to artificially present Rust as better when there's actually stuff to talk about and come to that conclusion. But please once in a while revise your scripts from the perspective of another language's user and think about how their view might be affected by unfair treatment towards their favorite "toy", which sometimes boils down to easily fixable things like poor research on fundamental concepts of languages (eg. Go isn't OO) or choice of words. I'm sorry for being so direct in this comment, but this is a thing that's annoyed me in many videos already and I hope you can incorporate my criticism into upcoming videos. I'm thrilled to see more from you, keep up the mostly good work and also I like your approach to error-correcting your videos, which I've found brilliant! No hard feelings
Totally agree. Rust is a great language, and he definitely has many valid points, but to praise Rust without giving other languages a valid or comprehensive explanation is just not cool .. i do enjoy the languages honestly, but i also believe different languages serve different purposes, it should be okay for someone to enjoy using languages A, language B or language C at the same time.
Message received, I can see now that playing favourites is no good, especially as I don't know very much about the others!
Really really loved this video. I had stopped watching programming videos on TH-cam for couple years now since all these channels have became repeating the same thing and also I don't like their general view on programming. I'm glad this one popped up on my recommendations. Coming from a JavaScript/TypeScript world, I've always wanted to take a look into Rust and see how it works and compares to its other related languages, now I actually I think I'm inspired to start from somewhere with your content and even start learning Rust.
I'm so pleased! I too noticed a lack of this kind of careful video. I'm doing the best I can, and learning each week!
Do let me know what you think of the fest of the series, there's 11 videos so far, all in this exact format. th-cam.com/video/Q3AhzHq8ogs/w-d-xo.html
@@NoBoilerplate I've already watched all of them, they're great! I like how every comment under the videos are so informative, it's like everyone here are learning together.
@@infiniteeyelashes6729 Wonderful! Yes, I'm also so excited about the great community here, everyone's really positive!
Beautiful work here. I especially like that you put an unobtrusive progress bar on the video.
Enthusiastically subscribed.
I'm glad you like that features, it's a default feature of reveal.js, and I think it's handy!
8:07 In the game osu!, the GitHub issues page specifically has a bulletin for performance issues caused by the garbage collector-it's written in C#. Sometimes people experience lag spikes in the middle of gameplay because the GC just _decided_ to clean some stuff up, taking way longer than a frame to do so. Nasty stuff.
Yikes!
"Speed is a feature.."
You're Goddamn right my man
like I said in my previous video, if your language is 73x faster than Python, you might not need much in the way of scaling (for CPU bound workloads!)
8:16 as a random side note, Nim actually has a GC that works fairly well in (as far as my personal experience goes) at least a few embedded devices, e.g. the ESP32
yup, you can even turn off the GC for embedded
C does not have a templating system. It has macros (as does also C++) which are, as you point out, a text substitution system. When you say about templates being "nightmare to use" it's partially true, but they have nothing to do with macros or just text substitution. I get you like Rust but there's no need to skew the facts to make it artificially look nicer. I think it's quite nice on it's own.
Never ascribe to malice that which is adequately explained by incompetence!
Thank you for the clarification, I'm new to C and C++. I now see the difference between C's macro system and C++'s template system.
However, I think I'm right about them being text manipulation, though, right? You can't execute arbitrary code at compile time and use the results of those executions to build new syntax like you can in Rust?
@@NoBoilerplate No. The c preprocessor (macros) is a legacy text manipulation facility with a number of inherent caveats and limitations and is present in both c and c++.
C++ templates are a whole different beast and can be used as essentially a type system for types (i.e. to create code parameterized on types) and in that role is far more powerful and flexible than any "generics" system I've seen in other languages, by far. It also can be used for heavy metaprogramming and compile-time code execution. The former used to require quite a lot of boilerplate but it's much more terse these days syntax-wise, and you can do the latter without using templates at all.
EDIT: grammar
@@politisch_unkorrekt_und_st7719 Does C++ template metaprogramming allow side-effects (such as writing to disk)?
@@NoBoilerplate Yes, but if you mark it as constexpr it won't.
@@mihailmojsoski4202 So no accessing the disk at compile time?
0:23 When Jai eventually becomes public, I think it will take Zig's and Go's place, but for now, it might be Zig (For c), and Go (For c++).
There's always something new just waiting to be the next big thing! Carbon too. Maybe Nim. Rust is here today 😀
Who said that Go is replacement for C++? For starters it has Garbage Collector so it must be slower than C++.
@@Robert-ht5kd Agreed, I think Java->Go is a better analogy, I was wrong in the video.
"we have to know, through convention and experience "!! I've been saying this for years when teaching beginners about types. It's the reason I don't think it's wise to teach languages with runtime types to beginners.
Agreed. It's far better to teach them a strict system first, then once they become a bit more comfortable it's fine to use runtime types. That's one of the reasons why I think Java is a good language for a beginner. Because of the highly explicit syntax, you're telling the system everything it needs to know. For that reason it is highly educational. Because the things you wouldn't think of in a language such as JavaScript or Python, you have to think about in Java. This is despite those very things being just as important in other languages.
@@CottidaeSEA I started with python, the moved to java. Head first java taught me more about programming then multipule python books and courses. Now I'm moving to rust
Exactly. Also, rust has a dynamic type system hidden inside it, if you need that functionality!
A course I tutor at my university (aimed at people with 6 months or so of programming experience) teaches people JS then moves them to TS whilst explaining why the weak typing of JS was risky in terms of code safety.
@@miguelguthridge I think Rust would be a great language to teach at university. Imagine the subjects this single language can be used to teach:
- Bare-metal robotics
- Reactive webgl websites
- Database apis
- REST apis
- Web programming
the list goes on! This is one of the reasons I'm most excited about Rust: I might never need another language for 20 years!
I'm just starting my Rust journey today after a few months kicking it back because of college. Awesome videos
Thank you, I'm excited for you! Keep reading, and if you get stuck re-watch my videos for inspiration, the learning curve is WORTH IT! XD
“C has a templating system that is hot garbage“ 🤣🤣🤣
I love this video, how did I just stumble onto this channel today! Gotta join that Discord server
Thank you. You'd be welcome!
8:38 literally is a prophetic text from a God sent book
It's a wonderful book, so well written!
I kinda want Rust's memory management in a Python interpreter. To me, that is the most compelling feature and the only major improvement that could be added to Python other than optional strict, static typing. (To simulate the latter, I use assert preconditions.)
As a python developer of 15 years, you should learn more about Python - it's a hot mess XD
I can't WAIT to only use Rust in my dayjob!
@@NoBoilerplate it might be, but it doesn't turn my stomach sour like JavaScript. I'm unconvinced that I can use Rust to do all the things I do with Python, for example having a multiplatform contract that commits to a single piece of code by its content hash.
that would probably be very hard to implement. you have to remember that borrowing is also a core part of what makes ownership work.
@@k98killer That seems like a pretty normal thing to do in most programming general-purpose languages, why can you only do that in Python?
Here's some concrete things:
- Python can't compile to webassembly,
- nor run natively on bare metal chips (micro/circuitpython isn't python, ask pip!),
- It runs 72x slower than rust in single process benchmarks and HUNDREDS of times slower in multiprocessing.
- and I guarantee there are bugs in your code that you'll only find in production, or maybe NEVER. They'll just be a lingering feeling that something is hidden under the waterline, waiting to bite you.
Have a look at th-cam.com/video/Q3AhzHq8ogs/w-d-xo.html where I dig in deep, and even give examples where Python falls short.
@@NoBoilerplate I'll check out that video. On the code/contract commitment topic, you could commit to the source code with Rust, but then you would have to recompile before running every single time to ensure you are running the code in the commitment. Of course, there is an implicit security assumption with implementing this in Python that the interpreters will be compatible, so it isn't that different. The secure distribution of software is still technically unsolved.
I suppose that the largest issue preventing my use of Rust is that I haven't been using it, so I lack the confidence to build things with it. Do you have any resources for Rust TDD that you would recommend to a Rust noob?
Edit for side note: I wish Python had an immutable/frozen dict type. It really does not make sense that it does not.
At 8:00, wouldn't the garbage collector memory cleanup be done in a separate thread?
locks on data cause the delays, I believe
I'd heard about Rust before these videos, but actually started learning it after these came out, and now I'm rewriting old Python projects in Rust.
On another note, I love the attention to detail here, and the fact that the errata comment even exists shows the quality of this channel!
Congrats on the enthusiasm, but I'm surprised that you would write something in python and then move it to Rust. Python is slow, but it's a great scripting language, therefore, it's being primarily used to ease of use of actual performant code (as in, write a lib in Rust, control it's API through Python).
Thank you so much! I acknowledge that I'm learning Rust too, and that very smart people comment and help with my learning!
@@GonziHere For context, I'm not actually working as a developer or anything, I'm a bored teen learning Rust. Rewriting old programs gives me an end goal in mind, so I find it easier to learn the language that way (and can visually see my growth!). Also, because I have to handle errors instead writing something that "just works", I think I become a better programmer.
@@GonziHere Oh and do you have any resources for learning how to control Rust libs in Python? I didn't actually know you could do that, that sounds really cool
@@camerontaylor8709 Oh, I see, as an excercise, it's a great idea! I cannot point you to a specific resource, but it should be googleable because that's really typical use for python.
1:48 "But a fast-executing language that crashes all the time, is like a supercar... that crashes all the time."
Richard Hammond (and James May in "A Scandi Flick"): _nervous glancing_
This guy is a rust ambassador, he creates FOMO in me.
I am going to learn rust 😅💯
rustup.rs - try it today!
I'm an ameteur programmer. I really only know java basics but have been looking for a language i can do basically anything i want with. Your vids have sold me on Rust, gonna make my Lightsaber as soon as i can.
Fantastic! I'm so pleased for you, it's an exciting world. Here's my playlist on how to get started:
th-cam.com/video/oY0XwMOSzq4/w-d-xo.html
Your lifetimes order_example() doesn’t compile. The tris Account variable has to be created outside that function. You can create it in main and then pass it into order_example but it won’t compile if it’s owned by that function.
Correct, that is exactly the error I am demonstrating, do read the text on the slide as well as the code, sorry it wasn't clearer!
@@NoBoilerplate ahh it’s right in my face… lol I’m an idiot!
I got a bit confused by the video, but now I get it. Thank you.
@@keatonhatch6213 No problem, you're not the only one, I will make it more obvious in future videos!
@@Krasbin you're not the only one, I will make it more obvious in future videos!
~ 7:00
I would argue, that the memory safetey of a language is independent of garbage collection? To me memory safety means no dangling pointers or references. On the other hand, garbage collector or not, one can always have memory leaks. One could even argue, that a garbage collector may help detecting lost / no longer accessible memory by analysing the object graph.
I see what you mean, but to me memory safety = a human doesn't get involved with memory management.
Either you free up memory when it's not used, or the garbage collector does.
Either method can cause memory unsafely, it's just that the garbage collector has perfect knowledge and doesn't make mistakes. (it can have bugs that cause problems, of course)
By the strict definition of systems languages, memory leaks aren't a safety problem, they're an operator problem. In GC languages, they represent a bug in the GC.
I wouldn't call Go object oriented when comparing it to C++. It does OO very differently. While calling it OO is technically true, it kinda implies inheritance, which it very much does not have.
Yes, I've made a mistake with Go there. I should learn more!
4:45 That's not pass by reference. It's pass by "move", which does shallow copy after compilation* (copies the address of the vectors data, its capacity and length), where as pass by reference "copies" only a single value: the reference to the triple (address of vectors data, capacity, length).
*) compiler might optiomize to use variable a onward instead of moving the contents to a new variable.
Thank you very much for explaining this to me.
Now that I see there's even more detail I didn't know, I'm convinced that Rust's ownership is wise in its clarify :-D
@@NoBoilerplate Yes it can be complicated and the compiler auto-inserting references where it needs them makes it harder to understand what is going on under the hood.
@@karelhrkal8753 Right, yeah. You can understand why languages like Zig have been deigned to have NO HIDDEN CONTROL FLOW. I think Zig takes it to unusual extremes, obviously I prefer Rust. I'm happy for things to happen behind the scenes if they're complex, and not complicated.
not so sure about Go being a replacement for C++
That's not necessarily what I meant, the Go team thought about what they would do if they could design C++ with a clean slate, today, based on all we know. They chose:
- Buillt-in GC
- Static compilation by default
- Batteries included standard library
- Simple concurrency
- simplified syntax with one obvious way to do things.
- etc.
And it's really paid off!
Currently going through The book - at chap 8th and am learning a ton, especially since im coming from Python and am not an experienced programmer. Great video!
Same here! Good luck friend!
Same here. But i strted with c++
b/c of school which was a terrible experience & then went with python.
0:40 No. I might agree, that Rust is not just a better C++ (honestly I think, it is), but Go is definitely not a better C++.
Rust and C++ have these in common, which go doesn't:
- generics (newest go has)
- no GC
- no reflection (runtime type information)
- focus on zero cost abstractions
- RAII
- low level programming abilities (pointer math, etc.)
Rust basically takes all the general ideas of C++ and implements them in a cleaner and safe way.
I can see I need to learn more about Go, apologies!
Rust *does* have (opt-in) RTTI, in the form of `Any` and `Any::is`
Also, Rust *does* have runtime - you almost always end up using tokio (or unfortunately less popular async-std). In addition, GC does *not* introduce indirection by itself. You can think of it as just another allocator implementation with tracing collection in places where it's impossible to directly infer where Rust-analog of .drop() is called.
Sure, I mean like a full mandatory heavyweight dynamic language runtime. Tokio has no std options I believe!
A GC's indirection is due to lack of control over memory, it seems to me.
I’m not sure about the rocket analogy. That implies C or C++ is on average slower than Rust. Which is definitely not the case. Instead, Rust is the car that doesn’t allow you to ride it if you plan on ever breaking road laws. Sure, the guy who isn’t bound by road laws will arrive at the destination 10% faster. But he also has a risk of dying in a car crash. The Rust car makes it impossible for you to get into an accident at a small speed cost.
That's a great analogy. I wasn't thinking of a rocket being faster than a car, but an entirely different kind of vehicle with different principles and operating modes.
Hey, I have been watching your videos on Rust and you make it much cooler. Love it keep up 💪
thank you so much! Honestly, the language itself sells itself, my goal is to just SHOW it to more people!
"Rust has an Algebraic Type System, and if you know what that is you already know you want it in your language"
Somebody out there may know what it is and not want it, but I haven't met them.
Exactly :-D
How does Rust handle the RC (reference counter) type without a garbage collector? Isn’t that what a garbage collector does? Keep track of how many times data is referenced until it can be safely dropped?
You can think of a RC type as a single garbage collected value.
This is how things work in Rust: Everything's supported, you just import and use a-la-carte!
I had my Go pitchfork ready when you said it was object oriented! (saw ERRATA later)
Jokes aside, great video once again!
What a surprise! Go has gone up in my estimations greatly!
Dude. The cat name thing? You didn't need to blow my mind with a joke WHILE blowing my mind with rust
hehe, I was a bit mean - Many cat owners have said their pets DO come when you call them!
You are one of the most articulate, and sophisticated programming TH-camr I have ever seen, subscribed!
Thank you so much Theo, I'll try to be accurate too!
The language I use depends on the environment and problem I am solving at the time. All languages have macros, it is just that the macro part is not built in : ) I regularly run code through a macro processor before running / compiling. I started running Pascal through gpm because at 300 baud it was far to verbose : ) For many problems you can define a model to solve the problem, a virtual machine to implement a programming language to solve the problem.
Peter! I spotted your spectrum in your profile picture and blasted through a bunch of your chiptune videos - fantastic!
I don't disagree with your sentiment, one should always chose the right language. HOWEVER I beg you to feel out Rust so you can make that decision, you might be surprised at what you can do! Here's my showcase video on loads of Rust's features that you can't really find in one place elsewhere th-cam.com/video/0rJ94rbdteE/w-d-xo.html
I'd love to know what you think!
You left out the most important feature of Rust: screaming at you every other line of code for something weird and hard to debug. At least this is how I felt on my first week learning Rust 😅. The more I keep pushing through the more I enjoy it (I'm probably becoming a masochist 🤣).
Anyhow, great video!
Very true! The way I think of it is the compiler is forcing you to fix all your future edge cases TODAY!
The classic Rust road:
Beginner: "Why the fuck does this code not compile!? It's obviously correct! Borrow checker you pedantic idiot!"
Intermediate: "Wow thanks borrow checker for saving my ass again! I totally missed this weird edge case!"
Expert: ""Why the fuck does this code even compile?! It's obviously wrong! Borrow checker you sloppy idiot!"
ive started learning Rust semi recently and like
I write code and get a bunch of errors and i look at one and its like
"why the fuck would this not work? this is how i would code it in any other language"
... thinking ...
"oh frick that would totally have a major bug in this edge case"
"No Garbage Collector" is not necessary a feature. It is just one of the options to manage memory. And it can act better than ref-counts because you do not intermix your work with increments/decrements/conditions. And can sometimes act better than explicit management since it may improve some locality of accessed memory by batching frees and it can be tuned for system it is starting on.
Stack allocation, "Never free", and hierarchical - yet another options.
They have their own compromises. Rust, indeed, helps to reduce surface where those are usually expose themselves. But it is not zero. Don't forget that call to free() function is not free.
P.S. I expect Rust, modern C++ and Zig to have means to pluggin in GC too.
Thank you for your wisdom here, but perhaps my point wasn't clear enough:
If you have a garbage collector, you're now blocked from:
- Embedded development where constraints mean you can't run a GC
- Webassembly - where the browser brings its own GC, you will have to disable yours (can you do so? Go can't, you must use an experimental alternate compiler, for example)
- Real time applications where there must be STRICLY NO GC pauses.
This is what I mean when I say "No GC is a feature".
@@NoBoilerplate
I guess, I got where that "feature" stems from. Maybe in this case "having choice to be free from GC" - that's the feature 🙂
P.S. Sorry if my previous comment sounded arrogant (hope that's the right word).
@@virkony I didn't think you sounded arrogant, I thought you sounded knowledgable. Thank you very much for talking about these concepts with me, I'm learning much!
I guess the million dollar question is, should GC be an "opt out" feature or an "opt in" feature. In Rust, it's an opt in feature. There are crates that provide "smart pointers" with batched destructors and free. As well as custom allocators, that can do something similar.
It's fairly rare that you need a full blown global garbage collector.
@@KohuGaly A great question, and I'm certainly not smart enough to know the answer. HOWEVER, here's my feeling:
If GC is default, removing it is difficult as it breaks a lot of assumptions.
If GC isn't default, adding one is easy.
My source for this is the Nim language, which is trying to go from GC -> Arc, and it's been a lot of work. In Rust, Arc's just a type we can use if we fancy it, on a case by case basis.
I don't see how Enums and Structs are a "weird" feature?
This is the way
@@NoBoilerplate That is a very confusing response
@@something4074 Stop worrying, you are already there.
Get Oxidized
I think he meant enums that can hold data. That's a staple in functional languages but sorely missing from OO ones.
3:51 I think line 3 in the second code snippet is supposed to be `b = "newname"`, right?
SIGH yes it is, thank you I'll put it in the errata. I compile my rust examples, not js!
How a developer starts interacting with rust.
- Look at the code once, gets confused by a lot of unique features.
- Start studying the book. Gets even more confused by all the technical details.
- Start writing a few projects. Gets a lot of errors, start hating the language and all the time spent trying to making the compiler work.
- Finish writing the project. Start testing and debugging. Realize it takes a few minutes to debug and test the ENTIRE project.
- Finds out how fast the project runs.
- Realize that all frameworks in rust are written in a similar way. No need to re-learn every time like in javascript.
- Start loving Rust.
That's it! For the first half of that learning, you're gonna need a lot of motivation. I started writing my videos for that reason
@@NoBoilerplate Yes. But it's definitely worth it. Feels like entering the "cool coders" club.
I used to wonder why it ranks so high each year in SO's surveys for being the most loved. That is until I tried it. Yep, definitely feels like a cult devoted to worshipping Rust.
- Starting to love how long the compilation takes :-P do not get me wrong tough I like this language
@@devnexen Keep your rustup up to date, every edition gets faster!
been learning rust for about 1 month now and I actually understand what is going on at 10:57 :). First watched this video about 2 weeks ago and I had no clue what any of that meant
Fantastic! I'm delighted :-)
I'm unconvinced by the "no garbage collector" part.
AAA games use a bunch of hand picked allocators to handle millions of entities without any lag.
Low-end Embedded devices will often use static allocations for fine grain control over memory layout.
Wasm doesn't come with an allocator, so producing nice wasm requires the programmer to think about memory management.
The (safe) rust solution is to just let the borrow checker spam malloc and free calls.
I do believe you can write rust code that's as fast or faster than C, but the performance critical parts of the code *will* end up looking at lot like C code.
The borrow checker shouldn't be spamming malloc and free calls. Memory should only be allocated on the heap if you use a Box, Rc or RefCell (or their parallel friendly cousins), and should only be freed if one of those objects goes out of scope.
Rust is smarter than these mistakes you are guessing at, why assume the worst?
@@taragnor Don't forget the probably most used Vec. There are a few other data structures from standard libary that are heap allocated. But the language (without std lib) itself doesn't magically use allocators. If it would, it wouldn't be a system language I'd say. You have the same power as C and C++ (although it requires sometimes unsafe Rust)
@@khaared Yeah, Vec and the other data structure classes too. Still have no idea where he's saying that the borrow checker is spamming malloc and free calls. At worst that might happen on a growing Vec, but you can set it to reserve a set amount of space when you create it if you want to avoid it resizing a bunch of time as you grow a big one.
I don't think you understand how the borrow checker works, but maybe I'm reading this wrong. It's a compile-time feature.
Static allocations are possible. This isn't an issue really. Wasm is a virtual instruction set. Instruction sets don't come with allocators, OSes and standard libraries do.
The one thing that Rust can't do that you mentioned is usage of various custom allocators for various scenarios. Rust currently can use only one custom allocator globally, per crate (library).
From my experience, it's not the best language for tasks that require very fine-grained memory management (altough some people wrote entire kernels in Rust), but it works very well for a lot of performance-critical code .
5:46 No runtime types - does this mean it's impossible to interrogate the type of a variable at runtime? If so, how does the cat/dog example know which type is being passed in?
Yes. You can't check the type of a variable at runtime because you don't need to: you already know. In the cat/dog example the type of pet is stated in the function signature; `pet: Animal`
In statically typed languages, there is nothing to interrogate at runtime - the value could only be exactly of one type, otherwise the code would not compile.
The cat/dog example works, because rust enum is a tagged union. It has a hidden discriminator field, that is used by the "match" statement to branch the code for the different variants of the enum.
Rust also has a dyn modifier for pointers, that allow you to do dynamic dispatch (the pointer can store any type that implements a given interface, but there's no way to get the concrete type out of it).
And then there's also the Any trait, which in combination with dyn let's you do downcasting to concrete types. But that's rarely used, as it is mostly pointless and unergonomic in statically typed language.
Imagine it this way: The cpu doesn't understand types, it only knows about bytes and a few operations. Runtime types are an elaborate fiction that stops us being confident in what we're doing!
The compiler checks type on assignment, it can therefore never be anything else as it throws a compiler exception. You can get the type at runtime, but unless you're using unsafe, there's really no point in doing so as it can never be anything else outside of it. Check std::any::type_name if you want to see how you can get the name of the type. It also takes into account whether or not the value is a reference or not.
Thanks everyone for all the answers :) I understand perfectly now.
My cat comes when I call his name 😻, but even the vet thinks he acts more like a dog than a cat. 😅
Another great video.
Thank you! Maybe you have a fox!
6:55, interestingly, if you really hate explicitly naming types(I personally don’t mind that much) there are languages like ML that can do essentially all type inference for you( and display it to you) without any explicit annotation. This comes with it’s trade offs , but there you go
I started hearing a lot about Rust recently, so I decided to read up about it before trying it.
I decided not to use it and without mincing words, I just don't trust a language with that foundation list.
What do you mean with "foundation list"?
@@NoBoilerplate The Rust Foundation. It's continued development was announced by several companies. I just don't trust most of them.
@@ONIscrooge Ah! Mozilla, Google, AWS, Microsoft, and Huawei. Yeah.
I don't really know about Google and Huawei's plans for Rust, other than they are happy to pay to help development.
But Mozilla, AWS, and Microsoft are building and hiring with Rust HUGELY:
Microsoft ported all of the windows api to rust:
crates.io/crates/windows
AWS are porting all of the aws cloud api to Rust:
github.com/awslabs/aws-sdk-rust
And Mozilla, well they've lost their way a little at the moment haven't they. I hope they can find their way back. At least they're still putting huge amounts of money into Rust, so I won't write them off just yet!
What's the 'trust' part here? What don't you trust them to do, vis Rust? I'll take TH-cam's advertising money to do good Rust education, even though I don't trust them!
@@NoBoilerplate I don't trust them to make good decisions long term in Rust's development. I can't really give specifics, because anything under the sun is a possibility with their track record.
@@ONIscrooge Here's hoping the Rust Foundation keeps it's independence, which is has thus far.
I have to say I love your videos they make me so happy. Thank you so much!
Thank you so much! Did you check out my podcast? I'm so proud of it!
@@NoBoilerplate no but I will right now! Thank you so much for responding it made my week :)
@@skyesamuels8657 My pleasure! I hope you like it, would love to know what you think! th-cam.com/video/p3bDE9kszMc/w-d-xo.html
I completely disagree with your statement on how rust is not a better c++ and that go is.
First of all, c++ no does not rely on object orientation and its type system is way more complex than go, the only part of c++ standard library that relies on classical object oriented with dynamic dispatch are streams and exceptions, all other parts relies primarily on meta-programming and secondly on functional programming.
Think of std::string for instance, std::string is an alias for the template std::basic_string.
If you want a new string type using another allocator, you just change the allocator, creating a whole new type in the process. Giving this template a new allocator is actually giving him something that holds a set of functions to call when needed, this is an approach of functional programming. From this simple and overused class example, you can see directly where the traits in rust came.
Same for all collections, iterators, same for the whole and libraries, meta-programming and functional programming, C++20 with concepts is giving us an alternative to rust traits (concepts were planned on c++11 at first), C++20 new library is directly based on functional programming, C++20 is integrating the fmt library in the standard which rust took almost as it was.
Secondly, C is not the fastest between C, C++ and rust. C could be the fastest if the programmer is actually taking a lot of time to adapt its code to the compiler translation in assembly that could not be portable to another architecture and/or could change with a compiler update. Most of the time C++ is faster because the compiler is free to make way more optimizations on code and rely a lot more on compilation-time calculation Rust is almost at the same level of c++ in term of performance and have way less delta between two runs. Rust is taking the whole philosophy of c++ on zero cost abstraction.
The sum type is not rust-specific, rust almost literally took it from functional languages, especially Ocaml. You can do sum types in c with an union and an enum, you can do sum types in c++ with std::variant or std::optional.
For the "data ownership" and "garbage collector" sections, this is relying yet on another C++ mechanic that is the core of this language and as Bjarne Stroustrup said, it would be the first thing he would do if he was asked to rewrite C++ today : RAII (Resource Acquisition Is Initialization), Go didn’t get this and preferred a Garbage collector. C++ is memory safe as long as you don’t use c functions and no longer use operator new and operator delete. Rely on smart pointers like std::unique_ptr, look at std::box::Box and see how things seems similar. Rust is taking this safety and ensure you do it the right way.
These are all the reasons why rust, for me, is a better c++. Rust is actually a C++ if we give up the C code compatible constraint, everything that rust do better than C++, it can because rust designers didn’t care about C retro-compatibility (except for exceptions).
Const correctness is really important for C++ for instance, C retrofitted the keyword because it was helpful but C++ did it before C. But because C++ had to be retro-compatible, a value declaration could never be const by default, thus const has to be written, rust is not bonded to be C retrocompatible, thus all values are const by default, only mut values are variables.
Same for move semantic.
I think you missed an important point on rust : its very name. Rust has been named like that because it does not invent many things; it uses things that has been experienced throughout the decades of programming, taking the best of everywhere and making it better.
Rust is a better C++, taking its whole philosophy, the same goals on performance, the same use, the same goals on how to make things on many things. It’s just making it way simpler, giving up C retrocompatibility that makes no sense now, taking years of experiences and tests in C++ without having to prevent to break compatibility with existing code and taking whole parts of functional programming language in the process to make it better.
Go is nowhere near that, RAII has been abandoned, performances too, compile time operation and meta programming as well. In many ways, go is way closer to python than C++, making a language as simple as possible, really easy to learn, provided with lots and lots of modules, used a lot for scripts and to be used online primarily. Go for me is like Python and Java having a baby, the performances and garbage collector approach of Java, the learning simplicity coming with batteries of Python.
Yes I regret the Go analogy, woops!
This is a great explanation. Thanks.
Excellent video! Content structure, presentation and even the way it is narrated is very well done 👍 subscribed ✅
Thank you so much! Do check out my other Rust videos, there's more of this style there!
Every time I write Rust I feel like it's hugging me and saying "you can calm down now. You're safe. Things can be good, see?"
A kind driving instructor!
"Now over there, that's a runaway truck, we're just going to ease into the next lane and let it pass... that's right... a little faster..."
Can anyone provide any source for the part starting at 1:44? (concerning the speed of languages compared to C) Would love to check it out
There's so many benchmarks, which is why I was so vague. A simple pure CPU benchmark is github.com/kostya/benchmarks