3 ms·
That hides default logic in the signature. Why would you favor that over def f(a=3, b=None): b = b or a+1 # or use a more explicit version return (a
by crystalis 16y ago
That hides default logic in the signature. Why would you favor that over
def f(a=3, b=None):
b = b or a+1 # or use a more explicit version
return (a + b) / 2
- chc 16y agoThat is code is logically convoluted — that's one reason not to love it. Why do you think is the more straightforward statement, just in general? - "Let B be one greater than A unless otherwise specified." - "We have no default value for B. If B has a value, then let B be equal to that value. If B does not have a value, then let B be one greater than A."
- sjs 16y agoBecause that can be said more succinctly. It is even easier to read as there is less to read, which I realize is mostly subjective.
- crystalis 16y agoI'm pretty sure this is the same argument used to make Perl a bad guy.
- sjs 16y agoI disagree, but we've gotten a bit off topic. I think Python's behaviour is confusing and basically never what anyone actually wants. Regardless of whether or not you can use other params in defaults, the defaults should be evaluated on each call.