Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I default to C. It's fast, runs everywhere, works with everything, and has few surprises. It's standardized and not captured by any individual or organization.

I can't think of a language that comes close to any of that.



C++


> has few surprises

C++ has few surprises? This is from Scott Meyers, author of several books on the intricacies of C++:

> I no longer plan to update my books to fix technical errors.It's not that I'm too lazy to do it. It's that in order to fix errors, I have to be able to identify them. That's something I no longer trust myself to do.

He then goes on to explain how the language is so complex, that in two years he has already forgotten enough of the gotchas to trust himself. This is far short of a language with no surprises.

[0] https://scottmeyers.blogspot.com/2018/09/the-errata-evaluati...


You will be surprised with the surprises hidding in C code.

When the choice comes down to C vs C++, the only possible answer is C++ when safety matters.

If more languages are allowed into the decision pool, then both of them should be avoided.


I write in C only when I need to; in my case I have a limited runtime environment available, so I can't use some other language (which I might otherwise prefer) with a larger runtime requirement, and I also already know C, but not C++. Also, none of the libraries I have to use have C++ APIs. Had I already known C++, and if there were C++ APIs available for the libraries I need, then sure, I might have used C++, but as it is, the results (a C++ program but full of C-style programming because of the APIs) would not be worth the effort of learning C++. C++ also imposes a cost; that of reducing possible contributors to those people who already know C++ – knowledge of C is simply more common than C++.

A C++ program which calls nothing but C libraries will not have the “shape” of a C++ program, but essentially the shape and structure of a regular C program. And the small pieces that remain C++-shaped might not be large enough or provide enough architectural benefit for the drawbacks of C++ to be worth it.

(Paraphrased from this thread: https://news.ycombinator.com/item?id=20849570)


C++ provides lots of safety knobs over raw C, without having to go crazy with language features.


If C++ had no operator overloading, and if it had no exceptions, and if the C++ standard specified name-mangling so FFI could work right, then maybe it would come close.


You are not obliged to use all of that in C++ code.

And if lack of standard specified name-mangling disqualifies C++, so it also does to C, because there is no such thing as a C ABI, only OS ABIs that happen to be written in C, and the C compilers of the platform follow the OS ABI, which you can get in C++ with extern "C".


>which you can get in C++ with extern "C".

True, but then you add translation layers everywhere because you used C++ in your function interface.


Are you aware that GCC, clang and MSVC C standard library is actually written in C++?


C++ compilers let you disable exceptions. I always do this when possible.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: