@property - take it behind the woodshed and shoot it?

kenji hara k.hara.pg at gmail.com
Fri Jan 25 00:43:39 PST 2013


2013/1/25 Walter Bright <newshound2 at digitalmars.com>

> On 1/24/2013 5:15 PM, kenji hara wrote:
>
>> 1. Optional parentheses for normal functions should work shallowly IMO.
>> 2. Optional parentheses for property functions should not work. Applying
>> () for
>> property function name always applied to its returned value.
>>
>> #1 is a ratification of current behavior. It allows the combination of
>> UFCS and
>> removing redundant ()s.
>> #2 is a breaking change. If we need it, community consent is required.
>>
>
> There is a way to do #2 without breaking existing code.
>
> Create a new property attribute, say, @prop. Imbue it with the new
> behavior. Leave the old @property as it is, and let it cycle through the
> usual warning, deprecation, removal process.
>

Instead, we can simply change the semantic behavior, when -property switch
is specified.
Because -property switch should have been used for enabling "experimental
feature".

In phobos, we need to care the semantic change by adding `static if`
branches.
By the following code we can detect whether the -property switch is really
specified or not.

enum enforceProperty = !__traits(compiles, {
    int prop(){ return 1; }
    int n = prop;
});

Kenji Hara
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130125/f2f137c6/attachment.html>


More information about the Digitalmars-d mailing list