[Python-Dev] PEP 318: Decorators last before colon (original) (raw)
Josiah Carlson jcarlson at uci.edu
Tue Mar 30 16:11:17 EST 2004
- Previous message: [Python-Dev] PEP 318: Decorators last before colon
- Next message: [Python-Dev] Rich comparisons shortcut
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> The one major problem that i can see with this kind of > syntax is that it is a /special case/ when standard Python > block structure does not apply.
It warns you that the expressions in the "using:" block will be evaluated later -- after the "def:" block.
It still violates the standard Python block rules. "Special cases aren't special enough to break the rules."
Typically the suite (things indented after the colon) are all of the same type.
using classmethod: def funct(arg1, arg2): pass
Funny, but this isn't the case with Python anywhere else; I can have functions, class and variable definitions inside any other suite.
using classmethod: .version = 2134 .author = "anonymous" def funct(arg1, arg2): pass
gets the block structure right, but it moves true transformations (such as classmethod) too far away. (Well, unless there is only ever one decorator per function, but then this is overkill.)
No, it doesn't get the block structure right. If I were making a quick pass with my eyes through the source, I'd notice that funct was a function definition, but I wouldn't even notice the 'using' keyword or various metadata that was inserted. The wonderful thing about Python is that indentation is scope. By making this 'using' syntax not based on standard Python indentation syntax and scoping rules, you (and other suggesting this) are breaking one of the things that makes Python so damn easy to learn.
Neither I, nor anyone else who happens to need to read Python source with decorators, shouldn't have to reverse grep the source to discover what is done to this definition.
I don't know if anyone else has said it precisely like this (Ka-Ping has said it nicer), but the best thing about the decorator syntax 'c' (as referred to by Ka-Ping) is that decorators get the hell out of your way when you don't want to see them, but when you want to, are in the perfect location; the function definition. The other variants ('a', 'b', various 'using' or other syntaxes) lack these two desireable features.
The one other syntax that does seem to visually work is the use of a dictionary literal for metadata, which would suggest the use of a list literal for decorators. Both have the drawback of being currently valid syntax, and changing the meaning of currently valid syntax is generally frowned upon.
As stated previously by other people, keeping various author and version information per function definition is overkill, and I doubt would be a real use case.
- Josiah
- Previous message: [Python-Dev] PEP 318: Decorators last before colon
- Next message: [Python-Dev] Rich comparisons shortcut
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]