Purely emotional perspective

Peter Hansen peter at engcorp.com
Mon Aug 9 12:03:35 EDT 2004


Jeffrey Froman wrote:

[...]
> Now come decorators, introducing a non-alphabetic symbol (instead of say, a
> new keyword), and worst of all for readability, they come *before* the
> function declaration that they supposedly decorate.
> 
> I understand that doing things this way has certain technical advantages,
> but this is the first time I (in my short history with python) have noticed
> readability being sacrificed for any reason. 

I think those pushing the syntax with decorators *before* the function
def believe that *that approach* provides greater readability.  This
isn't an argument about whether or not decorators should be readable,
but about what constitutes readability.  Obviously this is largely a
matter of opinion.

I think putting them before the def right now is probably going to
be seen by those folks as more readable, largely because they are
not used to having decorators at all, so having them stand out right
up front seems best.

This is like the third, center brake light on cars though --
once every car had them, they stopped standing out quite so
much, but it's too late to remove them now.

After a while, when everyone is used to decorators, it won't
be important to have them way out front like that, and they
could just as well, and perhaps more readably (at that time),
be moved to after the def.

Unfortunately, whatever we start with will stick, so they
will always be out front even though the advantages of that
position will have evaporated.

I say look to the future and realize that after a period of
adaptation, we'll all be just as capable of spotting decorators,
especially if they are still @ or | prefixed, if they come
after the def, as in list-after-def or as in this:

     def func(some, arguments, that, might=span,
         multiple=lines):
         | staticmethod
         | foobarbaz(x=5)
         | doc('''A sample function''')
         # and the body goes here

Yes, I know, people might think those lines are executed
in the body of the function, every time through.  Well, those
people obviously didn't notice the decorator syntax, or read
about decorators, so it's not important whether or not they
think that, because they clearly won't understand anything about
the function at this point.

Those who know about decorators will know, as with some of the
other warts of Python, that they are executed *after* the
function is defined, not on execution.

-Peter



More information about the Python-list mailing list