[Python-Dev] Re: new syntax for wrapping (PEP 318)

Shalabh Chaturvedi shalabh at cafepy.com
Thu Feb 26 01:58:54 EST 2004


Hello python-dev people:

Just joined, intro below :)

Barry Warsaw wrote:
> I've rewritten some of my code to use both the [] and the 'as' syntax.
> Neither is ideal, primarily because the interesting information tends to
> get pushed way off to the right, where I think the eye is lazier because
> of the more ragged nature of "code right".
>
> Putting the decorator between the def and the method name actually
> doesn't look so bad to me, e.g.:
>
> def [classmethod] func(a, b, c):
>
> but I think with a longer decorator list, it might be problematic.  I
> think that one element decorator lists will be the most common use and
> in that case, I like this syntax because it almost reads like English.

I completely agree. This is the second-most elegant syntax, the
most-elegant being:

def classmethod func(a, b, c):

Has this been completely rejected? The pep's argument is it becomes
cluttered and obscure when the decorator is a function call:

def synchronized(lock) classmethod func(a):

Can we also require that decorators be identifiers only (no expressions
allowed), forcing clean looking definitions? The above would be rewritten
as:

sync = synchronized(lock)
def sync classmethod func(a):

In fact sync would probably be reused throughout the class body. This
keeps simple things simple, and complex things possible. In addition it
encourages using few decorators, keeping the def line short. And did I
mention no new keywords? The alternatives - using [], (), <> and/or
expressions - only make it more cluttered, leaving the simple (and IMO
most common) cases hard to read and write. They do provide power that is
useful for specific domains, but unnecessary for general purpose
programming. Which would be ok (since when is power a bad thing?) if it
wasn't at the cost of readability.

Cheers,
Shalabh Chaturvedi

PS: I am a software consultant and have been using Python for four years
(which includes two years of full time development :-). Needless to say,
it is my first choice for solving problems. Recently I have become more
interested in development and promotion of Python.



More information about the Python-Dev mailing list