4 ms·
Having learned C/C++ as my first languages I can say I'm quite glad for it. I was able to learn so fucking much. 1. Object oriented programming, complete with
by insanitybit 4y ago
Having learned C/C++ as my first languages I can say I'm quite glad for it. I was able to learn so fucking much.
1. Object oriented programming, complete with inheritance and virtual dispatch
2. Pure Functional Programming, lambdas, const correctness, template metaprogramming
3. Type system fuckery - the things you can do in C++'s TMP is insane. Both nominal and duck typing in the language.
4. Hardware - I watched so many talks on how CPUs work that explained things via C/C++. I learned about tools like valgrind and cachegrind, how to profile code, etc.
5. Security - The original reason I wanted to learn them, to understand how to exploit C and C++ programs and their common vulnerabilities
6. Data structures - C++ is awesome for building data structures from scratch and understanding their low level semantics
I don't want to write them professionally, but learning them was massively helpful, with skills propagating through every other language I've used.
- magicloop 4y agoI'm glad someone pointed out these things, as I concur. I learnt C++ via the C++ programming language book, and it gave me many of the above benefits/insights. (The book has its faults though). It is akin to trawling through the CLRS book. It does make you a better programmer but no-one knows why. (An attempt at sarcasm - I know most of us never need to do advanced data structures/algorithms but it helps refine the mind for programming challenges).
- gridspy 4y ago7. Fundimental underpinnings - Every other language is written essentially in C - you can often understand how their features WORK if you know C extremely well. ... I'd argue that 1,2 are covered by rust. 3 and 6 by unsafe rust. Once you have that, a transition to pure C for the full 7 makes sense, and would be trivial for a rust dev.
- insanitybit 4y agoI'm fairly proficient in Rust and I think it has its own strengths for learning, but its own downsides too. Pros: 1. Way easier to get "live" help, I've found the barrier to ask for Rust help is lower than any other language I've ever used (and I've used a lot) 2. Way easier tooling like cargo, error messages are far better, especially with regards to generics vs templates 3. Some things are more explicit in Rust. Like `Box<dyn Trait>` is very explicit about dynamic dispatch, I don't recall that being the case in C++. Cons: 1. Rust's "codex" of knowledge is nowhere near C++. There are tons of conference talks, books, blog posts, etc on C++. Not just on C++ but also on hardware as seen through C++, security, etc. 2. Implementing low level data structures in Rust is an advanced practice. Implementing them in C++ is trivial. I get that it's trivial because C++ doesn't give a fuck about your pointers, but if you're just trying to learn data structures you really just need to be focusing on happy paths and whatnot (as a student). So idk, at this point I tend to recommend Rust, but I also end up having to link people to talks on C++ sometimes! Herb Sutter and Scott Meyer are amazing speakers and writers and that's a very hard thing to replace.
- gridspy 4y agoAn accurate summary. I was reflecting exactly your cons when I left gaps in what I said Rust was good for. Con (1) (Existing examples / training) is a legacy language strength in general, C++ is going to lead in this for a long time. Con (2) (Low level data structures) I 100% agree. A toy example of a datastructure in C++ is going to be really easy to express but also dangerous to use. I think you'd really enjoy this chapter of the Rust Docs on making your own Vec https://doc.rust-lang.org/nomicon/vec/vec.html https://doc.rust-lang.org/nomicon/vec/vec.html And you are correct (Con 2 again), it IS an advanced practice. The result of making a data-stucture the rust way is a bulletproof class anyone can use, rather than a C++ foot-gun so it's worth the effort (but less so for learning). You might find you can make your whole module unsafe and write a very similar data-structure in rust to your C++ solution (pointers and all) and it would compile and run fine.
- lumost 4y agoThe big thing to know about rust datastructures is that you need to use unsafe to implement anything cyclic. There is nothing wrong with using unsafe for a few lines of code - just review carefully.