H
hank lawson
When designing a function it is important to order the parameters in
order the expected probability that they must deviate from their
default values. However, when more parameters are needed, one
inevitably runs into cases where some parameters should be set with
non-default parameters while the preceeding parameters should still
use default values.
For example, consider the following function:
void func( int a, int b, int c = 0, int d = 1, int e = 2, int f = 3 )
{
....
}
The programmer may need to write:
func(a,b,0,1,2,0);
which can become inconvenient because it requires filling in all the
default values, which is cumbersome and increases the chances of
bugs.
A better and more flexible solution for passing parameters would be to
allow syntax such as the following:
func(a,b,f=0);
In this case, all parameters assume their default values except for
f. The notation is not ambiguous and is easy to understand. It is
also simple for the resolution to be evaluated statically so there is
no loss of runtime performance.
Moreover, it makes the code more flexible because the function can be
refactored by changing the order of unused parameters without breaking
the calling code.
order the expected probability that they must deviate from their
default values. However, when more parameters are needed, one
inevitably runs into cases where some parameters should be set with
non-default parameters while the preceeding parameters should still
use default values.
For example, consider the following function:
void func( int a, int b, int c = 0, int d = 1, int e = 2, int f = 3 )
{
....
}
The programmer may need to write:
func(a,b,0,1,2,0);
which can become inconvenient because it requires filling in all the
default values, which is cumbersome and increases the chances of
bugs.
A better and more flexible solution for passing parameters would be to
allow syntax such as the following:
func(a,b,f=0);
In this case, all parameters assume their default values except for
f. The notation is not ambiguous and is easy to understand. It is
also simple for the resolution to be evaluated statically so there is
no loss of runtime performance.
Moreover, it makes the code more flexible because the function can be
refactored by changing the order of unused parameters without breaking
the calling code.