Might.

Might. Might is a dangerous word.

Might is a word that lends hope to empty promises. It’s a word that bestows risk.

“I thought it might be useful,” is one of my least favorite phrases in software development. It’s the reasoning of a well-intentioned developer but it also hints at a particular code smell.

Might is the hallmark of the speculative generality.

Speculative generality refers to code that’s added to a project just in case. It may take the form of an unused class or method. It might also appear in less obvious forms:

  • Reference validation where a null reference is not possible
  • Methods with unused parameters
  • A base class with a single descendent
  • and so on…

In whatever form it may appear, speculative generalities result in code bloat. They are extra baggage for your project to haul around. Unused code creates confusion; it trips up unknowing developers who inevitably pause to consider why such code exists. It’s another code path to unit test. And, worst of all, every extra line of code is a potential vector for bugs.

So, when you encounter code that might be useful, ask it’s creator, “why?” A clarification may lead to an new understanding of perfectly justifiable code. However, if the question is received with a shrug, you’ll be on your way toward ensuring a slimmer and more maintainable code base.

 

Comments are closed.

Create a website or blog at WordPress.com

Up ↑