3 ms·
what he says is correct about languages like modula-2, oberon, ada, ocaml, c, and c++, at least within a single compilation. you can have multiple implementati
by kragen 3y ago
what he says is correct about languages like modula-2, oberon, ada, ocaml, c, and c++, at least within a single compilation. you can have multiple implementations of the interface described in a single .h file, but you have to choose at most one of them every time you go to compile. this is distinct from how things like java work; java doesn't have this problem
c++ compilation is mostly slow not because c++ compilers use lalr parsers (they don't) but because c++ programs commonly wedge lots of the implementation into the "interface", i.e., the .h file, and use recursive textual #include
non-c++ compilers are super fast
- pjmlp 3y agoNowadays, import std; import something_with_templates; int main () { std::println ("Hello World"); something_with_templates::my_func("data"); } Is also super fast.
- kragen 3y agothanks! this is interesting! for me, with the something_with_templates commented out, that gives these errors: $ g++ -Wall -Werror -O -std=c++23 pjmlp-hello.cc -o pjmlp-hello pjmlp-hello.cc:1:1: error: ‘import’ does not name a type 1 | import std; | ^~~~~~ pjmlp-hello.cc:1:1: note: C++20 ‘import’ only available with ‘-fmodules-ts’, which is not yet enabled with ‘-std=c++20’ pjmlp-hello.cc: In function ‘int main()’: pjmlp-hello.cc:5:8: error: ‘println’ is not a member of ‘std’ 5 | std::println ("Hello World"); | ^~~~~~~ $ g++ -Wall -Werror -O -std=c++23 -fmodules-ts pjmlp-hello.cc -o pjmlp-hello In module imported at pjmlp-hello.cc:1:1: std: error: failed to read compiled module: No such file or directory std: note: compiled module file is ‘gcm.cache/std.gcm’ std: note: imports must be built before being imported std: fatal error: returning to the gate for a mechanical issue compilation terminated. so it looks like it could conceivably be super fast if it worked. perhaps std.gcm should be included in the libstdc++ package or built as part of apt install? still, though i wasn't able to test, i anticipate some slowness due to the semantic model of template expansion, which is one step removed from preprocessor textual expansion
- pjmlp 3y agoYou have chosen the compiler that currently has worst support for modules from the big three. Try the same with Visual C++, the currently leading one in ISO C++ support. When std still isn't available as compiled module, Build started at 12:21... 1>------ Build started: Project: ConsoleApplication1, Configuration: Debug x64 ------ 1>Scanning sources for module dependencies... 1>std.ixx 1>std.compat.ixx 1>Compiling... 1>std.ixx 1>std.compat.ixx 1>ConsoleApplication1.cpp 1>ConsoleApplication1.vcxproj -> C:\.......\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 12:21 and took 08,078 seconds ========== After changing the message contents and recompiling, Build started at 12:22... 1>------ Build started: Project: ConsoleApplication1, Configuration: Debug x64 ------ 1>Scanning sources for module dependencies... 1>ConsoleApplication1.cpp 1>ConsoleApplication1.vcxproj -> C:\.....\ConsoleApplication1\x64\Debug\ConsoleApplication1.exe ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 12:22 and took 00,567 seconds ==========
- kragen 3y agoit took 567 milliseconds to compile six lines of code? i used to use visual c++ last millennium when people paid me to, but i recall it compiling more than eleven lines of code per second, even on the hardware of the time
- RealiZM 3y agoCynics would say that C++ (and in some sense) C took almost 50 years to catch up with Pascal.
- pjmlp 3y agoIn what concerns fast compilation times, and type safe linkage, there were other languages doing it before Pascal. The language extensions for units/modules in Pascal are influenced by other languages from the 1960's and 1970's. ESPOL/NEWP, PL/I dialects, ALGOL dialects, Mesa, Modula-2. Linker technology that the C authors decided to ignore, "Although we entertained occasional thoughts about implementing one of the major languages of the time like Fortran, PL/I, or Algol 68, such a project seemed hopelessly large for our resources: much simpler and smaller tools were called for. All these languages influenced our work, but it was more fun to do things on our own." -- https://www.bell-labs.com/usr/dmr/www/chist.html https://www.bell-labs.com/usr/dmr/www/chist.html
- RealiZM 3y agoI used Borland's Pascal. And I know this: it had insane compile/build time, even with TurboVision or OWL libraries for UI. Borland's C++ compiler of same age weren't even close. And despite all language extensions, Pascal was quick to parse and to generate not great, but okay code. Over 20 years later, GCC without -O1 generates countless coping for very simple C code. Not to mention all brainpower and money behind C and C++ versus behind Pascal. This quote proves that computer industry often goes after the worst option and is very fond of reinventing wheel.