On Saturday, 23 March 2013 at 08:20:19 UTC, J wrote:
On Saturday, 23 March 2013 at 05:43:22 UTC, J wrote:
auto s=callNamed!(fun,`x,y`)(10,20);

Thanks, but this is a non-solution.

The name must be next to the value ( x=10, y=20), so they it will scale from 2 to 7 to 17 arguments and maintain readability.

For a use case, compare this call

reflectAndTranslate(2, 4, 5, 6, 1, 2, false, true, 15, false, true, false);


Quick, without looking at the docs, what does the false after 15 do?

It's very hard to tell. Compare that to:


reflectAndTranslate(x=2, y=4, z=5, offset=6, alpha=1, beta=2, invert=false, twist=true, colorBrush=15, stideReduce=false, bindMatrix=true, slow=false);


It's self documenting.

I'd argue that with or without named parameter, that code is ugly as hell.

First, boolean can be replaced by enums for great benefice. Secondly, the usage of struct would also improve things quite a lot (x, y, z) is a point or a vector or something.

At the end, it is about giving semantic to your code.

BTW, monadic style named parameters have been proposed earlier, and I have to say this is really nice.

Reply via email to