Arbitrary abbreviations in phobos considered ridiculous

Steven Schveighoffer schveiguy at yahoo.com
Wed Mar 7 05:41:01 PST 2012


On Tue, 06 Mar 2012 11:38:09 -0500, Adam D. Ruppe  
<destructionator at gmail.com> wrote:

> One of the stumbling blocks on using std.datetime is how
> many bizarre abbreviations it has.
>
> auto time = Clock.currentTime(); // bzzt, wrong

I would have guessed Clock.now();

> if(time - something > duration!"hours"(4)) // bzzt, wrong

I would have guessed Duration.hours(4);

>
> writeln(time.toISOExtendedString()); // bzzt, wrong, but this used to  
> work!

I would have looked this one up regardless :)

> Why aren't we using real words here? Real words are easier
> to remember and easier to type.

First, it doesn't matter what you pick.  People have their expectations,  
and nobody has the same ones.  It's all about learning the library and  
getting used to what is there.

Second, I agree that to abbreviate a couple characters is somewhat petty.

Third, I don't think any of the names in datetime are horrible.   
dur!"seconds" is immediately clear what it means.

Fourth, I kind of like having names that aren't going to be common field  
names.  For example, duration may be a common field that I would put in  
some kind of timer object.

You could make the same argument against dup vs. duplicate, or writeln vs.  
writeLine, I could go on forever.  There are no perfect names, because  
everyone has a different opinion.

> And the dmd spellchecker doesn't always help:
>
> Error: template instance duration!("hours") template 'duration' is not  
> defined, did you mean Duration?

This is a red herring.  The spellchecker cannot possibly know what you  
meant unless you were only a couple characters off.  It's not a  
mind-reader.

> std.datetime isn't the only one that does this, of course.
> rndGen() in the middle of sane names like "unpredictableSeed"
> and "randomShuffle". There's more, too.

Again, it's a matter of learning the library.  Try going from Java to C#,  
you have to learn Console.Out instead of System.out.  Neither is intuitive  
or perfect, you just have to learn it.

On your grounds, I would object to your proposed names as much as I do the  
current ones, since I didn't guess them to begin with.

-Steve


More information about the Digitalmars-d mailing list