Daniel Keep wrote:
> 
> Walter Bright wrote:
>> The issue is what if b is a property, returns a temporary object, and
>> that temp's .c field is uselessly set to 3?
>>
>> It's a classic problem with properties that are implemented as functions.
>>
>> I don't see how C#'s special property syntax adds any value for dealing
>> with this.
>>
>> One thought I had was to simply disallow the '.' to appear after a
>> function style property.
> 
> Maybe the compiler could rewrite the above as:
> 
> auto t = a.b;
> t.c = 3;
> a.b = t;
> 
> Unless it can prove it doesn't need to.  Same solution as to the op=
> conundrum.

YES.

I'd always suspected C# properties did something like this, though it's
been so long since I've used C# now that I'm wondering if it's bad memory.

Anyhow, this is why properties must have their own semantics.  Anything
else will likely have some nasty corner case that you haven't thought of
yet.  Just bite the bullet and do this.  Put the beast to rest.

For another example

        array.length++;

becomes

        auto t = array.length;
        t++;
        array.length = t;

Even that case works just like the programmer expects.  You'd never have
to hear another n00b bitch about "array.length++; doesn't work!!11" ever
again.

Reply via email to