Namespacing in Io and Ioke
I’ve been working with Io and Ioke more than usual lately and starting to get into projects that need to go beyond a single source file. I’ve hit a wall though: how should namespacing in prototype based languages be done? I’ve come up with a couple ways, and I’d love to see some alternatives.
A naive way would just be to keep a consistent naming scheme, like the top-level object being Module, and members of that module being named like ModuleMember, all in the top level or lobby namespace.
A better way would be to use slots from containing objects to simulate Ruby-style modules and namespacing. This works extremely well for single file projects:
Module := Object clone do(
Member := Object clone do(
foo := method(...)))
The problem arises when you stretch it across files. If you put each Member in its own source file with a Module := Object clone instantiation, only the most recently instantiated Module will be available because the old object will have been overwritten. The cure is to do something like this:
Module := Object clone
doRelativeFile("module/member1.io")
doRelativeFile("module/member2.io")
Where the memberX.io files have this structure:
Module do(
Member := Object clone do(
foo := method(...)))
That way, the Module top-level objected is only being extended in each source file, rather than re-instantiated.
I could be going about namespacing all the wrong way though, and trying to apply the techniques of other languages to languages it just doesn’t work with. Really I’m just trying to work out a way to manage larger projects in languages like Io and Ioke.