80 points · by lelf · 12y ago · 42 comments
This doesn't mean the standard will be 1:1 to what Clang currently offers.
Don't underestimate the cost of just reading in all that text and parsing it. Modules allow you to cache some pre-parsed AST or similar internal representation of any exported template definitions which should greatly reduce the cost of instantiating them in the importing translation unit due to savings in IO and parsing time. Importantly, importing translation units never even have to look at definitions they don't use whereas currently they have to fully parse everything that gets dragged in by the headers they include even if they only use a tiny subset of the functionality.
A module enabled STL with well implemented compiler and linker support should greatly reduce build times for codebases that make heavy use of STL by simply replacing #include <header> with import std.header. The proposal eliminates all the unnecessary overhead of templates (re-parsing huge amounts of text) and leaves only the necessary / desirable overhead (instantiation from some internal representation with the specific types used). It's that final instantiation that gives templates their runtime performance advantages over other models (like C# generics) so you wouldn't want to lose that.
It's really an elegant solution considering the constraints they're working under.
[1] Preprocessor macros don't leak from includers to includees, so headers become independent of each other.
Borland came up with an approach that instantiated templates multiple times, and then weeded out duplicates. That was relatively easy to implement, so everyone else followed suit. Extern template makes it possible to make sure some instantiations are instantiated only once, so the compiler doesn't have to weed out extra instantiations (I wish I could use "instantiate" fewer times in that description, but I can't see how to pull that off).
In Java, the compiler reads a Java file once, produces a class file and the class file contains all the information needed to compile other files that refer to its contents.
In C++, the compiler has to read all of source declarations that are used by a compilation unit, over and over again. An arbitrary cpp file can transitively include tens to hundreds of header files. Modern C++ compilers can play caching tricks, but the model is intrinsically O(n^2) compilation rather than O(n) compilation where n is the number of source files.
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n402...
A more digestible description of this can be found in a Modula 2 reference manual:
http://www.modula2.org/reference/modules.php
The Modula 2 compiler I worked with years ago simply had you put the definition modules into .def files and the implementation modules into .mod files. So it's vaguely like headers, except that the .def files have structure and can be compiled; the compiled info is then referenced during compilation of the client modules. The .def file is never directly referenced as text.
C++ design goal of being able to target unmodified C toolchains as a means of being accepted by C developers, meant C++ also had to keep away from modules.
Luckily C++ can stand on its own nowadays and depart from such decisions.
Now with Java and .NET upcoming adoption of ahead of time compilation to native code in the next versions.
Additionally with other languages like D, Rust, Go, Swift, Ada, Haskell, OCaml fighting for a place at the Sun.
There will be lots of options for those looking into languages with support for ahead-of-time compilation to native code in their reference implementations.
Thus pushing C++ deeper into the OS realm, while at the same time giving to those people other options to look for.
Hence my remark.
[0] There were other options, but they were largely ignored by the mainstream.
"Worse is Better" is Worse in the long run, I guess.
But even just considering new projects, I'd expect that C++'s inertia in terms of reputation, ecosystem and people's skillset/experience means that C++17 or even later will have plenty of time to measure up against the competition.
C++ will continue to be used, much like Cobol has continued to be used for an eternity.
I've got coworkers who's first job in the programming business was Cobol maintenance. Old programmers from the 1960s are retiring in their 80s, and they need maintainers to write new code for various ancient mainframe systems.
Do remember, IBM is still selling System/360 systems today. http://en.wikipedia.org/wiki/IBM_System_z
These systems are running Cobol code from the 1960s, and they need to be updated to include XML, REST and all the other latest developments of development.
http://www.itworldcanada.com/article/the-future-of-cobol-why...
Similarly, C++ programmers are probably going to have an even _larger_ legacy than Cobol.
Cobol is very much alive today.
In fact by some measurements, Cobol is still more popular than Java and Javascript.
http://www.computerworld.com/article/2502430/data-center/cob...
The point is that many of us, go to C++ because it is one of the few languages with ahead-of-time compilers available across multiple systems.
Now that we are experiencing a going native wave in terms of compiler toolchains for other programming languages, that reason is slowly becoming less relevant.
So many might choose another language, instead of waiting a few more years for the support to appear.
> And what is "C++ triad"?
gcc, clang and Visual C++.
HN posts about C and C++ tend to forget there are many more C and C++ compilers out there.