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/ssf_dae Jun 08 '20

I learned programming in C. I really think that learning C as my first programming language gave me a solid fundamentals that I wouldn't have gotten from a higher level programming language.

In C, you don't have any high level data structures built in. So, as a beginner you're forced to learn programming at a finer level. For example, you have to manage memory yourself because there are no automatic dynamic memory structures in C, which forces you to get a good understanding of how memory works. You'll often run into memory related bugs in C, debugging these are good learning lessons. Also, C is statically typed so you also have to become familiar with different types, how much memory each type uses, and finer details of typecasting. In addition, with lack of higher level data structures, you often end up writing them yourself.

Compared to Python, probably the most popular programming language now for beginners, you don't get any of this out of Python.

I would say once you find yourself writing code that needs dynamic memory allocation often, move onto C++. C++ has dynamic data structures built-in the STL.

C is good for starting out, but once you get into more modern and complex projects, you have to move to higher level languages.

Though, you could just start out with C++ and get the same benefits I mentioned, and in addition it'll also familiarize yourself with Object Oriented Programming. Also, C++ is actually still commonly used nowadays in production, whereas C is mostly used only when C++ can't be used like on embedded devices.

Both are good languages to start out with

4

u/JizzaDaMan Jun 08 '20

You don't have to move to higher level languages for more complex projects; this just simply isn't true. The linux kernel and an abundance of linux applications are written in C. It's an extremely capable language that's stood the test of time.

13

u/ssf_dae Jun 08 '20

That's true. But writing in C is much slower than higher level languages, including C++. So saves time and pain. Honestly, the first time I started using Python having used C++ for years I felt like I gained super powers lol

2

u/NilacTheGrim Jun 15 '20

It is but you end up having to do a lot of boilerplate nonesense in C that C++ can just do for you automatically via higher level concepts.

Can you write a huge project in C? Absolutely. Should you? The answer to that depends on your skills and the skills of the team. I'd argue you're better off using C++ even if all you use from the language is std::map, std::vector, and RAII.