Decorator Syntax

M

Mike Patterson

In my Python class the other day, the professor was going over
decorators and he briefly mentioned that there had been this huge
debate about the syntax and using the @ sign to signify decorators.

I read about the alternative forms proposed here (http://
www.python.org/dev/peps/pep-0318/#syntax-alternatives).

Has anyone thought about just using dec to declare a decorator?

For example:
dec dec2
dec dec1
def func(arg1, arg2, ...):
pass
 
B

Benjamin Kaplan

In my Python class the other day, the professor was going over
decorators and he briefly mentioned that there had been this huge
debate about the syntax and using the @ sign to signify decorators.

I read about the alternative forms proposed here (http://
www.python.org/dev/peps/pep-0318/#syntax-alternatives).

Has anyone thought about just using dec to declare a decorator?

For example:
dec dec2
dec dec1
def func(arg1, arg2, ...):
   pass
--

dec and def look too similar. It would get confusing. Also, it
wouldn't be immediately obvious that the line is associated with the
function declaration below. The whole point in the decorators is that
it makes it easier to tell that the function is being wrapped.
 
I

Ian Kelly

dec and def look too similar. It would get confusing. Also, it
wouldn't be immediately obvious that the line is associated with the
function declaration below. The whole point in the decorators is that
it makes it easier to tell that the function is being wrapped.

Also "dec" would then have to become a keyword. Unnecessary
keywording is frowned upon because it breaks any script that happens
to use the keyword as a name, thus creating backward
incompatibilities. And I'm willing to bet that there are plenty of
scripts out there that use "dec" as a name for Decimal objects.
 
L

Laurent Claessens

And I'm willing to bet that there are plenty of
scripts out there that use "dec" as a name for Decimal objects.

You won. I owe you a beer ;)

Laurent
 
R

Rafe Kettler

In my Python class the other day, the professor was going over
decorators and he briefly mentioned that there had been this huge
debate about the syntax and using the @ sign to signify decorators.

I read about the alternative forms proposed here (http://www.python.org/dev/peps/pep-0318/#syntax-alternatives).

Has anyone thought about just using dec to declare a decorator?

For example:
dec dec2
dec dec1
def func(arg1, arg2, ...):
    pass

I personally love the @ syntax for two reasons:
1. It makes it very, very obvious that a decorator is being used
2. It feels closely tied to the function or class that it's
decorating
The 'dec' syntax isn't quite as good in those regards, IMO. It
basically looks like any other statement, which makes it less visible,
and it doesn't seem as closely tied syntactically.

Of course, that's all opinion. But what's done is done; it's doubtful
that the decorator syntax will ever change significantly.

Rafe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top