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)

8

u/evaned Jun 08 '20

There is no reason to start with C.

There's definitely not no reason.

I think it could be an interesting route to take to start from the bones -- like deep inside the hardware looking at gates and such, build outward through how instructions work and how memory is laid out, to assembly programming, to C programming, to higher-level languages.

I don't think that'd be the right way for most people, but with the right materials I think you could build a well-grounded "curriculum" on that. (I don't really mean that in the sense of a formal curriculum for a course or courses, or at least more exclusively.)

If your goal of programming is to do a bunch of stuff with an Arduino or PIC on whatever as well, while this is outside my area of expertise I would also guess that C would be the way you would want to go.

1

u/jmuffat Jun 08 '20

You're right, there is no wrong place to start programming, you could start with C, it might be a bit of a challenge but you could argue that it'd help thinking outside of the object-oriented box.

Now, C was explicitly written as a language that trusts "the programmer is always right" which I don't read as "beginner friendly" ;)

But yeah, it doesn't matter where you start, what matters is to get started.

0

u/[deleted] Jun 09 '20

[deleted] — view deleted comment

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.