3 ms·
Operators are an argument for why it should be opt-in. Most code you write doesn't use imported operators, and when you do use them, you aren't using many of th
by hombre_fatal 6y ago
Operators are an argument for why it should be opt-in. Most code you write doesn't use imported operators, and when you do use them, you aren't using many of them. Encumbering everyone's code for code that they might write isn't usually the right trade-off.
Just make provide the feature via opt-in. Other languages do this just fine:
from Lib import (foo, (+)) // Just +
from Lib import (foo, (...)) // All operators
Good defaults are important so that the ecosystem develops good conventions. Else you get "well, you can qualify imports if you want" as seen in this thread. After reading code all weekend, nobody qualifies imports in Nim.
And I also believe in escape latches, not absolutism. If your templating argument were the best reasoning, then it makes sense for that to be an isolated idiosyncrasy rather than a reason for all code to pay the penalty of unqualified imports by default.
Just like you can opt-in to importing entire namespaces into scope in other languages, but you only do it on occasion when it makes sense, not by default.
Anyways, I know this is classic HN bikeshedding, but Nim gets mentioned a lot on HN, the developer clearly has a good eye for attention to detail and thoughtfulness. So it surprised me that Nim had what I consider one of the fundamental mistakes in programming languages along with, say, a lack of first class Optional<T>.
- Varriount 6y agoIt's true that custom operators aren't implemented very often, but what about templates and generics? Both are used quite frequently.
- AnIdiotOnTheNet 6y agoI'm not convinced unqualified imports are necessary or helpful for generics. Zig has generics just fine without unqualified imports.
- arc619 6y agoWhat is the perceived penalty of unqualified imports in Nim specifically? The only one that seems valid is you can't immediately see the module a proc is defined in, but you can opt in as you say with module qualifiers if you want to. None of the "namespace pollution" stuff applies to Nim since ambiguity is a compile time error and there's no performance penalty for having everything imported as Nim uses dead path elimination.