Charles recently blogged on the topic of wonder and technology:
It’s important to maintain that sense of wonder. The net is a pretty amazing thing, held together by a bunch of people who are probably massively unappreciated in their attention to the plumbing.
This must have been resonating around the back of my brain, because it leapt to mind when Mitchell—my eight year old—reminded me of another sense of wonder, a kind of wonder all boys know at age eight . He said:
I wonder what this custard tastes like with honey-barbeque sauce in it.
And like Charles, I also conclude that it’s important to maintain that sense of wonder.
Hans Nowak and Richard Jones both had a few bones to pick with a previous post, Things That Annoy Me About Python, and left comments saying so.
Closures
When I wrote that Python has “no closures,” I was completely wrong. Thankyou to Hans for pointing this out so kindly. What I meant to say was “Python doesn’t has have Smalltalk (or Ruby or Lisp) style block-closures.” As Hans points out, Python’s approach is still quite flexible, despite the long-winded syntax.
Documentation
I also wrote that the Python documentation is “out of date”. That is wrong. the new Python 2.3 Language Reference and Library Reference manual are both up to date with new-style classes and attributes. The tutorial still neglects to mention the existence of the object class, but this is a small thing.
I had based my statement on the Python 2.2 documentation—which is out of date.
def and class Statements
In Python, def and class are statements rather than declarations, unlike Java, C++ or Pascal. I wrote that this sometimes leads to obscure bugs. Here is a simple example:
class Dog:
dogTracker = AnimalTracker()
def __init__(self):
# ... whatever ...
class AnimalTracker:
# ... whatever…
This code causes an error when the containing module is imported because the assignment to dogTracker in class ‘Dog’ references the variable ‘AnimalTracker’ which hasn’t been defined at that point.
If the assignment to dogTracker were inside the Dog init() method instead, there would be no problem because the code referencing AnimalTracker would not be executed until the init() method is called, which would not be until after the AnimalTracker
This is not an annoyance which affects me every day, but it is one that caught me in my early Python days, and one I end up explaining to people learning Python again and again. On the other hand, Richard Jones points out that Python has many anti-pitfalls for newbies.
Coding Styles
I wrote that “there is no broad agreement on Python coding style.” Integrating with code written elsewhere requres a lot of time looking up not just method names, but their exact spelling (smallCamelCase, BigCamelCase, or with_underscores). Richard points to PEP-008, probably the closest thing that Python has to a universal coding standard. But PEP-008 is not widely accepted. One does not have to go far to find code that doesn’t comply:
All of this code looks straight-forward and well written, so maintenance is not the issue here. The problems only start when trying to integrate codebases that used different standards.
It would be nice if Pythoneers could just agree on One True Coding Standard, as the Java world has done. It is both rare and frustrating to come across code Java that doesn’t largely adhere to Sun’s Code Conventions for the Java Programming Language and the AmbySoft Inc. Coding Standards for Java.
And, Finally
The annoyances I have with Python are minor. I only wrote up a few tiny whinges so that my next “Python is Wonderful” post will look balanced.