[Python-ideas] Python Isn't Perfect: adding a 'gotchas' section to the tutorial
tjreedy at udel.edu
Mon Dec 12 01:13:23 CET 2011
On 12/11/2011 4:30 PM, Richard Prosser wrote:
> However I still feel that there are some aspects of the language which
> are not in the true spirit of Python (i.e. 'intuitive').
While 'intuitive' may be part of the 'true spirit of Python', it is not
included in the Zen of Python, perhaps because it it so slippery and
person dependent. Python is more in tune with everyday life and
therefore with naive intuition than some other languages.
> The discussion about default mutable types is one of these. It seems to
> me that the essential problem is that of assignment in general, which (I
> believe) creates a reference on the LHS to the object on the RHS, rather
> than having a copy operation to make the two objects completely
> separate. That can be confusing in other contexts, not just with default
When an organization reassign the role 'president' to a new person, they
do not copy the person. Neither does Python. We use aliases (multiple
ways to refer to the same entity) all the time in real life.
Python is quite consistent. Expressions evaluate to objects, either
pre-existing or new. "Target = expression" binds the target to the
object resulting from evaluating the expression. "f(expression)" binds
the first parameter name of f to the expression object.
> If I am to write a 'gotchas' FAQ or whatever then I would like to
> understand the reasoning behind such design decisions but I can't find
> any 'deep' explanations at present - just several posts about people
> being puzzled! A similar comment applies to the lack of type declarations.
Both behaviors reflect the fact that Python is a named object language,
rather than a named memory block language, and that in Python types are
a property of objects rather than of names. This is similar to at least
some uses of names in everyday life. For instance, the name Buddy could
be bound by a particular person to a person, dog, other pet, story,
boat, or even a rifle.
Terry Jan Reedy
More information about the Python-ideas