17 ms·
Having recently learned C++/C.. I don't see why it would be taught as a first language outside of specializations. The gains from C/C++ coding are vastly outwei
by lumost 4y ago
Having recently learned C++/C.. I don't see why it would be taught as a first language outside of specializations. The gains from C/C++ coding are vastly outweighed by the costs. The reality is that there is no good, agreed upon standard in C++ for how to manage memory... how would you teach this to junior engineers at university?
- insanitybit 4y agoHaving 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 ago
- soinus 4y agoBut there is! Use local variables and value semantics. Use references to borrow stuff. Never touch new or delete. Use smart pointers when need an owning pointer (rare). Anything beyond that: ask next in seniority to supervise. That should be enough to live a happy C++ life for a junior.
- gridspy 4y agoAh, I think the parent was referring to C++ circa 1990 to 2010 - prior to the much more happy modern world with standard smart pointers.
- UltraViolence 4y agonew / delete?
- bodhiandphysics 4y agoI use malloc more often than I use new and delete!!!
- P5fRxh5kUvp2th 4y agoI learned programming in the 90's using C++. When someone expresses this intent I always ask the same question. Am I a supergenius or are you mistaken?
- lumost 4y agoOne could learn in C++ using a variety of methods… including the ignore memory management variety. The question is why? For a student learning dfs for the first time or hash tables/queues etc. python will be much easier to learn. Java/rust/go will likewise be easier if you want to talk about types.
- hedora 4y agoJava and Python's notions of type safety are completely brain damaged. I can't imagine how things would have gone if I'd learnt them as first languages. Rust, C and C++ get that better, in my opinion (you have to consciously choose to write type safe code in two of those languages, but at least it is possible in all three). Go's thread safety is way behind Rust's. meh.
- P5fRxh5kUvp2th 4y agoI would argue C++ type system is superior to even C# and I'm a huge fan of C#. But more to the point, people claim it's somehow harder in C++ to learn programming so either I'm super smart or they're wrong.
- gridspy 4y agoThe C# standard library is more consistent and powerful (batteries included, more modern). That means there is a "standard, correct" way to do most things in C# in a multi-platform way. C/C++ has massive variety here. Memory management is trivial in C#. So yeah, C# is easier to learn. Perhaps you're super smart?
- 4y ago
- WhiteDawn 4y agoI'm always conflicted with this. My gut says any new student should start with an interpreted language like Python or JS/TypeScript. As that gets you to running code, and core concepts like variables, loops and if statements in little to no time. However, there is value in learning some of the under the hood concepts such as pointers, structs, memory layout, endianess, pass by reference, compilers etc. I don't think schools need to teach employable C/C++ skills, but C/C++ is a great language to play with and experience these core concepts. However I'm not sure if the value in learning these concepts are real, or it's just my own interests/nostalgia. You can have a successful career in this industry without having to manage a single byte of memory, and it arguably makes sense to accept abstractions at their face value so you can focus on what builds your skills/product.
- mywittyname 4y ago> pointers, structs, memory layout, endianess, pass by reference, compilers etc. C++ is a bad language to teach any of these concepts. Sure, people will be exposed to the concepts, but they are presented in a rather esoteric fashion. Not to mention, actually leveraging those concepts in is bad practice anymore, i.e., using a pointer arithmetic to loop over arrays instead of iterators or the like. I didn't grok a lot of those concepts until I took computer architecture, which was taught in assembly language. And we weren't taught x86, but a toy assembly language designed for teaching. Another big pain point I had in school is that every professor / TA had different opinions on what was a right and wrong way of doing things in C++. And sometimes their opinions would conflict with the damn documentation too. There's nothing like having to relearn core language concepts every year at the whims of professors. This is probably where most of my disdain for the language has come from.
- zabzonk 4y agothe chance of you being taught correctly by your so-called "professors" (they are not professors unless they have been appointed to a chair) is vanishingly remote, but this has zero to do with the language
- kingaillas 4y ago
- __turbobrew__ 4y agoI definitely would not advocate teaching students C++. C on the other hand is a relatively compact language and is the lingua franca of operating systems and shared libraries.
- ngngngng 4y agoMy recent hot take is that students should never learn on a language older than they are. There are so many options, why did I have to battle linker errors in my intro to CS class with C++? Nothing we were doing required C++.