On Mon, Jul 27, 2009 at 4:34 PM, Chad
This seems to me like it adds more syntactic clutter than adding a
keyword would:

PropertyDecl:
       PropertyGetter
       PropertySetter

PropertyGetter:
       Type 'opGet_' Identifier '(' ')'

PropertySetter:
       Type 'opSet_' Identifier '(' Type ')'



Jarrett Billingsley wrote:
Nono,

<snip>

they're just functions with "magical" names.

I agree with Chad. The opGet_Xxxxx syntax is terrible, with both syntactic and semantic clutter. To whit:

1) This convention has four syntactic parts: "op", "Get|Set", "_", and an identifier. Adding a new keyword (like "property") would only add one syntactic element to the declaration.

2) A property is not an operator. So the "op" prefix is lying to you.

3) The existence of "magical" identifiers complicates the language design. Because the rules that apply to those magical identifiers is different than the rules applying to non-magical identifiers.

There's nothing wrong with the mechanics of the proposal. I especially like how it allows the getter/setter to have different protection attributes, and that it allows each function to be overridden separately. You could even implement the getter in a read-only superclass and implement the setter in a read-write subclass. Nice!

But I think the same thing can be more elegantly written using the "property" keyword:

  private int _x;
  public property int X() { return _x; }
  protected property X(int value) { _x = value; }

The only disadvantage I see there is the introduction of a keyword. And that's definitely a disadvantage. But, compared to the "op" syntax, I think it's the lesser of two evils.

--benji

Reply via email to