Decorator Syntax

Discussion in 'Python' started by Mike Patterson, Mar 22, 2011.

  1. 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
     
    Mike Patterson, Mar 22, 2011
    #1
    1. Advertising

  2. On Mon, Mar 21, 2011 at 8:59 PM, Mike Patterson
    <> wrote:
    > 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.
     
    Benjamin Kaplan, Mar 22, 2011
    #2
    1. Advertising

  3. Mike Patterson

    Ian Kelly Guest

    On Mon, Mar 21, 2011 at 7:31 PM, Benjamin Kaplan
    <> wrote:
    > On Mon, Mar 21, 2011 at 8:59 PM, Mike Patterson
    > <> wrote:
    >> 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.


    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.
     
    Ian Kelly, Mar 22, 2011
    #3
  4. >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
     
    Laurent Claessens, Mar 22, 2011
    #4
  5. Mike Patterson

    Rafe Kettler Guest

    On Mar 21, 8:59 pm, Mike Patterson <> wrote:
    > 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
     
    Rafe Kettler, Mar 22, 2011
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sandy Norton

    tweaking @decorator syntax

    Sandy Norton, Aug 4, 2004, in forum: Python
    Replies:
    14
    Views:
    490
    Dave Brueck
    Aug 6, 2004
  2. Delaney, Timothy C (Timothy)

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

    Delaney, Timothy C (Timothy), Aug 5, 2004, in forum: Python
    Replies:
    16
    Views:
    566
    =?ISO-8859-1?Q?I=F1igo?= Serna
    Aug 6, 2004
  3. C. Barnes

    Decorator syntax

    C. Barnes, Aug 5, 2004, in forum: Python
    Replies:
    23
    Views:
    743
    Hallvard B Furuseth
    Aug 8, 2004
  4. Sakesun Roykiattisak
    Replies:
    1
    Views:
    244
    Christopher T King
    Aug 5, 2004
  5. glomde
    Replies:
    5
    Views:
    525
    glomde
    Mar 29, 2007
Loading...

Share This Page