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

I see one of the core reasons C is chosen over C++ is the speed of compilation. My question would be, to what extent is compilation speed relevant? What time differences are we talking about? I agree that every second counts, and I understand that fast compilation just feels good to work with for a hobby project, but what serious relevancy it has? At least the way I do it is divide program (a game for example) into several projects and compile them into dll's, this way compilation time is drastically reduced and with a side benefit of clear separation of different parts of the program.


C++ compile times are a huge problem for large projects (and painful even on medium projects). The Go designers joke that Go was conceived while waiting for a C++ compile. (Google engineers I know tell me their full C++ compile times can be measured in hours.) AAA game devs I've met tell me their C++ project times are usually 30 min to an hour.

On even the medium size projects I work on, the compile time difference between C and C++ can be magnitudes.

C++ encourages templates, which are typically included by everything, which in turn causes lots of files to need to be recompiled.

Both C/C++ have fragile ABIs so if you have built libraries and you change their memory layout, you need to recompile world. And in some cases, even if your library is internal and not external to your project, a bad build system or a bug can fail to detect this kind of change leading to subtle bugs/crashes, which then in turn encourages developers to do full rebuilds periodically.

It is hard to find real world data converting C++ to C to measure compile times because nobody wants to invest in rewrites like this. However, I am also among those people that have shifted back to pure C from C++ and seen compile times improve by magnitudes. I sometimes work on slow devices, like the Raspberry Pi, and this really magnifies the difference. (On this, the C parts can take 10-20 minutes, and the C++ parts are measured in many hours.)

This one person recently wrote about he switched back to C from C++. He mentions his build times went from about 10 minutes to 4 seconds.

http://chrismdp.com/2015/04/how-i-doubled-the-speed-of-my-ga...


Most C++ projects I have worked with, regardless of their size, had re-compilation times that routinely exceeded 20, sometimes 30 seconds. There are various reasons for this, among which uncontrolled use of templates and nested header inclusions where a forward declaration would have sufficed.

C, with its simpler grammar and the absence of template, tend to re-compile under 5seconds even for sizeable projects.


So, roughly speaking, you can expect for a difference in the order of tens of seconds. But my question was, how relevant is this? At least in my experience, and I have worked with projects that took up to 50 minutes to fully recompile (before we moved to newer ms compiler) when taking all dlls, the full recompilation is rarely required. Sometimes you have to recompile project, which can take minute or so, but most often you do incremental compilations that barely takes a second. So for me it's hard to imagine compile time having considerable impact on delivery. Most of the time is used while reading the code and thinking how to solve a problem, not typing the keyboard and waiting for compilation to finish. And I would argue that properly written C++ can greatly improve the biggest part of work - reading and understanding the code. I admit that properly written code is not a given etc., but for personal project you can write however you want. In the end it's probably more personal prefference and how confortable you feel rather than strict rational choice. I think both C and C++ are very close calls, especially considering all the other choices there are.


As for understandability, I used to work with a lot of EE people building various equipment that required both hardware/software. Everybody was smart, but not necessarily an expert in programming. We also used various programming languages. The rule was keep all code at an "8th grade level" and write everything like C. Everybody regardless of language background can read C. C has become the universal pseudo-code.

Nobody agrees on what "properly written C++" is. A colleague with a C++98 background told me C++11 looks like a completely foreign language to him.


Sorry, I didn't make myself clear. My bad.

By "recompilation", I actually meant incremental compilation. I have yet to see a C++ project in my day job that takes less than 10 seconds. Not a deal breaker, but kinda flow-disrupting. As for full re-compilation, I have known one C++ project that took less than 5 minutes. The rest always took more than 10 minutes.




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

Search: