3 ms·
I haven't been following C++ for quite a while but when I did, I wanted modules. And now it looks like they're here and they've done it wrong. Or at least misse
by mypalmike 6y ago
I haven't been following C++ for quite a while but when I did, I wanted modules. And now it looks like they're here and they've done it wrong. Or at least missed an opportunity to do it really right.
They've done the equivalent of * imports in languages like Java and Python. And style guides in those languages universally recommend against doing that.
Why? With named imports, if you see a symbol anywhere in the codebase, its declaration is somewhere within the file itself. If you see a call to foo(), it's going to be either a local function or a declared import. With C++ modules (as with C++ includes) it could come from any of the imports, so you have to look outside of the file to figure out where it came from.
Sure, IDEs help paper this over somewhat. But it just seems sloppy for a post-1980s language feature to throw all imports into the global namespace.
- yuushi 6y agoThat's because modules and namespaces are the same thing in languages like Python, whereas they are separated in C++. The code in the imported module will go into whatever namespace it is in within that module, not the global namespace.
- mypalmike 6y agoI had forgotten about C++ namespaces. It's been quite a while. I'm not sure that this addresses my concern though. Do namespaces enable the import of specific symbols from a module?