DEV Community

Cover image for Piece of wisdom — Data clump
Lucas Fernandes
Lucas Fernandes

Posted on • Edited on

Piece of wisdom — Data clump

Don’t know what it is? Data clump is easy to identify and a good example of code smell to start refactoring your code.

Wait… What? A quick definition

Is called data clump when you have the same pair of arguments/parameters that you pass together all the time.

That is a code smell and a strong indication that you should extract an object to hold those values instead. A simple way to test if you have a data clump is to remove one of the pieces of arguments and see if the remaining one still makes sense. If these things are going to coexist and have an implicit reliance between them, then it is better to extract them into a named object.

This approach also saves you time when explaining your code to someone else. For instance, imagine that you have a start_date and an end_date scattered throughout your code. You would have to constantly explain, "Well... we always have a start date and an end date to begin with."

Therefore, when you have something implicit in your code that can be made explicit by extracting them, it will always be a significant advantage.

Top comments (0)