LangWart: Method congestion from mutate multiplicty

Mark Janssen dreamingforward at gmail.com
Sun Feb 10 19:45:03 CET 2013


On Sun, Feb 10, 2013 at 5:30 AM, Oscar Benjamin
<oscar.j.benjamin at gmail.com> wrote:
> On 10 February 2013 04:53, Mark Janssen <dreamingforward at gmail.com> wrote:
>> I have to agree with Rick, I think requiring the user to explicitly
>> create a new object, which is already a good and widely-used practice,
>> should be the Only One Way to Do It.
>
> Why should I copy a potentially large data structure just to iterate
> over it in reverse order? And why on earth would you want to remove
> the more efficient ways of doing this?

You're right.  I responded too fast. I think reversed() and sorted()
might be the only legit methods in this regard and I thank Steve
D'Aprano for pointing that out.

But Rick still has a valid point: it should not be taken as a general
practice.  The point, as I see it, is that there's no clear,
documented standard on the "right way" for people to think about the
issue.  The existence of sorted() and reversed() actually *misinform*
programmers as if this is the best practice.  It isn't, it just that
these are very special cases (one for a real machine efficiency and
one for a very common "user efficiency") and there should probably be
documentation to make that clear, so programmers don't start going
that direction.  I don't think there are other cases where such an
idiom would be recommended.

Mark



More information about the Python-list mailing list