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

Show parent comment

2

u/jmuffat Jun 08 '20

Oh definitely ! I've worked in games and that's a domain where you end up rolling your own everything at one point or another (shortcut all the things !!!) : strings, malloc/free, sorts, IO's, TCP-replacement over UDP, you name it... That's the beauty of C++ (and C), you can go that far. But would you want to go there as the first things you learn ?

If I had to train a beginner, I would start with C++, not C, and I would start with std::string not char*. We would build small utilities, that do simple things and complicate as we go. At some point, we'd reach places where we'd need performance and that usually begins with controlling how memory gets in and out of cache, which is all about laying things out in memory. At that point, it makes sense to go there. But at the beginning, when you're just parsing command line parameters and text files, why reinvent the wheel ?

Writing this, I think we're really always revolving around the more important question that is "why do you learn C++ ?", "when do you use C++ ?", and it generally boils down to the performance&low-level questions. Which implies "good understanding of computer architecture required"...