4 ms·
def foo_with_edge_case(x): if x == EDGE_CASE: return 36 return foo(x) seems clearer to me than stuffing the edge case handling into the foo
by MattHeard 9y ago
def foo_with_edge_case(x):
if x == EDGE_CASE:
return 36
return foo(x)
seems clearer to me than stuffing the edge case handling into the foo method
- oneeyedpigeon 9y agoI don't think the parent was supposed to be production-ready code, it was more illustrative of a different (more interesting, IMO) point.
- thejosh 9y agoIf only you could pattern match x in the function def, would remove the need for this whole thing.
- wruza 9y agoAside from compile-time optimization, pattern matching is just this additional if at runtime. It is questionable if pattern matches make code more readable since when you see foo(42) call and def foo(42) is defined elsewhere, you can spend some time on original function until realizing that it’s not what you’re looking for. The same for type-based and operator overloading. It only makes code beautifu^W hard to guess. Though it does look nice for fib and fac.