remaining decorator syntax options
Shalabh Chaturvedi
shalabh at cafepy.com
Tue Aug 10 17:04:34 EDT 2004
Steven Bethard wrote:
...
> *** List notation
>
> Assuming a pre-def, non-indented decorator, here are the remaining
> list notations:
>
> (1)
> <indicator> dec1
> <indicator> dec2
> <indicator> dec3
>
> (2)
> <indicator> [dec1, dec2, dec3]
>
> (3)
> <indicator> dec1, dec2, dec3
>
> I believe that version 3 was vetoed because it makes it too hard to
> break lists of decorators across lines. GvR's preference is
> definitely for 1, but that may be influenced by his decision for the
> indicator. I have a feeling that how long the indicator is directly
> affects which of (1) or (2) is preferred. Compare:
>
> @dec1
> @dec2
> @dec3
>
> vs.
>
> @[dec1, dec2, dec3]
>
> and
>
> using dec1
> using dec2
> using dec3
>
> vs.
>
> using [dec1, dec2, dec3]
>
> It seems like with a single symbol character, the non-list syntax is
> much more concise, and probably clearer. However with a keyword
> syntax the list seems the better option.
For short single names, yes. But also compare
@staticmethod
@foo.moredecoration(a="hello",b="world")
@foo.bar.baz()
def myfunc():
vs.
using [staticmethod ,foo.moredecoration(a="hello",b="world"), foo.bar.baz()]
def myfunc():
(I find the first version clearer.)
In some usability testing I did myself, I found that having one
decorator per line increased usability because:
1. All decorators line up at the left directly above the function name.
When you look at a function it's immediately visible how it is decorated
- no scanning required.
2. Moving and deleting decorators around is easy (cutting-pasting entire
lines is easier than parts of lines).
3. Adding decorators is easy (you just have to locate the start of a
line, not somewhere in the middle).
So I would not support multiple decorators per line.
Btw, I think your summary of the current state is good. However I feel a
new keyword has been pretty much ruled out as well.
Since there are a number of supporters of GvR's pie-decorator syntax
(myself being one of them), I doubt we will see anything else unless
most of us @-supporters are swayed. So I am happy, unless we end up with
the flagstaff syntax:
|staticmethod
|foo.moredecoration(a="hello",b="world")
|foo.bar.baz()
def myfunc():
pass
In which case I am happier :)
Cheers,
Shalabh
More information about the Python-list
mailing list