Excellent advice on building frameworks and libraries from John Roth, via the XP mailing list:
Reuse is an interesting issue. There’s a rule of thumb that you should write it three times, then you’re in a position to make a resuable library or framework the fourth, because you now know what you need; you’re not speculating.
For the fourth time, if you simply take the first three and remove duplication you might even get it done faster that doing it separately.
That’s certainly been my experience. Try to make a tool reusable too early, without having gone through iterations with it, and it rarely works well without modifications. But take something you’ve done several times, pull out the common components, remove the duplication, and you might just have something there.
It’s one of the great things about Rails. It came from a real project, with real needs, and was really solving them.