Another Properties Proposal

Reiner Pope some at address.com
Wed Aug 22 23:52:27 PDT 2007


Chris Nicholson-Sauls wrote:
> Chad J wrote:
>> Another possible syntax (without new keywords, almost looks better too):
>> in Type foo(getFoo); // RO property
>> out Type foo(setFoo); // WO property
>> inout Type foo(getFoo,setFoo); // RW property
>>
>> So far this is pretty much what Ender KaShae suggested in the original 
>> thread.
> 
> I like the idea of re-using in/out/inout, but I think a new 'property' 
> keyword and a pair of braces are also a good idea.  Properties really 
> ought to be whole entities (encapsulation), or at least it seems so to 
> me -- and then maybe we could re-use the precedent established with 
> templates (that of a member with the same name as the template).  Then 
> use operator overloads to do the rest.

I just want to say that I don't think this precedent is a good one. It 
has the annoying problems of effectively only allowing one member 
(admittedly, not an inherent problem of the idea) and of requiring you 
to repeat the name inside the template. Consider writing a 
meta-programming template:

(off-the-cuff, sorry if it's wrong, or a little roundabout)

template IndexOf(T, U...)
{
     static if (U.length == -1)
         const IndexOf = -1;
     else static if (is(T == U[0]))
         const IndexOf = 0;
     else static if (IndexOf!(T, U[1..$]) == -1)
         const IndexOf = -1;
     else
         const IndexOf = 1 + IndexOf!(T, U[1..$]);
}

For every "return" statement, you have to write the template's name. It 
makes renaming the template a pain. Contrast this with the nice thing D 
has done with the constructor, calling it "this()" -- there's no reason 
the constructor needs to know the class's name, so it shouldn't 
syntactically be there; and it really makes refactoring easier.

   -- Reiner



More information about the Digitalmars-d mailing list