Python's "only one way to do it" philosophy isn't good?

Steven D'Aprano steven at
Thu Jun 21 12:19:48 CEST 2007

On Wed, 20 Jun 2007 17:23:42 -0400, Douglas Alan wrote:

>> But "Scheme has macros" isn't a justification for why Python should
>> have them.
> No one ever gave that justification.  The justification is that they are
> *good*.
> Macros are a way to abstract syntax the way that objects are used to
> abstract data types and that iterators and generators abstract control,
> etc.

But why is the ability to abstract syntax good?

One criticism of operator overloading is that when you see X + Y you have 
no real idea of whether it is adding X and Y together, or doing something 

Now allow syntax to be over-ridden as well, and not only can't you tell 
what X + Y does, but you can't even tell what it *means*. Maybe its a for-
loop, calling the function Y X times.

The usual response is "That's insane, no sane programmer would do that!", 
and that's true as far as it goes (except for the programmers who are 
just too clever for their own good). Nevertheless there is a real issue 
there. When I program in Python, I always know what the syntax means, 
because there is no possible way it can be changed. That's one less thing 
I have to keep in my head, one less thing to worry about.

Sometimes, more freedom is not better. If you had a language that let you 
redefine the literal 1 to mean the integer zero, wouldn't that make it 
much harder to understand what even basic arithmetic meant?

If I wanted a bondage-and-discipline language, I'd use something with 
static typing and declared variables and a compiler that made sure my 
shoelaces were tied correctly before I did anything. But I don't, I use 
Python, and I appreciate the dynamic typing and runtime errors and the 
relatively few compiler checks.

But that doesn't mean I want a language where anything goes -- there's a 
balance between too little freedom and too much. If Python became the 
sort of language where I had to think about every module imported, every 
function called, just to be sure that 1+1 would equal 2, I'd have to 
reconsider whether Python was the language for me. There would have to be 
some serious advantages before I'd be comfortable.


More information about the Python-list mailing list