4 Comments
Aug 17, 2022Liked by Kent Beck

More and more these days I find I turn to explaining function name rather than explaining variable name. So I end up writing

return widthFor(a, b, d, z) * heightFor(a, b, c, y)

Expand full comment

We can have more elements to simplify if the rules of generating these elements are pretty clear. Anyway, there are some exceptions, at least for extra-classes.

Expand full comment

So let's think about other cases.

Consider this straw-person argument: in my imaginary case, the sub-expressions are not so clear-cut and easy-to-name.

widthOrBreadth = ...big long expression...

heightOrWidth = ...another big long expression...

Is it still good to do this? Bad? Useful, because it shows there's an underlying conceptual problem?

Expand full comment

I also find that it reduces the cognitive load to understand it.

Considering the "seven plus or minus two" rule for the number of short-term memory slots, there are chances that the original return statement does not fit in short-term memory. Making it hard to understand from a quick glance so tiring, which adds up at the end of the day, but also would more easily let mistake hide in there.

What I really like, is that it gives names explaining the sub expressions, so allow thinking in terms of what they represent instead of there formula.

A sign that it would be beneficial to replace it in general cases, would be the existing `/* width * height */` comment.

Expand full comment