r/cpp • • Jun 08 '20

Programming in C vs C++

I’ve read about the differences between them on the Internet but I wanna hear more from a more personal perspective. Which one would you recommend starting with and to be proficient with?

0 Upvotes

43 comments sorted by

View all comments

8

u/jmuffat Jun 08 '20

There is no reason to start with C.

I learned C++ in the late 80’s, starting with the book « C++ for C programmers » by Ira Pohl. I went from BASIC, to Pascal, to C, to C++ as the PC grew in performance, that was the usual path in those days. But it took me years to realize C++ wasn’t C. At all. It is a very different state of mind, so if you learn C to learn C++, you’ll have to unlearn a lot of things later on. I sure did have to unlearn a lot !

Just start with C++, embrace RAII as a foundation rather than some late realization, think of C++ as a language in itself without trying to trace things back to C. As far as I know, C++ doesn’t emerge from C, C++ used C as a foundation mainly because it was there... (caricaturing)

0

u/[deleted] Jun 09 '20

[deleted]

2

u/bikki420 Jun 09 '20

^ this. It's simple and you learn the fundamentals for looping, conditional branching, functions, the primitive data types, memory management (pointers, references, dynamic allocation on the heap, deallocation etc) and more. Some of which you'll avoid most of the time (e.g. manual (de)allocation, raw owning pointers etc), but are still very important to have a decent grasp on. Then when one moves to C++ one can appreciate all the nice quality of life stuff like destructors, RAII, smart pointers, value semantics, ADT classes, C++ strings, destructors, templates, aliases, namespaces, and what have you.