Passing function parameters by name

Leandro Lucarella llucax at gmail.com
Thu Dec 6 06:08:58 PST 2007


Bill Baxter, el  6 de diciembre a las 16:58 me escribiste:
> 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.

I don't see what's the big problem with named parameters being part of the
API (when, by convention, you are told so). This is widely used on Python
and works just great and it's damn useful.

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
A can of diet coke will float in water
While a can of regular coke will sink



More information about the Digitalmars-d mailing list