DIP 1019--Named Arguments Lite--Final Review
Ethan
gooberman at gmail.com
Sat Aug 24 22:24:44 UTC 2019
On Saturday, 24 August 2019 at 13:57:17 UTC, bachmeier wrote:
> Maybe an example will make my point more clear. You start with
> this:
>
> FooParams params;
> params.x = 4;
> params.y = 8;
> params.z = 9;
> params.screen = scr1;
> params.widget = wg2;
> params.options = opts;
> params.menu = menu3;
> foo(params);
>
> Then you change a single parameter and call foo again:
>
> params.x = 5;
> foo(params);
>
> It's crystal clear what is the difference in those two calls to
> foo. No need to parse a large list of arguments and hope you
> get right which parameters changed and which didn't.
While we're all throwing around overly complicated examples that
distract from the need for named arguments, here's another:
void func( int a, float b, string c, int d, double e )
{
import std.stdio : writeln;
writeln( a, ", ", b, ", ", c, ", ", d, ", ", e );
}
struct FromTuple( T... )
{
T vals;
}
int main()
{
static if( is( typeof( func ) Params == __parameters ) )
{
FromTuple!Params p = { 1, 2.0f, "3", 4, 5.0 };
func( p.tupleof );
p.tupleof[ 2 ] = "three";
func( p.tupleof );
}
return 0;
}
-----
Both the original example and the quoted example are belabored to
prove a point, and hey, turns out programmers can do tons of
weird stuff that makes code hard to read but still works
perfectly.
Didn't they teach anyone about API complexity in compsci 101?
About how adding a struct means you now need to read multiple
places in source to understand how to use something?
But now I'm digressing. The point of named arguments is not to
dictate programming standards. It is simply to make overriding
defaults easier. And you can look no further to my talk at DConf
this year to see what I think of providing default behavior with
overrides.
-----
Also, I agree with the sentiment in general in this thread. Don't
half-bake the implementation because you think it'll get accepted
and in use quicker. Do it properly, basically just like Walter's
suggestions.
More information about the Digitalmars-d
mailing list