Function calls

Steven Schveighoffer schveiguy at yahoo.com
Fri Jan 29 05:27:13 PST 2010


On Thu, 28 Jan 2010 17:54:33 -0500, Pelle Månsson  
<pelle.mansson at gmail.com> wrote:

> On 01/28/2010 11:23 PM, Michiel Helvensteijn wrote:
>> Andrei Alexandrescu wrote:
>>
>>> I agree. So where's the consensus? Things seemed so clear when people
>>> were beaten with @property over their head.
>>
>> If I read the TLP correctly, @property seems not to be working  
>> correctly.
>>
>> @property (or any other notation marking property getters/setters)  
>> should be
>> enforced. Functions that have it must only be invoked using property
>> syntax. Functions that don't have it must be called with parentheses.
>> That's the whole point. To give the designer of the class control over  
>> how
>> it is used.
>>
>> The problem is people blurring the line between what's supposed to be a
>> function and what's supposed to be a property, by abusing property  
>> syntax
>> to invoke actions without parentheses.
>>
>> In reality, I believe there's not only a clear line between the two
>> intentions, there's a demilitarized zone. You just need to enforce it.  
>> You
>> can't have your cake and eat it too.
>>
>
> I don't understand what any of this would improve. Is the byLine example  
> less readable without the ()? Is it more bug prone?
>
> The only thing achieved as I can see is that every class designer makes  
> up his own rules about which functions are property and which are not.  
> If this is somehow enforced, it will become a guessing game about how to  
> call no-argument functions. For what?

Just as every class designer makes up his own rules about naming  
functions.  The parentheses are part of the name of a function.  Whether  
in your view the parentheses have meaning or not is your opinion.  But you  
should not be able to attach your own meaning to my functions.  What if we  
allowed a feature where you could call functions with just an unambiguous  
prefix?  so something like:

stdin.by();

Is that ok with you?  It's not unambiguous, is it just as easy to  
understand as using the full name?

The fact that byLine is just as descriptive as byLine() makes no  
difference.  It is not a quintessential example of ambiguity.  It should  
be a property IMO because of what it does, but even if it's not, it's not  
ambiguous.  There are other cases which are ambiguous.

-Steve



More information about the Digitalmars-d mailing list