Michael> The "def name [modifiers]:" is unpythonic because: Michael> * It re-uses the "[]" for a completely new purpose, unrelated Michael> to lists or indexing. Not necessarily. It names a list of functions to be applied to this function to get the final definition (I'll leave it to others to figure out the order of application :-). In particular, you could probably dream up some rather "interesting" list constructors which would allow the programmer (or even the user) to modify the behavior at function definition time: def is_enabled(m, fname, tracers=os.environ.get("TRACERS", "")): "ex: TRACERS=func1:trace,func2:count_lines ; export TRACERS" return tracers.find("%s:%s"%(fname,m.__name__)) != -1 modifiers = [trace, profile, count_lines] def func1(a,b,c) [m for m in modifiers if is_enabled(m, "func1")]: ... def func2(a,b,c) [m for m in modifiers if is_enabled(m, "func2")]: ... that it would necessarily be good to always use such complex constructs, but it might provide some as-yet-unanticipated power for debugging or other magic. If you are going to add [...] as a function modifier syntax, I would argue that it should allow the full power of list (or generator) comprehensions. Michael> * It relies heavily on punctuation (the placement of the Michael> ":"). The placement of the ":" hasn't changed. It's still at the end. A list constructor was just stuffed in between the argument list and the colon. Michael> * It doesn't "read like english". No doubt, but then not everything in Python does. Michael> * There's no good way for a newbie to look it up. How about in the language reference manual section on function definitions? I don't think every bit of the language needs to be tagged with a keyword so that people can more easily search the documentation. How do people find out about operator precedence? How do people learn about function names with leading underscores or leading and trailing double underscores? The language manages to succeed even though the most frequently used function name in Python is probably "__init__" and that the most common sorts of expressions are keyword-free. A newbie won't know off-the-bat what the "__"s mean and even though non-programmers will probably never have seen the "**" operator, they still manage to figure it out. Michael> All of these would be addressed by using a keyword. The only Michael> objection seems to be "we couldn't find a word we all Michael> liked". But that's hardly a good reason to go with pure Michael> punctuation. I think another keyword would be pretty superfluous. Function modifiers would be a fairly advanced feature anyway (I personally have yet to use classmethod or staticmethod), so the extra keyword would probably be unnecessary for most people reading and needing to truly understand a bit of code. If they are deemed not all that advanced, they should probably be discussed in the tutorial. Skip
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4