4 ms·
I strongly believe nested expressions increase cognitive overhead. Between the two examples in the blog post def calculate_something(): big_number = ge
by mkehrt 2y ago
I strongly believe nested expressions increase cognitive overhead. Between the two examples in the blog post
def calculate_something():
big_number = get_big_number()
small_number = get_small_number()
return math.sqrt(big_number - small_number)
vs
def calculate_something():
return math.sqrt(get_big_number() - get_small_number())
I'll pick the first one every time. This is a bit of an extreme example, but our languages provide us with the ability to extract and name subexpressions, and we should do that, rather than forcing people to parse expression trees mentally when reading code.