try: finally: question

Peter Hansen peter at engcorp.com
Thu Jul 8 13:45:04 CEST 2004


Antoon Pardon wrote:

> Op 2004-07-07, Peter Hansen schreef <peter at engcorp.com>:
> Personnaly I think that allowing += operators for unmutable
> object will lead to subtle bugs too, because if you see
> code like
> 
>   b = a
>   a += c
> 
> You don't know whether a and b are still the same object or not.

I agree with you on this one.  I don't like the way += etc
works.  Also don't use it except for integers...

> Well I think it really isn't that hard to define the behaviour
> of 
> 
> try:
> except expr1:
> finaly:
> except expr2:
> 
> to be the same as
> 
> try:
>   try:
>     try:
>     except expr1:
>   finaly:
> except expr2:

Interesting, except that this is *not* how it was implemented
before.  Why don't you write a PEP and see if you can get your
solution to the problem implemented?  Presenting it as a reason
why the previous, *different* solution should have been kept
doesn't make sense.

> However I'm not going to write a PEP. 

Dang.

> Maybe the python community should make up its mind and decide
> what it wants. A language for consenting adults or protection
> against subtle bugs.

It wants to avoid subtle bugs, but unfortunately it sometimes
makes mistakes in how it does that.

> One can argue the opposite too. Why remove it, if the subtle
> bugs can occur only in unusual cases. Let those who need it
> and know what they are doing use it. That is what I understand
> about a language for consenting adults.

You misunderstand (IMHO) what "consenting adults" is about.
I tried to make the point in a previous thread about subtle
problems with threads... some types of bugs are too subtle
to allow the consenting adults thing to hold sway.  That's
just my opinion, though.  I'm not sure it's really shared by
anyone else in the community.

Threads I happen to know very well, and know many (but perhaps
not all) of the risks involved.  I also know very many good
programmers who don't really understand threading issues
fully, yet.  Nobody knows how to test well for threading
problems, so advice like "always use a Queue" is best.

Exceptions are not generally things that are exercised by
normal application runs, or even by most unit tests (unless
you are doing test-driven development).  Therefore subtle
problems with exceptions should be "disallowed" by appropriate
language changes.

Something like += should work exactly like people expect
it to.  The fact that it sometimes doesn't means it is a
wart and we should reconsider it.  That probably won't happen,
so we're stuck with it. (?)

The thing that "consenting adults" usually applies to is
either access control (private, public, etc), or types.
Improvements in the area of types are expected in the future,
so let's ignore that one.  Access control: this is now
pretty well understood to be a "problem" that is more in
the programmer's brain than in reality.  Not having it in
the BSDM (BDSM?) style of C++ or Java doesn't lead to
subtle bugs, and the huge number of working Python programs
which have *no* access specifiers (or whatever they're called)
proves the point.

I'd go on, but thankfully for those of you reading I've got
a meeting I can just barely make it to so I'll stop here. :-)

-Peter



More information about the Python-list mailing list