Function calls

Michel Fortin michel.fortin at michelf.com
Fri Jan 29 17:14:50 PST 2010


On 2010-01-29 17:22:11 -0500, Gerrit Wichert <gw at green-stores.de> said:

> [skipping a long part]
> But I don't want to advertise any Perl, just hoping the idees behind
> Moose can be helpful. So back to D.

Objective-C properties look like that too. You declare a property with 
a name, a type and some flags (like readonly), and you can either 
provide your own accessor functions or tell the compiler to synthesize 
them.

All this reminds me the debate about what to do with properties a long 
time ago. Walter finally settled for @property, so that's what we have 
now. I don't really want to reopen the debate.

Thinking about it, I'm wondering if @property wouldn't be better named 
as @accessor. After all, each function labeled @property isn't a 
property in itself, it's an accessor for that property constituted of 
all the overloaded accessor functions having the same name. But that's 
just a small cosmetic issue and I don't mind very much.


> Now to your problem with byLine:
> 
>> Some said it should be stdin.byLine(), some others said it should be
>> stdin.byLine. They invoked contradictory rules that led to contradictory
>> conclusions.
> 
> If byLine  internally constructs a new range instance that happens to
> use stdin for iterating by line, this to me ist clearly a function. And
> then the normal rules for calling a function in the D language must
> apply. This has nothing to do with properties.
> 
> If you have a single ByLineRange instance stored in stdin that is simply
> handed out by the byLine  function,  than  this  can be seen  as  a
> getter function of a byLine property and *both* forms should be applicable.

I think that's not exactly how it should be. I'd rather say: if you can 
conceptualize stdin as containing a ByLineRange then it is fit as a 
property. The actual implementation of stdin and byLine shouldn't 
matter.


> So, that is my opinion about properties. I hope it makes some sense to
> you or is helpful to anyone.

It makes sense in that it's a valid way to think about properties. I 
just don't feel it's worth reopening that debate now that we have 
something.


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




More information about the Digitalmars-d mailing list