Thursday, September 12, 2013

say no to "common'ers"

let's take a bet. I say your test suite have any of the following as name of the class, file or folder
  • Common*
  • Helper*
  • Generic*
  • Utils
Gotcha! And if I were true, then you are heading your suite to a death march.

I would relate any such "file or folder"  to a lazy bachelor's apartment table or shelf. That is where we can though whatever we want to through, it will happily hold it. If you want to find something you would spend lot time in searching for it, and you may or may not find it. And that would make the place look messy.

Let's take an example. Assume we have file read and file write operation in multiple places in our project. We would extract these operations into methods. Rather than placing these methods in class/file with generic name (called, "HelperMethods" or "CommonOperations") put them into a class or file with more specific name (called "TextFile").
In the place where you use it, it would look elegant.In our case the choice is obvious.
  • HelperMethods.CreateFile() 
  • TextFile.Create()
If someone new in the team wants to use a text file related operation, the chances are more that he/she would use this method. Also if they introduce a related methods, say 'delete' in our case, they will be in ease in choosing where to put the method.

Let's go back to our test suites and clean them if they have any "common'ers". Read through the methods, group the related methods and move then into a new file/class with name more specific, unique and meaningful for the group of methods.
Even if it means having a single method in a class, lets go ahead and do it. Rather than having unrelated methods in a single class/file, making the whole the place messy let's have classes with single methods which will be more meaningful.