Friday, June 8, 2012

Speculative Generality: Build something even if you don’t need it right now!

Today we will have a short discussion about Speculative generality, it yet another kind of code smell, not in case of actual code but in case of design.

Did you ever write code that was not needed right then , rather you wrote it in case you needed it in future?, If the answer is yes then you probably, in fact did introduced Speculative generality with or without knowing it.

Here is advice from the Experts

“Please don’t write anything in your code base unless your needed it!”

Lets be frank we don’t know what client want, infect the preceding statement is not true for all cases for instance when you follow strict water fall, but that is a whole different store as far as software development processes is concern. So in an ideal world I would say that on 80% client don’t know what they want so its obvious that developers can not predict, when we build something and show it to customers, customers will always will have some opinion on average case they want some modification.

So we have to build just what is necessary for reaching a short goal, after that along the way we would start fit whatever is necessary.

An Interesting Example could be, event though we don’t need any Abstract class for a view we spontaneously created an interface and an abstract class.

We can put down lots of stuff like that.


  1. If there is only one class that implements a interface probably we don’t need it.
  2. If there is only one sub class of a superclass, again probably we don’t need it.
  3. If only single function works okay for a method we don’t need any overload.
  4. And so on.

So from now on we would avoid any code that is not necessary.

No comments:

Post a Comment