Thursday, October 11, 2018
For Coupling, Ask "Is There an Hidden Relationship?"
Today's code quality question pertains to coupling: "Is there a hidden relationship?"
The most dangerous kind of coupling is that which you don't know is there. If you find yourself writing some code and you can't explain why you're doing what you're doing just by reading the code around it or the tests, you probably have implicit coupling.
So be vigilant. As you write new code, maintain old code, or review others' code, ask the question "Is there a hidden relationship?"
This is a tricky one. You're not going to catch it all the time, at first. That's okay. If you can prevent 10% of the implicit coupling you otherwise would have written or clean up 10% of the implicit coupling you otherwise would have passed by unnoticed, it's a win.