Decorator syntax (was Re: PEP 318 - PyFIT comments)

Steven Bethard steven.bethard at gmail.com
Thu Aug 5 12:53:09 EDT 2004


Istvan Albert <ialbert at mailblocks.com> wrote in message news:<lN6dnZpvi_ErB4zcRVn-rg at giganews.com>...
> I always felt that Java was too rigid and that any kind
> of loosening feels like a breath of fresh air.

Yeah, I felt the same way.  I really like that Python hasn't been
deathly afraid of backwards incompatibility, at least when it was
minor and introducing the backwards incompatibility made the language
cleaner and more powerful.

The whole @ syntax reminds me of Java's : syntax for their enhanced
for-loop. From http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat:
"Many developers are asking why they didn't add the foreach and in so
that we can write:
    foreach (element in collection)  
The fact of the matter is that adding new keywords to a language such
as Java is quite costly. In addition, it wouldn't be compatible with
existing source code that uses the in keyword, for example, as in
System.in. So the whole idea is just to keep things
upwardly-compatible."

These are, of course, the standard reasons against introducing new
keywords, and the same reasons that Python tries not to introduce them
unnecessarily. Still, I think, for example, the 'yield' generator
syntax (which was introduced relatively recently) is much clearer than
doing something strange with punctuation would have been.  I guess I
just don't see why decorators merit strange punctuation when
generators didn't...

(Notice that if Java's 'foreach' discussion came up in Python --
assuming Python didn't already have the 'for' construction -- the
'foreach' keyword would probably have been added without hesitation
because it would be quickly deemed a very minor backwards
incompatibility.)

Steve



More information about the Python-list mailing list