When you remove duplication like this you are making your code DRY. DRY stands for don’t repeat yourself. In the first example you can see that we repeated the algorithm for processing the columns for each column we needed to process. We can see that the only thing that changed was the column name, and extract that part out, and then have a generic method to process columns.

My colleague had heard of DRY, but thought that he shouldn’t use it here since he was pretty sure that we would change and want to process columnA differently than columnB in the future. While this argument makes a certain amount of sense, we need to remember that we are not psychic, and while we can speculate on how a software project might evolve, we are never really sure. The requirements and priorities change under our feet, and our guesses are often wrong.

In my opinion, and in my experience it is always better to keep your code clean because you want to be able to make changes easily. If, at some point, in the example above, column A and column B processing diverge, then (and only then) you should change the code to accommodate this.