ERRATA - 6:50 - there should be no backticks in the macro, some copypaste error has happened here! (Thanks to @ilyvion on the Rust Programming Language discord for pointing this out) - `#[derive(...)]` is an attribute that executes macros to perform the derives (thanks to @TheDestroyer19 and /u/LoganDark for this) - Python 3.10's case statement is actually structural pattern matching, so they didn't JUST wait for 15 years to do it, it's actually improved from Guido's original PEP - There is ACTUALLY no Rust 2.0 because the Rust teams are strongly committed to backward compatibility. I over-stated the effect macros have on this. - Linked lists ARE possible in safe rust, using various techniques (Box and Rc) - rustc spends most of it's time in LLVM and not in static analysis. - Go is not written in C++! Wikipedia confused me. It has been bootstrapped since 1.15, before it was written in C. All standard libraries including the compilers are now written in Go.
technically, proc macros can also go directly as #[...] as seen in for example: #[clap(short)], not only in derives. so really more like #[...] can mean proc macros. but i think it's fine to simplify as macro!() in the video since you showed examples of the macro_rules! only, without mentioning the more powerful proc macros, and macro_rules! macros can only be invoked with the bang attribute macros also don't take arbitrary contents, they are applied on otherwise valid rust items, so again, you pointed out that syntax extensions are clearly marked with a bang, but attribute macros aren't really syntax extensions, they just generate boilerplate. there's a joke about your username in there somewhere
> "Linked lists ARE possible in safe rust, using various techniques (Box and Rc)" sure, but only because Box and Rc have unsave code internally. The thig bothering the borrow checker are doubly linked lists specifically. Who owns a node; The predecessor or the successor? With a mutable doubly linked list, both need to have a mutable reference to the node in question. Two mutable references to the same object are prohibited in save rust, thus the necessity to use unsave somewhere persists.
I recently had a very fun “turtles all the way down” realization. You have no clue how happy I was when I saw that String was just a wrapper around vec like I thought.
You convinced me to try out Rust. I ignored it because there were a lot of people claiming "Rust will replace C", which sounded ridiculous to me. After seeing your videos I still think Rust will not replace C, but it sure as hell looks like it will replace C++.
I think the writing is on the wall that Rust might replace C/C++ in *new* projects. My single strongest piece of evidence is that, for the first time in 30 years, we now have TWO blessed languages to write Linux kernel modules in: C and Rust.
There are more people wanting to write in something else than C than you might think. For example D implemented subset called "better C" because people wanted to use D in places that you would normally use C.
Yes, my day job is (currently) not yet in rust. It's a great language to learn though! Do read Amos's blog: fasterthanli.me/articles/a-half-hour-to-learn-rust
@@hundvd_7 Backend? BACKEND? I should have called the video "Turtles all the way UP"! Yew is a faster frontend framework than React (pure webassembly!) yew.rs/docs/getting-started/build-a-sample-app
@@NoBoilerplate, do it! @Tomato Cat, learning Rust will make you a better programmer. It demands from you an awareness of program statefulness that will help you in all other languages, and indeed, not even only programming languages, either; I understand the semicolon in English composition because of Rust.
Have been trying to learn Rust for a while now, and I find it hard to learn something bit by bit without knowing what the big picture is. This series had helped a lot and given me some much needed inspiration to continue.
You and me both, friend! I had that EXACT problem when I started learning Rust. It's SUCH a steep learning curve (TWO STRING TYPES!?) that I had to have a chat to my friend who already understood rust to sell me on it again, then I'd get back to it a week later and do a little better :-D
Yeah also read the rust cookbook! It is honestly the best way to understand wtf is going on They explain how and why the language works differently than others, in great detail
An important thing to realise about Rust taking longer to compile is that the compiler is doing things that instead happen at runtime in almost all other languages. You are trading speed of compilation for speed of execution. And as a bonus you get to discover bugs when compiling instead of when running in production.
TLDR: rustc is spending time in LLVM and not in static analysis. No, that is not in fact the reason. That wouldn't even make sense, unless the analysis is insanely expensive (which it really is not). It turns out, that in modern compilers, you spent the vast majority of time in LLVM and the linker, and not in fact in the frontend. It turns out if your project is a few K, and the stdlib is a few M, you spent time wherever you touch the whole stdlib, i. e. the linker. Who would have thought that would be the case, right? On a hello world: - The rust compiler takes 150ms (plus 90ms load). - Of that, 60ms is literally the linker. - And 50ms is llvm. - 9ms is borrow and type checking (!). Almost NO TIME is spent in rust's "safety" features. In C, equivalent hello world: - Takes clang 50ms (plus 30ms load) (which is like 1/3rd the time) - Takes gcc 85ms (plus 15ms load) (which is 60% faster) - gcc: 40ms for preprocessing+load cpp, ~1ms for compiling, ~30ms to assemble the file, and ~30ms to link it. - clang: who knows im not going to try to even understand the clang trace format lul. But in summary: - Statis analysis is not the expensive part - It turns out (surprise!) that LLVM and linking are slow, because (1) needs to do a lot of *stuff* and (2) is a single chokepoint. Also, funny thing: LLVM gets a lot less expensive if the frontend optimizes the IR at least a bit, because llvm needs to do less *stuff*. It also helps if you don't emit 15 functions when the user wanted one.
Rust's macro system is absolutely magical. One of the craziest things I have ever seen. I very rarely use it however, they are very difficult to build and debug. The thing I find about Unsfe Rust and memory management in Rust is that a lot of the memory module and safe abstractions are not explained properly. You pretty much have to know what you are doing before diving in. Which usually means it is better to have some experience from writing low level C and C++ code before learning Rust. The Rustonomicon is a great resource though. Probably the best introduction to memory management in general. Even for people learning C or C++.
I agree, the macro system is very very powerful, but it's sometimes quite difficult to debug when you have things like nested macros and things like that
@@livingbutterfly The thing that really doesn't help is the lack of resources. Almost every facet of Rust has a well kept book about how to get stuff working. While Rust's macros are kind of just left out of the conversation. I'm sure there must be a book somewhere, however the official website barely makes any mention or links to any resources for macros. The resources that do exists might be outdated or offer trivial surface level information.
@@thestemgamer3346 yeah the only _offical_ resources are a small chapter on the book and the rust reference, which makes it quite complicated to get started. When I started, I had ever user macros before, and things like macro hygiene were quite complex at the start because I couldn't find almost anything that explained that kind of things. A macro book would be actually great!
@@livingbutterfly The issue about making a great Macro book is that it would require someone who is both: good at writing books, and understands the macro system at a very deep level, and who is great at relaying information to new users/beginners.
Very good comment, I agree that macros can be super complicated. I found this video to explain their purpose in a new light, though, which I loved! Loving your channel btw - keep up the memes! :D
really like the way you present these features. As someone curious on the language, I really enjoy this type of presentation vs code examples and syntax tutorials, because it lets you see why you would even want to dedicate time to learn it in the first place.
Indeed, I am not a Rust expert, so I can't YET give you perfect guidance on the technicalities. I AM, however, a good cheerleader, and can get more people interested in Rust, where I can direct them to the official rust book, or Amos (fasterthanli.me) for more deep dives!
2:35 that’s partially true. You can’t get an intrusive (non-owning) linked list or a double linked one in safe rust BUT a singly linked, owning, partially intrusive linked list is very simple and a very common structure for me to use while in the early stages of architecting my code / in non performance critical cases where there is no clear owner of the list. It’s just an Option member in whatever struct you’re using and the same for wherever you’re storing the head (you can also store the head inline)
Please keep making these - I've been trying to figure out what language to expand my knowledge to, and your videos have convinced me to take a look into rust. It could be nice to hear your perspective and opinion about web frameworks in rust, because you seem to have a good way of highlighting the strong parts.
Like a whole "SO YOU WANT TO BUILD A WEB SITE IN RUST" video? I sure can, though it won't be a perfect step-by-step tutorial, there are plenty of those that exist, it'll be much faster. Think that makes sense for my format? rocket.rs is where I'd recommend you start, if you're looking, though Poem is lovely for an API.
@@NoBoilerplate Not necessarily a step-by-step, but more about what is available, what are more serious than others, what strengths and weaknesses they have - for a noob it is hard to figure out what might be the best option to start with.
@@NoBoilerplate I'll keep that in mind :) I remember reading some complaints about rocket.rs being developed by a single dev, which gives it a bus factor of 1. Need to see if how well my experience with Laravel and Phoenix translates into that one.
After your first video I tried Rust for the first time... and I'm loving it! Honestly it is now one of my most favorite languages, if not the most. Before I also used Python and was very admired of Pythons simplistic nature, but always missed static typing and safety of compiled languages. But yes, it has its flaws, nothing is perfect, but I would love to do more work on Rust since it is so brilliantly and carefully designed language
Also, I would say that I just love the Enums in Rust, they are so versatile. My object oriented mind immediately started thinking in objects, inheritance and polymorphism, however I realized that Enums work much better in some situations instead of trait objects. And the fact that each of them can hold different data types - oh my god. I remember thinking that Enums in Java are great since they are objects and can have constructors and fields, but this is just mind-blowing. And most importantly - without needless overhead on runtime (zero cost abstraction baby!)
I absolutely adore this channel - Thanks for creating these videos, they soothe my mind and make me very happy about the future of Rust! Best explanation I ever saw of Macros and Unsafe Rust, well presented and to the point! Looking forward to your next one!
Thank you so much! I have received feedback that I've got a few small technicalities wrong, so always check my pinned comment, where I put the inevitable errata! My plan is for a video every two weeks while I get used to the platform, if things go well, I'll up that to weekly, if not, well it was a fun experiment!
My most favourite feature of rust is the naming for numbers. omg i just LOVE IT. instead of using the words like, int, short, double, long, etc. rust uses the words u32, u16, f64, i64, etc. the u letter specifying that the number is unsigned is great, now i can allocate double the space in the same amount of bits when im storing positive values, it also gives me so much more confidence on bit operations knowing what every bit will be like. it also removes the words int and double from your mind, changing it and making you know the exact amount of memory you will use up, making you know, this number can be an f32 it doesn't need the precision of an f64. this loop doesn't require 32 bits to hold it, i can do fine with just 8. It is by far my most loved small feature in rust.
@@samu350 I can share with u how I feel about it because I have exact same feeling. First point is that I work as python developer and I have much more experience with it so I can create scripts that I need in no time. Second is that I don't really need deep functionality of Rust to create for example mafia host assistant which is just random generator+timer. I just feel like I waste a lot of time building such simple app in Rust that I'm not familiar with. But I'm trying to find any excuse to use Rust. And sometimes it's just not worth it. Still learning it, but I can't find myself interested in project that is worth my time playing with rust. I wish u got answer that u've looked for (not English native, sorry if it was hard to read)
@@lukivan8 Your english was fine you shouldn't put that statement in the end :) I get it, I was doing Leetcode with JS (a lang I know well) and decided to roll with Rust to learn it. Not going to lie, I spend twice as much time in each exercise because of how unused I am to the language.
Far out. I have a language design document and I keep seeing "new, unique" language features I had "invented" in your Rust videos. Not the same implementation, but the same intent at least. Hard to gauge the veracity of this, but that's the Internet for you. As I wrote in another video, this series is inspirational. It tells me "these things can be done", or rather, "have been done". I need to get a Rust book and look into it for real. It was on the list of Things To Read but it's now on the top of that list. Thanks for the content.
Yeah, I couldn't believe all these language features were in ONE language, and not only that but it's so popular I could stand a good chance at getting PAID to use it! I started with the official, free, book, it's great! doc.rust-lang.org/stable/book/
Thank you so much! I've always liked public speaking and audio production, and now I've had 8 seasons of practice producing my hopepunk/scifi podcast, Lost Terminal! (www.lostterminal.com)
Mission accomplished! Here's my recommendations: If you're new to programming, start with The Book doc.rust-lang.org/stable/book/ If you'd like to get started faster, fasterthanli.me/articles/a-half-hour-to-learn-rust (then hit the book!)
Amazing explanation. Makes me want to look into Rust further. I also love that the video background color matches the UA-cam dark mode's and there's a single pixel-high progress bar at the bottom. So thoughtful! :D
Obsidian is awesome! Would 100% recommend it to anyone who needs to take notes, brainstorm ideas, or even just link loads of stuff together. I use it for classwork, D&D, loads more.
What I love the most about this language is how easy it is to write code that is both easy to understand AND efficient. Sure, there are lifetimes, there are macros, there are unsafe blocks. But each of these get limited to their own little "complexity boxes" far away from the rest of the code. With good documentation it is very easy for a developer to understand what these "complexity boxes" do without worrying about what each line does. Since the compiler optimizes a lot. "Easy to read" code often performs more efficient than "smart senior dev" code. It's going to optimize away a lot of the repetition, will remove unused parts of the code, apply branchless programming. If an iterator runs a limited number of times (like 10 times), it might create that number of blocks in a row. Only to then optimize all of the blocks again...
It's SO good to be building high-level web services in a language you KNOW you don't have to eventually FFI out to C once performance gets important at scale!
What really impressed me about rust macros was the peg library. It parses data with rules you define directly into typesafe values, without the need to walk any kind of tree yourself.
Keep up the good work, I checked your history of content, looks like you've been dormant for some time and now your content is Rust specific, 🙏 please continue. I thoroughly enjoyed your last two vids, I subscribed in effort to convince you to stay. Excellent work.
Yeah! I've been practising audio editing for 2 years producing my hopepunk podcast, LostTerminal.com, and now I've found a great way to give back to the rust community!
You have convinced me to try it now I just need some totally useless project that I can waste hours on. Also it's blessed by the sacred gods of the Linux kernel so that's pretty cool.
Thanks for telling me to learn rust! my motivation on learning rust was dwindling around that time because of school. Thanks to your comment I finally got the motivation to continue learning rust and finally made a fire-spreading simulation built on rust after weeks of learning fundamentals and syntax. o7
With things like async being just another library, how do you choose what lib to use when multiple libs are available? I know this is a problem for every language out there, but I'm curious if Rust has some way to deal with this…
Stuff like this will always be a problem. Rust even doesnt take anything big that can be opinionated into the standard library, which reduces the chance of having a default to go to. This is just to let the community figure out the best solutions and change them over time, which makes rust more future proof.
4:34, in C++, it's possible to overload most operators without using metaprogramming. And it can be restricted to a class or not. Tied to a class, it's not bad form, because the class meaning should be self-explanatory. 9:01, how many lines of code this mean? In C++, 5s for ~10k lines, with optimization flags on.
Oh interesting, I'm not very familiar with C++, thank you for the operator overloading explanation. I'm uncertain how many LOC the 100 libraries I'm compiling in 10s there are. But certainly Rust is slower than C++'s builds, but that is because there's a great deal that the Rust compiler does that the C++ compiler doesn't do. Macro expansion for one. Rust is extremely different isn't it! No inheritance, new syntax for lifetime annotations and borrows, and the compiler hates a lot of the standard normal patterns we've been using for decades. Yes Rust is very different from what we're used to. But that's the point. Two features you can't get in C++ that I think you'll like are Macros and the Unsafe system. Macros are nothing like templates or cmptime (they're more like lisp macros), and the unsafe system is a genius way to ring-fence pointer arithmetic, to allow us to build safe abstractions around unsafe pointer code. I did a video on both of them here, and I'd love your opinion on it: ua-cam.com/video/PuMXWc0xrK0/v-deo.html Cheers!
@@NoBoilerplate I don't know Lisp macros. C++ has 3 special ways to deal with compile time: - constexpr: it can make all calculations, but the result must be const. It can be attributed to a const, though. - template: a model of how a f() will work. It will make 1 for each type, according to calls. - macro: it pretends you wrote the code in a specific way. I heard the difference is that Rust uses "hygienic" macros. Probably avoiding the classical error: #define add(a, b) a + b int x = 3*add (1, 2); //Resulting in 3*1 + 2 = 5, not the expected 3*(1 + 2 = 3) = 3*3 = 9. There's also a 4th hidden way, dealing with variables at compile time: making template f()s generate other template f()s, with different constants, according to "variable" changes. PS: I forgot to say that that C++ time has exceptions flags off. PS2: your link shows this same video.
2:18 that’s just false. Linked list are possible in safe rust using Rc and RefCell. RefCell shifts the borrow check from compile time to run time, but it’s still memory safe (as in: the code will just panic and shut down when you violate the borrowing rules)
Ahhh man, all your videos just make me really, really wanna write Rust code. I wanna try all these cool things! When I was first learning about C/C++, I heard that everything was built from its self, and I thought it was so cool that you can just add features to the language you're writing in. But Rust makes this a far deeper and clearer goal, less just a cool side effect of being able to write low-level code and more an intentional mechanic built into the greater whole.
Mission accomplished! I have designed the start of this rust series to get people excited about rust's unique features. However you have work ahead of you: the reason you need this excitement is that rust has quite a bit more to learn than other popular languages. Not as much as Haskell, but more than JavaScript. Keep that in mind when you're learning: you get out what you put in! Try the official rust book, link in the description, and good luck!
@@NoBoilerplate I have found it to be a significant challenge to learn compared to most other languages. I'm learning loads from watching this series, but I really need to set aside some time to learn it because there is most certainly a lot. Oh, and thanks for the well wishings!
Really love these videos, makes want to try out rust. As someone who does a lot of scientific programming I've been loving Julia, I see a lot of similarities between it's macros and rusts macros
Huge fan of Julia! I think data scientists should switch from python TODAY! For big infrastructure projects, web apps, games and such, Rusts the the clear winner 👌
Totally agree everyone should be using Julia, but it'll take a lot of time to get the support python has. Ye no question different tools for different jobs
It does feel like that sometimes XD Have you read The Book? I'd start there, it's super easy to get going. You might like fasterthanli.me/articles/a-half-hour-to-learn-rust too!
Great video. Could someone please tell me where I can find the "cmd!() macro" that is shown at 7:37? It doesn't seem to be part of the standard library.
Thank you so much! The words I speak at that exact timestamp are "the cmd macro, which is from the command-macros" crate. In Rust, crates are the name of the libraries, and you can find them all at crates.io! crates.io/crates/command-macros :-)
@@NoBoilerplate Oops you're right haha, my bad, I don't know how I missed that, sorry. 😅 Thanks a lot for the response! I appreciate it. Also, I'm sure you've been told this a gazillion times but your videos are fantastic and very well-made, the scripts are perfect, and your voice is so nice and "listen-able" :D I've also noticed that you tend to reply to most of the comments under your videos which is so amazing to see! Keep up the great work! 🤍 I hope you get to 100k very soon!
I don't really use Rust, and don't really have need for it yet but your videos about it are quite inspiring and relaxing (somehow lol). Your arguments in favor of it are sound. Will definitely try it out in once I have some time for it.
Thank you so much! I'm so please to have inspired you, that's the whole point of these videos: To get more people trying out this incredible language. If you want to hear me read something ACTUALLY relaxing, I produce a hopepunk podcast about a little AI, check it out! (I made the videos in rust!) ua-cam.com/video/p3bDE9kszMc/v-deo.html
My apologies, though I didn't say it, on-screen is a *doubly* linked list, as in the standard library. You're quite right that a singly linked list is fine - where the borrow checker trips up is in ownership cycles, which is why you must break out of safe rust to do this.
@@NoBoilerplate I guess doubly linked list would still be implementable with some safe abstractions like Rc, Arc, BUT I'd have to type some unsafe lines if it was to be efficient like in std.
To gcc, I can pass the -E flag to see only the output from the preprocessor step. Is there a way to do this with cargo or rustc directly? I would be curious to see to what the tokio main macro compiles!
@@HermanWillems Boring is safe. A lot of companies want safe! However, plenty of companies don't, that's where the fun is :-) I have chosen and am recommanding Rust because it's the safest, most mature language that has the great features that I mention. Language at the top-right of this graph are safe, but language in the top-right 25% of this graph are safe enough and GOOD redmonk.com/sogrady/2022/03/28/language-rankings-1-22/
Great video! Just wanted to point out one thing that Go has bootstrapped since 1.15. All standard libraries including the compilers are now written in Go.
I did think that was the case, but my suspicious were aroused by Wikipedia's sidebar meta data claiming that go is "written in" go, c++, and asm", whereas the rust pahe just says "Rust". There are other comments by expert-sounding people suggesting that there are a few assembly parts, and that initial compilation is c++ bootstrapped?
@@NoBoilerplate Go has been written in Go since 1.5, not 1.15. I assume that was just a typo on Jereon's part. The original Go compiler was in C. With Go 1.5, Go was able to bootstrap itself with any working Go compiler. C++ was never used in the main compiler. Maybe the wkipedia article has been updated to clarify this since, but C++ is only used for the GCC Go compiler frontend. I believe that means the Rust wikipedia article can be updated to also say that C++ is an implementation language of Rust now that the GCC Rust project is being mainlined. That's purposefully a bit facetious but hopefully the point comes across. In a bit more seriousness, the Rust compiler does have a small amount of C++ code for their rust_llvm/llvm-wrapper. For Go, it's a bit harder to track down exactly if the Go compiler is using C code directly or not, because the compiler uses the standard library & runtime and there are a few places where cgo is optionally used. As for assembly, it is true that the Go standard library includes Go assembly in a handful of packages.
While I do appreciate all that Rust is doing, I'm writing Scala and it's near identical in features. The only major difference is that it's a GC'd language but is much more mature than Rust. There are very powerful macro tools (since Scala 3.0). For low level code there's Scala Native. To transpile to JS there's ScalaJS. The entire Java ecosystem is at your disposal in normal circumstances. I will be keeping an eye on Rust but for now, from what I what people are saying, the ecosystem is still a bit small.
On pure package numbers, Cargo is about where NPM was in 2013, for context. Quite enough for serious use (I can REMEMBER working in Javascript startups in 2013!) --- I love Scala, my functional language journey started with it! ([1..] still gets me excited!), so thank you for pointing me at scala native. However, there is a pattern with high-level languages that they eventually all add-on low-level exceptions to their GC sandbox. JNI or Scala Native or similar. But these additions FEEL like additions, not first-class features. ScalaJS even more so. What makes me excited about rust is that it had unsafe (for low level) and macros (for high-level) right from the start, these essential features are core to the language. The whole language works in webassembly, everything works without libc* on bare metal, it's all rust.
@@BloodnutXcom ha! No no, I meant this: ``` [1..] ``` Which is actually, now I look at it again, HASKELL code XD (it's a lazy list of all positive ints)
It really is! There's two huge discord communities, r/rust is fantastic, and it's all very friendly. There are about the same number of github projects as Swift, Obj-C, Go, and Kotlin. I learned principly from The Book doc.rust-lang.org/stable/book/ but also from Amos over at fasterthanli.me
Nim is another very good but very underrated language which has both features you mentioned. There are plenty of memory management strategies available, including manual memory management The macro system is also super powerful in Nim
Love nim! I'm co maintainer of inim repl! We could talk about the technical similarities and differences of nim and rust all night, however ultimately for me it comes down to popularity: if I want to hire and build a team, I can do so with rust but not nim.
@@NoBoilerplate However; the situation can be changed if people like me and you (specially people like you who have a media of some sort) actually start talking about Nim and it's capabilities.
@@m.m3633 I have not been able to do so, nor would I be able to support myself while doing that. Rust has won hearts and minds, be thankful that we have such a language that is so popular, that has goals so similar to nim's goals. I also think Rust is technically better than Nim, to be clear. As I've talked about in my last video, though the borrow checker was designed to solve memory safety, it's SO MUCH MORE than that. Here's an old video of mine, talking about inim. ONE MONTH LATER I would discover Rust. C'est la vis!
@@NoBoilerplate optimal number of programmers for a team at first is like 3 or arguably even 1. Hiring programmers to use a language is dead easy, pay enough and suddenly smart people do what you want I'm a professional D programmer, there are enough of us to run multiple companies on, surprised?
Each time I watch one of your Rust videos, I fell motivated to do something in Rust again. Last time I wanted to do something with OpenGL and egui but failed 😅. Anyway, keep up your videos. I really like those RevealJS slides.
Thank you! Want to do some native app development? Tauri (a better electron, written in rust) just got their 1.0 release TODAY! IT'S FATE! tauri.studio/
@@mondei1 Good luck! Tell me how you find it (I'm @0atman on twitter) 12 hours ago the release was cut, looks like github.com/tauri-apps/tauri/releases/tag/v1.0.0
Just a quick note: *Elixir* macro system is very similar to Rust's with regard to, let's call it, _computing power_. Elixir macros are functions that implement AST-->AST transformation with full access to the standard library. Their crown jewel is Unicode module in standard library which is autogenerated by a macro from the actual Unicode specification file: > "The similar technique is for example employed by Elixir to generate String.Unicode module. Essentially, this module is generated by reading UnicodeData.txt and SpecialCasing.txt files where codepoints are described. Based on the data from this file, various functions (e.g. upcase, downcase) are generated."
That's EXTREMELY cool! This is why I love macro systems, you can do incredible things that you otherwise have to build non-standard tooling for! I'm a big fan of Elixir, but I am bound by practicality to restrict my search to the top 20 languages, as shown by Redmonk redmonk.com/sogrady/2022/03/28/language-rankings-1-22/
at some point in any language the rubber mmets the road and some code will need to be written in C or assembly language to deal with low-level details. Rust allows one to stay in Rust language when writing some of this kind of code but doing so in unsafe context where various safety features of Rust compiler will be restrained. At least on doesnt have to deal with things such as pinning or marshalling garbage collected memory, etc., as is necessary in other popular languages' glue layers
I THINK and maybe someone can correct me, that no c code is needed with rust - this is the whole point of the unsafe system! Certainly you can write online assembly, for hardcore optimisation, so you're right there.
@@NoBoilerplate Yeah, I've used Rust to wrap a C ABI library and that's pretty much true - when shifting into Rust unsafe mode can do pretty much anything necessary for interacting with C style library APIs.
@@NoBoilerplate Though I would argue that “unsafe” is an overly broad keyword. It really needs an optional specifier so you can say “I’m doing just these few unsafe things (see list), please check and enforce all other safety rules”.
The part about Python's `case` isn't fully correct. The reason they only now decided to add it is that the match-case statement is NOT a switch-case. It is called "structural pattern matching" for a reason.
Oh yes so it is! Thank you very much for the correction. I suppose structural matching is a better sell for the core developers than JUST nested ifs. Thank you!
@@NoBoilerplate When mCoding made a video on this feature, guess how the comments looked lol Seriously though, considering *so* many people mistake it for a switch-case when it's not, I'd say that they should probably have thought a bit more about making it look like a switch-case.
The safe vs. unsafe code thing reminds me of "managed C++" for use with .NET. That was a hot mess, though, because it required trying to retrofit safety features into C++ long after the fact. Funny story: when I tried "managed C++", the first thing I discovered is that because you had to give up the standard STL containers for the .NET container classes, you lost that trade of compile time for execution time that STL gave you. I've limited experience with Rust myself, but it seems like they learned a lot of those same lessons, and because things like generics and safety weren't bolted on after the fact as with C++, it could be done in a sane, useable manner.
Yeah, exactly - rust's core language is SUCH a good foundation - unsafe + borrow checker + algebraic types + macros = the most exciting language in the world.
not that I don't love hearing you talk about rust, because I love to hear you talking about rust, but would you consider doing a more general video about your experience with software development, and the languages you know? I'm thinking of learning rust and would love to hear your opinion on prerequisite languages, or necessary programming knowledge
@@NoBoilerplate I know python and java, but both of those are high level, so it certainly feels like learning rust means relearning how to program. I would love any and all suggestions, as a very confused compsci/maths freshman
@@shmendusel Excellent! Great start, those language will get you solid work for decades. As you already are familiar with programming, I would start here: fasterthanli.me/articles/a-half-hour-to-learn-rust and then, when you are excited, install rust with rustup.rs and go through the official book, which is what I did doc.rust-lang.org/stable/book/
@@NoBoilerplate that comment isn't actually pinned. probably because you edited it and it got unpinned i guess? weird that youtube enforces that for editing your own comments as the video creator
The bit about Go having assembly and C++ code… Go does support C through CGO, and there is an unavoidable need for some assembly, mainly when Go has to interact with the OS via system calls, but w.r.t the standard library and toolchain, Go has not relied on C/C++ in quite some time. The point being made is still correct though
Not just being able to, but it being exceedingly easy to build completely static (and thus highly portable) binaries is something I really like about Go.
Me too, it was a hard requirement when I was evaluating languages. Rust goes one step further and lows you to write no_std code that doesn't even depend on libc!
@@NoBoilerplate same with Go :) CGO_ENABLED=0 will disable any calls to C, including libc. -tags netgo instructs the compiler to use the Go network stack. If you do need *some* CGO anyhow you can add -extldflags '-static' to -ldflags to tell it to pack external libraries into the binary. The neatness/simplicity of this is what I like about it, compared to say, building manylinux wheels for Python...
@@jfolz you just gave me ptsd reminding me about python wheels... YES love this for Go and Rust - give me a single binary that I can sling somewhere (a container, a lambda, wherever!) Not using libc is a great feature for Go, I'm delighted to learn it has it - but the garbage collector will always make embedded/bare metal/webassembly deployment more complex than Rust, where there's nothing at runtime other than your program!
You mention on 7:04 that the numerical value of 3 will not be inserted and would rather have to be calculated at runtime. My rust is a little ... rusty. But I was almost sure that the compiler will precalculate all such redundant cases. Maybe what you meant is that the value of 3 will not be inserted during the macro expansion, but during the later compilation stages?
3:07, I think Python have Pyrex/Cython if you want to stick with Python-like syntax. 5:17 - forgot some other exceptions like Forth (immediate words), XL (with its tiered languages), probably Ciao, Template Haskell also uses explicit indication and rewrite rules if you want to modify source code without changing semantics. I most likely missed a lot including term rewriting languages.
Python-like syntax isn't python, though. I can't use, say, the `requests` library to make get requests using cython. It's a different language, albeit one that looks very very similar to python. Yep, compile-time code execution is a great strategy, I would imagine we could trace all of these examples back to lisp in the 50s and call it a day.
@@NoBoilerplate I didn't had much experience with Cython, but I would expect that it also allows to call high-level code at least same way how Python can be integrated as script for native program. This sounds more like tailoring requiremenets to the language though. When you need to do something low level it is weird if you are planning to mix it with some high-level things at same level. As for compile-time code exection. Everything can be traced to something. Not sure if 64 years old Lisp without types is a good choice in my opinion to get fair comparison for Rust when you say about type safety. Clojure might be a better choice. I wanted to ensure that we do not forget about other old and relatively new languages in videos where Rust gets most of the spotlight. E.g. Haskell Templates seems like was suggested in 2002. And in my opinion they share same important properties mentioned in video.
@@NoBoilerplate I like ideas of Rust as I'm in past practical C/C++ developer and like playing with Haskell. I can see how Rust can take over C++ and Zig taking over C. I really love traits/adhoc polymorphysm in Haskell. That's something that me and probably other C++ developers (remember about traits-like thingy in STL) were missing. Even without borrow checker it was already good enough in my opinion. And I agree that Rust macro is very powerfull addition when comparing with its direct competitor C++ to boost experimenting/desiging new language features. But it is not the only one. Though Rust is told as closing gap between low/high level code, I perceive it being more powerfull at low level.
@@virkony Thank you for sharing your insights, I think we're on the same page with much of them. The bottom line, is that I can't build a team in Haskell, or even Clojure - but I CAN build a team in Rust. The excitement for me is not that these features are NEW (as you've pointed out, they are not) But they're in a language that is POPULAR. We've not seen this before!
One interesting complaint I have heard maybe once or twice with regards to Rust, is the fact that it does not have a C-style for loop. There's a while loop, a regular infinite loop, and an iterator-based loop. But the standard (initial; condition; step) type loop we see in C and many C-like languages is missing... except it isn't if you use the cfor crate, which supplies a macro for this exact purpose.
You've been talking to C developers again haven't you! (kidding!) As an industry, we've moved past the old `int i; i < 9; i++` method of looping, now we've got iterable objects and such - even in modern languages where you can do a C-style loop, it's almost universally bad practice. `for x in y` is SO human, much nicer for us. ALSO in rust you absolutely can do this trivially. (as I read from doc.rust-lang.org/rust-by-example/flow_control/for.html): ``` for i in 0..array.length {} ``` And I imagine doing iterable.map() unpacks out to a nice simple for loop too. My advice is be careful who you talk to! Always consult the Rust Book for answers, it's great.
@No Boilerplate You're only covering the case where the "initial" assigns zero, the "condition" is "less than N" and the "step" is "increment by one". There are so many variants to that which are used often, and without that "raw" approach there's more learning curve and, possibly, less readability in some cases than the C approach. Not saying Rust isn't still better... just noting your rebuttal was weak. ;-)
@@peter9477 Iterators can do far more complex iterating than initial, condition, step. The old C way is entirely missing from Python and bad practice to use in Javascript, it was a conscious language choice to leave it out of Rust.
@@NoBoilerplate I'm well aware. (C since 85, Python since 99, Rust since 2022...). Was merely pointing out that example with 0..length does not reflect more than the most basic case of what the C for loop is used for.
just ran my first Rust program! by which I mean I wrote `pkg install rust` `cargo init` `cargo build` `cargo run` in Termux while sat on the… on the bus.
Linked list and doubly linked list arent imposible in safe rust. You can use weakref and refcell if the user of the data structure do not own the nodes, but if it do own them you can just use mut ref or indirect offsets (using an index to the list of nodes)
And when i learn about how to do a doubly linked list in rust, rust forced me to learn about the possible bugs and memory errors involved by these data structures. WeakRef and RefCell may be rust types but they are also abstruct consept that you really need to know before writing linked list in c, the difference is that rust forces you to know the potential risks and gurrentess you must provide before you can push to production
I'm still gonna stick with my C/C++, but I'm happy they finally have competition. C++14 onwards feels like a well-intentioned mess at the end of the day, so I can certainly see why people are looking elsewhere
For a long time I thought Rust was just C++ with stricter memory management and typing rules, because the crowd of people who just say "muh unique memory model *soyface*" and nothing else did an extremely poor job of explaining what was worth the effort of switching. But saying "It's C but with built-in Lisp macros and contracts" has me completely sold.
Thank you! I actually use an audio editor (www.reaper.fm) to make them, it's SO GOOD. My mic is a Rode Procaster through a CL-1 pre-amp into a Focusrite 2i2 interface. However, you shouldn't bother with this - I've tested the USB version of my mic, the Rode Podcaster, and it's SO SIMILAR you should just get that. No faff. I use a standard Gate -> EQ -> Compressor+makeup chain to punch up the vocals. I bought the mic to make my Hopepunk podcast, Lost Terminal, and it's been a fantastic investment, hear more: ua-cam.com/video/p3bDE9kszMc/v-deo.html
I want to contend for a moment that Python has first-party facility for metaprogramming, and also say that DSLs are only tangentially related to metaprogramming. Metaprogramming in Ruby is extremely common and mostly takes the form of automating rote declarations of methods, method decorators, and so forth; actual DSLs are rare mostly because the language itself allows for very free-form syntax. Ruby's metaprogramming is also of the SmallTalk family, meaning it works at the level of objects and methods, rather than the level of syntax.
Agreed with everything here. As I said in the video, the reason I didn't call Macros 'metaprogramming' is to not mix up with these techniques. "Build Tools" feels more like something you run before you execute your code, as macros do, so I thought it would be a better analogy.
coming from JS and React, i've loved macros - it lets people write really nice WASM frameworks with the same ergonomics as JSX, but without the normal JS complications of transpilation, bundlers, and a massive tool set edit: i do want to criticize your point that there's no Rust 2.0 - there have been multiple editions with new language features, but it's not quite as big a deal as other languages
I too love this feature, the pages of my two podcasts lostterminal.com and modemprometheus.com are written in using docs.rs/yate/0.1.3/yate/ to output a static site! Others have said the same, I have a note in the ERRATA pinned comment about this, thanks!
Over in Kotlin, we have inline functions, where you can pass lambdas in and it will all be inlined much like a macro. This is frequently used to make things which look like new language features, but which are just a library. Of course, in Kotlin, you can't just use any old content inside the function call - it still has to be in Kotlin syntax, which is the difference from Rust. Having tried both approaches, they each have their pros and cons. In the Kotlin case, you can read some source file and understand it without having to understand macros. But any "new syntax" you make will really just be syntax which was already valid, but perhaps which people didn't expect. You can't make anything new-new. (Still, `cmd(http get localhost)` is valid Kotlin - `cmd`, `http`, `localhost` are top-level functions while `get` is a top-level infix function. No need to introduce new syntax for that example. ) In the Rust case, you can make entirely new syntax. But now, someone reading the file has to understand what all the macros do, so it's less work to write the code, but more work to read it. LISPs of course do have both ways. Racket often trumpet that Racket is a language for writing other languages. Racket, for what it is worth, is another language which has an obvious One Good UI Library, because it has a UI library provided as part of the standard library. It's a language which I had a lot of interest in until discovering that some of the core team members weren't the best personalities.
Yikes, yeah don't meet your heroes! I had a bad experience meeting Richard Stallman, as you probably can imagine XD Thanks for letting me know about Kotlin's inline functions, that sounds good!
The comment at 3:31 that “you and I… will certainly never write unsafe code in our normal work” was a bit of a turn-off. While it’s important to let people know they don’t need to delve into the unsafe system to work effectively with Rust, I think we’re often at risk of giving developers the impression that there are dark magic crannies that they must never look at. If you need to, you *can* understand superficially arcane topics like network protocols, instruction scheduling, CPU caches, and manual memory safety. They can be hard, but you can learn them, and you’re already learning all the time. Saying people will “never” do things is an invitation to switch off, close doors, expect things to be unapproachable. Sometimes, a good engineer *does* find an appropriate opprtunity to use sophisticated techniques, in the process of solving core business problems, and this can even be a great opportunity to simultaneously contribute to open source - be it a fix for a crate you’re relying on, a new tool, or whatever. Often, solving really difficult problems *does* involve understanding these hidden fundamentals better, and that should be *exciting*.
I only say this because otherwise I feel like it’s a great approachable intro to these topics! I feel like that only means there’s *greater* onus to help people recognise what’s within their reach. Julia Evans blogs/zines are a great distillation of this kind of philosophy, e.g. the “so you want to be a wizard” zine
Omg thank you for showing me Julia Evans, she's amazing! Though everything you've said is correct, I still really think that what I said is true: Most developers aren't concerned with low-level bits and bytes, and are happy in the middle. Web developers, certainly, are happy to just horizontally scale any performance problems away, rather than optimise! (Though actually, that could be the inability to optimise their typically slow high-level languages like python, which is 80x slower than C) I should make a point in the future that these features (unsafe and macros) are GOOD TO HAVE.
Ooh, I'm learning this for the first time! How exciting! Given how GHC is *the* compiler for Haskell, despite others existing, I would imagine we'd gravitate towards a single popular one. Would you say GCC Rust is Rust without LLVM?
@@NoBoilerplate Its a Rust frontend for the Gnu Compiler Collection backend. It uses the same Rust corelibs as the LLVM based compiler, but it uses GCC's optimizations, compileflags and tools (binutils such as ld, gdb for debugging, etc.). This makes it easier to include rust support in existing projects and toolchains that use GCC (such as the Linux kernel and many more). But the GCC rust frontend is still in development, and very unfinished (It can compile simple rust programs already). There are some good presentations about the project by the lead maintainer on youtube.
@@NoBoilerplate Also, regarding your comment about gravitating towards a single compiler, that might not happen. It may have happend for Haskell; but if we look over at C and C++ land, we see many compilers that are all being used. Examples are the LLVM based clang, GCC based g++ or gcc, Intel's compiler, Nvidia's cuda/c++ compiler, MSVC. All of these are being used in production and have their own usecases.
D has some great features. As does Go, and V, Haskell, and lisp. What makes me excited is that the Rust developers have put SO MANY of the features I like in a really popular language, and they DIDN'T put in so many of the features I don't like.
@@NoBoilerplate I think what I like with D is that aloft features are written in the language itself (like rust) and you are not forced to use specific paradigm. The borrow check in D is new it's probably not as good as Rust right now.
I am not a programmer by trade.. And I don't really understand the benefit of rust.. Because in my understanding the reason why c++ is considered bad is because it is easy to make mistakes.. And so rust is like an abstraction of safer c++.. But still allow unsafe code too with unsafe block.. But personally.. I think I understand c++ for example when a variable is passed into a function or for loop just use constant reference.. Although I am a little curious why they didn't do pass by reference in the constructor? Usually I just see people copy it into the constructor function.. Constructor in rust is an explicit static function declared in the implementation block
Sure, that's the simplest possible macro you can build. Zig also has comtime functions, which I'm a big fan of. Though I don't really understand C, I see that there are a bunch of constraints on consteval, and the one that sticks out to me is it must not allocate memory. This seems like it must be used for very simple purposes. I'll remind you that rust macros can do anything rust can do, including access the disk, use crates, and access the network.
These are simmliar to 'const' keyword in Rust (but as alywas rust does better job with it). Closest thing to rust's macros is C/C++ Preprocesor but it sucks. Like you can write #define add(a,b) (a+b). But these macros are primitive - they cannot create their own syntax, and the language itself makes it very difficult to use them.
Somehow I cannot trust a language which does not have a formal specification. Saying that "the specification is the compiler itself" does not feel right...
ERRATA
- 6:50 - there should be no backticks in the macro, some copypaste error has happened here! (Thanks to @ilyvion on the Rust Programming Language discord for pointing this out)
- `#[derive(...)]` is an attribute that executes macros to perform the derives (thanks to @TheDestroyer19 and /u/LoganDark for this)
- Python 3.10's case statement is actually structural pattern matching, so they didn't JUST wait for 15 years to do it, it's actually improved from Guido's original PEP
- There is ACTUALLY no Rust 2.0 because the Rust teams are strongly committed to backward compatibility. I over-stated the effect macros have on this.
- Linked lists ARE possible in safe rust, using various techniques (Box and Rc)
- rustc spends most of it's time in LLVM and not in static analysis.
- Go is not written in C++! Wikipedia confused me. It has been bootstrapped since 1.15, before it was written in C. All standard libraries including the compilers are now written in Go.
It might be a good idea to pin this comment.
technically, proc macros can also go directly as #[...] as seen in for example: #[clap(short)], not only in derives. so really more like #[...] can mean proc macros. but i think it's fine to simplify as macro!() in the video since you showed examples of the macro_rules! only, without mentioning the more powerful proc macros, and macro_rules! macros can only be invoked with the bang
attribute macros also don't take arbitrary contents, they are applied on otherwise valid rust items, so again, you pointed out that syntax extensions are clearly marked with a bang, but attribute macros aren't really syntax extensions, they just generate boilerplate. there's a joke about your username in there somewhere
@@sodiboo Thank you!
@@ThisIsTheBestAnime Thank you, I thought I had!
> "Linked lists ARE possible in safe rust, using various techniques (Box and Rc)"
sure, but only because Box and Rc have unsave code internally.
The thig bothering the borrow checker are doubly linked lists specifically. Who owns a node; The predecessor or the successor? With a mutable doubly linked list, both need to have a mutable reference to the node in question. Two mutable references to the same object are prohibited in save rust, thus the necessity to use unsave somewhere persists.
I feel like I'm being indoctrinated into a cult - and it's working.
All will be oxidised
Seems like a pretty nice cult, yeah
a Cargo Cult? 😉
@@dwylhq874 oh, that's for sure why the cargo/crate naming thing happened.
Source: Uh... sounds right to me
The accent certainly helps
I recently had a very fun “turtles all the way down” realization. You have no clue how happy I was when I saw that String was just a wrapper around vec like I thought.
You convinced me to try out Rust. I ignored it because there were a lot of people claiming "Rust will replace C", which sounded ridiculous to me. After seeing your videos I still think Rust will not replace C, but it sure as hell looks like it will replace C++.
I think the writing is on the wall that Rust might replace C/C++ in *new* projects.
My single strongest piece of evidence is that, for the first time in 30 years, we now have TWO blessed languages to write Linux kernel modules in: C and Rust.
@@NoBoilerplate Ah did it actually finally happen? I only heard that they were discussing that, did they now actually allow Rust to join the kernel?
@@Ma1ne2 huh maybe? hackaday.com/2022/05/17/things-are-getting-rusty-in-kernel-land/
@@NoBoilerplate awesome! Also thank you for sharing the article :)
There are more people wanting to write in something else than C than you might think. For example D implemented subset called "better C" because people wanted to use D in places that you would normally use C.
I dont write in rust, but the way its told by people is heartwarming and makes me happy that people are this enthusiastic about it
Yes, my day job is (currently) not yet in rust. It's a great language to learn though! Do read Amos's blog: fasterthanli.me/articles/a-half-hour-to-learn-rust
I haven't even worked on the backend since school, and I'm not even all that interested in it. But Rust looks awesome
@@hundvd_7 Backend? BACKEND? I should have called the video "Turtles all the way UP"! Yew is a faster frontend framework than React (pure webassembly!) yew.rs/docs/getting-started/build-a-sample-app
@@NoBoilerplate, do it!
@Tomato Cat, learning Rust will make you a better programmer. It demands from you an awareness of program statefulness that will help you in all other languages, and indeed, not even only programming languages, either; I understand the semicolon in English composition because of Rust.
@@samhughes1747 Haskell too
Have been trying to learn Rust for a while now, and I find it hard to learn something bit by bit without knowing what the big picture is. This series had helped a lot and given me some much needed inspiration to continue.
You and me both, friend! I had that EXACT problem when I started learning Rust. It's SUCH a steep learning curve (TWO STRING TYPES!?) that I had to have a chat to my friend who already understood rust to sell me on it again, then I'd get back to it a week later and do a little better :-D
Yeah also read the rust cookbook!
It is honestly the best way to understand wtf is going on
They explain how and why the language works differently than others, in great detail
@@kartonrad Seconded on the cookbook - it's VERY compatible with reading the official book at the same time - the chapters align well!
@@NoBoilerplate oh lol i actually meant the official book 😅
The cookbook is great too though if you get stuck or need a place to gain intuition
@@kartonrad Ha! Yeah, big fan, the link's in the description AND HERE doc.rust-lang.org/stable/book/
Love the channel, the amount of knowledge that everyone gets in 15 minutes is off the charts. Wish all the best
Thank you so much! I'll try to keep it to not much more than 10 mins 😁
An important thing to realise about Rust taking longer to compile is that the compiler is doing things that instead happen at runtime in almost all other languages. You are trading speed of compilation for speed of execution. And as a bonus you get to discover bugs when compiling instead of when running in production.
Absolutely - compile once, run forever!
TLDR: rustc is spending time in LLVM and not in static analysis.
No, that is not in fact the reason. That wouldn't even make sense, unless the analysis is insanely expensive (which it really is not). It turns out, that in modern compilers, you spent the vast majority of time in LLVM and the linker, and not in fact in the frontend. It turns out if your project is a few K, and the stdlib is a few M, you spent time wherever you touch the whole stdlib, i. e. the linker. Who would have thought that would be the case, right?
On a hello world:
- The rust compiler takes 150ms (plus 90ms load).
- Of that, 60ms is literally the linker.
- And 50ms is llvm.
- 9ms is borrow and type checking (!).
Almost NO TIME is spent in rust's "safety" features.
In C, equivalent hello world:
- Takes clang 50ms (plus 30ms load) (which is like 1/3rd the time)
- Takes gcc 85ms (plus 15ms load) (which is 60% faster)
- gcc: 40ms for preprocessing+load cpp, ~1ms for compiling, ~30ms to assemble the file, and ~30ms to link it.
- clang: who knows im not going to try to even understand the clang trace format lul.
But in summary:
- Statis analysis is not the expensive part
- It turns out (surprise!) that LLVM and linking are slow, because (1) needs to do a lot of *stuff* and (2) is a single chokepoint.
Also, funny thing: LLVM gets a lot less expensive if the frontend optimizes the IR at least a bit, because llvm needs to do less *stuff*. It also helps if you don't emit 15 functions when the user wanted one.
@@pitust Thank you so much! I was not aware of this, I will add it to my notes and the ERRATA
Rust's macro system is absolutely magical. One of the craziest things I have ever seen. I very rarely use it however, they are very difficult to build and debug.
The thing I find about Unsfe Rust and memory management in Rust is that a lot of the memory module and safe abstractions are not explained properly. You pretty much have to know what you are doing before diving in. Which usually means it is better to have some experience from writing low level C and C++ code before learning Rust.
The Rustonomicon is a great resource though. Probably the best introduction to memory management in general. Even for people learning C or C++.
I agree, the macro system is very very powerful, but it's sometimes quite difficult to debug when you have things like nested macros and things like that
@@livingbutterfly The thing that really doesn't help is the lack of resources.
Almost every facet of Rust has a well kept book about how to get stuff working. While Rust's macros are kind of just left out of the conversation. I'm sure there must be a book somewhere, however the official website barely makes any mention or links to any resources for macros.
The resources that do exists might be outdated or offer trivial surface level information.
@@thestemgamer3346 yeah the only _offical_ resources are a small chapter on the book and the rust reference, which makes it quite complicated to get started.
When I started, I had ever user macros before, and things like macro hygiene were quite complex at the start because I couldn't find almost anything that explained that kind of things. A macro book would be actually great!
@@livingbutterfly The issue about making a great Macro book is that it would require someone who is both: good at writing books, and understands the macro system at a very deep level, and who is great at relaying information to new users/beginners.
Very good comment, I agree that macros can be super complicated. I found this video to explain their purpose in a new light, though, which I loved!
Loving your channel btw - keep up the memes! :D
really like the way you present these features. As someone curious on the language, I really enjoy this type of presentation vs code examples and syntax tutorials, because it lets you see why you would even want to dedicate time to learn it in the first place.
Indeed, I am not a Rust expert, so I can't YET give you perfect guidance on the technicalities. I AM, however, a good cheerleader, and can get more people interested in Rust, where I can direct them to the official rust book, or Amos (fasterthanli.me) for more deep dives!
I literally refreshed your page and saw this, thanks for the amazing content!
Thank you so much!
2:35 that’s partially true. You can’t get an intrusive (non-owning) linked list or a double linked one in safe rust BUT a singly linked, owning, partially intrusive linked list is very simple and a very common structure for me to use while in the early stages of architecting my code / in non performance critical cases where there is no clear owner of the list. It’s just an Option member in whatever struct you’re using and the same for wherever you’re storing the head (you can also store the head inline)
Thank you! You're not the only person to say so! I have updated the errata
If Rust had a voice this would be it!
Please keep making these - I've been trying to figure out what language to expand my knowledge to, and your videos have convinced me to take a look into rust. It could be nice to hear your perspective and opinion about web frameworks in rust, because you seem to have a good way of highlighting the strong parts.
Like a whole "SO YOU WANT TO BUILD A WEB SITE IN RUST" video? I sure can, though it won't be a perfect step-by-step tutorial, there are plenty of those that exist, it'll be much faster. Think that makes sense for my format? rocket.rs is where I'd recommend you start, if you're looking, though Poem is lovely for an API.
@@NoBoilerplate Not necessarily a step-by-step, but more about what is available, what are more serious than others, what strengths and weaknesses they have - for a noob it is hard to figure out what might be the best option to start with.
@@flipperiflop understood, I'll put it on the backlog! However, noobs should start with rocket.rs 😂
@@NoBoilerplate I'll keep that in mind :) I remember reading some complaints about rocket.rs being developed by a single dev, which gives it a bus factor of 1. Need to see if how well my experience with Laravel and Phoenix translates into that one.
After your first video I tried Rust for the first time... and I'm loving it! Honestly it is now one of my most favorite languages, if not the most. Before I also used Python and was very admired of Pythons simplistic nature, but always missed static typing and safety of compiled languages. But yes, it has its flaws, nothing is perfect, but I would love to do more work on Rust since it is so brilliantly and carefully designed language
Also, I would say that I just love the Enums in Rust, they are so versatile. My object oriented mind immediately started thinking in objects, inheritance and polymorphism, however I realized that Enums work much better in some situations instead of trait objects. And the fact that each of them can hold different data types - oh my god. I remember thinking that Enums in Java are great since they are objects and can have constructors and fields, but this is just mind-blowing. And most importantly - without needless overhead on runtime (zero cost abstraction baby!)
Exactly! Structs and functions are wonderful!
data - > fn - > data'
I absolutely adore this channel - Thanks for creating these videos, they soothe my mind and make me very happy about the future of Rust! Best explanation I ever saw of Macros and Unsafe Rust, well presented and to the point! Looking forward to your next one!
Thank you so much! I have received feedback that I've got a few small technicalities wrong, so always check my pinned comment, where I put the inevitable errata!
My plan is for a video every two weeks while I get used to the platform, if things go well, I'll up that to weekly, if not, well it was a fun experiment!
Love this series!
I GUESS I'M WRITING A SERIES!
I selftaught Rust then went into Cpp, it made learning Cpp way easier, and frankly a lot of comparisons were made. Rust is great!
Why did you start learning C++?
Fantastic! Cpp for the present, Rust for the future!
Understanding something that's well-designed makes it easier to understand a poorly-designed version of it :D
I agree. Many c++ errors make much more sense if you understand move semantics and reference types.
@@Outfrost ha!
My most favourite feature of rust is the naming for numbers. omg i just LOVE IT. instead of using the words like, int, short, double, long, etc. rust uses the words u32, u16, f64, i64, etc. the u letter specifying that the number is unsigned is great, now i can allocate double the space in the same amount of bits when im storing positive values, it also gives me so much more confidence on bit operations knowing what every bit will be like. it also removes the words int and double from your mind, changing it and making you know the exact amount of memory you will use up, making you know, this number can be an f32 it doesn't need the precision of an f64. this loop doesn't require 32 bits to hold it, i can do fine with just 8.
It is by far my most loved small feature in rust.
I love that too! It's so clear! And if I want a magical integer that promotes itself at runtime, there are crates for that 👌
Haven't used rust all the much ever since I started my job. Your videos are making me want to start using it on side projects again
oh me TOO! Even thought probably I should be writing my personal scripts in python, I'm having such fun writing them in Rust!
@@NoBoilerplate Why do you feel you should be writing them in Python?
@@samu350 I can share with u how I feel about it because I have exact same feeling. First point is that I work as python developer and I have much more experience with it so I can create scripts that I need in no time. Second is that I don't really need deep functionality of Rust to create for example mafia host assistant which is just random generator+timer. I just feel like I waste a lot of time building such simple app in Rust that I'm not familiar with.
But I'm trying to find any excuse to use Rust. And sometimes it's just not worth it. Still learning it, but I can't find myself interested in project that is worth my time playing with rust.
I wish u got answer that u've looked for
(not English native, sorry if it was hard to read)
@@samu350 to save me a compile. I'm thinking that I will use crates.io/crates/cargo-script#hashbang
@@lukivan8 Your english was fine you shouldn't put that statement in the end :)
I get it, I was doing Leetcode with JS (a lang I know well) and decided to roll with Rust to learn it.
Not going to lie, I spend twice as much time in each exercise because of how unused I am to the language.
Far out. I have a language design document and I keep seeing "new, unique" language features I had "invented" in your Rust videos. Not the same implementation, but the same intent at least. Hard to gauge the veracity of this, but that's the Internet for you. As I wrote in another video, this series is inspirational. It tells me "these things can be done", or rather, "have been done".
I need to get a Rust book and look into it for real. It was on the list of Things To Read but it's now on the top of that list. Thanks for the content.
Yeah, I couldn't believe all these language features were in ONE language, and not only that but it's so popular I could stand a good chance at getting PAID to use it!
I started with the official, free, book, it's great! doc.rust-lang.org/stable/book/
The videos of this serie are THE content I was looking for to get onboarded to Rust... it's beautiful.
Many thanks, amazing work!
I'm loving the journey you've taken! Thank you for the comments! What's you background in programming? My background is Web development.
@@NoBoilerplate thanks to you, indeed! Mostly web too, PHP a long time ago and JS (frontend and Node) for a while now
@@martinslns Sweet! You're gonna dig rocket.rs !
This is a beautiful video really like how to the point and informative your writing is while still being engaging and entertaining.
Thank you so much! I've always liked public speaking and audio production, and now I've had 8 seasons of practice producing my hopepunk/scifi podcast, Lost Terminal! (www.lostterminal.com)
Great videos, thanks for being a resource in the Rust community!
My pleasure! My goal is to get people EXCITED by rust, what should I do next?
Yes, so nice…you convinced me to learn Rust.
Mission accomplished! Here's my recommendations:
If you're new to programming, start with The Book doc.rust-lang.org/stable/book/
If you'd like to get started faster, fasterthanli.me/articles/a-half-hour-to-learn-rust
(then hit the book!)
Your voice is just.... *refreshing*
You want 8 seasons of it? I gotchu ua-cam.com/video/p3bDE9kszMc/v-deo.html
Amazing explanation. Makes me want to look into Rust further. I also love that the video background color matches the UA-cam dark mode's and there's a single pixel-high progress bar at the bottom. So thoughtful! :D
www.obsidian.md slide defaults!
Obsidian is awesome! Would 100% recommend it to anyone who needs to take notes, brainstorm ideas, or even just link loads of stuff together. I use it for classwork, D&D, loads more.
@@4P5MC I use it for D&D too!
What I love the most about this language is how easy it is to write code that is both easy to understand AND efficient. Sure, there are lifetimes, there are macros, there are unsafe blocks. But each of these get limited to their own little "complexity boxes" far away from the rest of the code. With good documentation it is very easy for a developer to understand what these "complexity boxes" do without worrying about what each line does.
Since the compiler optimizes a lot. "Easy to read" code often performs more efficient than "smart senior dev" code. It's going to optimize away a lot of the repetition, will remove unused parts of the code, apply branchless programming. If an iterator runs a limited number of times (like 10 times), it might create that number of blocks in a row. Only to then optimize all of the blocks again...
Absolutely stealing the "complexity boxes" idea - That's a genius way of thinking about it!
@@NoBoilerplate Go with it bro! You deserve more subs
Love your videos, please keep em comming.
You're too kind, I will! Do share with any friends who might be interested in Rust!
Rust says, "Cross here, if you know what you are doing!". Loved it! ---- 1:25
It's SO good to be building high-level web services in a language you KNOW you don't have to eventually FFI out to C once performance gets important at scale!
What really impressed me about rust macros was the peg library.
It parses data with rules you define directly into typesafe values, without the need to walk any kind of tree yourself.
Keep up the good work, I checked your history of content, looks like you've been dormant for some time and now your content is Rust specific, 🙏 please continue. I thoroughly enjoyed your last two vids, I subscribed in effort to convince you to stay. Excellent work.
Yeah! I've been practising audio editing for 2 years producing my hopepunk podcast, LostTerminal.com, and now I've found a great way to give back to the rust community!
You have convinced me to try it now I just need some totally useless project that I can waste hours on. Also it's blessed by the sacred gods of the Linux kernel so that's pretty cool.
Def try a web app, that's always my first try at a language. I recommend this framework rocket.rs
Thanks for telling me to learn rust! my motivation on learning rust was dwindling around that time because of school. Thanks to your comment I finally got the motivation to continue learning rust and finally made a fire-spreading simulation built on rust after weeks of learning fundamentals and syntax. o7
oh fantastic! is it on github? would love to see!
@@CunningBard now that is amazing, fantastic!
Your way of explaining is phenomenal, you should have at least 500k subs
ON IT
I really love this video format!! Please keep making these! :)
Noted! I will! Have you seen my other 3 in this format? This is my format, expect a lot more from me :-D
With things like async being just another library, how do you choose what lib to use when multiple libs are available? I know this is a problem for every language out there, but I'm curious if Rust has some way to deal with this…
Stuff like this will always be a problem. Rust even doesnt take anything big that can be opinionated into the standard library, which reduces the chance of having a default to go to. This is just to let the community figure out the best solutions and change them over time, which makes rust more future proof.
@@theroboman727 It makes sense. Thanks for the thoughtful reply :)
4:34, in C++, it's possible to overload most operators without using metaprogramming. And it can be restricted to a class or not. Tied to a class, it's not bad form, because the class meaning should be self-explanatory.
9:01, how many lines of code this mean? In C++, 5s for ~10k lines, with optimization flags on.
Oh interesting, I'm not very familiar with C++, thank you for the operator overloading explanation.
I'm uncertain how many LOC the 100 libraries I'm compiling in 10s there are. But certainly Rust is slower than C++'s builds, but that is because there's a great deal that the Rust compiler does that the C++ compiler doesn't do. Macro expansion for one.
Rust is extremely different isn't it! No inheritance, new syntax for lifetime annotations and borrows, and the compiler hates a lot of the standard normal patterns we've been using for decades.
Yes Rust is very different from what we're used to. But that's the point. Two features you can't get in C++ that I think you'll like are Macros and the Unsafe system. Macros are nothing like templates or cmptime (they're more like lisp macros), and the unsafe system is a genius way to ring-fence pointer arithmetic, to allow us to build safe abstractions around unsafe pointer code. I did a video on both of them here, and I'd love your opinion on it: ua-cam.com/video/PuMXWc0xrK0/v-deo.html
Cheers!
@@NoBoilerplate I don't know Lisp macros. C++ has 3 special ways to deal with compile time:
- constexpr: it can make all calculations, but the result must be const. It can be attributed to a const, though.
- template: a model of how a f() will work. It will make 1 for each type, according to calls.
- macro: it pretends you wrote the code in a specific way. I heard the difference is that Rust uses "hygienic" macros. Probably avoiding the classical error:
#define add(a, b) a + b
int x = 3*add (1, 2); //Resulting in 3*1 + 2 = 5, not the expected 3*(1 + 2 = 3) = 3*3 = 9.
There's also a 4th hidden way, dealing with variables at compile time: making template f()s generate other template f()s, with different constants, according to "variable" changes.
PS: I forgot to say that that C++ time has exceptions flags off.
PS2: your link shows this same video.
I was gonna say you should make podcasts with that voice and saw your description - pleasently surprised :D!
Thanks Eric! I do indeed, and I'd love to know what you think ua-cam.com/video/p3bDE9kszMc/v-deo.html
2:18 that’s just false. Linked list are possible in safe rust using Rc and RefCell.
RefCell shifts the borrow check from compile time to run time, but it’s still memory safe (as in: the code will just panic and shut down when you violate the borrowing rules)
Oh great! Thank you so much for telling me this, I will fix future videos. That's a great way of describing Rc and RefCell thank you!
Ahhh man, all your videos just make me really, really wanna write Rust code. I wanna try all these cool things!
When I was first learning about C/C++, I heard that everything was built from its self, and I thought it was so cool that you can just add features to the language you're writing in. But Rust makes this a far deeper and clearer goal, less just a cool side effect of being able to write low-level code and more an intentional mechanic built into the greater whole.
Mission accomplished! I have designed the start of this rust series to get people excited about rust's unique features. However you have work ahead of you: the reason you need this excitement is that rust has quite a bit more to learn than other popular languages. Not as much as Haskell, but more than JavaScript. Keep that in mind when you're learning: you get out what you put in! Try the official rust book, link in the description, and good luck!
@@NoBoilerplate I have found it to be a significant challenge to learn compared to most other languages. I'm learning loads from watching this series, but I really need to set aside some time to learn it because there is most certainly a lot.
Oh, and thanks for the well wishings!
@@jupiterskyyour not alone there friend, I gave up twice in 2020 when I first started to learn! I'm so glad I kept at it, the rewards are astonishing!
Thanks for the video. It was entertaining and educational, confirming my interest in Rust.
That makes me very pleased to hear, Thank you!
You convinced me two videos ago, now I am just enjoying the magic show.
fantastic!
Really love these videos, makes want to try out rust. As someone who does a lot of scientific programming I've been loving Julia, I see a lot of similarities between it's macros and rusts macros
Huge fan of Julia! I think data scientists should switch from python TODAY! For big infrastructure projects, web apps, games and such, Rusts the the clear winner 👌
Totally agree everyone should be using Julia, but it'll take a lot of time to get the support python has.
Ye no question different tools for different jobs
You sell rust like no other. Thanks
Honestly, once you stop telling people it's a better C++, it sells itself!
God has gifted us rust. Thank god. I am excited to learn rust.
It does feel like that sometimes XD
Have you read The Book? I'd start there, it's super easy to get going.
You might like fasterthanli.me/articles/a-half-hour-to-learn-rust
too!
@@NoBoilerplate Thanks XD. Will definitely look into it.
Great video. Could someone please tell me where I can find the "cmd!() macro" that is shown at 7:37? It doesn't seem to be part of the standard library.
Thank you so much!
The words I speak at that exact timestamp are "the cmd macro, which is from the command-macros" crate.
In Rust, crates are the name of the libraries, and you can find them all at crates.io!
crates.io/crates/command-macros
:-)
@@NoBoilerplate Oops you're right haha, my bad, I don't know how I missed that, sorry. 😅 Thanks a lot for the response! I appreciate it.
Also, I'm sure you've been told this a gazillion times but your videos are fantastic and very well-made, the scripts are perfect, and your voice is so nice and "listen-able" :D
I've also noticed that you tend to reply to most of the comments under your videos which is so amazing to see!
Keep up the great work! 🤍 I hope you get to 100k very soon!
@@amirhosseinahmadi3706 Thank you so much! I'm excited to get that play button! XD
I don't really use Rust, and don't really have need for it yet but your videos about it are quite inspiring and relaxing (somehow lol). Your arguments in favor of it are sound. Will definitely try it out in once I have some time for it.
Thank you so much! I'm so please to have inspired you, that's the whole point of these videos: To get more people trying out this incredible language.
If you want to hear me read something ACTUALLY relaxing, I produce a hopepunk podcast about a little AI, check it out! (I made the videos in rust!) ua-cam.com/video/p3bDE9kszMc/v-deo.html
I've created a singly linked list in SAFE Rust. I used an `Option`. It's NOT impossible to create linked list.
My apologies, though I didn't say it, on-screen is a *doubly* linked list, as in the standard library.
You're quite right that a singly linked list is fine - where the borrow checker trips up is in ownership cycles, which is why you must break out of safe rust to do this.
@@NoBoilerplate I guess doubly linked list would still be implementable with some safe abstractions like Rc, Arc, BUT I'd have to type some unsafe lines if it was to be efficient like in std.
I reedited my comment so that it doesn't state that you said it was impossible.
To gcc, I can pass the -E flag to see only the output from the preprocessor step. Is there a way to do this with cargo or rustc directly? I would be curious to see to what the tokio main macro compiles!
Yep, both with compiler flags and in ide tools let's you inspect what the macros are up to! 👌
Search cargo-expand, the command to see the macro compilation is there 🤝
@@livingbutterfly bookmarking that!
Every time I watch this guy talk about rust i suddenly get the urge to open my code editor and play around with the language for the 100th time
MISSION ACCOMPLISHED
It's just a shame that most companies just use regular languages like C#, Java for the most part. Super boring.
@@HermanWillems Boring is safe. A lot of companies want safe! However, plenty of companies don't, that's where the fun is :-)
I have chosen and am recommanding Rust because it's the safest, most mature language that has the great features that I mention. Language at the top-right of this graph are safe, but language in the top-right 25% of this graph are safe enough and GOOD redmonk.com/sogrady/2022/03/28/language-rankings-1-22/
I found the annual Advent Of Code a good excuse to practice it.
@@SimonClarkstone There are some nice Katas too, lovely!
Great video! Just wanted to point out one thing that Go has bootstrapped since 1.15. All standard libraries including the compilers are now written in Go.
I did think that was the case, but my suspicious were aroused by Wikipedia's sidebar meta data claiming that go is "written in" go, c++, and asm", whereas the rust pahe just says "Rust". There are other comments by expert-sounding people suggesting that there are a few assembly parts, and that initial compilation is c++ bootstrapped?
@@NoBoilerplate Go has been written in Go since 1.5, not 1.15. I assume that was just a typo on Jereon's part. The original Go compiler was in C. With Go 1.5, Go was able to bootstrap itself with any working Go compiler. C++ was never used in the main compiler.
Maybe the wkipedia article has been updated to clarify this since, but C++ is only used for the GCC Go compiler frontend. I believe that means the Rust wikipedia article can be updated to also say that C++ is an implementation language of Rust now that the GCC Rust project is being mainlined. That's purposefully a bit facetious but hopefully the point comes across.
In a bit more seriousness, the Rust compiler does have a small amount of C++ code for their rust_llvm/llvm-wrapper. For Go, it's a bit harder to track down exactly if the Go compiler is using C code directly or not, because the compiler uses the standard library & runtime and there are a few places where cgo is optionally used. As for assembly, it is true that the Go standard library includes Go assembly in a handful of packages.
@@losinggeneration Thank you for the clarification! Sorry about my mistake here, I've updated the ERRATA comment
This series is pure gold!
Thank you! What do you think I should do next?
@@NoBoilerplate Good question, I'm still relatively new to Rust. As long as its about Rust and its philosophical I'll watch.
@@michielnuyts7187 TIL I'm a philosopher! Thanks so much, stay tuned!
While I do appreciate all that Rust is doing, I'm writing Scala and it's near identical in features. The only major difference is that it's a GC'd language but is much more mature than Rust. There are very powerful macro tools (since Scala 3.0). For low level code there's Scala Native. To transpile to JS there's ScalaJS. The entire Java ecosystem is at your disposal in normal circumstances. I will be keeping an eye on Rust but for now, from what I what people are saying, the ecosystem is still a bit small.
On pure package numbers, Cargo is about where NPM was in 2013, for context. Quite enough for serious use (I can REMEMBER working in Javascript startups in 2013!)
---
I love Scala, my functional language journey started with it! ([1..] still gets me excited!), so thank you for pointing me at scala native.
However, there is a pattern with high-level languages that they eventually all add-on low-level exceptions to their GC sandbox. JNI or Scala Native or similar. But these additions FEEL like additions, not first-class features. ScalaJS even more so.
What makes me excited about rust is that it had unsafe (for low level) and macros (for high-level) right from the start, these essential features are core to the language.
The whole language works in webassembly, everything works without libc* on bare metal, it's all rust.
@@NoBoilerplate Scala 1?!? wow, but you sound so young in your videos!
Kidding!
@@BloodnutXcom ha! No no, I meant this:
```
[1..]
```
Which is actually, now I look at it again, HASKELL code XD (it's a lazy list of all positive ints)
Definitely considering learning Rust now! Seems like a cool language with a good community.
It really is! There's two huge discord communities, r/rust is fantastic, and it's all very friendly. There are about the same number of github projects as Swift, Obj-C, Go, and Kotlin.
I learned principly from The Book doc.rust-lang.org/stable/book/ but also from Amos over at fasterthanli.me
When I read the title, I was thinking "turtles" as in turtle graphics so I was so confused what you meant by that lol.
Oh cute! My first taste of programming was in turtle!
RT 90!
Nim is another very good but very underrated language which has both features you mentioned.
There are plenty of memory management strategies available, including manual memory management
The macro system is also super powerful in Nim
Love nim! I'm co maintainer of inim repl! We could talk about the technical similarities and differences of nim and rust all night, however ultimately for me it comes down to popularity: if I want to hire and build a team, I can do so with rust but not nim.
@@NoBoilerplate However; the situation can be changed if people like me and you (specially people like you who have a media of some sort) actually start talking about Nim and it's capabilities.
@@m.m3633 I have not been able to do so, nor would I be able to support myself while doing that.
Rust has won hearts and minds, be thankful that we have such a language that is so popular, that has goals so similar to nim's goals. I also think Rust is technically better than Nim, to be clear. As I've talked about in my last video, though the borrow checker was designed to solve memory safety, it's SO MUCH MORE than that.
Here's an old video of mine, talking about inim. ONE MONTH LATER I would discover Rust. C'est la vis!
@Unstable This is the way
@@NoBoilerplate optimal number of programmers for a team at first is like 3 or arguably even 1. Hiring programmers to use a language is dead easy, pay enough and suddenly smart people do what you want
I'm a professional D programmer, there are enough of us to run multiple companies on, surprised?
Each time I watch one of your Rust videos, I fell motivated to do something in Rust again. Last time I wanted to do something with OpenGL and egui but failed 😅. Anyway, keep up your videos. I really like those RevealJS slides.
Thank you! Want to do some native app development? Tauri (a better electron, written in rust) just got their 1.0 release TODAY! IT'S FATE!
tauri.studio/
Also, my slides are built and screenshotted from my second brain, obsidian.md (which does indeed use reveal!)
@@NoBoilerplate Dang it, today? I've also tried this tool a few weeks ago but somehow it failed to start in my environment. I might try it again soon!
@@mondei1 Good luck! Tell me how you find it (I'm @0atman on twitter)
12 hours ago the release was cut, looks like github.com/tauri-apps/tauri/releases/tag/v1.0.0
@@NoBoilerplate Definitely will do.
Just a quick note: *Elixir* macro system is very similar to Rust's with regard to, let's call it, _computing power_. Elixir macros are functions that implement AST-->AST transformation with full access to the standard library. Their crown jewel is Unicode module in standard library which is autogenerated by a macro from the actual Unicode specification file:
> "The similar technique is for example employed by Elixir to generate String.Unicode module. Essentially, this module is generated by reading UnicodeData.txt and SpecialCasing.txt files where codepoints are described. Based on the data from this file, various functions (e.g. upcase, downcase) are generated."
That's EXTREMELY cool!
This is why I love macro systems, you can do incredible things that you otherwise have to build non-standard tooling for!
I'm a big fan of Elixir, but I am bound by practicality to restrict my search to the top 20 languages, as shown by Redmonk redmonk.com/sogrady/2022/03/28/language-rankings-1-22/
at some point in any language the rubber mmets the road and some code will need to be written in C or assembly language to deal with low-level details. Rust allows one to stay in Rust language when writing some of this kind of code but doing so in unsafe context where various safety features of Rust compiler will be restrained. At least on doesnt have to deal with things such as pinning or marshalling garbage collected memory, etc., as is necessary in other popular languages' glue layers
I THINK and maybe someone can correct me, that no c code is needed with rust - this is the whole point of the unsafe system!
Certainly you can write online assembly, for hardcore optimisation, so you're right there.
@@NoBoilerplate Yeah, I've used Rust to wrap a C ABI library and that's pretty much true - when shifting into Rust unsafe mode can do pretty much anything necessary for interacting with C style library APIs.
@@TheSulross That's great!
@@NoBoilerplate Though I would argue that “unsafe” is an overly broad keyword. It really needs an optional specifier so you can say “I’m doing just these few unsafe things (see list), please check and enforce all other safety rules”.
will be a fantastic journey!
The part about Python's `case` isn't fully correct. The reason they only now decided to add it is that the match-case statement is NOT a switch-case. It is called "structural pattern matching" for a reason.
Oh yes so it is! Thank you very much for the correction.
I suppose structural matching is a better sell for the core developers than JUST nested ifs. Thank you!
@@NoBoilerplate When mCoding made a video on this feature, guess how the comments looked lol
Seriously though, considering *so* many people mistake it for a switch-case when it's not, I'd say that they should probably have thought a bit more about making it look like a switch-case.
@@SkyyySi Just call it match and give credit where credit's due! XD
The safe vs. unsafe code thing reminds me of "managed C++" for use with .NET. That was a hot mess, though, because it required trying to retrofit safety features into C++ long after the fact. Funny story: when I tried "managed C++", the first thing I discovered is that because you had to give up the standard STL containers for the .NET container classes, you lost that trade of compile time for execution time that STL gave you. I've limited experience with Rust myself, but it seems like they learned a lot of those same lessons, and because things like generics and safety weren't bolted on after the fact as with C++, it could be done in a sane, useable manner.
Yeah, exactly - rust's core language is SUCH a good foundation - unsafe + borrow checker + algebraic types + macros = the most exciting language in the world.
I feel like a complete rust tutorial from you would be more beneficial than the rust bible guide online.
You're too kind, I may yet do that, but I'm still learning too. Try fasterthanli.me
@@NoBoilerplate Thanks for the recommendation. I'll check it out. Will be waiting for your guide too
not that I don't love hearing you talk about rust, because I love to hear you talking about rust, but would you consider doing a more general video about your experience with software development, and the languages you know? I'm thinking of learning rust and would love to hear your opinion on prerequisite languages, or necessary programming knowledge
I will add it to the topic list! Are you learning your first language? I could make some suggestions for you.
@@NoBoilerplate I know python and java, but both of those are high level, so it certainly feels like learning rust means relearning how to program. I would love any and all suggestions, as a very confused compsci/maths freshman
@@shmendusel Excellent! Great start, those language will get you solid work for decades. As you already are familiar with programming, I would start here:
fasterthanli.me/articles/a-half-hour-to-learn-rust
and then, when you are excited, install rust with rustup.rs and go through the official book, which is what I did
doc.rust-lang.org/stable/book/
what's with the backticks at 6:50?
Well spotted, its in the errata pinned comment - some kind of copy paste error - apologies!
@@NoBoilerplate that comment isn't actually pinned. probably because you edited it and it got unpinned i guess? weird that youtube enforces that for editing your own comments as the video creator
@@sodiboo wtf thank you for telling me! Fixed.
The bit about Go having assembly and C++ code… Go does support C through CGO, and there is an unavoidable need for some assembly, mainly when Go has to interact with the OS via system calls, but w.r.t the standard library and toolchain, Go has not relied on C/C++ in quite some time. The point being made is still correct though
Not just being able to, but it being exceedingly easy to build completely static (and thus highly portable) binaries is something I really like about Go.
Me too, it was a hard requirement when I was evaluating languages. Rust goes one step further and lows you to write no_std code that doesn't even depend on libc!
Thank you for this examination. I will update the pinned errata comment!
@@NoBoilerplate same with Go :)
CGO_ENABLED=0 will disable any calls to C, including libc. -tags netgo instructs the compiler to use the Go network stack.
If you do need *some* CGO anyhow you can add -extldflags '-static' to -ldflags to tell it to pack external libraries into the binary.
The neatness/simplicity of this is what I like about it, compared to say, building manylinux wheels for Python...
@@jfolz you just gave me ptsd reminding me about python wheels...
YES love this for Go and Rust - give me a single binary that I can sling somewhere (a container, a lambda, wherever!) Not using libc is a great feature for Go, I'm delighted to learn it has it - but the garbage collector will always make embedded/bare metal/webassembly deployment more complex than Rust, where there's nothing at runtime other than your program!
babe wake up new NB Rust video just dropped
Ooh, I should make an NB logo...!
You mention on 7:04 that the numerical value of 3 will not be inserted and would rather have to be calculated at runtime. My rust is a little ... rusty. But I was almost sure that the compiler will precalculate all such redundant cases.
Maybe what you meant is that the value of 3 will not be inserted during the macro expansion, but during the later compilation stages?
Oh yes! well spotted! simple arithmetic will indeed be precalculated!
3:07, I think Python have Pyrex/Cython if you want to stick with Python-like syntax.
5:17 - forgot some other exceptions like Forth (immediate words), XL (with its tiered languages), probably Ciao, Template Haskell also uses explicit indication and rewrite rules if you want to modify source code without changing semantics. I most likely missed a lot including term rewriting languages.
Python-like syntax isn't python, though. I can't use, say, the `requests` library to make get requests using cython. It's a different language, albeit one that looks very very similar to python.
Yep, compile-time code execution is a great strategy, I would imagine we could trace all of these examples back to lisp in the 50s and call it a day.
@@NoBoilerplate I didn't had much experience with Cython, but I would expect that it also allows to call high-level code at least same way how Python can be integrated as script for native program. This sounds more like tailoring requiremenets to the language though. When you need to do something low level it is weird if you are planning to mix it with some high-level things at same level.
As for compile-time code exection. Everything can be traced to something. Not sure if 64 years old Lisp without types is a good choice in my opinion to get fair comparison for Rust when you say about type safety. Clojure might be a better choice.
I wanted to ensure that we do not forget about other old and relatively new languages in videos where Rust gets most of the spotlight. E.g. Haskell Templates seems like was suggested in 2002. And in my opinion they share same important properties mentioned in video.
@@NoBoilerplate I like ideas of Rust as I'm in past practical C/C++ developer and like playing with Haskell. I can see how Rust can take over C++ and Zig taking over C.
I really love traits/adhoc polymorphysm in Haskell. That's something that me and probably other C++ developers (remember about traits-like thingy in STL) were missing.
Even without borrow checker it was already good enough in my opinion. And I agree that Rust macro is very powerfull addition when comparing with its direct competitor C++ to boost experimenting/desiging new language features. But it is not the only one.
Though Rust is told as closing gap between low/high level code, I perceive it being more powerfull at low level.
@@virkony Thank you for sharing your insights, I think we're on the same page with much of them.
The bottom line, is that I can't build a team in Haskell, or even Clojure - but I CAN build a team in Rust. The excitement for me is not that these features are NEW (as you've pointed out, they are not) But they're in a language that is POPULAR. We've not seen this before!
@@virkony This perception that many people have that Rust is more suited to low-level programming I hope to challenge with my series.
One interesting complaint I have heard maybe once or twice with regards to Rust, is the fact that it does not have a C-style for loop. There's a while loop, a regular infinite loop, and an iterator-based loop. But the standard (initial; condition; step) type loop we see in C and many C-like languages is missing... except it isn't if you use the cfor crate, which supplies a macro for this exact purpose.
You've been talking to C developers again haven't you! (kidding!)
As an industry, we've moved past the old `int i; i < 9; i++` method of looping, now we've got iterable objects and such - even in modern languages where you can do a C-style loop, it's almost universally bad practice. `for x in y` is SO human, much nicer for us.
ALSO in rust you absolutely can do this trivially. (as I read from doc.rust-lang.org/rust-by-example/flow_control/for.html):
```
for i in 0..array.length {}
```
And I imagine doing iterable.map() unpacks out to a nice simple for loop too.
My advice is be careful who you talk to! Always consult the Rust Book for answers, it's great.
@No Boilerplate You're only covering the case where the "initial" assigns zero, the "condition" is "less than N" and the "step" is "increment by one". There are so many variants to that which are used often, and without that "raw" approach there's more learning curve and, possibly, less readability in some cases than the C approach. Not saying Rust isn't still better... just noting your rebuttal was weak. ;-)
@@peter9477 Iterators can do far more complex iterating than initial, condition, step.
The old C way is entirely missing from Python and bad practice to use in Javascript, it was a conscious language choice to leave it out of Rust.
@@NoBoilerplate I'm well aware. (C since 85, Python since 99, Rust since 2022...). Was merely pointing out that example with 0..length does not reflect more than the most basic case of what the C for loop is used for.
just ran my first Rust program!
by which I mean I wrote
`pkg install rust`
`cargo init`
`cargo build`
`cargo run`
in Termux while sat on the… on the bus.
Extremely cool! I too have recently discovered termux rust!
Linked list and doubly linked list arent imposible in safe rust.
You can use weakref and refcell if the user of the data structure do not own the nodes, but if it do own them you can just use mut ref or indirect offsets (using an index to the list of nodes)
And when i learn about how to do a doubly linked list in rust, rust forced me to learn about the possible bugs and memory errors involved by these data structures.
WeakRef and RefCell may be rust types but they are also abstruct consept that you really need to know before writing linked list in c, the difference is that rust forces you to know the potential risks and gurrentess you must provide before you can push to production
Thank you! You're not the only one to tell me this. Have added this to the ERRATA pinned comment!
That's a fantastic take on it, thank you!
I'm still gonna stick with my C/C++, but I'm happy they finally have competition. C++14 onwards feels like a well-intentioned mess at the end of the day, so I can certainly see why people are looking elsewhere
Yeah, that's totally reasonable. I've started to think of Rust as not replacing C++, but replacing C++ *for me*.
For a long time I thought Rust was just C++ with stricter memory management and typing rules, because the crowd of people who just say "muh unique memory model *soyface*" and nothing else did an extremely poor job of explaining what was worth the effort of switching. But saying "It's C but with built-in Lisp macros and contracts" has me completely sold.
RIGHT! So many people are saying it's a faster horse, when it's actually a spaceship!
noboilerplate: "rust build times are slow" *10sec compile time*
me, who writes c# code and have to wait 2 years to finish compiling: "pathetic"
hehe, yeah they're not bad at all - it's mostly dynamic language folks who are scared.
Why do we need macros to be replaced at compile time, though? Are macros like inline functions?
Now you're getting it - rust macros are functions that run at compile time. Check out my 'witchcraft' and 'turtles' videos for more details!
10k subs. 1.5m subs quality channel. Keep it up this is great
Thank you very much, I'm having a great time!
Will be following
5:00 Haskell has something that has capabilities as Rust macros and isn't a lisp.
Template haskell! Yes I'm familiar! Really love haskell, but no one will tell you that template haskell is *good* 😂
I was always fascinated by trap soft, been listening to trap long ti and i finally decided that i will try to make my own but i was so
Could you explain more?
thanks for another great video.
Thank you so much!
I absolutely love your editing, also what mic do you use?
Thank you! I actually use an audio editor (www.reaper.fm) to make them, it's SO GOOD.
My mic is a Rode Procaster through a CL-1 pre-amp into a Focusrite 2i2 interface. However, you shouldn't bother with this - I've tested the USB version of my mic, the Rode Podcaster, and it's SO SIMILAR you should just get that. No faff.
I use a standard Gate -> EQ -> Compressor+makeup chain to punch up the vocals.
I bought the mic to make my Hopepunk podcast, Lost Terminal, and it's been a fantastic investment, hear more: ua-cam.com/video/p3bDE9kszMc/v-deo.html
I want to contend for a moment that Python has first-party facility for metaprogramming, and also say that DSLs are only tangentially related to metaprogramming. Metaprogramming in Ruby is extremely common and mostly takes the form of automating rote declarations of methods, method decorators, and so forth; actual DSLs are rare mostly because the language itself allows for very free-form syntax. Ruby's metaprogramming is also of the SmallTalk family, meaning it works at the level of objects and methods, rather than the level of syntax.
Agreed with everything here.
As I said in the video, the reason I didn't call Macros 'metaprogramming' is to not mix up with these techniques. "Build Tools" feels more like something you run before you execute your code, as macros do, so I thought it would be a better analogy.
@@NoBoilerplate It is, and I agree. Few AOT compiled languages has the entire language available at compile time like Rust has.
@@everything-narrative Love how much of lisp snuck in to Rust!
There we go
Some errata: Not all rust macros have the !
#[derive(...)] is also a macro.
Thank you, that's true, I suppose it's better to say "if you see ! or #, that's a macro".
@@NoBoilerplate # can also be used to denote raw strings xD
@@zyansheep OH GOD! My errata comment is clear, ignore my over-simplification here!
@@NoBoilerplate it's also often used for compiler built-in attributes more than it is used for macros. Sadly no way to simplify this :(
@@VixieTSQ Noted, thank you!
I wouldn't have clicked if not for the title, but now you gout me wanting to drop my use of python and learn rust.
That was my path too! Python's great, but Rust is something else! Try this video of mine: ua-cam.com/video/oY0XwMOSzq4/v-deo.html
coming from JS and React, i've loved macros - it lets people write really nice WASM frameworks with the same ergonomics as JSX, but without the normal JS complications of transpilation, bundlers, and a massive tool set
edit: i do want to criticize your point that there's no Rust 2.0 - there have been multiple editions with new language features, but it's not quite as big a deal as other languages
I too love this feature, the pages of my two podcasts lostterminal.com and modemprometheus.com are written in using docs.rs/yate/0.1.3/yate/ to output a static site!
Others have said the same, I have a note in the ERRATA pinned comment about this, thanks!
Over in Kotlin, we have inline functions, where you can pass lambdas in and it will all be inlined much like a macro. This is frequently used to make things which look like new language features, but which are just a library.
Of course, in Kotlin, you can't just use any old content inside the function call - it still has to be in Kotlin syntax, which is the difference from Rust.
Having tried both approaches, they each have their pros and cons.
In the Kotlin case, you can read some source file and understand it without having to understand macros. But any "new syntax" you make will really just be syntax which was already valid, but perhaps which people didn't expect. You can't make anything new-new.
(Still, `cmd(http get localhost)` is valid Kotlin - `cmd`, `http`, `localhost` are top-level functions while `get` is a top-level infix function. No need to introduce new syntax for that example. )
In the Rust case, you can make entirely new syntax. But now, someone reading the file has to understand what all the macros do, so it's less work to write the code, but more work to read it.
LISPs of course do have both ways. Racket often trumpet that Racket is a language for writing other languages. Racket, for what it is worth, is another language which has an obvious One Good UI Library, because it has a UI library provided as part of the standard library. It's a language which I had a lot of interest in until discovering that some of the core team members weren't the best personalities.
Yikes, yeah don't meet your heroes! I had a bad experience meeting Richard Stallman, as you probably can imagine XD
Thanks for letting me know about Kotlin's inline functions, that sounds good!
The comment at 3:31 that “you and I… will certainly never write unsafe code in our normal work” was a bit of a turn-off. While it’s important to let people know they don’t need to delve into the unsafe system to work effectively with Rust, I think we’re often at risk of giving developers the impression that there are dark magic crannies that they must never look at. If you need to, you *can* understand superficially arcane topics like network protocols, instruction scheduling, CPU caches, and manual memory safety. They can be hard, but you can learn them, and you’re already learning all the time.
Saying people will “never” do things is an invitation to switch off, close doors, expect things to be unapproachable. Sometimes, a good engineer *does* find an appropriate opprtunity to use sophisticated techniques, in the process of solving core business problems, and this can even be a great opportunity to simultaneously contribute to open source - be it a fix for a crate you’re relying on, a new tool, or whatever. Often, solving really difficult problems *does* involve understanding these hidden fundamentals better, and that should be *exciting*.
I only say this because otherwise I feel like it’s a great approachable intro to these topics! I feel like that only means there’s *greater* onus to help people recognise what’s within their reach. Julia Evans blogs/zines are a great distillation of this kind of philosophy, e.g. the “so you want to be a wizard” zine
Omg thank you for showing me Julia Evans, she's amazing!
Though everything you've said is correct, I still really think that what I said is true: Most developers aren't concerned with low-level bits and bytes, and are happy in the middle. Web developers, certainly, are happy to just horizontally scale any performance problems away, rather than optimise! (Though actually, that could be the inability to optimise their typically slow high-level languages like python, which is 80x slower than C)
I should make a point in the future that these features (unsafe and macros) are GOOD TO HAVE.
I am not clear about go being partly written in C++ and Assembly, especially the C++ part
I'm far from the expert here, Wikipedia says so! I'd be interested to know what the c++ parts are too.
Love your videos
Thank you so much!
Damn, you have such a soothing voice, you can sell me literally anything by this point 😆
LET ME SELL YOU MY PODCAST ua-cam.com/video/p3bDE9kszMc/v-deo.html
@@NoBoilerplate, 😍😍😍😍😍😍
@@denisvolin7489 Season 9 starts on Monday!
2:22 Noone ever said, linked lists are impossible in Rust.
Double linked lists are impossible in (safe) Rust.
Ah! That makes sense!
I wonder how rustc will compete with GCC's rust when it's fully implemented (it still misses the borrow checker)
Ooh, I'm learning this for the first time! How exciting!
Given how GHC is *the* compiler for Haskell, despite others existing, I would imagine we'd gravitate towards a single popular one.
Would you say GCC Rust is Rust without LLVM?
@@NoBoilerplate Its a Rust frontend for the Gnu Compiler Collection backend. It uses the same Rust corelibs as the LLVM based compiler, but it uses GCC's optimizations, compileflags and tools (binutils such as ld, gdb for debugging, etc.). This makes it easier to include rust support in existing projects and toolchains that use GCC (such as the Linux kernel and many more). But the GCC rust frontend is still in development, and very unfinished (It can compile simple rust programs already). There are some good presentations about the project by the lead maintainer on youtube.
@@ironnoriboi Oh fantastic! That really sounds worth following, thank you!
@@NoBoilerplate Also, regarding your comment about gravitating towards a single compiler, that might not happen. It may have happend for Haskell; but if we look over at C and C++ land, we see many compilers that are all being used. Examples are the LLVM based clang, GCC based g++ or gcc, Intel's compiler, Nvidia's cuda/c++ compiler, MSVC. All of these are being used in production and have their own usecases.
@@ironnoriboi that's a very good point.
Why don't you increase the code don't size? Why that much empty spaces around...
Please file a bug with reveal.js, apologies!
you- should have seen their first video... A lot more people complained
@@VixieTSQ omg that first video...
D has something similar CTFE and introspection. You can even transpiler ex Pascal in D with CTFE if you what
D has some great features. As does Go, and V, Haskell, and lisp.
What makes me excited is that the Rust developers have put SO MANY of the features I like in a really popular language, and they DIDN'T put in so many of the features I don't like.
@@NoBoilerplate I think what I like with D is that aloft features are written in the language itself (like rust) and you are not forced to use specific paradigm. The borrow check in D is new it's probably not as good as Rust right now.
I am not a programmer by trade..
And I don't really understand the benefit of rust..
Because in my understanding the reason why c++ is considered bad
is because it is easy to make mistakes..
And so rust is like an abstraction of safer c++..
But still allow unsafe code too with unsafe block..
But personally..
I think I understand c++
for example when a variable is passed into a function or for loop
just use constant reference..
Although I am a little curious why they didn't do pass by reference in the constructor?
Usually I just see people copy it into the constructor function..
Constructor in rust is an explicit static function declared in the implementation block
And also delete the pointer if assign new
Take a look at my other videos for the benefits of rust, I've done quite a few!
So basically, aren't cpp's "consteval" and "constexpr" similar to the given example of macro "add!" ?
Sure, that's the simplest possible macro you can build. Zig also has comtime functions, which I'm a big fan of.
Though I don't really understand C, I see that there are a bunch of constraints on consteval, and the one that sticks out to me is it must not allocate memory. This seems like it must be used for very simple purposes.
I'll remind you that rust macros can do anything rust can do, including access the disk, use crates, and access the network.
These are simmliar to 'const' keyword in Rust (but as alywas rust does better job with it). Closest thing to rust's macros is C/C++ Preprocesor but it sucks. Like you can write #define add(a,b) (a+b). But these macros are primitive - they cannot create their own syntax, and the language itself makes it very difficult to use them.
@@Lord2225 Thank you for the explanation! I agree with C templates, they're a templating language, string manipulation - gross!
@@NoBoilerplate thanks! Your videos raised my professional curiosity about Rust
@@Lord2225 thanks!
Somehow I cannot trust a language which does not have a formal specification. Saying that "the specification is the compiler itself" does not feel right...
How interesting, perhaps this is something that will come in time? C wasn't specified from the start!
Why do you want a specification?