DMD 0.177 release

BCS BCS at pathlink.com
Wed Dec 13 21:00:00 PST 2006


Walter Bright wrote:
> BCS wrote:
> 
>> With constructors, it is not only simpler code, but looks like what is 
>> happening.
>>
>> struct S
>> {
>>     static S err;
>>     int k, l;
>>
>>     this(int i, int j)
>>     {
>>         k=i;
>>         l=j;
>>
>>         if(!ret.test) this = err;
>>     }
>>
>>     bool test(){...}
>> }
> 
> 
> Assignment to this inside a constructor is a mistake as it breaks the 
> assumptions the language makes about constructors.

What assumptions does it break? This would be valid:

struct S
{
     static S err;
     int k, l;
     this(int i, int j)
     {
         k=i;
         l=j;
         if(!ret.test)
         {
            this.k = err.k;
            this.l = err.l;
         }
     }
     bool test(){...}
}

and as far as I can tell, they are the same.
OK well maybe it should have been written as this:

         if(!ret.test) *this = err;
                    // ^- add this

Either way, I think the original argument still holds. The constructor 
form still looks more like what is acutely happening, and as a result 
has less of a "phantom" cost.



More information about the Digitalmars-d-announce mailing list