On 5/20/2014 12:30 PM, Chris Barker wrote:
     >>>> [].sort() is None
     > True
     >>>> "ABC".lower() is None
     > False

Is there a reference anywhere as to *why* the convention in Python is to
do it that way?

In short, reducing bugs induced by mutation of aliased objects. Functional languages evade the problem by prohibiting mutation (sometimes at the cost of inefficiency).

In an alternate universe, the example above might become

>>> a = []; a.sort() is a
True
>>> a = "ABC"' a.lower() is a
False

As I suggested earlier, having pure mutation methods not return anything made is easy to suggest a mutation + non-self return method, list.pop. If all mutation methods had previously returned 'self', there might have been disagreement over whether the item return should augment or replace the self return. Before you say the latter, consider the inconsistency of only sometimes returning self and the potential consistency between

>>> most, last = 'a b c'.rsplit(maxsplit=1)
>>> most, last
('a b', 'c')

>>> most, last = [0, 1, 2].pop()
>>> most, last
([0, 1], 2)

One could also consider first, rest pairings.

--
Terry Jan Reedy

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to