Properties: a.b.c = 3

Chad J chadjoan at __spam.is.bad__gmail.com
Wed Jul 29 15:27:09 PDT 2009


Steven Schveighoffer wrote:
> On Wed, 29 Jul 2009 15:01:47 -0400, Chad J
> <chadjoan at __spam.is.bad__gmail.com> wrote:
>>
>> So we could have semantics that actually work, but you don't want them
>> because, oh man, my code might have to do a few more assignments.  A few
>> assignments.  Really?!
> 
> Hold on a second, don't we already have semantics that work?  I mean we
> can already write
> 
> auto tmp = a.b;
> tmp.c = 5;
> a.b = tmp;
> 
> So what is the big deal?  If your widget.position is a struct with
> fields, then the compiler should be able to detect the error (not yet?)
> and tell you "no, it's an rvalue."
> 
> Why should the compiler make assumptions about the logic of code when
> they may be incorrect, and might be better optimized by a person?
> 
> I would think that macros would be a better fit for this.
> 
>> Assignments aren't even that expensive!  They are one of the easiest
>> operations your CPU can perform!  It's like you'll have a few more MOV
>> operations laying around in the worst case.
> 
> It's not the assignments, its the idea that the compiler should
> workaround the poor design of the code by writing possibly incorrect
> code.  I'd rather be in charge of the design of my code, thanks.  If the
> compiler help prevent me from making obvious *provable* mistakes, then
> fine.  If it makes decisions that might be based on incomplete
> information, I don't want that.
> 
> -Steve

Ah, well that argument has some weight.

I'd like to know though, what assumptions does this make about the code?
 Why might they be incorrect?

Those are not rhetorical questions.  Just to be clear, I acknowledge
that me saying "it is unlikely to produce incorrect code" is a poor
argument for a feature.  My intent here is to find out what exactly is
wrong with the proposed transformation.

If the compiler /knows/ that something being used is a property, I just
don't understand how that information is incomplete.

Also macros aren't a good fit for this because they aren't going to
exist in D2, or necessarily ever.  Well, properties may not pop up in D2
either, but if they're going to happen it'd be nicer if they did.



More information about the Digitalmars-d mailing list