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

Neil Cerutti horpner at yahoo.com
Thu Jun 21 16:20:24 EDT 2007


On 2007-06-21, Douglas Alan <doug at alum.mit.edu> wrote:
> Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> writes:
>> On Wed, 20 Jun 2007 17:23:42 -0400, Douglas Alan wrote:
>>> 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?
>
> It allows the community to develop language features in a
> modular way without having to sully the code base for the
> language itself.  

That's not an advantage exclusive to macros, though.

Some time last week I found myself writing the following thing in
Python:

def do_until(body, test):
  body()
  while not test():
    body()

I don't remember why I thought I needed it; it had to do with
getting really annoyed with the code repetition needed for
certain kinds of while loops in Python.

I deleted it right after I tried to use it the first time. Using
it is more cumbersome than simply repeating myself, due to syntax
limitations of Python.

Until iterators came along there wasn't a good, Pythonic
solution. The lack of a syntax-extension facility in Python meant
everyone had to wait until iterators were finished.

But today there *are* a few syntax extension facilities in
Python, notably descriptors, upon which Python's object system is
based.

And other, more bizarre syntax extensions have been perpetrated.
mx.TextTools uses Python tuples to write a completely different
programming language.

> A prime example of this is how CLOS, the Common Lisp Object
> System was implemented completely as a loadable library (with
> the help of many macros) into Common Lisp, which was not an OO
> language prior to the adoption of CLOS.

Is there a second example? ;)

Seriously, maybe Python looks like 'blub' (thanks, Paul Graham),
to the skilled Lisp user, but it makes a lot of other languages
look like 'blub', too, including, sometimes, Lisp: Lisp has to
'blub' generators.

-- 
Neil Cerutti



More information about the Python-list mailing list