OK. I admit it. At times I do generalize prematurely. Premature generalization is a term given to the act of adding functionality or abstraction to your code simply to account for the “what if...” cases that might (or might not) arise in the future. Sometimes referred to as “over-abstraction”. Your requirements might be to code X, but you think it would be really cool to also account for the possibility of YZ so you abstract, or overly generalize your code to include for the future possible need for XYZ. You brag to your fellow programmers or to your client about how not only you can do X, but also if you ever need to do Y or Z then that is already built in. “How cool is that?!”. Well, it might be cool, but chances are that Y and Z will never be needed.
Sometimes it is hard to separate your desire to make something cool, out of your passion for programming, from sticking to the needed requirements for a task. I mean, don't you sometimes feel almost like you are doing a crappy job of something because it could be so much better?
I code because I love to code. I love writing code and I get a big sense of satisfaction out of doing something that no one else has thought of. I try to change. I try to make the time I code more profitable by strictly adhering to the defined requirements and only the defined requirements. It is hard because I want so badly to make it cooler, better, whatever. I hope to someday be able to live by extreme programming techniques that will lead me down the road to deferred generalization. Some XP'ers say that there is much satisfaction in deferring generalization. But for now I do so prematurely.
No one is happy when you prematurely generalize. If you're working fixed bid then you're screwing yourself. If you're billing hourly then rest assured that your client will not agree that the overly-generalized code is cool. All they wanted was X. How does one deal with the urge to prematurely generalize? Don't get me wrong, I don't consider premature generalization one of the anti patterns. It's not like you're necessarily creating a bad solution. Just an unneeded one. I certainly don't think that premature generalization is the root of all evil. However, even with a failing design you shouldn't be guessing at the level of needed abstraction based on it's cool factor. I guess what it comes down to is that I just want the up-front design to be cooler. Customers never want that, so what you going to do.
My name is Ryan, and I am a premature generalizer.