handling many default values

Ben Finney bignose+hates-spam at benfinney.id.au
Sat Nov 11 14:22:02 EST 2006


"Alan Isaac" <aisaac at american.edu> writes:

> There are *many* parameters, and the list can change, so I want to
> avoid listing them all in the Param class's __init__ function, using
> the strategy above.
>
> Q1: Is this approach reasonable?
>     (This is a newbie question about unforseen hazards.)
> Q2: Is it horrible design to isolate the parameters in a separate class?
>     (Comment: currently several classes may rely on (parts of) the same
> parameter set.)

It's a bad design smell to have functions that accept large numbers of
parameters, many of them optional. Such an interface is difficult to
document, maintain and test.

You should certainly be examining such code and seeing how much of it
can be implemented instead as functions with small, well-defined
parameter lists. This may mean writing more functions, or more layers
of functions, or more classes, or whatever; but having a result that
uses small, well-defined interfaces is a valuable property.

-- 
 \        "The number of UNIX installations has grown to 10, with more |
  `\     expected."  -- Unix Programmer's Manual, 2nd Ed., 12-Jun-1972 |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list