Why are functions atomic?

Michael michael.forbes at gmail.com
Mon May 7 20:35:31 EDT 2007


On May 4, 7:54 pm, a... at mac.com (Alex Martelli) wrote:
> Michael <michael.for... at gmail.com> wrote:
> > Thus, whenever I need to pass information to a function, I use default
> > arguments now.  Is there any reason not to do this other than the fact
> > that it is a bit more typing?
>
> You're giving your functions a signature that's different from the one
> you expect it to be called with, and so making it impossible for the
> Python runtime to diagnose certain errors on the caller's part.
...
> The miniscule "optimization" of giving a function an argument it's not
> _meant_ to have somewhat breaks this part of the "Zen of Python", and
> thus I consider it somewhat unclean.

That is a pretty good reason in some contexts.  Usually, the arguments
I pass are values that the user might like to change, so the kwarg
method often serves an explicit purpose allowing parameters to be
modified, but I can easily imagine cases where the extra arguments
should really not be there.  I still like explicitly stating the
dependencies of a function, but I suppose I could do that with
decorators.

Thanks,
Michael.




More information about the Python-list mailing list