Imortis wrote:From what I can see, it is just about not separating implementation from interface?
No. It is not just that. The base principle is separate compilation, like C does for multiple C files.
However there are multiple ways to practically implement that. Header/C file is basically rock bottom, with little checking. While C files are compiled separately, the header is still a dumb include.
If that is there case, there is absolutely nothing keeping you from doing that in FB. Just include a .bi or .bas file with both the Declares and Function bodies.
The whole point of module systems is that you don't do that. IOW that the state of the compiler is reset at the start of each compilation unit. This means you can compile the module independent from the source where it is used.
C is not entirely clean in that regard, because you still #include the header, so it _does_ get all the state before it is included, and this could be different when #included from source a.bas compared to when b.bas includes it. This means that headers must be recompiled everything they are used, which slows down compilation (you can imagine a fat windows.h header included in multiple C files can slow down quite a bit). Moreover, different sources can interpret headers slightly differently.
Is there some benefit that I am not seeing here?
One of the big problems with the C model is that the compiler doesn't notice things being out of sync. It also doesn't know which files to compile (must be done by makefile or something). The makefile does some crude checks with filetimes, but often you only notice if already compiled files don't match when linking.
Other systems do this differently. Pascal stores the declaration part in a separate file, and even parts from the compilation that are used directly. (e.g. inline functions and templates). This means that in Pascal you can inline functions that are not entirely in the header. Similarly the template doesn't have to be completely in the header. Also, this precompiled file has a checksum over a binary representation of the declarations, and every compiled file (.o file, or a file with associated metadata) lists these checksums.
This way if you have a units A en B that both use unit C, but have different checksums for the interface, then either one of the units will be automatically rebuilt, or if that still causes problems (e.g. there are multiple source files called "C"), the compiler halts with an error.
This avoids enormous list of missing symbols (that are often not very clear, specially when they are mangled like in C++) at the linking, and aborts earlier, so saves time.
But this is fairly old, though efficient. Java and C# do it differently. They don't have a separation but still each file is compiled in isolation. Symbols declared before the include (IMPORT/USING in C#/Java )or preprocessor state (#define) USING) don't influence the files that are referenced that way. But these languages work totally different internally, and often don't even compile the complete program before they start running.
Some terminology to search on. Assume a program is split into multiple parts.
- separate compilation, compile parts of a program separately from others. https://www.cs.bu.edu/teaching/c/separate-compilation/
- compilation unit. Each part of a program tsuch a split program in isolation. So the main ".c" file is a part, and all the other c files are also each a part. https://en.wikipedia.org/wiki/Single_Compilation_Unit
- unit system or module system: a system to also keep the above parts automatically in sync, and not only keep the implementation (.pas/.c./bas) but also declaration parts in a separate isolated compile. This is a form of https://en.wikipedia.org/wiki/Modular_programming
In Pascal you just point to the main file, and specify some search dirs, and the compiler will automatically compiler everything. No makefile or the like needed. A second compile will automatically only compile changed parts and parts that depend on it.
I can't find a large post quickly, but here are some fb.net threads with longer posts from me talking about it.
best I could quickly find:viewtopic.php?f=17&t=14640&hilit=module+systemviewtopic.php?f=9&t=26728&p=247884&hilit=unit+system#p247884viewtopic.php?f=2&t=26466&p=244109&hilit=unit+system#p244109viewtopic.php?f=17&t=26275&p=242352&hilit=unit+system#p242352viewtopic.php?f=17&t=14640&p=126653&hilit=unit+system#p126653viewtopic.php?f=2&t=12517&p=109157&hilit=unit+system#p109157viewtopic.php?f=3&t=11717&p=102450&hilit=unit+system#p102450viewtopic.php?f=14&t=9540&p=85594&hilit=unit+system#p85594viewtopic.php?f=8&t=25923&p=237949&hilit=module+system#p237949