4 ms·
Modules 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 collis
by mostlylurks 3y ago
Modules 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.