Cohesion with falafel and hummus
Today I wanted to cook something. What about some falafel? I dug a bit more and found a can of hummus. It made me think about cohesion.
I told myself: “Those 2 items goes well together. Maybe they should be close together”.
This is what we call “Cohesion” in software development.
When I see falafel, I don't forget I also get seasoning with it. I don't have to look for it or remember I bought some hummus. It's there!
If I see only one of them, I can lose motivation. “I need to go to the store and buy falafel” or ”I need to make my own hummus”. Sometimes I want to do it, sometimes I don't. Having them close together allows me to make quick and low energy decision.
In a codebase, the more a concept is close to another, the more we see it and options come to our mind.
In other hand if both concepts exist far away, we may rewrite the second one because we did'nt know it existed elsewhere.