Martelli's response. ;-)
---------- Forwarded message ---------- From: Alex Martelli <[EMAIL PROTECTED]> Date: Sun, May 4, 2008 at 2:36 PM Subject: Re: [Edu-sig] How does Python do Pointers? To: Anna Ravenscroft <[EMAIL PROTECTED]> Cc: [email protected] With thanks to Anna for forwarding this... > From: David MacQuigg <[EMAIL PROTECTED]> ... > Note that Martelli says "all argument passing in Python is by value" > (Python in a Nutshell, p.74), but I think this may be an error. Taken completely out of context, it might well be, because of the connotations often carried by the "by value" tag; if you however read the whole paragraph (just six short lines) you'll also see "Python passes the object itself, not a copy" which should abundantly suffice to dispel the mistaken belief that "by value means a copy". Within six short lines, I can't cover all the permutations and nuances that might best teach this issue to students coming from many different languages. Somebody coming from Java (perhaps the most popular first-language these days) has the least need for clarification, as I might basically say "it's just like in Java" (perhaps adding "without the complications and exceptions whereby e.g. int values appear to be treated differently";-). See for example http://javadude.com/articles/passbyvalue.htm -- "Java is Pass-by-Value, Dammit!" by Scott Stanchfield -- I do agree with the "Dammit!" part at least;-). A similar position is expounded at http://www.javaranch.com/campfire/StoryPassBy.jsp . Somebody coming from Fortran or Basic (still surprisingly popular first-languages, even though dated) needs most hand-holding, because they're used to think in terms of "passing a variable" rather than "passing a value". C of course is thoroughly by-value BUT with the added twist of an implied copy at each argument-passing (or assignment -- identical semantics to argument passing of course). (Scott would disagree as he claims that by-value MEANS copy -- but he also says Java has pointers, "Dog d;" declares a POINTER to a Dog, etc...). To somebody knowing only C, I might explain that "everything in Python is a pointer" (on which you however cannot perform pointer-arithmetic), much like the above Java articles explain things (but without the need to mention 'int' as somehow distinguished); or I might say a bit more precisely that every NAME is a pointer, and also ITEMS in containers are pointers. So argument passing (and assignment) most definitely ARE by value -- but of course, value of the POINTERS (_those_ pointers get copied around -- but the copy of a pointer points to the same object as the original pointer!), because that's what names always are in Python. Alex -- cordially, Anna -- Walking through the water. Trying to get across. Just like everybody else. _______________________________________________ Edu-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/edu-sig
