Passing function parameters by name

Bill Baxter dnewsgroup at billbaxter.com
Wed Dec 5 23:58:32 PST 2007


Janice Caron wrote:
> On Dec 5, 2007 1:48 PM, renoX <renosky at free.fr> wrote:
>> I could ask the opposite question: why should we restrict the API to the function and object name instead of using the full data that we have?
> 
> I often write constructor functions which look something like this
> 
>     this(int x_, int y_, int z_)
>     {
>         x = x_;
>         y = y_;
>         z = z_;
>     }
> 
> If parameter names were part of the API, then anyone calling my code
> would have to refer to those constructor parameters as x_, y_ and z_,
> complete with trailing underscores
> 
> Of course, I could go back and change all my code to
> 
>     this(int x, int y, int z)
>     {
>         this.x = x;
>         this.y = y;
>         this.z = z;
>     }
> 
> but that would be a lot of code to change, and it might break calling code!
> 
> 

That's why any named parameter proposal is going to have to flag the 
named parameters somehow.  Non-flagged parameters will continue to 
behave as always.

--bb



More information about the Digitalmars-d mailing list