DIP 88: Simple form of named parameters

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 24 02:40:10 PST 2016


On Sunday, 24 January 2016 at 10:14:53 UTC, default0 wrote:
> On Sunday, 24 January 2016 at 02:51:43 UTC, Jonathan M Davis 
> wrote:
>> On Saturday, 23 January 2016 at 14:19:03 UTC, Jacob Carlborg 
>> wrote:
>>> This is mostly to prevent ugly hacks like Flag [1].
>>>
>>> http://wiki.dlang.org/DIP88
>>>
>>> [1] https://dlang.org/phobos/std_typecons.html#.Flag
>>
>> Regardless, I for one, hope that we never have named 
>> arguments. It's just one more thing that's then part of the 
>> function's signature that you can't change without breaking 
>> code and will cause that much more bikeshedding. At least 
>> right now, parameter names don't matter much, whereas if 
>> they're part of the API, then they're open to all of the 
>> issues that function naming has.
>>
>> And while I appreciate that this DIP does not make named 
>> arguments the default behavior for a function, making it up to 
>> the library writer whether they support named arguments or not 
>> is likely to create a lot of bikeshedding and debates over 
>> whether a particular function or library should support named 
>> arguments. Personally, I'd never use them under any 
>> circumstances.
>>
>> - Jonathan M Davis
>
> So given this method:
> void M(int a, int b = 1, int c = 2, int d = 3, int e = 4, int f 
> = 5, int g = 6, int h = 7, int i = 8)
> {
> }
>
> You prefer calling it this way:
> M(5, 1, 2, 3, 4, 5, 6, 7, 23);
> As opposed to:
> M(5, i: 23);

Anyone who wrote a function like that is just plain writing bad 
code. With that many parameters, they should be creating a struct 
to hold the values. Named arguments really only seem to help in 
cases where functions are badly designed. I don't want to use 
them in my code, and I don't want to have to deal with them in 
other people's code. And as a library writer, I don't want to 
have to argue with anyone about whether the names that I picked 
for my parameters were good or not. We already get way too much 
bikeshedding over function names as it is without adding 
parameter names into the mix.

I would strongly argue that anyone who feels the need for named 
parameters should rethink how they're designing their functions.

- Jonathan M Davis


More information about the Digitalmars-d mailing list