Coupling and cohesion: 80% of programming
If I had to keep two ideas above all others in programming, they would be coupling and cohesion.
1 min read
“What’s the most important thing in programming?” To this question from someone just starting out, I answered without hesitation: coupling and cohesion.
Aim for low coupling
Coupling is the links between two elements. You want low coupling — minimize those links. For example, a function that validates both a postal code and a phone number creates coupling that’s too tight. Two separate functions are better.
Aim for high cohesion
Cohesion, on the other hand, should be high: grouped elements should be closely related so they work together meaningfully. Using the previous example, validating a postal code and a phone number together reflects low cohesion, because the two validations don’t share enough logical connection.
A universal lens
These ideas apply to every element in programming: functions, classes, modules, inheritance. And if you look at the SOLID principles, you’ll find they all point, directly or indirectly, back to coupling and cohesion.
Truly understanding these two principles, and knowing how to apply them, already means you’ve grasped more than 80% of what programming is.