HACKER Q&A
📣 Forgret

Which is better in your opinion: C or C++.Justify your answer?


Which is better in your opinion: C or C++.Justify your answer?


  👤 ankurdhama Accepted Answer ✓
Given the choice between these I will probably pick C++ because of its feature that allows creation of higher level of abstractions. Abstractions are not just about "nice code", they are more about helping you think through complex problem.

👤 RS-232
You would reach for one or the other depending on what you’re trying to do. They excel at different things.

C: language interop/FFI

C++: systems programming

But if you HAD to pick one, it has to be C for ubiquity.


👤 aarkaay
C for more control, C++ for easier coding. Depends totally on use case. In some cases, where speed matters, C is KING.

👤 incomingpain
When I coded in C++, it was nearly indistinguishable from C. I didnt use any of the ++ benefits.

Now that I have many many years of experience, would I code more in C++? Lol no, you couldnt pay me enough $ to code in C or C++.


👤 drweevil
In my programming career I mainly used both C and C++ on DOS/Windows, SunOS, and Linux (with a side of Pascal and Python). Mostly C++ though.

C: Pre C++, C was it. (It was Borland's excellent Turbo C that got me going in C.) After C++ became available C was still what one used for device drivers and other system-level modules, and was the choice for FFI interfacing for languages such as Python.

C++: for userland layers of instrument control systems, user programs, GUIs, etc.

C++ offers a few very important advantages:

  * Its object system allows for better abstraction facilities. For example, smart pointers were very useful in mitigating memory leaks. (I even wrote a smart pointer that--under a generalized pointer interface--specialized in allocating and managing DOS extended memory. Remember that shit? Doing the same in C was a PITA.)

  * Later, template metaprogramming took this to a new level. Though C++ metaprogramming is not nearly as flexible as the ones in Lisps, it is still tremendously useful.

  * The STL arose from both of these features, and provides a rich set of abstractions: queues, maps, trees, etc.
People did tend to overuse the OOP facilities (everything is an object!) but it's hard to overstate how useful OOP and metaprogramming can be. Use C++ unless there is a good reason to use C.