Arbitrary abbreviations in phobos considered ridiculous

Jonathan M Davis jmdavisProg at gmx.com
Wed Mar 7 11:27:38 PST 2012


On Wednesday, March 07, 2012 08:47:48 Steven Schveighoffer wrote:
> On Tue, 06 Mar 2012 12:09:47 -0500, Andrej Mitrovic
> 
> <andrej.mitrovich at gmail.com> wrote:
> > I'll never forgive std.datetime for this mistake:
> > 
> > auto sw = StopWatch(AutoStart.yes);
> > writeln(sw.peek.hnsecs);
> > writeln(sw.peek.nsecs);
> > writeln(sw.peek.usecs);
> > writeln(sw.peek.msecs);
> > writeln(sw.peek.secs); // bzzzzz NOPE
> > writeln(sw.peek.seconds);
> > 
> > I misspell this thing every single time I use stopwatch to count seconds.
> 
> this is a no-brainer:
> 
> Duration dur(string units)(long length) @safe pure nothrow
> if(units == "weeks" ||
> units == "days" ||
> units == "hours" ||
> units == "minutes" ||
> units == "seconds" ||
> units == "secs" || // added
> units == "msecs" ||
> units == "usecs" ||
> units == "hnsecs" ||
> units == "nsecs")
> {
> return Duration(convert!(units, "hnsecs")(length));
> }
> 
> // etc, everywhere "seconds" is used, add "secs" as well.
> 
> I'll see if I can do a pull request.

I've avoided that primarily because it results in inconsistent code. It's 
pretty much equivalent to adding extraneous aliases, though it's not as bad, 
since it's not a general symbol. But if it's a sufficient usability improvement, 
then maybe it's a good idea.

- Jonathan M Davis


More information about the Digitalmars-d mailing list