properties

Steven Schveighoffer schveiguy at yahoo.com
Tue Jul 28 11:03:57 PDT 2009


On Tue, 28 Jul 2009 13:51:11 -0400, Bill Baxter <wbaxter at gmail.com> wrote:

> On Tue, Jul 28, 2009 at 10:20 AM, Steven
> Schveighoffer<schveiguy at yahoo.com> wrote:
>> I want to use the parentheses or lack thereof as part of the human  
>> meaning
>> for the function/property.  Making them optional means I can't do that.
>
> I think Andrei's right here.
> .seconds() really was too ambiguous a name to begin with.   Even if we
> had properties I would be inclined to think that was just something
> you forgot to mark as a property because a property-like meaning is
> all that makes sense to me.   The meaning of .fromSeconds() is much
> more obvious.

I think in the sense that 'seconds' is not a verb, and therefore, it's not  
obvious (perhaps to some) that

TimeSpan.seconds(5);

returns a TimeSpan that represents 5 seconds is a valid point.  But what  
happens in those cases is the user is slightly confused and looks up the  
docs (probably once).  The argument from Andrei is simply dodging the  
issue.

ts.seconds = 5;

Means the same thing (even with Andrei's new rule), and not because I  
poorly named the function, but because I happened to name it the same as a  
member function.  That you can call a static function via an instance is  
one bug IMO, and the other is that the function is even considered as a  
property.

> The example of adjectives or nouns that are also verbs is much better
> --- .empty  vs .empty().    Others that come to mind:  clean, dirty,
> end, begin.  (begin isn't really a noun but it's been used that way
> for so long in STL that C++ people think of it as a synonym for
> "beginning".)

I was using a real-life example, I think that has some power to it.  But  
you are right, naming the static method differently was probably the right  
move anyways, and there are better theoretical examples.  There was some  
pressure to make the usage less verbose...

-Steve



More information about the Digitalmars-d mailing list