Message: 3

Date: Fri, 25 Aug 2006 15:28:46 +0200

From: "Fredrik Lundh" <[EMAIL PROTECTED]>

Subject: Re: Consistency in Python


Brendon Towle wrote:


So, my question is: Someone obviously thought that it was wise and

proper to require the longer versions that I write above. Why?


a) maybe they had a working carriage return key ?


Riiiiight. Now that we've got the "Frederik gets sarcastic with a relative Python newcomer" bit out of the way, is there an actual *answer* somewhere in the community?


b) http://pyfaq.infogami.com/why-doesn-t-list-sort-return-the-sorted-list

   (this also explains how to handle your specific use case)


Well, I posted working code, so I thought it should have been obvious that I knew how to handle my use case, and was (am) looking for a language-design level answer as opposed to a working-code level answer. Besides, the article above (although useful *and* freshly modified) doesn't explain how to handle the use case I posted with append(), or the ones I didn't post with extend(), insert(), remove(), dict.update(), and a bunch of others I can't think of off the top of my head.


c) in general, mutating *and* returning may be confusing; consider:


    lst = [1, 2, 3]

    for item in lst.reverse():

        print item

    ... some other code ...

    for item in lst.reverse():

        print item


I guess I have three responses to this. The first is that generations of Lisp programmers seem to have handled mutating *and* returning just fine for about the last 50 years; maybe it really isn't all that hard. ("Always know where your CONS cells are coming from." is pretty ingrained in my programming DNA; the Python analog isn't hard.)

My second response is that if "... some other code ..." is so long and involved that you've forgotten that you already reversed lst, then your function probably needs to be refactored and/or rewritten.

My third response is that it's *always* possible to shoot yourself in the foot. Protecting a naive user from one particular metatarsal projectile insertion at the expense of letting the power-user write more concise code seems a bad tradeoff to me -- but, I'm not involved with Python design, which brings me back to my original question above. Anyone?

B.

--
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie Learning, Inc.
The Cognitive Tutor Company ®
Helping over 375,000 students in 1000 school districts succeed in math.


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to