While writing the code or during design do you try to generalize the problem at the first instance itself or try to solve that very specific problem.

I am asking this because trying to generalize the problem tends to complicate the things (which may not be necessary) and on the other hand it will be very difficult to extend the specific solution if there is a change in the requirement.

I guess the solution is to find the middle path which is easier said than done. How do you tackle this type of problem ? If you start generalizing it at what point of time you know that this much of generalization is sufficient?

Too often when you try to design for the future, your predictions about future needs turn out to be wrong. It's usually better to refactor when you actually know how the needs have changed than to overdesign your system on day one. At the same time, don't shoot yourself in the foot, either. There's certainly a middle ground, and knowing where that is is more art than science.

To boil it down to one rule of thumb: less is more.
