Premature Generalization Is Evil

DonaldKnuth once wrote that PrematureOptimization is the root of all evil. At the time, object-oriented programming either hadn't been invented or wasn't in wide use, and so he did not utter what could be another important idea: that premature generalization is the root of all evil. Well, they can't both be root, can they...

Abstract classes, base classes, and interfaces are in part generalizations drawn upon their descendants or implementors. It's probably important not to create an abstract base class or an interface until you can think of at least two descendants or implementations - that you are actually going to use right now.

Because YouArentGonnaNeedIt.


See also PrematureGeneralization, YouArentGonnaNeedIt, Ron's article on TheCostOfAnticipatoryDesign?, http://www.xprogramming.com/xpmag/cost_of_antici.htm

Contrast ThereAintNoSuchThingAsPrematureGeneralization.


"DirectedAcyclicalGraph? of all evil" doesn't have the same ring somehow. -- WillSargent [How about 'DAG of all evil'? That sounds cool.]

Premature generalization makes one construct a root of all evil? Root of some evil?


This is referred to in the RefactoringBook as SpeculativeGenerality, clarified in ThereAintNoSuchThingAsPrematureGeneralization as PrematureCommitmentToGeneralizationIsEvil?, and seems to really refer to TooMuchAnticipationIsHarmful?.

There is also debate as to WhatIsGeneralization. There seems to be general agreement that making code smaller to still do the same thing often involves generalization. There is debate though as to whether adding extra methods and hooks etc (because you might need them later) which is agreed is often bad and against YouArentGoingToNeedIt, constitutes generalization or specialization.


CategoryEvil


EditText of this page (last edited July 29, 2005) or FindPage with title or text search