[Python-ideas] Python Isn't Perfect: adding a 'gotchas' section to the tutorial

Richard Prosser richard.prosser at mail.com
Sun Dec 11 22:30:54 CET 2011


I accept your comment about the tutorial - I wasn't sure about that. Thanks.

However I still feel that there are some aspects of the language which are
not in the true spirit of Python (i.e. 'intuitive').

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 parameters.

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.

So if you or anyone else can explain exactly why such odditties are
implemented I would be grateful.

Unfortunately it is almost certainly too late to propose fixes (if
appropriate) for such quirks in Python 3 but at least I should be able
provide arguments as to why things are done the way they are.


On 11 December 2011 01:21, <python-ideas-request at python.org> wrote:

> Message: 2
> Date: Sat, 10 Dec 2011 13:34:15 -0500
> From: Ned Batchelder <ned at nedbatchelder.com>
> To: Richard Prosser <richard.prosser at mail.com>
> Cc: python-ideas at python.org
> Subject: Re: [Python-ideas] Python Isn't Perfect: adding a 'gotchas'
>        section to the tutorial
> Message-ID: <4EE3A627.8010002 at nedbatchelder.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> On 12/10/2011 9:16 AM, Richard Prosser wrote:
> > Although I love Python there are some aspects of the language design
> > which are disappointing and which can even lead to problems in some
> cases.
> >
> > A classic example is a mutable default argument having the potential
> > to produce unexpected side-effects, as a consequence of the
> > non-intuitive scoping rules.
> >
> > Another awkward 'feature' is the requirement for a trailing comma in
> > singleton tuples, due I believe to the use of expression parentheses
> > rather than (say) the use of special brackets like chevrons.
> >
> > Something that I personally wish for is the ability to declare
> > variable types 'up front' but that facility is missing from Python.
> >
> One of these things is not like the others.  Mutable default arguments,
> and singleton tuples are surprises that make sense once you understand
> things on a deeper level.  It makes sense to call them out as a
> "gotcha": a common stumbling block for learners.  But "no type
> declarations" is not a wart, it's a fundamental feature of the language
> that is immediately apparent from the first lesson.
> --Ned.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111211/28c53824/attachment.html>

More information about the Python-ideas mailing list