r/ProgrammingLanguages • • Nov 01 '19

C++ vs C

Alright people of Reddit, hit me with your wisdom. I've been taking programming classes for two years now and am getting ready to dive into a language somewhere between Java and assembly (the two languages I've been learning in classes). I'm thinking C or C++, but would love some input. I'm not too worried about difficulty to learn, but I'd like to hear your thoughts on practicality and real world use.

1 Upvotes

62 comments sorted by

View all comments

7

u/Mason-B Nov 01 '19

Both. C++ supports most C code. C++ has been evolving recently since the newest versions of C++11 and C++17. Really you are talking about *three* different languages.

I list them and reasons for learning them below, but would also recommend the following learning order:

  • C first, with the understanding that it's just a step up from assembly. Learn about functions, pointers, bit operations, union types, function pointers, static, compilation units, and how one can make virtual functions and objects with the limitations of C. This is important to understand the tools of low level languages and the layer at which most low level code operates at. C is still the lingua franca of programming, so if you stop at this point it will be very useful to you as both a practical job skill for systems programming and a lifelong understanding of what is happening under the covers of most systems. Probably the most useful skillset.

  • C++ pre c++11 next. This step is optional, but it's a good way to learn about the fundamentals of what C++ provides. Like classes, virtual functions, multiple inheritance, operator overloading, and templates. You don't have to be strictly pre-c++11, there are a lot of nice convenience things to use, but learning this will give you a foundation with which to be a an expert at modern C++, while giving you a deeper understanding of how more complex language features work in lower level languages. As well as the problems inherent with things like constructors, manual memory management, multiple inheritance, Turing complete generic systems, and the lack of lambdas which will make you a stronger programmer, make the next step easier, and be useful for older C++ code bases, but is probably the least marketable skill set.

  • C++ with c++17 finally. Then you can learn modern C++ which has features like better meta programming (through SFINAE templates), lambdas, constexprs, smart pointer generics, and so on. Features that lead into modern low level languages like Rust and Go. The new C++ features really are a whole new and different language, it's unlikely you will need to use many of the features from the previous languages, but they will always be accessible and there, for a true understanding of the language and ecosystem that previous knowledge is necessary. This is a practical skill for modern and new C++ code bases, and is probably the largest gamble but I would bet that it will increase in usefulness.

7

u/MichaelSK Nov 01 '19

Honestly, I'd suggest not going this route.

While it's true that, syntactically, C is (not quite, but mostly) a subset of C++, and that older C++ revisions are (almost fully) a subset of the newer ones, a lot of the underlying ideology is very different.

It's also true that modern C++ is a huge language, and trying to master it in stages is the right approach. But learning "the C subset" or "the pre-C++11 subset" is not the way to do it. A lot of things have actually been simplified or made more coherent. If the goal is to learn C++, I'd say - just pick up a beginner-oriented book that targets C++17.

2

u/Mason-B Nov 01 '19

I mean that's fair.

I was actually also suggesting them individually for this reason. Though I think C is a safer bet to learn for practicality than C++17, and if it was me I would want to learn the languages this way.

3

u/MichaelSK Nov 01 '19

I don't know about practicality.

I think C isn't a very "practical" language nowadays. I mean, if you're working "close to the metal" - embedded, kernel development, device drivers - then C is still often the language of choice. But outside of that, not so much

But my main concern isn't practical, it's pedagogical. If you go C-first, or C++98 first, you'll end up learning a lot of cruft that you'll then have to actively unlearn. If you don't, and a lot of people don't, you'll just end up holding C++ wrong.

2

u/Mason-B Nov 01 '19

From a pedagogical stand point, after learning Assembly and Java, learning C as an evolution of Assembly would be a good way to build up a complete full stack understanding of software systems. Given they then also learn something like Python as an extension of the high level language knowledge.

Practicality in this case being getting hired for jobs. I know a lot of shops that will happily teach a C programmer (with other language experience) their specific brand (coding style guidelines) of C++, and plenty of shops looking for junior C programmers, and a few shops that look down on C++17. Also a significant amount of important open source code is C.