function with a lot of parameters --maintainability issue

Alex Martelli aleaxit at
Thu Nov 2 12:44:05 CET 2000

"Thomas A. Bryan" <tbryan at> wrote in message
news:3A0002E2.B2F24058 at
> A class might be cleaner, depending on what you're doing.  Another
> approach that might be simpler is to use keyword arguments.

Yes, but you're not using keyword-argument syntax sugar in the
following example:

> In,
> # Define it here so that func isn't so ugly
> configDict = ['a': 1, 'b': TRUE,...]
> def func(sid, dictArg):

Change this to
    def func(sid, **dictArg):
to have func take keyword-arguments.

>     myDict = configDict.copy()  # use a copy to avoid corrupting the
>     myDict.update(dictArg)      # override defaults with values passed to
>     for i in myDict.keys():
>         setVariable(sid, ... , myDict[i])
> In the main program,
> from blarblar import *
> def callYou():
>     func(sid, {'a': 1, 'b': FALSE})

Change the call to
    func(sid, a=1, b=FALSE)
if keyword-argument syntax is wanted.

> def callTwo():
>     func(sid, {'c': 'Non default'})

    func(sid, c='Non default')

> # Now, it doesn't matter whether callYou() has been called
> callTwo()

Yes, this is an important semantic characteristic of your
solution.  I'm just showing the little syntax-sugar changes
that are needed to it if one does want to use keyword
arguments -- it works just the same way!-)


More information about the Python-list mailing list