DIP23 draft: Fixing properties redux

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Feb 3 06:35:26 PST 2013


On 2/3/13 3:50 AM, Jonathan M Davis wrote:
> On Sunday, February 03, 2013 03:16:08 Andrei Alexandrescu wrote:
>> Destroy.
>
> Overall, it looks good. It sounds like it's basically arguing for fully
> implementing @property as intended save for the fact that parenless function
> calls on normal functions are allowed. And that's pretty much what I've been
> arguing for during all of this latest @property debate.
>
> However, one issue that I'm concerned about with regards to properties which
> hasn't really been discussed much and which doesn't have a whole lot to do
> with how they're declared (but rather the syntax of how they're used) is how
> to handle symbol clashes. For instance, if you have the free function
>
> auto prop(int[] arr) {...}
>
> in module a.b.c, and you have
>
> auto prop(int[] arr) {...}
>
> in module a.d.e, how do you deal with code that does
>
> import a.b.c;
> import a.d.e;
> auto var = arr.prop;

First off, defining a top-level property ought indeed to have an air of 
definitive-ness, so this is good. It also illustrates that defining 
top-level properties should be rare.

To fix this, no need to add syntax:

import a.b.c;
import a.b.c : prop1 = prop;
import a.d.e;
import a.d.e : prop2 = prop;

auto v1 = arr.prop1; // goes to a.b.c.prop
auto v2 = arr.prop2; // gies to a.d.e.prop


Andrei


More information about the Digitalmars-d mailing list