News for hackers. Stuff that matters.
Re:Local Variables as Accidental Breadcrumbs for Faster Debu... by mkehrt on Friday October 11, 2024 @01:16PM (#41811344)
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.

There are no comments on this comment yet.