3 ms·
Some of us like explicit invocations, not being unsure if something comes from a .h filenor some other importing mechanism (what if a .h file collides with anot
by throwawaymaths 2y ago
Some of us like explicit invocations, not being unsure if something comes from a .h filenor some other importing mechanism (what if a .h file collides with another import mechanism)
Naked imports are also annoying. Which import did that MessageBoxA come from? windows? or winuser? Is it in the language kernel?
Explicit is better than implicit. The utter pain for the code writer of four or five keystrokes here and there is not worth confounding the code reader.
- WalterBright 2y agoImports are found along the search path (just like .h files are searched for by the C preprocessor). The first one found it the one selected (just like the C preprocessor does). > Which import did that MessageBoxA come from? If it exists in two or more imports, the compiler will give an ambiguity error. To resolve the ambiguity error, qualify the call with the name of the import: windows.MessageBoxA(null, "world!", "Hello", 0); or, one can do this: import windows : MessageBoxA; or this: import windows, winuser; alias MessageBoxA = windows.MessageBoxA; You can be as explicit as you like, and don't need to worry about ambiguity because the compiler will issue an error for that. It works the same way for D imports.
- throwawaymaths 2y agoCompiler giving a compiler error still favors the writer, not the reader of code. It seems like in its design in general D favors the writer of code with all its complicated bells and whistles that one must keep in mind as a reader. I think decades of experience has shown us that it is way better to favor the reader.
- WalterBright 2y agoYou can do it either way in D. It's nice to have a choice! I use both methods, depending on the context.
- mst 2y agoSeems like "if it's obvious where it came from, use the unadorned name, if it'll be non-obvious to a future reader, use the more explicit form" is a solid heuristic and letting the programmer decide is a feature. (it might be worth having some sort of lint option that will flag using the non-explicit form because I can see large multi-developer projects finding it preferable to add 'use the explicit form' to their local coding style ... but I don't have a dog in this fight so 'free thought, worth exactly what you paid' applies ;)