James Harris said:
No solution would be perfect.
Well, when they added designated initialisers to the language, they could
have thrown in keyword parameters too, as it's a similar sort of thing. I
think the latter would be more useful.
How about
OpenWindow(
WIN_Width, 40,
WIN_Height, 40,
WIN_BlockPen, 1,
WIN_Title, "Simple",
WIN_IDCMFlags, CLOSEWINDOW,
WIN_Type, WBENCHSCREEN,
WIN_Flags, WINDOWCLOSE | SMART_REFRESH | ACTIVATE |
WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH |
NOCAREREFRESH,
0
);
Genuine question. Is that good/bad/mediocre?
For C it's good. I've used the same approach at some time or other (often
when needing to provide some options out of a large selection, not
necessarily when using parameters).
The disadvantages compared with proper keyword parameters:
* You need to use the mechanisms for varargs, and specially designed
function interfaces (you can't apply directly to existing functions)
* There are overheads with processing the list of pairs, and assembling the
parameters properly.
* There is no compile-time checking of parameter names and argument types,
or whether you've passed the same parameter twice for example.
* You can't mix positional and keyword parameters (except I think by
specifying a fixed number of positional parameters, although that might
depend on how varargs works, and the order they are pushed).
(Keyword parameters can be applied any function, including existing library
functions (they just need named parameters, but that can be arranged); there
are no extra overheads involved; there would be compile-time checking; and
can have positional parameters as well. There would usually also be a
mechanism to specify a default value.)