Revised RFC on range design for D2
Steven Schveighoffer
schveiguy at yahoo.com
Tue Sep 30 06:42:43 PDT 2008
"Michel Fortin" wrote
> On 2008-09-29 12:55:18 -0400, "Steven Schveighoffer" said:
>
>> Stdout.newline.formatln("Hi there {}", var);
>>
>> Is newline a property of Stdout, on which I'm calling formatln, or is
>> newline a function that I'm calling, and then using the result of that
>> function to call formatln? Compare with:
>>
>> Stdout.newline().formatln("Hi there {}", var);
>>
>> There is no ambiguity. newline is clearly a function, not a property.
>
> Interesting. To me both of these things have exactly the same meaning.
> Perhaps it's because I'm used to D, but I think it's more because I can't
> count how many times I've seen this pattern in C++:
>
> SomeSimgleton::Instance().doSomething();
>
> where Instance() is simply an accessor.
Yes, that is a workaround for not having property constructs available. The
intuitive label of 'property' comes from the name of the getter 'Instance'.
It screams that you are getting the instance of the class, and it's well
accepted as a property. What has happened is that instead of relying on the
compiler to enforce what is a property and what is not, you are relying on
the interpretation of English words.
But in a language like C#, you would define Instance as a property, not a
function. So it would never look like that.
In D, properties are equivalent to functions, so you have a choice as to
whether to use the parentheses or not. But that isn't the problem, the
problem is really that you can call functions as properties.
> In my opinion, "newline" isn't a good function name for what it does
> because it has no verb. Having no verb makes it look like an accessor much
> more than the absence or presence of parenthesis.
So newline() seems like a property to you more than 'start a new line'? I
suppose I can see that, but consider if you were used to a system where
properties *prohibited* parentheses, and functions *required* them. It
becomes less about interpretation of English vocabulary and more about
compiler-enforced interface. I like that system better.
-Steve
More information about the Digitalmars-d-announce
mailing list