Software Design: Tidy First?

Share this post

User's avatar
Software Design: Tidy First?
Cohesion

Cohesion

Kent Beck's avatar
Kent Beck
Nov 01, 2022
∙ Paid
40

Share this post

User's avatar
Software Design: Tidy First?
Cohesion
6
Share

We want to change a couple of lines in the middle of a big long function. First we extract a helper function of just the lines we want to change. Then we change those lines. Then we inline the helper function back into the original function. And this was good technique. What just happened?

Finally, we come to the topic that took me the longest time to understand well enough to explain. I understood the definition of cohesion just fine, I just couldn't articulate why it was important, why more cohesion is generally better. You can tell me at the end of the chapter if I got it.

We'll start by assuming that some coupling is inevitable. Perhaps we chose a coupled design on purpose because of discounted cash flows. Perhaps we don't know how to eliminate coupling. Our design skill & experience isn't up to the task. Perhaps we started making a change that uncovered unsuspected coupling. Anyway, we have some coupling and we're going to pay the price of it the next time we want to change the behavior of the system.

What can we do?

Walking around a messy farmyard, you have to watch every step you take. What can we do? Put all the manure in one pile. That's what we do with cohesion--put everything that changes at the same time in one place.

This post is for paid subscribers

Already a paid subscriber? Sign in
© 2025 Kent Beck
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share