[Python-Dev] PEP 8: Discourage named lambdas? (original) (raw)
"Martin v. Löwis" martin at v.loewis.de
Sun May 4 08:13:08 CEST 2008
- Previous message: [Python-Dev] PEP 8: Discourage named lambdas?
- Next message: [Python-Dev] PEP 8: Discourage named lambdas?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I guess that's inevitable (given lambda's existence... and human nature;-) and about on the same plane as another hatefully redundant construct I find myself having to beat upon over and over in code reviews:
if : result = True else: result = False return result vs the simple "return " [[or bool() if it's actually mandatory to return a bool and can't be relied upon to produce one]].
Indeed, I think these are the same phenomenons. If lambdas where not available, people would, instead of writing
Thread(target = lambda: foo())
write
def target(): foo() Thread(target = target)
Your example above demonstrates that the boolean type is a concept that is very difficult to grasp (not the notion of boolean expressions, which are easy to understand - it's the boolean type that is difficult, i.e. that a boolean expression can be used not just in conditional statements, but also assigned to variables, returned, etc.).
When I ask students in the exam to rewrite your code above (and assuming they use Java), so that "it is a single line", they typically write
return ? true : false;
Likewise, apparently, the notion of generic callables is difficult to understand. Unless you have written it yourself, you won't recognize an expression as callable.
Regards, Martin
- Previous message: [Python-Dev] PEP 8: Discourage named lambdas?
- Next message: [Python-Dev] PEP 8: Discourage named lambdas?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]