4 ms·
One of the reasons is that any reasonably interesting C++ program has lots of classes, and quite frequently, each class is in a separate file. Which actually me
by wglb 15y ago
One of the reasons is that any reasonably interesting C++ program has lots of classes, and quite frequently, each class is in a separate file. Which actually means two files, one for the .cpp and another for the .h.
One implication of this is that if one of the header files is changed, any cpp file that uses that header file or cpp file that uses a header that uses the changed header is going to need recompilation.
Further, lots more is happening during compile for C++ as compared to Java, where more happens at run-time. Depending on their extent of usage, templates can consume measurable compile time. Extensive optimization can cause measurable increase in compile time.
Also contrast the compile time you get with go, which is ridiculously faster than C++ when measured by the edit-compile-link-run cycle.
I am now of the opinion that the C++ compilation model is broken, or more charitably, has been shown to not have learned from the compilation models of the following languages:
* python
* ruby
* go
* java and other jvm uses such as clojure
* and many others
despite what Herb says about how modern c++ is.
- lunixbochs 15y agoEvery language you listed (except Go, which tries very hard for the fast compilation times) just compiles to bytecode and runs on a virtual machine later. This can be considered a much simpler task than compiling to machine language directly. When you use a virtual machine, much of the machine code required to execute the resulting program has already been compiled. Some languages/runtimes also use a JIT to compile code at runtime instead of build-time.
- chc 15y agoWhy is it necessarily much simpler to generate bytecode than machine code? Aren't they basically the same thing except one is run by a virtual machine and the other by a real machine?
- karussell 15y agoYeah, would be interesting for me as well :) !!
- wglb 15y agoOk, you made me throw in Lisp now. SBCL compiles directly to machine code. It does not have separate include files.
- ggchappell 15y ago> I am now of the opinion that the C++ compilation model is broken, or more charitably, has been shown to not have learned from the compilation models of the following languages: I think that both are correct. But it should be noted that what you call a lack of learning, is really quite deliberate. Since it began, one of the design constraints of C++ has been almost total backward compatibility with C. That means that C++ is permanently stuck with a 40-year-old compilation model.