Omittable parens is an evil

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Aug 4 15:59:23 PDT 2008


"Bruno Medeiros" <brunodomedeiros+spam at com.gmail> wrote in message 
news:g77dh7$1k7q$1 at digitalmars.com...

> My initial brainstorming gives me this design:
>
> class Foo {
>
>   private int bar;
>
>   int op_bar() { return bar; } // getter
>   int op_bar(int value) { return bar = value; } // setter
>
> }
>
> No additional "property" syntax is required. You may note that this is 
> more redundant (both the "int" type and the "bar" name have duplicate 
> occurrences). However, if your properties have default getters and setters 
> (the ones that only get and set respectively), then you can just use a 
> mixin to avoid the redundancies:
>
>
> class Foo {
>
>   private int bar; mixin(propGetSet!(bar));
>
> }

I kind of like that.  One of the things that a true property construct would 
enable, however, is better information when introspecting types.  I know 
that in writing the binding library for MiniD (and Kirk has encountered this 
in PyD as well), I've really wished that there were some way to get the 
getter/setter(s) of a property given a name, instead of having to derive 
those types and running the risk that the class writer did something weird, 
like having two params on the setter with the second one optional.  If we 
had true properties, the language could be queried for this kind of 
information and types would be restricted.

> Most likely :(
> And it sucks because the implicit function call syntax is more problem 
> than worth.

I feel the same about const-correctness.  Sigh, whatever.

OT, you often tend to reply about two weeks late.  Why is that? 





More information about the Digitalmars-d mailing list