4 ms·
Only for us needy humans to be able to use short names. Modules can be thought of as prefixes to function names. You already have this global key value of name
by pyrolistical 3y ago
Only for us needy humans to be able to use short names. Modules can be thought of as prefixes to function names.
You already have this global key value of names to functions. The name just happens to be module+function name
- Kinrany 3y agoEverything on top of machine code exists solely for the benefit of human understanding.
- tripleo1 3y agoAnd program optimization, no? Am interesting theory.
- yakubin 3y agoExcept now you can handle name collisions by renaming imports. If you have two modules that share a name, you can rename them in the import line (e.g. in Haskell or Go). Without modules though if you have two libraries which used the same prefix for their functions, now the compiler will complain about redefinitions and the linker will complain about symbol collisions.
- mostlylurks 3y agoModules are obviously the best solution for this purpose, but not the only one. Even in C, which has neither modules nor namespaces, you can avoid prefix collisions with a little bit of macro usage by making the prefix configurable in such a way that the consumer of the library only has to define a preprocessor constant before including the library if they're unlucky enough to have stumbled upon two different libraries with the same prefix, with no action required otherwise. Even for the author of an library this approach doesn't require any unreasonable levels of macro usage. In practice this approach is rare, but I've seen a couple of libraries use it, so it's not completely theoretical.
- yakubin 3y agoThat will only work for open source libraries. It won't work for libraries provided in binary form (which is common in commercial contexts I've worked in so far). I also tend to dislike the preprocessor and other forms of syntactic programming in favour of solutions working on the semantic level. The more I know about the preprocessor, the less simple and more puzzling it is to me, especially after implementing it.