DIP4: Properties

Michiel Helvensteijn m.helvensteijn.remove at gmail.com
Sat Jul 25 03:10:09 PDT 2009


Daniel Keep wrote:

> Basically, the idea is that this:
> 
> interface I
> {
>     int foo();
>     int foo(int);
> }
> 
> becomes:
> 
> interface I
> {
>     int opGet_foo();
>     int opSet_foo(int);
> }

It's a little better. But there's still ambiguity:

interface I {
    int foo;
    int opSet_foo(int);
}

foo = 5; // which foo is used?

To fix that one, you need to report an error when both a var and a property
of the same name are declared. Even though they don't have the same name in
the interface.

interface I {
    int opGet_foo();
    void delegate() opGet_opGet_foo();
}

auto x = opGet_foo;

Is that the function or the property? Well, perhaps this is not an actual
ambiguity in D. But it sure isn't pretty:

auto x = opGet_foo; // it's the property
auto x = opGet_foo(); // it may be either?
auto x = &opGet_foo; // it's the function

I just don't understand this resistance against a dedicated property syntax.

-- 
Michiel Helvensteijn




More information about the Digitalmars-d mailing list