Passing function parameters by name
Bill Baxter
dnewsgroup at billbaxter.com
Thu Dec 6 07:00:42 PST 2007
Leandro Lucarella wrote:
> 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.
In Python you cannot overload functions based on argument types.
Keyword arguments help to fill the void that leaves. So C++ and D don't
need keyword args quite as badly as Python.
Also a D implementation probably would lack many of the features of
Python's keyword args. I doubt you would be able to do things like
passing an AA as a set of keyword arguments.
I think in the end this is a feature that would be nice but
A) probably needs to be designed as part of the language from the
beginning.
B) needs to be a pet peeve of the person writing the compiler.
--bb
More information about the Digitalmars-d
mailing list