[phobos] review for environment

Jonathan M Davis jmdavisProg at gmx.com
Thu Nov 4 03:34:58 PDT 2010


On Wednesday 03 November 2010 05:02:33 Lars Tandle Kyllingstad wrote:
> Sorry for not responding to this myself earlier, but I was on vacation
> with limited internet access.
> 
> I did try adding ranges, but quickly saw the issues Steve mentions.
> There are probably ways of working around them, but it won't improve
> performance, and I feel it's complete overkill for such a simple thing.
> 
> What I would like to get some feedback on is the way I've simulated a
> singleton object by using an abstract final class as a namespace for the
> various functions.  To my knowledge, this has no precedent in Phobos.
> It does feel a bit weird, but it seemed like the simplest solution.

I did that in a couple of places in datetime, except that I didn't make the 
class abstract. Rather, I made this() private and marked it with @disable. I 
quite like the idiom for certain circumstances (for instance, I used it for the 
clock in datetime), but Andrei doesn't seem to like it much. However, I think 
that the main reason that nothing like that has been done in Phobos thus far is 
because modules are generally either a bunch of completely related functions (so 
the module works perfectly as a namespace for them), or they're a bunch of 
completely unrelated functions (so there's no need to group them into further 
namespaces). As module become more heterogenious - particularly once we have 
more that have actual types in them mixed in with free functions and aren't just 
a bunch of free functions - I expect that it will become more desirable to have 
explicit namespaces in some cases (though it could still be a fairly rare need). 
We'll have to see how that goes though. Regardless, I think that using a final, 
uninstantiatable class is the best way to create a namespace within a module in 
D at the moment.

> Also, would it be OK to mark getenv(), setenv(), and unsetenv() as
> deprecated, now that environment has been present in two releases?
> (Note that setenv() and unsetenv() are POSIX-only.)

I actually used those in a couple places in datetime. I'll have to switch them 
over to using environment (though they're only applicable to datetime on Posix 
systems).

- Jonathan M Davis


More information about the phobos mailing list