I just had the debatable pleasure of seeing some of my old code reused in a library by someone else. This caused quite a headache when it turned out to rely on assumptions some clients just can't afford. The code was fine in its original environment, just not as a general solution.
Be very careful and thoughtful when you promote existing code to library status. Almost no code is written with reusability in mind, as the cost is prohibitive and rarely (maybe never) justifiable up-front. What's good enough in one instance isn't necessarily good in another. As the number of clients increases, the cost for changing anything in the library increases as well, and code that was easy to patch up on its own becomes a maintenance burden. Ask yourself "suppose everybody had to use this without change, would they run into insurmountable problems"? This isn't an easy question to answer (who's "everybody"?) but it's a good start.
The goal is not to write code that is "as general as possible" or "maximally reusable". This is massively overrated and very few people can even articulate what they mean by such abstract goals. The goal is code that, in a broad set of circumstances, will be useful on the whole and not obstructive in part. That's the benefit of the library, which should offset its cost (which you pay in increased maintenance cost). This requires a solid design that's easy to grasp, with well-documented borders. Simply shifting code to its own codebase is not enough.
No comments:
Post a Comment