In various languages I came across during my career require some import/using/include etc. to refer to the code in other file.
while the same languages also require a package manager or a list of files to be provided. for instance
- in C++ all CPP files need to be provided to the compiler
- in PHP there is a autoload.php that refers to all the files, and autoload is then included from thereon
- in typescript import is used but the files are specified the tsconfig file.
so if all compilers need a list of files, when it comes to single file compilation, are the missing symbols can be marked and compilation of each file would result in some symbols to be resolved. Most probably a multipass compiler would be more suitable here.
so why haven’t we seen any compiler even in 2024 that does it and not require us to provide the import/include etc in the files.
4
There’s a difference between what you could do, and what you want to do.
Let’s say my program uses three files, X, A and B. X uses a function made available in A, but spells it wrong and it matches a function made available in B. Since B is not included, the compiler can tell you that you made some mistake. If neither A nor B need to be included, it is impossible for the compiler to know that you made a mistake, and at runtime your code in X will just call the wrong function.
I love redundancy.
And there is always the question: Which other files do I have to look at to understand the code in X? Answer: Look for the include statements, and that’s what you need to know. If it’s not included (directly or indirectly) then you don’t need to understand it to understand X. Worst case, you have to go through all the files to find which ones are relevant to some particular code.