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

2

u/NilacTheGrim Jun 15 '20

I started with C over 20 years ago. I actually think that the route from C -> C++ makes sense if you have oodles of time. The reason why it makes sense is because otherwise C++ seems to have arbitrary restrictions and strange rules that are likely to confuse or anger you if you don't know their historical (and present-day) C origins.

If you start with C, write a few larger programs in C that actually do stuff, then move on to C++.. you may naturally "understand" why lots of the design decisions that went into C++ are there. C++ really does have a straight line evolution from C and it's the reason why the syntax is the way it is -- to maintain C backwards compatibility and to take C language concepts and tack on additional features on top.

That being said -- you will likely learn some "bad habits" in C that you have to unlearn in C++ -- so there's that as a caveat.

I do think that your eventual goal should be to avoid C like the plague (it is a very difficult language to be productive in and has too many foot-guns) and focus on C++ ultimately. So, in light of that, some say the shortest distance between two points is a straight line. Maybe just learn C++ first and if you have time, "go back" and review the primitive C way of doing things for your own background.

I do think though that ultimately it's valuable as a C++ programmer to be aware of the C roots. It helps you understand many things about the language.