Why return None?

Antoon Pardon apardon at forel.vub.ac.be
Fri Aug 27 05:42:08 EDT 2004


Op 2004-08-27, Paul Rubin schreef <>:
> Antoon Pardon <apardon at forel.vub.ac.be> writes:
>> but having operators like '+=' which have a different kind of result
>> depending on whether you have a mutable or immutable object is IMO
>> not such a good design and I wonder what design principle inspired them.
>
> += was added to Python fairly recently (in 2.0, I think) and there was
> a lot of agonizing about whether to add it.  It was one of those
> things like the ?: construction.  On the one hand there was the
> abstract objection you raise.  On the other hand there were lots of
> users frustrated at being unable to say v[f(x)] += 1 instead of having
> to call f twice or introduce a temp variable or something.
> Eventually, practicality beat purity.

Fine practicality beats purity, but then the proponents shouldn't
put that much weight on consistency, because practicality breaks
consistency.

In this case I think the practicality of method chaining beats
the purity of not allowing side-effects in print statements and
of having only one obvious way to do things.

I don't see that much difference in the frustration of having
to write: 

  t = f(x)
  v[t] = v[t] + 1

and the frustration of having to write

  lst = f(x)
  lst.sort()
  lst.reverse()

-- 
Antoon Pardon



More information about the Python-list mailing list