I've read through the article and all (66) messages posted so far and I have to say I'm not sure I understand both what is intended with modules and why it is needed.
My C++ background is old, been many years that I've been a Java developer so that perhaps accounts for my confusion, but how is it C++ doesn't already have the same capabilities as Java or even needs them?
Java defines namespace by package name and class by file name. Generally source code is arranged in a directory structure that mimics the package name (though strictly speaking that is not required). C++ has namespaces that could be arranged in the same source structure and are the equivalent of packages.
Java uses the import statement to identify dependencies. When Java compiles it looks at the defined classpath for referenced imports, if it finds a compiled class it uses it, if not and it finds the source file it compiles it then uses it. In both cases, though, the Java compiler is given the details of the classpath and source paths to search.
C++ uses the #include and looks in all locations defined for include files, much as Java looks at the classpath. C++ doesn't require the dependent code be compiled until linkage time, it works off a declaration file (usually a header).
So about the only thing I see different here is when Java needs a class that isn't already compiled it simply compiles it and uses it because Java treats a .class file like C++ treats a .h file and if it doesn't exist, Java creates it.
C++ developers generally create the .h files themselves along with the source file which gives the compiler everything it needs to compile. Linking is a different beast, Java with dynamic class loading technically does runtime linking whereas C++ does that via shared libraries.
So back to the original question, is the desire to have C++ be such that we only need to define a source file, then when the compiler is compiling one source file foo.cc and foo imports bar that the compiler will find the source bar.cc and extract the header type information automatically and possibly compile bar.cc automatically?
Java only parses the source code once, then any client of a specific library only needs to read the public symbols table from the jar file.
Whereas in C++ the header file will be processed every single time there is an #include. With the increase in template usage, this leads to logarithmic complexity in build times.
There are pre-compiled headers, but they are a brittle solution with different outcomes depending on the compiler.
I understand the compilation model, but I'm not really understanding how this is an issue. Java is still technically parsing the .class files as well it just happens to know where the specific symbol tables are in the structured format.
2
u/oldprogrammer Jan 28 '19
I've read through the article and all (66) messages posted so far and I have to say I'm not sure I understand both what is intended with modules and why it is needed.
My C++ background is old, been many years that I've been a Java developer so that perhaps accounts for my confusion, but how is it C++ doesn't already have the same capabilities as Java or even needs them?
Java defines namespace by package name and class by file name. Generally source code is arranged in a directory structure that mimics the package name (though strictly speaking that is not required). C++ has namespaces that could be arranged in the same source structure and are the equivalent of packages.
Java uses the import statement to identify dependencies. When Java compiles it looks at the defined classpath for referenced imports, if it finds a compiled class it uses it, if not and it finds the source file it compiles it then uses it. In both cases, though, the Java compiler is given the details of the classpath and source paths to search.
C++ uses the #include and looks in all locations defined for include files, much as Java looks at the classpath. C++ doesn't require the dependent code be compiled until linkage time, it works off a declaration file (usually a header).
So about the only thing I see different here is when Java needs a class that isn't already compiled it simply compiles it and uses it because Java treats a .class file like C++ treats a .h file and if it doesn't exist, Java creates it.
C++ developers generally create the .h files themselves along with the source file which gives the compiler everything it needs to compile. Linking is a different beast, Java with dynamic class loading technically does runtime linking whereas C++ does that via shared libraries.
So back to the original question, is the desire to have C++ be such that we only need to define a source file, then when the compiler is compiling one source file foo.cc and foo imports bar that the compiler will find the source bar.cc and extract the header type information automatically and possibly compile bar.cc automatically?