Article of interest: Python pros/cons for the enterprise

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sun Feb 24 03:08:33 EST 2008


On Sat, 23 Feb 2008 19:45:45 -0800, Jeff Schwab wrote:

> Paul Rubin wrote:
>> Jeff Schwab <jeff at schwabcenter.com> writes:
>>> One great thing about C is that
>>> a programmer can realistically hope to know the entire language
>>> definition; maybe Guido would like the same to be true of Python.
>> 
>> C is horrendously complicated, with zillions of obscure traps.  C++ is
>> even worse;
> 
> Who feeds you this stuff?
> 
> 
>> there's actually a published book specifically about C++ pitfalls.
> 
> Mercy, a whole book?

Well, that might not be "zillions", but it is sure a lot of pitfalls.


> My current favorite book of language-specific pitfalls:
> 
>      http://www.javapuzzlers.com/

I'm not sure what you are trying to communicate here.


> Wait a few years.  A Python Puzzlers book will surely be on the shelves
> eventually.

You wish.

If so, then it will either be an incredibly short book, or the language 
"Python" in 2012 will be nothing like Python now.



> Here are some of the top results when Googling "python
> pitfalls:"
> 
>      http://zephyrfalcon.org/labs/python_pitfalls.html
>      http://evanjones.ca/python-pitfall-scope.html

Yeah, let's have a look at those. From the first link:

1. Inconsistent indentation
2. Assignment, aka names and objects
3. The += operator
4. Class attributes vs instance attributes
5. Mutable default arguments
6. UnboundLocalError
7. Floating point rounding errors
8. String concatenation
9. Binary mode for files
10. Catching multiple exceptions

Ten pitfalls. You might be able to pad that out to a twenty page leaflet, 
including an index. Number ten is already gone from Python 3; numbers 7 
and 9 aren't Python specific at all; most of the others are only a 
pitfall if you come to Python thinking that Python is C or Java, or 
whatever other language you're used to.

The second link is just bizarre. It claims that Python "does not have 
nested, block variable scopes like I am accustomed to in nearly every 
other programming language I use, like C, C#, C++, Objective C, Perl, and 
Java." (Notice the common denominator?) But that's nonsense -- Python 
does have nested block variable scopes. This "pitfall", if it is one, is 
that Python doesn't create a new scope for if-blocks. Coming from a 
Pascal background instead of C, it never even occurred to me that if-
blocks could be a new scope, or that anyone would possibly want it to be.

Again, the real pitfall is not Python, but imagining that Python is C.


 
> Maybe C++ needs better pub.  The guy who wrote the first of those
> articles says elswhere on his web site:
> 
>      "My Python pitfalls article seems to be a popular read. It's
>      written from a somewhat negative viewpoint: things that can go
>      wrong. (Of course, that's useful; you're never going to do these
>      things wrong again. Right? ;-) To counter-balance this, I think
>      there should an article with a more positive viewpoint as well. So
>      I was wondering, if I could collect 10 "anti-pitfalls"; parts of
>      the Python language that are especially clever, elegant and
>      intuitive."
> 
> 
> Good luck with that.

[quote]
I've seen Python criticized as "ugly" precisely because it doesn't have a 
trick-based view of the world. In many ways, it's a dull language, 
borrowing solid old concepts from many other languages & styles: boring 
syntax, unsurprising semantics, few automatic coercions, etc etc. But 
that's one of the things I like about it. -- Tim Peters

But even given that, here's a good start, the first four things that came 
to mind:

1. Program structure follows indentation. No more wars over where to put 
the braces. The presentation *is* the structure.

2. Namespaces.

3. Generators and iterators. Especially generators.

4. Exceptions. try blocks are fast, don't be scared to use them.



-- 
Steven



More information about the Python-list mailing list