Function calls

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Thu Jan 28 14:05:21 PST 2010


Michiel Helvensteijn wrote:
> Andrei Alexandrescu wrote:
> 
>>>> foreach (line; stdin.byLine()) { ... }
>>>>
>>>> vs.
>>>>
>>>> foreach (line; stdin.byLine) { ... }
>>>>
>>>> How do I choose?
>>> byLine is a property.  It is fetching a range on stdin.
>>>
>>> -Steve
>> Damn. I was sure the answer will be different.
> 
> byLine() is a function. It changes the state of stdin. Calling it
> consecutively will in general result in different return values. If there
> were two guys: stdin.currentLine (property) and stdin.nextLine(), it would
> be a different story.
> 
> A property should act very much like a field. The advantages of properties
> are that they can be derived (not have a one-to-one relation with a storage
> location) or can do some clever caching/memoizing/logging.

I agree, but I'll also note that I got contradictory opinions from 
different supporters of @property. So now it looks all the more like a 
judgment call, which is exactly what I was worried in the first place.

> Omitting parentheses on an action just because you can is stupid. It
> actually makes the language less readable and less predictable. And all
> that for saving two keystrokes.

I found my code to be more readable and just as predictable with the 
current rule. And it's not about two keystrokes, it's about persistent 
and ubiquitous syntactic noise.

Gosh, @property does suck. I was afraid that'd be true.


Andrei



More information about the Digitalmars-d mailing list