Namespaces provide two things:
- An optional name prefix to avoid naming conflicts.
- A way of grouping functions so that you can find them again when you need them.
Here are some suggestions for how namespaces could be improved or removed in programming languages:
- Allow regex-like imports, like
import *_listto get all the list functions, or
import print_*to get all the printing functions. This way I don’t have to decide if
print_listgoes in my
- Use tags instead of namespaces. In the previous example,
print_listwould have the tags
list. This would be slightly better than using regex-like imports because then we do not require names to follow a convention nor would we need to enforce an ordering to the parts of a functions names. Should I choose
list_print? With tag imports, either would be fine. I leave it to the reader to think of a good system for how to tag functions.
I suggest a radical idea based on option 2 listed above. Functions are automatically named the hash of their implementation (perhaps on a normalized form of the syntax). Functions have tags, as described, as well as some documentation so that we can find functions that we want without relying on their name (which is quite unhelpful in this system). Every function imports every function it needs individually.
The benefit of this idea is that backward-compatibility is impossible to break. Every time a function changes, it’s name changes, which means that any dependent function which wants to upgrade to the new function must also change it’s import, which changes its own implementation, and therefore its name. Every change causes a rippling update through the dependency tree of functions.
This idea seems hard to implement without being unwieldy, but I believe with some good tooling, it would be possible to provide a good programmer experience.