[phobos] Time to get ready for the next release

Steve Schveighoffer schveiguy at yahoo.com
Fri Apr 22 08:05:08 PDT 2011


The problem with RTFM is, they have a point.  s.seconds = 5 looks like it should work.  So that response looks like you don't care about usage.  D isn't a dynamic language.


If you *want* to express that a function can be called both ways, then we have to look into overloading properties and non-properties of the same name with the same arguments, or using an annotation.  But that's a separate enhancement.  We'd have to look at the merits of that separately, and I personally feel the ability to do that is not worth the trouble -- you can just as easily rename the function version, and it actually ends up reading clearer.  Yes, it's not always DRY, but DRY is never fully achievable, and is secondary to usage semantics IMO.


-Steve


>________________________________
>From: David Simcha <dsimcha at gmail.com>
>To: Discuss the phobos library for D <phobos at puremagic.com>
>Sent: Friday, April 22, 2011 10:42 AM
>Subject: Re: [phobos] Time to get ready for the next release
>
>
>
>
>
>On Fri, Apr 22, 2011 at 10:39 AM, Steve Schveighoffer <schveiguy at yahoo.com> wrote:
>
>Bug reports.  People having stupid arguments just like this one on why you should change how the code works to fit their style ;)
>>
>>
>>Essentially, ambiguously named functions in the context of "I can call this as a property or a function" lead to people getting surprising behavior and then complaining about the surprise, when I can do nothing about it.
>>
>>
>>I've actually had this happen.  I had to change function names in Tango in order to avoid people complaining.  The example was, I had a bunch of generator functions in TimeSpan, like
>>
>>
>>// create a time spand that represents the given number of seconds
>>
>>static TimeSpan seconds(int s)
>>
>>
>>
>>which would be used like this:
>>
>>
>>auto s = TimeSpan.seconds(5);
>>
>>
>>But it could also be used as a property.  So this compiled and constructed a temporary time span and throw it away:
>>
>>
>>TimeSpan s;
>>
>>
>>s.seconds = 5;
>>
>>
>>So we had to change seconds to fromSeconds.  It still allows code like this:
>>
>>
>>s.fromSeconds = 5;
>>
>>
>>but instead of being disallowed, it just looks horrible, hopefully cluing the reader to go examine the documentation for TimeSpan.  That's the best we can do.  I have no power to enforce the usage.
>>
>>
>>
>>-Steve
>>
>>
>
>Nor should you.  People who are confused should RTFM.  BTW, what if you, as a library designer, want to express the notion that something can be called both ways? 
>
>_______________________________________________
>phobos mailing list
>phobos at puremagic.com
>http://lists.puremagic.com/mailman/listinfo/phobos
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20110422/7157bcbe/attachment-0001.html>


More information about the phobos mailing list