New in C#4

Ary Borenszweig ary at esperanto.org.ar
Thu Oct 30 04:15:08 PDT 2008


Robert Fraser escribió:
> Denis Koroskin wrote:
>> I once had the following Color class:
>>
>> class Color
>> {
>>     this (byte alpha, byte red, byte green, byte blue) { ... }
>> }
>>
>> and used it as follows:
>>
>> Color c = new Color(255, 0, 255, 0); // opaque green color
>>
>> After refactoring, alpha became last argument in ctor:
>>
>>     this(byte red, byte green, byte blue, byte alpha) { ... }
>>
>> Note that this change didn't raise any compilation error, nothing that 
>> would notify my of possible error.
>>
>> Needless to say that I didn't enjoy searching all the code that used 
>> Color to reorder parameters (although some artifact were nice :)
>> It would save me quite some time if I initialized all my instances as 
>> follows:
>>
>> Color c = new Color(alpha: 255, red: 0, green: 255, blue: 0);
>>
>> Now compiler could raise an error if parameters order was changed. 
>> Even better - compiler could reorder parameters for me automatically 
>> if given that all of them are specified and no params ommited (unlike 
>> Python). This makes code more robust to refactoring.
> 
> The first thing  I thought of when reading this is Eclipse JDT's "Change 
> Method Signature" refactoring that will look up all the calls in your 
> project & automatically reorder the parameters for you.

Me too. :-)



More information about the Digitalmars-d mailing list