4 ms·
Ask HN: Which is better in your opinion: C or C++.Justify your answer?
- RS-232 1y agoYou 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.
- ankurdhama 1y agoGiven 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.
- Forgret 1y agoI will choose C for one simple reason: less unnecessary overhead. In C++, a lot of additional stuff can be added to the binary after compilation, which makes it harder to fully control. With C, I get a clean binary right away, and that’s what I prefer.
- incomingpain 1y agoWhen I coded in C++, it was nearly indistinguishable from C. I didnt use any of the ++ benefits.
- aarkaay 1y agoC for more control, C++ for easier coding. Depends totally on use case. In some cases, where speed matters, C is KING.
- drweevil 1y agoIn 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.