What value should be passed to make a function use the default argument value?
apardon at forel.vub.ac.be
Fri Oct 6 12:57:01 CEST 2006
On 2006-10-06, Fredrik Lundh <fredrik at pythonware.com> wrote:
> Antoon Pardon wrote:
>> IMO this is a very natural thought process for a python programmer.
>> So a python programmer seeing the first will tend to expect that
>> last call to work.
> on the other hand, if a Python programmer *writes* some code instead;
> say, a trivial function like:
> def calculate(a, b):
> # approximate; gonna have to fix this later
> return a + b * 1.2
> chances are that he did *not* intend this to be called as
> calculate(a=1, b=2)
> or, for that matter,
> calculate(b=2, a=1)
> calculate(1, b=2)
Well maybe he didn't intend that, but how is the reader of the
documentation to know that? The reader can only go by how
things are documented. If those are not entirely consistent
with the intend of the programmer, that is not the readers
> just because the Python calling machinery currently happens to allow
> that. And chances are that he did *not* expect to be stuck with those
> argument names for the foreseeable future, just because someone else
> decided to interpret things in the most literal way they possibly could.
And how it the reader of the documentation to know about the
expectations of the programmer? It isn't the readers fault
if those expectations aren't easily inferred from the documenation.
> Python 2.X doesn't provide convenient support for distinguishing between
> accidental and intentional argument names when you implement a function;
> that's a wart, not a feature, and it may be addressed in 3.X.
Again that is not the fault of those that read the documentation. If
this discinction can't be easily made in python 2.X, you can't fault
the reader for coming to a conclusion that seems to follow rather
naturally from how python currently works.
More information about the Python-list