Giving Complex Expressions Names [VU4]
Tip VU4
Literals aren’t the only kind of “value” that we might encounter in code. “Values” may often be computed from more complex expressions combining one or more terms with different operators. Giving names to these complex expressions is often beneficial.
See examples below:
Beyond readability, introducing intermediate variables for sub-components of a larger expression has benefits for debuggability. Many debuggers only support reliably inspecting values stored in variables, so you have no way inspecting the results of intermediate components of complex larger expressions (particularly when functions, which may have side-effects, are involved). Bugs are going to happen, and developers are going to have to step through code in a debugger for gaining ground-truth understanding. They shouldn’t have to go through extra effort like modifying code to debug something they need to.