6 ms·
As someone with experience only in Python, is Rust a decent place for me to learn lower-level concepts or should I go with C/C++?
by whonut 11y ago
As someone with experience only in Python, is Rust a decent place for me to learn lower-level concepts or should I go with C/C++?
- steveklabnik 11y agoThis is a very common question, and there's two camps: 1. Learn C, then learn some C++. You won't appreciate Rust until you've felt the pain that it solves. 2. Learn Rust. Why bother going through all that trouble on your own when you can have the compiler help guide you. and a third position: 3. Rust is still new enough that you'll find way more information with C, so you should just learn that even if Rust is better in a vacuum. Learning is easier with copious help and tutorials. I personally fall in camp 2, and sometimes 3.
- Dewie3 11y agoRE: 1) : Smart people learn from their mistakes. But the real sharp ones learn from the mistakes of others.
- whonut 11y agoThanks for the reply. I'm leaning towards Rust. I'm required to learn C for university next year (I do physics) so I'm going to have to go through the pain anyway. There's also the quwation of usage in physics circles. It'll probably come down to the material I'm trying to learn each with. The Rust book looks very good, finding anything decent and modernish for C has been a nightmare.
- barosl 11y agoThis is a nice summary! FWIW I'm more likely 1, as I've seen many people coming from dynamic languages being frustrated about the "Rust way". Not only the ownership model, but also compiling, optimization, etc. 3 is certainly a problem, but personally I found enough materials to learn Rust even for now. However more "friendly" resources would be definitely welcome.
- Jweb_Guru 11y ago> but also compiling, optimization, etc. These are going to be the same in C anyway so I wouldn't decide whether to learn Rust or C based on that.
- e12e 11y agoWhile I'm new to rust, and have just been dabbling in C -- as another comment mentions here: you really have to deal with the borrowing in C as well (and the compiling/optimization). If you don't deal with in C (without any real language support) -- you'll get bugs. If you're very lucky, and made a great effort in turning on warnings[1] -- you'll be aware of those bugs. Most likely you won't. [1] See eg: https://github.com/incrediblesound/Graph-Reply/commit/929e5733caf02ff1873e59add4b4834555dcfbfa https://github.com/incrediblesound/Graph-Reply/commit/929e57... for a little bit about C and warnings.
- mparr4 11y agoI'm in the same boat as you. I've been working through Learn C The Hard Way [1] as a way to learn some of these concepts. I've been finding it incredibly valuable/rewarding. That said, even the author of LCTHW (Zed Shaw) recommends writing in languages other than C. He specifically mentions Go, Swift, and Rust. Check out his rant on K&R C at the end of LCTHW for his thoughts on your question: http://c.learncodethehardway.org/book/krcritique.html http://c.learncodethehardway.org/book/krcritique.html [1]: http://c.learncodethehardway.org/book/ http://c.learncodethehardway.org/book/
- castell 11y agoWeird rant. C is not dead, especially not for really low level high performance things. But Go/Rust/Swift are more modern and easier to use for some of C and many of C++ use cases.
- e12e 11y agoYou already have a lot of good answers, here's some more: C and C++ really isn't the same thing. Certainly not "modern" C++. Unless you know of any C++ projects/frameworks/libraries you really want to use/contribute to -- I don't think I would recommend looking to hard at C++. It certainly isn't a dead language, and has many uses -- but at least outside of the gaming industry, I can't think of any segment were C++ would be the preferred language -- except when dealing with legacy code (which of course, realistically is the biggest segment...). Perhaps C++ paired with qt for GUI programming. But even for games, you don't need C++ -- if you are free to start from scratch anything will work. > is Rust a decent place for me to learn lower-level concepts Which lower level concepts? C maps quite neatly to assembler -- but to appreciate that I'd recommend learning a bit of assembler. amd64 with nasm/intel syntax is rather pleasant[1]. It'll let you see what calling conventions/ffi, data layout and the difference between c-strings and pascal strings are all about. If you take a canonical hello-world from C, C++ and rust and look at the generated assembly -- rust and c++ will be (IMNHO) closer to each other than to C. The assembler generated by the c-compiler will be straight forward, and quite readable -- while both C++ and rust will look a little more convoluted. (This is also true for Nim, which compiles to C -- but needs it's own runtime. I've not looked too hard at code generated by go -- but given the runtime, I think that assembly would also be much more difficult to make heads and tails of, than something output by a C compiler). If your goal is more to learn a low-overhead compiled language, I would recommend rust. If your goal is to find a compiled language that is easy to integrate with others, I think I would recommend C (for now) -- and a bit of basic assembler. I think after learning a bit of assembler and C -- one also gets a better appreciation for why Pascal was so popular for a while. With any luck, and more work -- hopefully rust will be able to sneak into quite a few of Cs use-cases, like writing libraries for easy consuption by python/ruby/etc. But I don't think rust is quite at a place where it makes sense to reccomend it for that use-case to a novice (low-level) programmer. I'd love to be wrong about that. [1] Unfortunately, I don't really know of any good introductions to amd64 assembly. There are a couple of great tutorials for 32bit/x86 -- but a lot of things are simpler in our amd64 world. While it might be good to know how to write bootloaders (16bit) and 32bit code -- I'd love for there to be a simple tutorial focused on just amd64. I like this asm tutorial (unfortunately for 32-bit): http://www.drpaulcarter.com/pcasm/ http://www.drpaulcarter.com/pcasm/ And "HLA" is another great resource for 32-bit assembler: http://www.plantation-productions.com/Webster/www.artofasm.com/index.html http://www.plantation-productions.com/Webster/www.artofasm.c... Sadly, neither have been ported/updated to a version with a focus on amd64 only. Intel has an ok overview article focused on 64-bit: https://software.intel.com/en-us/articles/introduction-to-x64-assembly https://software.intel.com/en-us/articles/introduction-to-x6...