Hi my friend, as a fellow C programmer, who switched to Rust a year ago after 30+ years of C. I would highly recommend dropping the OS packaged rust (i.e. using apt or rpm) and use rustup instead! The packaged versions tend to be several version behind, and Rust is hyper evolving right now (including the stable version. for example there is a major CVE that got addressed in 1.58.1 that plagues all previous versions). Also, with rustup you will get the latest and greatest version of rust-analyzer which in-turn makes integration with IDEs a lot cleaner.
@@vlya1533 No. Rust ships on the same schedule as Firefox. Every 6 weeks a new beta is branched off. If it survived 6 weeks of beta testing, it's pushed as the next stable release. Once it's been released as stable, it guarantees backwards compatibility. So any code which compiled with a previous stable compiler must still compile with the new compiler, and any code it can compile must compile with all new stable compilers further along. The amount of bugs on stable is almost nonexistent. I know of one serious bug in 2 years and about 10 bugs in total that was fixed with patch releases over that period. Just because it doesn't work as things had always worked doesn't mean it isn't as stable. The one doesn't necessarily imply the other. If you have empirical evidence of rustc's instability compared to MSVC, gcc and clang, that's another matter altogether.
@@vlya1533 > usually "current" is "unstable". So, you literally said "rust is so much more unstable than a lot of others languages" I wrote that to explain why "current" isn't necessarily "unstable".
C succeeded because it enabled engineers to get stuff done. Whether Rust overtakes C depends on whether Rust developers can get stuff done more quickly to the point that the advantages are clear. This means the learning curve must not be too steep, and there cannot be chronic situations where the developer has to learn something that won't be used for another sixth months.
@@verified_tinker1818 true, but, you can gradually adopt the more complex parts of c++ and basically just write c to begin with. Which makes it MUCH simpler/easier/quicker to get started with and become productive with than Rust
The binary is huge because this is an unoptimized version. You can get it way smaller if you compile it in release mode. There's no runtime in Rust. All the checks are made at compile time.
Building in release mode and stripping the binary results in a ~310Kb exectuable. This still includes parts of the rust standard library which is statically linked. When using no_std like you would in embedded, this size is again smaller by an order of magnitude.
@@dansanger5340 But its runtime is similar in what it does and what it provides to the C runtime (and yes, C also has a runtime which sets up the stack and calls your main()).
In rust you don’t necessarily need to provide the “return” or the semicolon on the last line as long as it’s what you intend to return from your function
What I'm not quite get is why its positioned as a replacement to C and not C++. Its much much more complicated than C with all impl/move/async/smart pointers/generics/lifetimes semantics, whereas C is basically an assembler macroses. So I think rust should in theory replace C++ then, but speaking of C++ - there's already 20'th redaction with move semantics/smart pointers/generics etc and lots of code analysis too. So idk, having nothing against Rust though, but this obsession on "replacing" C....
It's definitely a topic I'd like to learn more about. I don't see a world where Rust ever COMPLETELY replaces C, but I think there's room for replacement in small quantities.
@@LowLevelTV Sure, I actually love languages that have smth unique in this day of c-like llvm/jvm languages everywhere, rust definitely fun to write with its immutability by default and borrow-checker way of thinking, so kudos for it! xD
Are you sure about that you're not just looking at this wrong? The question isn't whether Rust is more complex than C. The question is whether writing code that is memory safe with absolute certainty is more difficilt in Rust or C.
@@SkyyySi it’s not really that difficult to write memory safe code, once you’ve learned it. And you have brilliant profilers that test this. And size of binaries does matter. Especially in the embedded world. So I don’t see Rust as a C/C++ killer. Just another language that complements the list of nice compiled languages.
@@codigodesenior3995 sigsev is a blessing, not a curse. What would happen if the OS were not protecting that memory address would be potentially catastrophic, not just slightly frustrating. Imagine learning to program back in the day when you could accidentally brick your device while programming.
There are other languages as old as C, even older. But nobody ever hears about them anymore, because they weren't so good or didn't have such uses as to still hold up after so many years, as opposed to C (or are still used in niche cases, not popular ones). So "old" isn't really an argument. It's an excellent language in so many ways.
@@ElSantoLuchador it's going to be interesting to watch whether there will be an uptick in the use of those older languages, as we approach the end of Moore and start going into more optimization.
C is the Latin of computer languages. Still used directly by a powerful but obscurantist elite (for Latin the Catholic Church hierarchy, for C the kernel and assembly level developers), and a direct ancestor of the languages most of the planet now uses. FORTRAN is really the only other language that old that’s still in use. One of C’s often overlooked strengths is that it really IS a basically zero overhead, portable assembly with a good syntax. Yeah you don’t get all this invisible magic code and “safety”, but that’s because C was designed for writing the very bottom of the software stack, the foundations upon which things like that rest. One thing I really wish Rust hadn’t done was import some of Python’s bonehead syntax decisions. “Less ‘unnecessary’ punctuation” sounds nice until you realize that HUMAN languages moved in the exact OPPOSITE direction over the past ~250 years, for very good reasons like clarity and ease of reading.
@@zackyezek3760 You're forgetting the largest part of this powerful elite (maybe on purpose-are you one of them?), embedded programmers. And they secretly control absolutely everything that has electronics in it, which today is everything- your car, assembly line robots, life support equipment in hospitals, traffic lights, smart toilets, phones and computers have chips in them that run their own code completely invisible to the OS, flight control systems, electrical grids, washing machines, etc., etc., even your espresso machine. Their power is immense. If we anger them and they decide to abuse it, then we're all doomed.
Rust's biggest draw back in embedded is the limitation of architectures it supports due to LLVM. Now this can change, but as of right now, if LLVM doesn't support a chip, neither does Rust. And LLVM is lacking in a few areas. Hope to see this improve though.
Xtensa is still the main backend I'm waiting on, but at the same time I'm seeing more microcontrollers move to RISC-V like Espressif's new ESP32-C3 and Rust works amazingly out of the box on that platform
Of course, if it's not supported you are on your own, but it covers already a huge amount of architectures - many more coming. They are also working on a new Rust based compiler that will hopefully make porting to new architectures easier.
5:38 noo, 12345 doesn't point to anything, it's just a number. The type of the **number** is usize! The usize definitely doesn't mean "undefined size", it means "unsigned pointer-sized integer" lol, like size_t in C
I like the way this video was presented, and welcome to the Rust community! The only thing I'd like to mention is that I've noticed some of the information/code you share is not (entirely) correct, and might cause confusion for others. - Rust does not require explicit return statements, the last expression will be the return value; unless you want to perform an early return. - I would recommend using Rustup to install the rust compiler and other very useful tools, such as cargo (the package manager used by rust), and generally includes a more recent version of the compiler as well. - The binary you compiled was not optimized, therefore it will also include debug symbols among other things which drastically increase the size. - usize does not stand for undefined size, it stands for unsigned size, which is the unsigned variant of size (signed is called isize) which is a pointer sized integer that varies in byte size depending on the target architecture you are building for; for example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes. Anyways, keep it up.
It's great that you are excited about memory safety. You talked about it a lot in the video, but Java had memory safety back in 1995. That's 27 years ago! To me, one of the most interesting features of Rust is thread safety. This is the first time I ever heard of a language that guaranteed thread safety. IMHO, that's much more important (and more revolutionary) than memory safety.
@Igor Melo Both Java and Rust have a combination of compile-time and run-time memory safety. Nevertheless, some of the compile-time memory safety in Rust is very innovative.
That's good to know. Like I said though, I like the fact that it wraps the run-time into the binary so it remains portable. I would hate for there to be some arbitrary external dependency. Thanks for watching!
@@LowLevelTV I sure you have read this somewhere else at this point, but static linking is not the problem causing the large executable size. Building in release mode and stripping the binary results in a ~310Kb exectuable. This still includes parts of the rust standard library which is statically linked. When using no_std like you would in embedded, this size is again smaller by an order of magnitude.
@@LowLevelTV I'm fairly certain there is no runtime ? But I do know you can designate targets when compiling with cargo with the --target flag. I do that all the time to compile from my x86 machine and get an ARM binary for my raspberry pi. You can knock the size way down with the --release flag too.
It is easy to make mistakes in C but they're not impossible to avoid if you're aware of a few simple rules. Failing that, there are tools to help you like static analyzers. Adding optional extensions to the C language for safety and reliability would, in many cases, be a better approach than doing a complete rewrite in a different language.
@@TCSyndicate It's not easy. But in many cases it is different than doing complete application rewrites, which would undoubtedly introduce new problems. My point is, if you're motivated to tackle this problem, you should be looking at it from different angles, not just jumping to an entirely new language straight away.
@@saturdaysequalsyouth you've just got to be specific. Sure, rewriting a large application in a new language may introduce more problems than it solves, but "jumping to an entirely new language" may be fine for future applications. Restricting memory errors are definitely a vector that encourages the introduction ( and depending on the space, domination ) of new popular languages ( the most pop langs are gc'd ).
@@TCSyndicate Yes, in the future there will be space for languages like Rust. For people who can't, or don't want to go that route, there are ways to reduce memory errors with exiting langauges like C. Static analysis, dynamic profilers, language extensions and hardware solutions like CHERI.
@@saturdaysequalsyouth to be clear, the space already exists ( any app that wants speed & security guarantees ), the "future" part is continuing to make applications in that space.
C and C++ never die. The most powerful and the most versatile languages ever made. People just need different experiences and that’s why they are making alternatives.
One of the best things about Rust is the information the compiler gives you when the build fails. I taught myself Rust mostly just from the suggestions it offered and the occasional web search. Its syntax is superficially like C and Python had a baby, sure, but only on a line-by-line level. That breaks down quickly when you get into macros though.
C# was the baby of visual basic and c++ but came out looking like Java.
3 ปีที่แล้ว +10
The shortest tutorial in the world going from hello world to unsafe code, plus misnaming the concepts means it's a guaranteed misunderstanding for anyone who'd like a taste of rust.
I started programming with City & Guilds mnemonic code (most won't even have heard about it I guess) so C is a fairly recent language as far as I'm concerned. I have seen so many "this will be the death of C" articles written about new languages I've lost count. My guess is that C will still be a major force, especially in the embedded world where it is still dominant, for a long time to come.
@Bisweswar Bose , Amen to using C wrongly - I made every possible mistakes. But it is still my favourite language for its simplicity and elegance! Assembly can beat it but I haven't touched it since 32bit processors came out.
@Bisweswar Bose While I can't deny the part about immaturity and the ecosystem not being as big as other languages, it is slowly becoming an industry staple, with a lot of major companies/groups investing in it as a C/C++ successor. Also calling an actually used language esoteric is flat out wrong.
I think you miss a huge point of Rust, its toolchain. You completely side track that by only installing the compiler, but I think that is one important aspect of it since it was directly developed side by side. Memory management is also something that needs to be addressed, also some minor misconceptions sneaked in there. Up to the point that I think you should do an update/correction video once you are more familiar with it. (Read the book it is good)
@@tolkienfan1972 Na nit-picking and he corrected most of them in his later videos. (Also I would need to rewatch to do that, and I'm lazy 😉) Still if you are interested in Rust read the official rust book. (Its free and online) It is compared to other "official Programming Books" a really good read. Nothing for complete newbies but anybody who is a bit adapt with any kind of programming should manage just fine.
Toolchains are not the same as a programming language. Just as a compiler isn’t the same as a programming language. I can use any rust compiler or build system that I want.
@@baileyharrison1030 course you can, but then you are missing completely the point of rust being an ecosystem not just a language, much like your comment.
I looked at it (from c, c++, python) from time to time, just grasping the concepts without doing more that 3-liner tests. I like it on some points (match, get rid of exceptions, interfaces/traits instead of inheritance, compiler messages, promise of zero cost resource safety) but the langage feels big, too big to get it whole in my head even as a core subset. I think it's because it's hard to have a small orthogonal subset of it where everything flow from core concept without more and more syntax details and add ons. Once you get pointers, C has this feeling, then act as core for C++. And python has it from the start, thesis to it's pseudo-code feeling (although a little bit less so since decorators). Maybe it's the lack of a real practical use, but Rust don't give me this nice compact orthogonal feeling...
I completely get it. When I started with Rust it felt like this big thing with a lot of magic under the hood and a lot to learn. Now that I've used it for a while I think it's possibly the easiest language to really wrap your head around. While the learning curve is certainly steeper than other languages it's not anywhere near as long. There's actually no magic going on, just a very well thought out rule set that, once you got it, is rather simple.
Honestly goes away one you get practical with it. Its like using pointers for the first time confuses a lot of people but it really isn't a complicated thing. Once you get past that curve, its way more fun.
My personal opinion, is that if you have not programmed in C, you aren't still really a professional. Once you learn C, you can switch, and easily understand, any other more "powerful" language. But learn C first, to know the depths of programming.
I was really intimidated by rust coming in. It was between rust and go for me. Not sure what it is but the rust syntax and logic just makes more sense to me and is closer to what I would come up with if I had to write my own language. Excited to learn more
Is there a particular reason you chose to install rustc from the package manager and not rustup? Also please use the standard formatting as per rustfmt 🙏🏻
This whole time I had never even heard of Rust or knew that it existed although admittedly I'm behind on a lot of the newer languages as I haven't coded lately as much as I did when I was a teenager. Programming in C and C++ back in the 90's was a nightmare especially when it came to variables. Every time it came to working with strings, memory address and pointers I would panic and have to stop to pick up one of my C/C++ programming books and waste 30 minutes to an hour refreshing on how it all works to avoid crashing. The benefit of C aside from it being portable is that it's the closest thing to Assembly language and understanding Assembly language concepts help make C less painful. I haven't fully dived into C# but the little bit I've played with it looks like a fun higher level language kind of like Visual Basic which I love but it's limited only to Windows programs and there doesn't seem to have any low level capability. This Rust on the other hand appears to be high level and portable yet that option of being able to go unsafe {} to where you can get to the low level stuff is pretty remarkable and awesome. Glad I stumbled upon your video and thanks for sharing 😃
You're writing Rust like you're literally translating C, in Rust's style you're not meant to place your curly braces on newlines or add return, all functions will implicitly return () unless you specificy something else. You also mimic C in just installing the compiler, so you're missing the massive featureset of cargo and crates.io which makes managing dependencies ridiculously easy and allows much easier interfacing with the compiler. Side note, your binaries will be big because they get compiled in debug mode by default, the release mode is much more optimised in terms of space and speed.
Our numbering system doesn't make it easy to make counting mistakes though. This is a disingenuous statement, probably meaning something different than you intended. One liners are rarely good if they are on a controversial topic...
@@OppaMack Not sure if you're saying Rust programmers are babies or C programmers are babies, but neither option is true. C is a great historical achievement, but I'd rather not have a situation where programmers have to be perfect to avoid serious security vulnerabilities. No human makes no mistake ever. We should look for tools and languages which are better taking our fallibility into account.
@@OppaMack Ok so that's not true. You're obviously trolling or feel the need to prove your superiority somehow. Consider this the last time I'll respond. This can't be constructive. Enjoy C, but don't look down on other people with disdain based on a lack of knowledge as you're doing here.
I've spent the last month learning Rust. I've been programming C since 1987 and C++ since it first hit the scene. I find it to be delightful, controllable, and predictable. The learning curve isn't that steep coming from C/C++.
While C is old, the memory model and simplicity of C makes it extremely powerful still. It's awesome that you can do things like allocate 8 bytes of memory as a string and then treat that string as a 64 bit integer for fast comparisons. Mindblowing stuff on how to speed up string comparisons, for instance. :)
Wow nice video. I put some time to learn Rust last summer but didn't love it. Recently a friend told me again about it and I promised I'd have a look at it again. Then your video pops up 🤣
What I'm in a little disagreement is the "unfortunately" you used when saying modern OSes are written in C. Also, I believe we should mention Rust and C produce assembly that is very different and there is a tradeoff between safety and performance. 👍
Learning rust has been a side project, but golang has been my main focus lately due to the speed of development and less learning curve coming from other languages. I hope to see your channel include other languages such as Go...
Zig is the new C. Zig is faster is compilation time than Rust and doesn't have as many high-level constructs as Rust. Plus doesn't have as strong safety guarantees
rust is amazing, so far only downside is limited packages (but that is changing) and that it doesn't run on exotic hardware (C always can, in fact if you can't get C to run on the device its considered non-functional)
I really like Rust. I could have done without its pedantry around naming conventions, but I learned to live with it. Its learning curve was admittedly steep, even with my level of experience, but then again I was deliberately trying to make it do something it wasn't designed to do at the same time I was learning the language from scratch. I'm the kind of dev who has to learn by doing. Following tutorials just puts me to sleep.
Very important that they still let you do "unsafe" blocks. Rust is a pretty opinionated language after all, but rather than making its opinions required, it just makes them the default. Not only does it mean you can get up to the same bit magic hijinks that you can in C when the time calls for it, but it makes it much easier to debug down the line because you can easily search for all of the "unsafe" blocks in your code first. Rust has guardrails, but they neither compromise performance nor are mandatory.
Replacing C just because its 50 years old does not make any sense. Plus, C is very straight forward compare to Rust. Beginers make mistakes ,yes but mastering the language is part of the learning curve. You dont fix bad programming with a new language. We should instead raise the bar and awarness of critical case that could lead to problem with C, just my opinion
Intermediate-Master C programmers make tons of memory errors when writing thousands of lines of code that interface with complex systems. Statistics done by these companies show the number of errors continues to go up, and 70% are memory errors. This is precisely why Microsoft tried to make their own memory safe lang ( project Verona ) before eventually investing a million with other companies in the Rust foundation. You say we don't fix bad programming ( memory errors ) with a new language, but we did that successfully tons of time. That's what garbage collected languages are, and they're the most popular language. Rust serves the same function as a gc'd language ( gets rid of memory errors ) except u lose no runtime speed for it ( u lose learning and compiling speed ).
@@TCSyndicate exactly. It's every freshman in the world who reiterates what OP said. Real experts, with decades longer experience, all say the same thing. For instance there is a reason C++ became so successful, its interop with C and its so much stronger type system. The same goes for Rust. Writing good C and writing correct C are two different things. Being correct at all times is so, so, so much more difficult than writing "good code."
@@TCSyndicate Yeah, it baffles me how so many C diehards have this idea that they're so perfect they can't make mistakes, and therefore don't need any help from the compiler.
Would you learn Go as well and try to explain some key pointers how it differs from these common languages in good and bad? It seems to be used by quite a few companies. I remember Brian Kernighan talk about Go positively.
I just saw some information somewhere about C/C++ being replaced by Rust. I am very new to programming, I have not mastered any language so far, but I have some understanding of basic high level languages. I may possibly learn C/C++ at some point, and the reason for my intrigue is the level of granularity. Which seems to be the main issue with the language. I can understand the benefit of Rust creating what appears to be rules that prevent memory issues. My critique of your explanation, C or C++ is probably tedious to write, and you mentioned most operating systems rely on C/C++ in one way or another. Linux being entirely written in C. You then opened the rust compiler using Linux. You then downloaded the Rust Runtime environment that is written in Linux. What appears to be evident to me, is that someone took the time to provide a safe method of memory allocation and control written in C. I'm not trying to start some kind of serious debate about the languages, and I'm sure rust is a decent language to write in, but I thought that was kind of funny.
In C/++ you can basically write anything (they're both Turing complete after all). And yes, the Linux kernel running your Rust binary is written in C/++, so it's possible it has memory issues. The reason Rust can claim the safety badge where C/++ cannot is that the subset of memory operations allowed in Rust has been mathematically proven to be safe at a compiler level. In C/++, it's the developer's job to write that proof. The problem is that no normal developer ever will write that proof, so they rely on gut instinct, experience, and testing to determine what is/isn't safe. Rust let's a normal developer tap into the performance and safety of an experienced developer called "Mr Compiler"
It's very easy to call into C code, and it's very easy for C code to call into rust. That was actually a design constraint of rust, it has to be useable with C because Mozilla had a C code base that they didn't want the throw out while working on Rust.
You really shouldn't install rustc from the repos and compile it directly like its done with C. You should install rustup instead (From the repos if possible or website otherwise) and use cargo. Cargo manages projects, which allow you to easily add third party libraries (all of them open source) and lets you compile you package way easier. Important commands: cargo new NAME: create projekt cargo run : compile (Unoptimised) and run cargo build: compile (Unoptimised) file is in target/debug/NAME cargo build/run --release: Compile optimised (and run)
If you can be sure you'll never make a mistake which introduces a memory bug in the future and leak all your users' data or clobber important sensor readings ever, yes. If no, Rust should be something you watch and consider for new projects at some stage.
Because usually the new stuff is crap, or long forgotten old ideas taking a surface. Generally software gets worse with time, rust is only accelerating that trend. Well educated people know this, so they would not waste their time on yet another piece of crap.
So I tried to move to the Rust several times, and it's just not worth the trouble, it's sometimes so unnecessarily complicated to do very simple things that it throws me off. And if it's not worth the trouble for my small projects (up to 1k lines of code) then I believe it's way too unreasonable for bigger companies and projects to move from something that's simple (C, C++ is way too bloated) to something way more complicated like Rust. It certainly brings some great benefits (I love the compiler messages) but ultimately it's not really worth it in my opinion ;v
I think this would be a good language for that tbh, but I need to dive in. Now, in the embedded scene, Rust is completely not ready. Not saying it won't be ready in the future of course.
True. But that doesn't mean that we can't write new programs in Rust which might otherwise would've been written in C++ or C. For example, Linux kernel, where C++ does not even exist, will have Rust as its second language.
If you're here to start learning Rust, just read the official book. Somehow even in a hello world program in this video, a couple of conventions have been broken. Opening curly bracket should be on same line as function name and the return is unnecessary.
Holy crap I've been looking for a channel like this!!! Rust seems interesting, but this video popped up in my feed and so it's how I found the channel. I'm immediately going to grep all the C content, and then I'll check this out!!!
According to microsoft, the memory unsafety of C is the result of at least 71% of security vulnerabilities. That's pretty unfortunate. If some of the best programmers in the world can't keep from making mistakes then no one can.
@@Raleighthrbub123 This point is largely not applicable to operating systems programming. The Operating System MUST perform unsafe memory access, as it is the one who manages memory. It must literally implement its own malloc() to allocate memory, along with the paging system and virtual memory translation. In addition, it interfaces DIRECTLY with hardware, so it must perform unsafe memory accesses, often using constant shifts and addresses. Operating System programming would be unsafe even if done in Rust or C++, although you might get better markup (i.e. unsafe{}) in your code.
GCC has a builtin static analyzer, in active development, for C. So why switch to Rust when I can continue using C with using analysis tools to have safe code?
@UCU3SuQ4YhUIdqg2CyTtcXQw ehhh don't get me wrong, they're convenient but they're also a crutch if you think about it. C++ also has metaprogramming but look at the insanity of its standard library because of it. Rust & C++ have to use metaprogramming because of their own constraints to achieve the same thing C can achieve in a "dangerous" way. Realistically, perhaps C will have a sane and more simplified way of doing metaprogramming in the future but gotta wait for a maintainable implementation. For the moment, metaprogramming in C and Golang is simply generating code to be compiled later on.
@@kevinyonan9666 It's not about restraints, it's about doing work at compile time and in an abstracted way. Rust does it especially well, you can implement meta languages for compiler grammar rules as an example! It also has compiletime filesystem inclusion, etc. Trust me, I know how much of a mess the STL is - I myself am a Microsoft STL contributor, but Rust does it much better with a model which is older than C!
@@parallel4344 Microsoft? That explains everything. Windows has the shittiest C support out of the major OSs. MSVC is still missing alot of C99 and C17 features. Yea GCC and Clang aren't 100% C99 compliant but they support alot more of it compared to MSVC. Ofc instead of finishing the job, Microsoft opts to yet again switch to another language with this time being Rust, because apparently the C++, C# hybridization didn't work out too well... Here's a good question, C also has the potential to have metaprogramming (outside the preprocessor) but the thing with C and what makes it special is that whenever you come across a problem, the solution is typically writing more C as opposed to "we need a new feature" I've been writing C for 7 years, so far all I'd like for C is the defer statement from Golang, function literals so that I don't need to always define a static function, and type annotation so that compilers can have the potential to optimize void pointers as good as type parameterized generics.
A tutorial about debugging stm32s with probe-rs instead of GDB would be sweet as I couldn't find a good learning resource for embedded-rust-newbs for this. Anyways, keep up the good work!
You seem to argue that C’s age alone is a bad thing. I think that’s a weak foundation for an argument. Rust is great. But is it better for a application in production to rely on a language that has stood the test of time or shiny new one with a short history?
For a very wide range of applications, I would definitely trust a Rust codebase over a C codebase at this point. Plenty of things that used to be done in C are now done in other languages, and Rust while not the end of C is yet another option that eliminates more of the niches where C used to make sense, though it has more overlap with C++ usecases than with C's usecases.
No, instead of unknowingly breaking memory rules rust warns you at compile time. It tells you what you are doing wrong and why with the option to use unsafe if you truly need it.
It's fast, but Rust can be as fast. Rust with #[no_std] (not linking standard library) is about as small too. C is faster and smaller only when there's not enough runtime checks to make the code actually robust IME.
You can divide by zero in safe code. It will cause a panic (roughly similar to C++ exceptions except it is conventionally used for unrecoverable errors), which is classified as "safe" so the unsafe keyword is not needed. (Unsafe division by zero would be relying on the processor's behavior which would cause a SIGFPE or something.) Alternatively, you can use x.checked_div(y) and handle the error case yourself.
Rust is yet another new shiny thing. Techies love new shiny tech. It is exciting. It has possibilities. It is something new to explore. It is like Christmas morning. Yet, most of the new, shiny tech of just a few years ago has been replaced by yet another new and shiny thing. Rust has yet to stand the test of time. I’ll sit back and watch rather than run after every new and shiny thing. New is not necessarily better. Enjoy playing with your new toy. Have fun!
Totally agree! I'm trying to learn C++ using Stroustrup's latest book, and am frustrated by some things: #1 not able to find ANY reasonable explanation on line as to why I MUST learn pointers and passing by reference, especially in OOP, and #2 I wanted to make 2D games and can't seem to find a gui library anywhere that's easy to install and set up on Windows 10 to work with Visual Studio 2022 Community Edition. So I'm tempted to run for the hills, an area known as "come over here and try THIS shiny, new toy where you MIGHT stay for awhile until something ELSE gets in your way" :D
As all C programmers say, with great power comes great 'segmentation fault at line 115'
It gives line position where segfaults 🤯🤯
@@heroes-of-balkan it's worse when it doesn't. I've had segfaults but it gives me the line.
@@timecubed lucky you
hahaahah
As all JS developers say, with great power comes great '[object Object]'
Hi my friend, as a fellow C programmer, who switched to Rust a year ago after 30+ years of C. I would highly recommend dropping the OS packaged rust (i.e. using apt or rpm) and use rustup instead! The packaged versions tend to be several version behind, and Rust is hyper evolving right now (including the stable version. for example there is a major CVE that got addressed in 1.58.1 that plagues all previous versions). Also, with rustup you will get the latest and greatest version of rust-analyzer which in-turn makes integration with IDEs a lot cleaner.
True. But even so, the OS packaged version is *so much more current* than a lot of other languages, and I think rustup is the reason for that.
@@simonfarre4907 usually "current" is "unstable".
So, you literally said "rust is _so much more unstable_ than a lot of others languages"
@@vlya1533 No. Rust ships on the same schedule as Firefox. Every 6 weeks a new beta is branched off. If it survived 6 weeks of beta testing, it's pushed as the next stable release. Once it's been released as stable, it guarantees backwards compatibility. So any code which compiled with a previous stable compiler must still compile with the new compiler, and any code it can compile must compile with all new stable compilers further along. The amount of bugs on stable is almost nonexistent. I know of one serious bug in 2 years and about 10 bugs in total that was fixed with patch releases over that period. Just because it doesn't work as things had always worked doesn't mean it isn't as stable. The one doesn't necessarily imply the other. If you have empirical evidence of rustc's instability compared to MSVC, gcc and clang, that's another matter altogether.
@@louiscloete3307 who are you arguing with? I've not commented or asked anything about rust beta release cycle :)
@@vlya1533 > usually "current" is "unstable".
So, you literally said "rust is so much more unstable than a lot of others languages"
I wrote that to explain why "current" isn't necessarily "unstable".
C succeeded because it enabled engineers to get stuff done. Whether Rust overtakes C depends on whether Rust developers can get stuff done more quickly to the point that the advantages are clear. This means the learning curve must not be too steep, and there cannot be chronic situations where the developer has to learn something that won't be used for another sixth months.
But C++ also has a steep learning curve, yet it's so popular, so that can't be all.
@@verified_tinker1818 true, but, you can gradually adopt the more complex parts of c++ and basically just write c to begin with. Which makes it MUCH simpler/easier/quicker to get started with and become productive with than Rust
The binary is huge because this is an unoptimized version. You can get it way smaller if you compile it in release mode.
There's no runtime in Rust. All the checks are made at compile time.
Ye I was confused when he said this
Ironic that everyone using rust is non binary!
Building in release mode and stripping the binary results in a ~310Kb exectuable. This still includes parts of the rust standard library which is statically linked. When using no_std like you would in embedded, this size is again smaller by an order of magnitude.
@@laravelisbullschitt3281 im continuous
@@dansanger5340 But its runtime is similar in what it does and what it provides to the C runtime (and yes, C also has a runtime which sets up the stack and calls your main()).
In rust you don’t necessarily need to provide the “return” or the semicolon on the last line as long as it’s what you intend to return from your function
Using explicit return is actually against the official style. The return keyword is only used for early returns.
@@saadisave this is the case for Scala as well
Well, in this case you wouldn't need return even if you had to have returns, as it's a void function
it’s like gcc statement expression
Allowing to be untidy is part of the root issues of modern programming. Idiots are getting les rigorous and that is a major problem
5:10 - Just want to add something here, you can *always* dereference a pointer safely, unsafe mode also allows dereferencing *raw* pointers.
It's better to say reference instead of pointer though, or people will get confused and think you're talking about raw pointers
C is 50 years old but still a top 3 language. It won't be going anywhere anytime soon.
Maybe anytime soon could mean tommorow. Doesn't hurt to learn rust or an alternative. Don't be conservative with your tooling it's good to explore.
Open your mind.
@@jonathanmoore5619 Okay Morpheus.
@@ertugrulghazi334 nonce
@@jonathanmoore5619 come on, that was a good one.
I love that you're heading in the rust direction. Can't wait to learn along with you.
among us
What I'm not quite get is why its positioned as a replacement to C and not C++. Its much much more complicated than C with all impl/move/async/smart pointers/generics/lifetimes semantics, whereas C is basically an assembler macroses. So I think rust should in theory replace C++ then, but speaking of C++ - there's already 20'th redaction with move semantics/smart pointers/generics etc and lots of code analysis too. So idk, having nothing against Rust though, but this obsession on "replacing" C....
It's definitely a topic I'd like to learn more about. I don't see a world where Rust ever COMPLETELY replaces C, but I think there's room for replacement in small quantities.
@@LowLevelTV Sure, I actually love languages that have smth unique in this day of c-like llvm/jvm languages everywhere, rust definitely fun to write with its immutability by default and borrow-checker way of thinking, so kudos for it! xD
I do agree! It’s such a whiny complaining compiler. If you are a C/C++ developer it feels like torture.
Are you sure about that you're not just looking at this wrong? The question isn't whether Rust is more complex than C. The question is whether writing code that is memory safe with absolute certainty is more difficilt in Rust or C.
@@SkyyySi it’s not really that difficult to write memory safe code, once you’ve learned it.
And you have brilliant profilers that test this. And size of binaries does matter. Especially in the embedded world. So I don’t see Rust as a C/C++ killer. Just another language that complements the list of nice compiled languages.
What happens in unsafe stays in un-
SEGMENTATION FAULT(core dumped)
this is my nightmare
C++ feels
@@codigodesenior3995 sigsev is a blessing, not a curse. What would happen if the OS were not protecting that memory address would be potentially catastrophic, not just slightly frustrating.
Imagine learning to program back in the day when you could accidentally brick your device while programming.
@@nickscurvy8635 thx, i i didn't think about it...
There are other languages as old as C, even older. But nobody ever hears about them anymore, because they weren't so good or didn't have such uses as to still hold up after so many years, as opposed to C (or are still used in niche cases, not popular ones). So "old" isn't really an argument. It's an excellent language in so many ways.
FORTRAN...
@@Theineluctable_SOME_CANT my grandmother coded in that, I'm not even kidding
@@ElSantoLuchador it's going to be interesting to watch whether there will be an uptick in the use of those older languages, as we approach the end of Moore and start going into more optimization.
C is the Latin of computer languages. Still used directly by a powerful but obscurantist elite (for Latin the Catholic Church hierarchy, for C the kernel and assembly level developers), and a direct ancestor of the languages most of the planet now uses. FORTRAN is really the only other language that old that’s still in use.
One of C’s often overlooked strengths is that it really IS a basically zero overhead, portable assembly with a good syntax. Yeah you don’t get all this invisible magic code and “safety”, but that’s because C was designed for writing the very bottom of the software stack, the foundations upon which things like that rest. One thing I really wish Rust hadn’t done was import some of Python’s bonehead syntax decisions. “Less ‘unnecessary’ punctuation” sounds nice until you realize that HUMAN languages moved in the exact OPPOSITE direction over the past ~250 years, for very good reasons like clarity and ease of reading.
@@zackyezek3760 You're forgetting the largest part of this powerful elite (maybe on purpose-are you one of them?), embedded programmers. And they secretly control absolutely everything that has electronics in it, which today is everything- your car, assembly line robots, life support equipment in hospitals, traffic lights, smart toilets, phones and computers have chips in them that run their own code completely invisible to the OS, flight control systems, electrical grids, washing machines, etc., etc., even your espresso machine. Their power is immense. If we anger them and they decide to abuse it, then we're all doomed.
Rust's biggest draw back in embedded is the limitation of architectures it supports due to LLVM. Now this can change, but as of right now, if LLVM doesn't support a chip, neither does Rust. And LLVM is lacking in a few areas. Hope to see this improve though.
Rust is the future of computer programming. Expect good things concerning Rust.
Rust does have the WIP gccjit compiler and the GCC official implementation.
Both will allow you to compile rust to anything gcc can.
They are currently planning to remove LLVM from the toolchain
Xtensa is still the main backend I'm waiting on, but at the same time I'm seeing more microcontrollers move to RISC-V like Espressif's new ESP32-C3 and Rust works amazingly out of the box on that platform
Of course, if it's not supported you are on your own, but it covers already a huge amount of architectures - many more coming.
They are also working on a new Rust based compiler that will hopefully make porting to new architectures easier.
5:38 noo, 12345 doesn't point to anything, it's just a number. The type of the **number** is usize! The usize definitely doesn't mean "undefined size", it means "unsigned pointer-sized integer" lol, like size_t in C
Seconded, would love to see Rust running with Raspberry Pico.
I saw a video yesterday where it was...
it aldready does
I like the way this video was presented, and welcome to the Rust community! The only thing I'd like to mention is that I've noticed some of the information/code you share is not (entirely) correct, and might cause confusion for others.
- Rust does not require explicit return statements, the last expression will be the return value; unless you want to perform an early return.
- I would recommend using Rustup to install the rust compiler and other very useful tools, such as cargo (the package manager used by rust), and generally includes a more recent version of the compiler as well.
- The binary you compiled was not optimized, therefore it will also include debug symbols among other things which drastically increase the size.
- usize does not stand for undefined size, it stands for unsigned size, which is the unsigned variant of size (signed is called isize) which is a pointer sized integer that varies in byte size depending on the target architecture you are building for; for example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.
Anyways, keep it up.
It's great that you are excited about memory safety. You talked about it a lot in the video, but Java had memory safety back in 1995. That's 27 years ago! To me, one of the most interesting features of Rust is thread safety. This is the first time I ever heard of a language that guaranteed thread safety. IMHO, that's much more important (and more revolutionary) than memory safety.
@Igor Melo Both Java and Rust have a combination of compile-time and run-time memory safety. Nevertheless, some of the compile-time memory safety in Rust is very innovative.
That's an interesting point.
doesnt haskell have thread safety too
Lisp (65+ years old): Am I a joke to you?
You are missing the point. Many languages were memory safe before Rust (and even way before Java), but none of them was a system programming language.
You can actually enable dynamic linking instead of static to get lesser binaries, AFAIK
That's good to know. Like I said though, I like the fact that it wraps the run-time into the binary so it remains portable. I would hate for there to be some arbitrary external dependency.
Thanks for watching!
@@LowLevelTV I sure you have read this somewhere else at this point, but static linking is not the problem causing the large executable size.
Building in release mode and stripping the binary results in a ~310Kb exectuable. This still includes parts of the rust standard library which is statically linked. When using no_std like you would in embedded, this size is again smaller by an order of magnitude.
@@LowLevelTV I'm fairly certain there is no runtime ? But I do know you can designate targets when compiling with cargo with the --target flag. I do that all the time to compile from my x86 machine and get an ARM binary for my raspberry pi. You can knock the size way down with the --release flag too.
@@LowLevelTVtheres no runtime
It is easy to make mistakes in C but they're not impossible to avoid if you're aware of a few simple rules. Failing that, there are tools to help you like static analyzers. Adding optional extensions to the C language for safety and reliability would, in many cases, be a better approach than doing a complete rewrite in a different language.
if it were as easy as u think, microsoft could clear 70% of their security errors with some simple tools and tricks.
@@TCSyndicate It's not easy. But in many cases it is different than doing complete application rewrites, which would undoubtedly introduce new problems. My point is, if you're motivated to tackle this problem, you should be looking at it from different angles, not just jumping to an entirely new language straight away.
@@saturdaysequalsyouth you've just got to be specific. Sure, rewriting a large application in a new language may introduce more problems than it solves, but "jumping to an entirely new language" may be fine for future applications. Restricting memory errors are definitely a vector that encourages the introduction ( and depending on the space, domination ) of new popular languages ( the most pop langs are gc'd ).
@@TCSyndicate Yes, in the future there will be space for languages like Rust. For people who can't, or don't want to go that route, there are ways to reduce memory errors with exiting langauges like C. Static analysis, dynamic profilers, language extensions and hardware solutions like CHERI.
@@saturdaysequalsyouth to be clear, the space already exists ( any app that wants speed & security guarantees ), the "future" part is continuing to make applications in that space.
The rust docs are pretty good. I have been passively reading them for about two weeks 🙂
Yes they are!
C and C++ never die. The most powerful and the most versatile languages ever made. People just need different experiences and that’s why they are making alternatives.
I still prefer C, much easier to tell it to do what I want, even if what I want brakes things
One of the best things about Rust is the information the compiler gives you when the build fails. I taught myself Rust mostly just from the suggestions it offered and the occasional web search. Its syntax is superficially like C and Python had a baby, sure, but only on a line-by-line level. That breaks down quickly when you get into macros though.
C# was the baby of visual basic and c++ but came out looking like Java.
The shortest tutorial in the world going from hello world to unsafe code, plus misnaming the concepts means it's a guaranteed misunderstanding for anyone who'd like a taste of rust.
I started learning Rust a little while ago and I love it so far. I'm looking forward to this series!
I started programming with City & Guilds mnemonic code (most won't even have heard about it I guess) so C is a fairly recent language as far as I'm concerned. I have seen so many "this will be the death of C" articles written about new languages I've lost count. My guess is that C will still be a major force, especially in the embedded world where it is still dominant, for a long time to come.
What about the speed? Most people use C on embedded devices instead of python for reason of speed and binary size.
I think there's a future where computer speed has outpaced the cost that a language like Rust incurs in overhead.
@Bisweswar Bose , Amen to using C wrongly - I made every possible mistakes. But it is still my favourite language for its simplicity and elegance! Assembly can beat it but I haven't touched it since 32bit processors came out.
The speed compared to C is pretty much the same in most cases afaik.
@Bisweswar Bose While I can't deny the part about immaturity and the ecosystem not being as big as other languages, it is slowly becoming an industry staple, with a lot of major companies/groups investing in it as a C/C++ successor. Also calling an actually used language esoteric is flat out wrong.
Rust has same speed as C. There's some binary size issues with default config that can be worked around for embedded.
You keep saying that Rust is similar to Python but I just don't see it. At a glance it looks like C. Am I missing something?
I think you miss a huge point of Rust, its toolchain.
You completely side track that by only installing the compiler, but I think that is one important aspect of it since it was directly developed side by side.
Memory management is also something that needs to be addressed, also some minor misconceptions sneaked in there.
Up to the point that I think you should do an update/correction video once you are more familiar with it. (Read the book it is good)
You should list the misconceptions. It would be interesting to all of us with an interest in Rust
@@tolkienfan1972 Na nit-picking and he corrected most of them in his later videos.
(Also I would need to rewatch to do that, and I'm lazy 😉)
Still if you are interested in Rust read the official rust book. (Its free and online)
It is compared to other "official Programming Books" a really good read.
Nothing for complete newbies but anybody who is a bit adapt with any kind of programming should manage just fine.
Toolchains are not the same as a programming language. Just as a compiler isn’t the same as a programming language. I can use any rust compiler or build system that I want.
@@baileyharrison1030 course you can, but then you are missing completely the point of rust being an ecosystem not just a language, much like your comment.
I looked at it (from c, c++, python) from time to time, just grasping the concepts without doing more that 3-liner tests. I like it on some points (match, get rid of exceptions, interfaces/traits instead of inheritance, compiler messages, promise of zero cost resource safety) but the langage feels big, too big to get it whole in my head even as a core subset. I think it's because it's hard to have a small orthogonal subset of it where everything flow from core concept without more and more syntax details and add ons. Once you get pointers, C has this feeling, then act as core for C++. And python has it from the start, thesis to it's pseudo-code feeling (although a little bit less so since decorators). Maybe it's the lack of a real practical use, but Rust don't give me this nice compact orthogonal feeling...
I completely get it. When I started with Rust it felt like this big thing with a lot of magic under the hood and a lot to learn.
Now that I've used it for a while I think it's possibly the easiest language to really wrap your head around. While the learning curve is certainly steeper than other languages it's not anywhere near as long. There's actually no magic going on, just a very well thought out rule set that, once you got it, is rather simple.
Honestly goes away one you get practical with it. Its like using pointers for the first time confuses a lot of people but it really isn't a complicated thing. Once you get past that curve, its way more fun.
I love these humble "Im learning ..." videos. Just reminds us we are all students but never masters :) Openness is the key!
My personal opinion, is that if you have not programmed in C, you aren't still really a professional. Once you learn C, you can switch, and easily understand, any other more "powerful" language.
But learn C first, to know the depths of programming.
Instead of learning C, could i learn C++ first to understand the depths of programming? Is C++ for a starter a bad choice?
@@nikolacekov9099 yes its too complex. I'd start with C, then you can move on to C++
I was really intimidated by rust coming in. It was between rust and go for me. Not sure what it is but the rust syntax and logic just makes more sense to me and is closer to what I would come up with if I had to write my own language. Excited to learn more
Is there a particular reason you chose to install rustc from the package manager and not rustup?
Also please use the standard formatting as per rustfmt 🙏🏻
Your last name spells like yahoo while you put google icon as dp,that's a good one bro 😅✌
June 19 2022 4:11 pm ist
The wheel is thousands of years old, so...
Why learn Rust instead of C#? Sorry if dumb question.
This whole time I had never even heard of Rust or knew that it existed although admittedly I'm behind on a lot of the newer languages as I haven't coded lately as much as I did when I was a teenager. Programming in C and C++ back in the 90's was a nightmare especially when it came to variables. Every time it came to working with strings, memory address and pointers I would panic and have to stop to pick up one of my C/C++ programming books and waste 30 minutes to an hour refreshing on how it all works to avoid crashing. The benefit of C aside from it being portable is that it's the closest thing to Assembly language and understanding Assembly language concepts help make C less painful. I haven't fully dived into C# but the little bit I've played with it looks like a fun higher level language kind of like Visual Basic which I love but it's limited only to Windows programs and there doesn't seem to have any low level capability. This Rust on the other hand appears to be high level and portable yet that option of being able to go unsafe {} to where you can get to the low level stuff is pretty remarkable and awesome. Glad I stumbled upon your video and thanks for sharing 😃
@@vlc-cosplayer Oh cool I didn't know that .NET can run on other platforms. Good to know and thanks for the info 😀
You're writing Rust like you're literally translating C, in Rust's style you're not meant to place your curly braces on newlines or add return, all functions will implicitly return () unless you specificy something else. You also mimic C in just installing the compiler, so you're missing the massive featureset of cargo and crates.io which makes managing dependencies ridiculously easy and allows much easier interfacing with the compiler.
Side note, your binaries will be big because they get compiled in debug mode by default, the release mode is much more optimised in terms of space and speed.
Really cool. Looking forward to more videos on this!
C is 50 years old. But our numbering system is much older than that. Must mean we should invent a new way to count.
Our numbering system doesn't make it easy to make counting mistakes though. This is a disingenuous statement, probably meaning something different than you intended. One liners are rarely good if they are on a controversial topic...
Great point, they feel so special they want a EASY LANGUAGE BACAUSE I AM A BABYYYY
@@OppaMack Not sure if you're saying Rust programmers are babies or C programmers are babies, but neither option is true. C is a great historical achievement, but I'd rather not have a situation where programmers have to be perfect to avoid serious security vulnerabilities. No human makes no mistake ever. We should look for tools and languages which are better taking our fallibility into account.
@@louiscloete3307 Rust programmers are babies.
@@OppaMack Ok so that's not true. You're obviously trolling or feel the need to prove your superiority somehow. Consider this the last time I'll respond. This can't be constructive. Enjoy C, but don't look down on other people with disdain based on a lack of knowledge as you're doing here.
감사합니다.
Thank you Dennis!
I've spent the last month learning Rust. I've been programming C since 1987 and C++ since it first hit the scene. I find it to be delightful, controllable, and predictable. The learning curve isn't that steep coming from C/C++.
I wasnt even alive at 1987, lol
Delightful? 🤮 🏳️🌈
While C is old, the memory model and simplicity of C makes it extremely powerful still. It's awesome that you can do things like allocate 8 bytes of memory as a string and then treat that string as a 64 bit integer for fast comparisons. Mindblowing stuff on how to speed up string comparisons, for instance. :)
Wow nice video. I put some time to learn Rust last summer but didn't love it. Recently a friend told me again about it and I promised I'd have a look at it again. Then your video pops up 🤣
What I'm in a little disagreement is the "unfortunately" you used when saying modern OSes are written in C. Also, I believe we should mention Rust and C produce assembly that is very different and there is a tradeoff between safety and performance. 👍
On top of using rustup, as many have mentioned, you could also use cargo instead of manually calling rustc and then running the program every time
Learning rust has been a side project, but golang has been my main focus lately due to the speed of development and less learning curve coming from other languages. I hope to see your channel include other languages such as Go...
0:32 the most widely used operating system is ITRON
Feels good seeing you cover Rust! Looking forward to more Rust videos, good job!
Glad you enjoyed!
Zig is the new C. Zig is faster is compilation time than Rust and doesn't have as many high-level constructs as Rust. Plus doesn't have as strong safety guarantees
rust is amazing, so far only downside is limited packages (but that is changing) and that it doesn't run on exotic hardware (C always can, in fact if you can't get C to run on the device its considered non-functional)
I really like Rust. I could have done without its pedantry around naming conventions, but I learned to live with it. Its learning curve was admittedly steep, even with my level of experience, but then again I was deliberately trying to make it do something it wasn't designed to do at the same time I was learning the language from scratch. I'm the kind of dev who has to learn by doing. Following tutorials just puts me to sleep.
Interesting to know that rust was bootstrapped using OCaml.
This is actually a very interesting series. Looking forward for the next episode. Keep it up!
1:30 isn't installing rustup better?
Yes -- Ideally always install rustup so you get Cargo as well.
So what? 50 yo and still rocks.
Thank you for your video. I'm learning Rust. Hope to see more video about Rust from you.
More to come!
Very important that they still let you do "unsafe" blocks. Rust is a pretty opinionated language after all, but rather than making its opinions required, it just makes them the default. Not only does it mean you can get up to the same bit magic hijinks that you can in C when the time calls for it, but it makes it much easier to debug down the line because you can easily search for all of the "unsafe" blocks in your code first. Rust has guardrails, but they neither compromise performance nor are mandatory.
Replacing C just because its 50 years old does not make any sense. Plus, C is very straight forward compare to Rust. Beginers make mistakes ,yes but mastering the language is part of the learning curve. You dont fix bad programming with a new language. We should instead raise the bar and awarness of critical case that could lead to problem with C, just my opinion
I totally get what you're saying.
C is not straightforward. If it was, we wouldn't have segfaults.
Intermediate-Master C programmers make tons of memory errors when writing thousands of lines of code that interface with complex systems. Statistics done by these companies show the number of errors continues to go up, and 70% are memory errors. This is precisely why Microsoft tried to make their own memory safe lang ( project Verona ) before eventually investing a million with other companies in the Rust foundation. You say we don't fix bad programming ( memory errors ) with a new language, but we did that successfully tons of time. That's what garbage collected languages are, and they're the most popular language. Rust serves the same function as a gc'd language ( gets rid of memory errors ) except u lose no runtime speed for it ( u lose learning and compiling speed ).
@@TCSyndicate exactly. It's every freshman in the world who reiterates what OP said.
Real experts, with decades longer experience, all say the same thing.
For instance there is a reason C++ became so successful, its interop with C and its so much stronger type system.
The same goes for Rust. Writing good C and writing correct C are two different things. Being correct at all times is so, so, so much more difficult than writing "good code."
@@TCSyndicate Yeah, it baffles me how so many C diehards have this idea that they're so perfect they can't make mistakes, and therefore don't need any help from the compiler.
Just the video I wanted to see today! 😊
Perfect!
rust is great but it doesn't run on consoles easily yet (compiler is open source and console manufacturers don't wanna open source their code)
4:09 ... good this works it literally the best phrase you can hear when executing a code
Total respect and love for rust but C is amazing
Rust is garbage and so are the people using it
Would you learn Go as well and try to explain some key pointers how it differs from these common languages in good and bad? It seems to be used by quite a few companies. I remember Brian Kernighan talk about Go positively.
would love to see more of this
I just saw some information somewhere about C/C++ being replaced by Rust.
I am very new to programming, I have not mastered any language so far, but I have some understanding of basic high level languages.
I may possibly learn C/C++ at some point, and the reason for my intrigue is the level of granularity. Which seems to be the main issue with the language.
I can understand the benefit of Rust creating what appears to be rules that prevent memory issues.
My critique of your explanation, C or C++ is probably tedious to write, and you mentioned most operating systems rely on C/C++ in one way or another. Linux being entirely written in C.
You then opened the rust compiler using Linux. You then downloaded the Rust Runtime environment that is written in Linux.
What appears to be evident to me, is that someone took the time to provide a safe method of memory allocation and control written in C.
I'm not trying to start some kind of serious debate about the languages, and I'm sure rust is a decent language to write in, but I thought that was kind of funny.
In C/++ you can basically write anything (they're both Turing complete after all). And yes, the Linux kernel running your Rust binary is written in C/++, so it's possible it has memory issues. The reason Rust can claim the safety badge where C/++ cannot is that the subset of memory operations allowed in Rust has been mathematically proven to be safe at a compiler level. In C/++, it's the developer's job to write that proof.
The problem is that no normal developer ever will write that proof, so they rely on gut instinct, experience, and testing to determine what is/isn't safe. Rust let's a normal developer tap into the performance and safety of an experienced developer called "Mr Compiler"
Is it possible to mix C and Rust code?
I'w notice that is uses libc...
Yup! You definitely can.
It's very easy to call into C code, and it's very easy for C code to call into rust. That was actually a design constraint of rust, it has to be useable with C because Mozilla had a C code base that they didn't want the throw out while working on Rust.
You really shouldn't install rustc from the repos and compile it directly like its done with C.
You should install rustup instead (From the repos if possible or website otherwise) and use cargo.
Cargo manages projects, which allow you to easily add third party libraries (all of them open source) and lets you compile you package way easier.
Important commands:
cargo new NAME: create projekt
cargo run : compile (Unoptimised) and run
cargo build: compile (Unoptimised) file is in target/debug/NAME
cargo build/run --release: Compile optimised (and run)
So, if my program is memory safe and low level efficient then I don't need Rust.
If you can be sure you'll never make a mistake which introduces a memory bug in the future and leak all your users' data or clobber important sensor readings ever, yes. If no, Rust should be something you watch and consider for new projects at some stage.
yes just stick with hello world and you'll be fine
1:08 eventually take rust to Rpi pico
7:42 running rust on baremetal arm
hmm, those seem smth interesting :)
Alot of C people on the comments who don't want to learn something new lol.
Because usually the new stuff is crap, or long forgotten old ideas taking a surface. Generally software gets worse with time, rust is only accelerating that trend. Well educated people know this, so they would not waste their time on yet another piece of crap.
Great video 🔥
So I tried to move to the Rust several times, and it's just not worth the trouble, it's sometimes so unnecessarily complicated to do very simple things that it throws me off. And if it's not worth the trouble for my small projects (up to 1k lines of code) then I believe it's way too unreasonable for bigger companies and projects to move from something that's simple (C, C++ is way too bloated) to something way more complicated like Rust. It certainly brings some great benefits (I love the compiler messages) but ultimately it's not really worth it in my opinion ;v
Could you elaborate a bit more on what trouble you face? I am interested to see what issues ppl face.
can you do a video and explain where to start with low level system programming, what are the core areas,
I'm very interested in the potential of Rust in game development, can't wait to dive in when I have some time.
Check out bevy game engine written in Rust
I think this would be a good language for that tbh, but I need to dive in.
Now, in the embedded scene, Rust is completely not ready. Not saying it won't be ready in the future of course.
Ya, im takeing C# (most likely) and HTML5 (only if another class is full) next year in high school
Would you like to Talk about D.
I'm really interested in D
“And that was a big mistake, it was my mistake and I’m very sorry”
Hasn't every language since C been the future already?
great video! Thank you!
C has its flaws but I still prefer it to rust
How old is calculus? I guess we should use that common core math instead?
I doubt Rust would replace C anytime soon, just as COBOL or FORTRAN, there is simply too much to reprogram.
True. But that doesn't mean that we can't write new programs in Rust which might otherwise would've been written in C++ or C. For example, Linux kernel, where C++ does not even exist, will have Rust as its second language.
4:24 "... but in C, this is a syntax error because I'm indexing an int like a dummy"
Just learn assembly like a Chad.
If you're here to start learning Rust, just read the official book. Somehow even in a hello world program in this video, a couple of conventions have been broken. Opening curly bracket should be on same line as function name and the return is unnecessary.
@@BobAg_ That's why I said convention not rule...
virgins: rust OR c/c++
chads: rust AND c/c++
Holy crap I've been looking for a channel like this!!! Rust seems interesting, but this video popped up in my feed and so it's how I found the channel. I'm immediately going to grep all the C content, and then I'll check this out!!!
Thanks for hanging out! I’m working on more C content. There’s a ton out there so I need to make it interesting xD
Why do you think it's unfortunate that C is still a major part of operating systems?
According to microsoft, the memory unsafety of C is the result of at least 71% of security vulnerabilities. That's pretty unfortunate. If some of the best programmers in the world can't keep from making mistakes then no one can.
@@Raleighthrbub123 This point is largely not applicable to operating systems programming. The Operating System MUST perform unsafe memory access, as it is the one who manages memory. It must literally implement its own malloc() to allocate memory, along with the paging system and virtual memory translation. In addition, it interfaces DIRECTLY with hardware, so it must perform unsafe memory accesses, often using constant shifts and addresses. Operating System programming would be unsafe even if done in Rust or C++, although you might get better markup (i.e. unsafe{}) in your code.
You should redo this video to show how to install rust correctly to avoid frustrating new users, also the binary size bit is not the whole story.
Check the next video ;)
GCC has a builtin static analyzer, in active development, for C. So why switch to Rust when I can continue using C with using analysis tools to have safe code?
Metaprogramming alone should be a reason.
@@parallel4344 if C gets type annotations, void pointers could work as good as templates
@UCU3SuQ4YhUIdqg2CyTtcXQw ehhh don't get me wrong, they're convenient but they're also a crutch if you think about it. C++ also has metaprogramming but look at the insanity of its standard library because of it.
Rust & C++ have to use metaprogramming because of their own constraints to achieve the same thing C can achieve in a "dangerous" way.
Realistically, perhaps C will have a sane and more simplified way of doing metaprogramming in the future but gotta wait for a maintainable implementation. For the moment, metaprogramming in C and Golang is simply generating code to be compiled later on.
@@kevinyonan9666 It's not about restraints, it's about doing work at compile time and in an abstracted way. Rust does it especially well, you can implement meta languages for compiler grammar rules as an example! It also has compiletime filesystem inclusion, etc. Trust me, I know how much of a mess the STL is - I myself am a Microsoft STL contributor, but Rust does it much better with a model which is older than C!
@@parallel4344 Microsoft? That explains everything. Windows has the shittiest C support out of the major OSs.
MSVC is still missing alot of C99 and C17 features. Yea GCC and Clang aren't 100% C99 compliant but they support alot more of it compared to MSVC.
Ofc instead of finishing the job, Microsoft opts to yet again switch to another language with this time being Rust, because apparently the C++, C# hybridization didn't work out too well...
Here's a good question, C also has the potential to have metaprogramming (outside the preprocessor) but the thing with C and what makes it special is that whenever you come across a problem, the solution is typically writing more C as opposed to "we need a new feature"
I've been writing C for 7 years, so far all I'd like for C is the defer statement from Golang, function literals so that I don't need to always define a static function, and type annotation so that compilers can have the potential to optimize void pointers as good as type parameterized generics.
A tutorial about debugging stm32s with probe-rs instead of GDB would be sweet as I couldn't find a good learning resource for embedded-rust-newbs for this. Anyways, keep up the good work!
You seem to argue that C’s age alone is a bad thing. I think that’s a weak foundation for an argument. Rust is great. But is it better for a application in production to rely on a language that has stood the test of time or shiny new one with a short history?
For a very wide range of applications, I would definitely trust a Rust codebase over a C codebase at this point. Plenty of things that used to be done in C are now done in other languages, and Rust while not the end of C is yet another option that eliminates more of the niches where C used to make sense, though it has more overlap with C++ usecases than with C's usecases.
Rust is the future of iron, as Being an old man is the future of a young boy
ok so kind of interestingly i started with rust and now ended up loving C and kind of hating rust
Everything I've seen so far says rust is amazing. No one seems to mention any cons, which is suspicious. No language is perfect.
So basically instead of learning how to correctly work with memory we want knee pads
No, instead of unknowingly breaking memory rules rust warns you at compile time. It tells you what you are doing wrong and why with the option to use unsafe if you truly need it.
I learned c++ but I think it's similar to c anyway. A great language.
I don't think so. C is right now the universal language for embedded systems because it's very simple, fast and it have a small footprint
It's fast, but Rust can be as fast. Rust with #[no_std] (not linking standard library) is about as small too. C is faster and smaller only when there's not enough runtime checks to make the code actually robust IME.
@@louiscloete3307 "just as good" complete bullshit. dont post stuff like this
@Jamie Walkerdine entirely false! and spoken like a true windows user!
in unsafe mode, can you divide by zero to crash the code?
You can divide by zero in safe code. It will cause a panic (roughly similar to C++ exceptions except it is conventionally used for unrecoverable errors), which is classified as "safe" so the unsafe keyword is not needed. (Unsafe division by zero would be relying on the processor's behavior which would cause a SIGFPE or something.) Alternatively, you can use x.checked_div(y) and handle the error case yourself.
Rust is yet another new shiny thing. Techies love new shiny tech. It is exciting. It has possibilities. It is something new to explore. It is like Christmas morning. Yet, most of the new, shiny tech of just a few years ago has been replaced by yet another new and shiny thing. Rust has yet to stand the test of time. I’ll sit back and watch rather than run after every new and shiny thing. New is not necessarily better. Enjoy playing with your new toy. Have fun!
Totally agree! I'm trying to learn C++ using Stroustrup's latest book, and am frustrated by some things: #1 not able to find ANY reasonable explanation on line as to why I MUST learn pointers and passing by reference, especially in OOP, and #2 I wanted to make 2D games and can't seem to find a gui library anywhere that's easy to install and set up on Windows 10 to work with Visual Studio 2022 Community Edition. So I'm tempted to run for the hills, an area known as "come over here and try THIS shiny, new toy where you MIGHT stay for awhile until something ELSE gets in your way" :D
Write in C, write in C, write in C, write in C...
malloc, free and segfault - write in C!