DIP 88: Simple form of named parameters

default0 via Digitalmars-d digitalmars-d at puremagic.com
Sun Jan 24 03:49:16 PST 2016


On Sunday, 24 January 2016 at 10:40:10 UTC, Jonathan M Davis 
wrote:
> On Sunday, 24 January 2016 at 10:14:53 UTC, default0 wrote:
>
> 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.
>
> - Jonathan M Davis

I agree that functions like that are badly designed. However they 
exist and you can't always change them.
That said, if there'd be traits for parameter names you can 
probably automate the creation of a decent struct-wrapper, making 
this a non-issue for D (you could not do that in C#, so writing 
wrappers would be a huge pain there).
Regarding the bikeshedding: I honestly don't think this increases 
the amount of bikeshedding happening. There'll always be 
bikeshedding anyways, independent of if you give many 
opportunities for it or not.

Thinking further about this, though, and being the inexperienced 
D user I am, I assume you use struct wrappers sort of like this?
ArgStruct s;
s.param1 = 12;
M(s);

If yes, consider that a named argument alternative would be far 
less noisy:
M(param1: 12);

If my code above is far more verbose than what you'd usually do 
(ie comparable to the succinctness of the named argument), can 
you please give an example?


More information about the Digitalmars-d mailing list