Staying up to date with good practices in software can be difficult. What was a good practice only a moment ago has fallen out of favour replaced by something leaner, more agile and completely incompatible with the way we used to do things. While it’s great for all those guys who need ways to fill time between giving conference talks, we mere mortals have things like clients, bosses, legacy code and less than stellar teams to deal with.
So, I believe an easy win is in order. Presenting, the data clump.
“Whenever two or three values are gathered together – turn them into a $%#$%^ object.”
— Martin Fowler
So, what is a data clump?
Whenever the same variables are being passed around together, it’s generally because they’re related. This sort of implicit relationship means something within our code, it represents a “thing”. The problem with this is, we want our code to be explicit, no muddied waters, no things that aren’t things but really are things. Data clumps make code harder to understand, harder to change and as a result, harder to live with.
Awesome, now what?
Work out what the implicit relationship between the variables is, throw them in a meaningful class and marvel at your cleaner, explicit code.
Easy win, you say?
You only need to do this once and you’ll see the benefits. Do it twice and suddenly it starts to jump off the screen at you. Keep doing it and it becomes a habit that makes you a way better developer.