Pseudo namespaces
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Thu Dec 3 14:25:50 PST 2015
On Thursday, 3 December 2015 at 21:46:03 UTC, Chris Wright wrote:
> So maybe explicit namespaces within a module are justified
> sometimes.
I definitely think that there are times when it's justified, but
I also think that they should be used sparingly. I think that the
only time that I've used them is when conceptually I have a
global object that I'm calling functions on but don't actually
have an object - e.g. std.datetime.Clock has functions that get
the time from the system clock, but the system clock is not an
actual object, and std.windows.registry.Registry groups some
windows registry-stuff in single, conceptual object. Though while
conceptually I like having stuff like Clock.currTime, given that
the monotonic clock stuff is separated into core.time with pretty
much only the realtime clock stuff being in std.datetime, it
doesn't work very well to have a single place to query the clock
like that. So, much as I like it, having std.datetime.Clock was
probably a mistake.
Certainly, the only time that it makes sense to use a special
namespace like this is when it makes sense to force the user to
use the namespace every time they use the symbols in it rather
than letting the module system differentiate things normally and
let the user decide what they want to do. And there usually isn't
a good reason to do that.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list