DMD 0.177 release

Burton Radons burton-radons at smocky.com
Sat Dec 9 18:44:11 PST 2006


Walter Bright wrote:
> Jarrett Billingsley wrote:
>> What is the TRUE reason you don't want to give structs ctors?  I don't 
>> want to know why static opCalls are good, but why ctors are bad. 
> 
> Constructor:
> 
>     S(v);
> 
> static opCall:
> 
>     S(v)
> 
> What's the difference? I just don't see the point for adding constructors.

Here's the difference:

     struct S
     {
         this (int x)
         {
             w = calculate_something (x);
         }

         this (int x, int y)
         {
             this (x);
             z = calculate (y);
         }
     }

     struct S
     {
         static S opCall (int x)
         {
             S result;
             result.build (x);
             return result;
         }

         static S opCall (int x, int y)
         {
             S result;
             result.build (x, y);
             return result;
         }

         private void build (int x)
         {
             w = calculate (x);
         }

         private void build (int x, int y)
         {
             build (x);
             z = calculate (y);
         }
     }

Look at all that waste! More than 50% of the code there is just 
restating things. This was much harder to write, is harder to maintain, 
and has granted us no benefits whatsoever.



More information about the Digitalmars-d-announce mailing list