PROPOSAL: Named method parameters (works best in conjunction with default values)
Eric Raymond
ericraymond at allocade.com
Fri Mar 27 20:59:17 PDT 2009
Named parameters work best if they are combined with default values for
parameters. With defaults, there is no requirement to supply every
parameter defined (which can be a burden as the number of arguments
increase).
For example with the following example, both param1 and param2 need to
be supplied:
public void foo(String param1, int param2) ....
foo(param1: "123", param2: 4); // OK
foo(param1: "123"); // Not OK
foo(param2: 4); // Not OK
With default values, the caller can simply pick and choose the
parameters which are of interest (and ignore the other parameters).
public void foo(String param1 = null , int param2 = 0) ....
foo(param1: "123", param2: 4); // OK
foo(param1: "123"); // OK, param2 is 0
foo(param2: 4); // OK, param1 is null
More information about the coin-dev
mailing list