Function calls

Michel Fortin michel.fortin at michelf.com
Thu Jan 28 20:48:36 PST 2010


On 2010-01-28 17:27:58 -0500, Andrei Alexandrescu 
<SeeWebsiteForEmail at erdani.org> said:

> The problem is not localized change. The result of stdin.byLine changes 
> the _entire_ stdin.

No. Calling byLine doesn't change the stream. It returns a different 
view of stdin, which can be used to modify the stream, or not. I think 
it should be a property. If it was 'getNextLine' then it should be a 
function. As a proof, this doesn't have any effect:

	stdin.byLine;

If you put it in a foreach loop, then it has an effect. But it's 
foreach that has the effect of calling popFront on the byLine view of 
stdin. Getting byLine by itself doesn't do anything.

Another term I'd use for a property, perhaps a better one, is an 
'accessor'. A property, or an accessor, gives you access to an aspect 
of the object you're dealing with. In the case above, you get access to 
stdin line by line. Getting access to something might allow you to 
modify it, or it may not, depending on what it is exactly. But just 
getting access to it doesn't modify the object in itself.

Sorry to arrive late in this conversation. Let me address some other points:

I know not everyone get it right all the time. But that's not 
necessarily a contradiction, it just means that the concept isn't 
really well understood. If there was a good definition for it from an 
authoritative reference, it might help reduce the confusion. Currently 
the only authoritative element seems to be the syntax, no wonder it's 
confusing.

Andrei, you keep complaining it's a convention. It *is* a convention, 
because only a convention can differentiate actions from accessors. 
Ideally, we wouldn't need a special syntax: English words would be 
enough. But as you know English words alone are often ambiguous.

Either the convention is (1) how we name things -- like isEmpty vs. 
empty -- but I think you don't like that. Either it's (2) a syntactic 
convention -- empty vs. empty() -- but then the meaning becomes a 
little more subtle. Or (3) you can give the same meaning to both empty 
and empty(), but then people are left to guess what it means (action or 
accessor), and it creates incongruities with callables. Or (4) you can 
force empty() to always be with parenthesis and let people guess what 
it means; at least you don't have incongruities.

There's no perfect solution. But of all of these options, the one used 
in D1 (number 3) has the most drawbacks: you can't distinguish actions 
from accessors, and on top of that you have problems with returning 
callables.


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list