[Python-ideas] suggestion about the sort() function of the list instance

Stéfane Fermigier sf at fermigier.com
Wed Mar 1 12:26:48 EST 2017


Definitively not, just like M. Fowler: "Meyer likes to use command-query
separation absolutely, but there are exceptions. Popping a stack is a good
example of a query that modifies state. Meyer correctly says that you can
avoid having this method, but it is a useful idiom. So I prefer to follow
this principle when I can, but I'm prepared to break it to get my pop."

What I wanted to point out is that the paragraph quoted by Stephan ("In
general in Python (and in all cases in the standard library) a method that
mutates an object will return None to help avoid getting the two types of
operations confused. So if you mistakenly write y.sort() thinking it will
give you a sorted copy of y, you’ll instead end up with None, which will
likely cause your program to generate an easily diagnosed error.") doesn't
seem to be true in this case.

  S.

On Wed, Mar 1, 2017 at 6:23 PM, Cory Benfield <cory at lukasa.co.uk> wrote:

>
> On 1 Mar 2017, at 10:26, Stéfane Fermigier <sf at fermigier.com> wrote:
>
> Cf. https://martinfowler.com/bliki/CommandQuerySeparation.html
>
> But:
>
> >>> l = [1,2,3]
> >>> l.pop()
> 3
> >>> l
> [1, 2]
>
> => Not so true.
>
>   S.
>
>
> This is naturally a different circumstance: pop must return the element it
> popped, otherwise it would just be del. Surely you aren’t suggesting that
> pop should return self?
>
> Cory
>



-- 
Stefane Fermigier - http://fermigier.com/ - http://twitter.com/sfermigier -
http://linkedin.com/in/sfermigier
Founder & CEO, Abilian - Enterprise Social Software -
http://www.abilian.com/
Chairman, Free&OSS Group / Systematic Cluster -
http://www.gt-logiciel-libre.org/
Co-Chairman, National Council for Free & Open Source Software (CNLL) -
http://cnll.fr/
Founder & Organiser, PyData Paris - http://pydata.fr/
---
“You never change things by fighting the existing reality. To change
something, build a new model that makes the existing model obsolete.” — R.
Buckminster Fuller
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170301/9458c446/attachment.html>


More information about the Python-ideas mailing list