How does C compare to Rust? I’ve heard you can learn the syntax in a weekend, but you spend years trying to master it because of all the memory leaks and such that it leads to. Would you say that’s accurate?
Python is like your automatic transmission. It handles a lot of work on the backend to make life easier, but the trade off is performance and control.
In C/C++, you’re reaching into the gearbox and moving it by hand. It doesn’t clean up anything for you and doesn’t prevent you from making dumb mistakes. In exchange, it can be wildly faster than Python.
In Assembly/Binary, you’re crafting the gears before you can even start the car.
@[email protected] wrote “Assembly/Binary”, because an Assembly language is basically just a list of aliases (or mnemonics) for the different combinations of 0s and 1s.
For example, HLT (Halt) may translate to 00000001, which is then already what your CPU understands.
Rust is close to C++, in that you get a lot of high level constructs to help you. C is very low level, and you can learn the syntax in a weekend, but you’ll also have to learn memory management and implement advanced structures (linked lists, etc) yourself.
Memory management isn’t too hard, it’s mostly remembering who created what, who reads and writes to it, and who is responsible for cleaning up. With some additional comments as you go it’s not too hard.
Also, depending on what your doing, leaks may be acceptable. A short lived program can leak all it likes, and the OS will clean up for you ibthe end :D
So C is basically assembly with a bunch of syntactic sugar on top. It manages a lot of the book keeping and boilerplate, but at the end of the day there’s not a ton of difference between them in terms of the abstractions it provides. If you know assembly learning C is a piece of cake. If you don’t you’re probably going to take a while to really wrap your head around pointers and the myriad ways C can use them for great and terrible things. Beyond pointers (and race conditions if you’re crazy enough to do multithreading in C) the rest of C is super easy because there really isn’t much else there.
Rust on the other hand is a much higher level language more comparable to something like Java, C++, or Python. It gives you a lot of tools to solve complicated problems but unlike Java and Python and like C++ it still gives you the option of working at a low level when you need to. The big advantage it has over C++ is that it learned from the many mistakes C++ made over the years, and the borrow checker really is a unique and powerful solution to both memory management but also crucially concurrency problems.
No, for a good modern C alternative I’d look at Zig. The main reason C is used for the Linux kernel is because Linus hates C++ for a variety of reasons. For what it’s worth I agree with him. Most other OS kernels are written in C++. Linus allowed Rust in because it demonstrated that it could provide the same power as C++ without all of C++'s problems (mostly that over the years it became a kitchen sink language, anything that anyone ever thought might be a good idea got rolled in even when it was incompatible with some other feature already in the language).
Thanks for the suggestion. How does Zig compare to C safety wise? One of my main reasons for going for Rust was because I was looking for something like C but safer
It’s a bit safer and a lot more convenient to use, but still lets you do dangerous things with pointers. At its core it’s still fundamentally the same as C just with a bunch of helpful tools and features to make doing all the stuff you do in C easier and more convenient.
Really the biggest thing it does significantly better than C is its macro system. C macros are “dumb” in that the C pre-processor does a simple find and replace on the source files without doing any kind of processing on the underlying C code so you can E.G. write C macros that spit out mangled illegal C code when you run them. Likewise a C #include is literally the same thing as copy and pasting the contents of the included file before it gets fed into the compiler.
Zig on the other hand has a smart macro system that’s actually aware of the zig code and works in concert with it at compile time.
Somewhat. The issue isn’t memory leaks themselves so much as learning project architecture, patterns, and generally how to do things without shooting yourself in the foot.
Rust has plenty of gotchas and unintuitive elements, so they’re not too different in that sense. Though Rust is more likely to point out when you’ve done something wrong, where as C will exercise your debugging skills.
Modern C++ is also an option, and surprisingly easy to use. The only catch is that the errors can be very difficult to parse and it’s hard to find modern best-practice materials to learn from since most of industry is quite far behind compared to where the language is.
One benefit Rust has is that it’s quite new and niche, so the materials tend to be of fresh, without much legacy mindset, and of a relatively high quality. Tbh I’m not sure how Rust is for newbies, but it may be worth a shot. At the very least, the community is passionate and the errors will be readable…
generally how to do things without shooting yourself in the foot
In programming, as in life, this is key.
To your point, I have found the error messages and the documentation for Rust to be super helpful and easy to read. As a newbie it is straightforward enough, but it’s really an endurance game, because I think unlike other languages you need to cross a critical threshold before you can really understand the language well enough to use it even for simple tasks
C and assembly if you like learning how computers work
Python and typescript if you want to make blinky lights
How does C compare to Rust? I’ve heard you can learn the syntax in a weekend, but you spend years trying to master it because of all the memory leaks and such that it leads to. Would you say that’s accurate?
Python is like your automatic transmission. It handles a lot of work on the backend to make life easier, but the trade off is performance and control.
In C/C++, you’re reaching into the gearbox and moving it by hand. It doesn’t clean up anything for you and doesn’t prevent you from making dumb mistakes. In exchange, it can be wildly faster than Python.
In Assembly/Binary, you’re crafting the gears before you can even start the car.
Man people actually code in binary? That’s hardcore
They don’t type out the 0s and 1s, no. 😅
@[email protected] wrote “Assembly/Binary”, because an Assembly language is basically just a list of aliases (or mnemonics) for the different combinations of 0s and 1s.
For example,
HLT(Halt) may translate to00000001, which is then already what your CPU understands.In practice, these lists for the different Assembly languages will look like this: https://en.wikipedia.org/wiki/Opcode#Sample_opcode_table
Ah I see. That’s interesting thank you.
My favourite childhood game RCT2 was a masterpiece of assembly: https://youtu.be/ESGHKtrlMzs
It’s crazy to me that someone actually took the time to write a whole game in assembly. The skill required to do that is remarkable
Rust is close to C++, in that you get a lot of high level constructs to help you. C is very low level, and you can learn the syntax in a weekend, but you’ll also have to learn memory management and implement advanced structures (linked lists, etc) yourself.
Memory management isn’t too hard, it’s mostly remembering who created what, who reads and writes to it, and who is responsible for cleaning up. With some additional comments as you go it’s not too hard. Also, depending on what your doing, leaks may be acceptable. A short lived program can leak all it likes, and the OS will clean up for you ibthe end :D
Good to know, thank you for your input
So C is basically assembly with a bunch of syntactic sugar on top. It manages a lot of the book keeping and boilerplate, but at the end of the day there’s not a ton of difference between them in terms of the abstractions it provides. If you know assembly learning C is a piece of cake. If you don’t you’re probably going to take a while to really wrap your head around pointers and the myriad ways C can use them for great and terrible things. Beyond pointers (and race conditions if you’re crazy enough to do multithreading in C) the rest of C is super easy because there really isn’t much else there.
Rust on the other hand is a much higher level language more comparable to something like Java, C++, or Python. It gives you a lot of tools to solve complicated problems but unlike Java and Python and like C++ it still gives you the option of working at a low level when you need to. The big advantage it has over C++ is that it learned from the many mistakes C++ made over the years, and the borrow checker really is a unique and powerful solution to both memory management but also crucially concurrency problems.
Interesting. I always assumed that Rust would be more similar to C since they are now using Rust in the linux kernel
No, for a good modern C alternative I’d look at Zig. The main reason C is used for the Linux kernel is because Linus hates C++ for a variety of reasons. For what it’s worth I agree with him. Most other OS kernels are written in C++. Linus allowed Rust in because it demonstrated that it could provide the same power as C++ without all of C++'s problems (mostly that over the years it became a kitchen sink language, anything that anyone ever thought might be a good idea got rolled in even when it was incompatible with some other feature already in the language).
Thanks for the suggestion. How does Zig compare to C safety wise? One of my main reasons for going for Rust was because I was looking for something like C but safer
It’s a bit safer and a lot more convenient to use, but still lets you do dangerous things with pointers. At its core it’s still fundamentally the same as C just with a bunch of helpful tools and features to make doing all the stuff you do in C easier and more convenient.
Really the biggest thing it does significantly better than C is its macro system. C macros are “dumb” in that the C pre-processor does a simple find and replace on the source files without doing any kind of processing on the underlying C code so you can E.G. write C macros that spit out mangled illegal C code when you run them. Likewise a C
#includeis literally the same thing as copy and pasting the contents of the included file before it gets fed into the compiler.Zig on the other hand has a smart macro system that’s actually aware of the zig code and works in concert with it at compile time.
Somewhat. The issue isn’t memory leaks themselves so much as learning project architecture, patterns, and generally how to do things without shooting yourself in the foot.
Rust has plenty of gotchas and unintuitive elements, so they’re not too different in that sense. Though Rust is more likely to point out when you’ve done something wrong, where as C will exercise your debugging skills.
Modern C++ is also an option, and surprisingly easy to use. The only catch is that the errors can be very difficult to parse and it’s hard to find modern best-practice materials to learn from since most of industry is quite far behind compared to where the language is.
One benefit Rust has is that it’s quite new and niche, so the materials tend to be of fresh, without much legacy mindset, and of a relatively high quality. Tbh I’m not sure how Rust is for newbies, but it may be worth a shot. At the very least, the community is passionate and the errors will be readable…
In programming, as in life, this is key.
To your point, I have found the error messages and the documentation for Rust to be super helpful and easy to read. As a newbie it is straightforward enough, but it’s really an endurance game, because I think unlike other languages you need to cross a critical threshold before you can really understand the language well enough to use it even for simple tasks