Search code examples
agilecode-reuse

What Code is a Candidate for Re-use?


Imagine you work for a small lean software company. You know the future competitiveness of the company is in having a good reusable code base to draw upon. It’s going to be very important to manage the company’s re-use policy to ensure you deliver today, at the same time as providing a back-bone for the future.

In my mind there are two reasons to write re-usable code in business; 1) To share within the company to improve speed and efficiency in the future 2) To publish on the web and other people will help improve the code (crowd-sourcing in a sense).

Developers should always apply common sense to re-use of course. But to get a handle on this from a management perspective I want some overall code-reuse guidelines to ensure we are competitive now and in the future. These guidelines should encourage the developer to ask “Is my code a Candidate for Re-use?”. What should these guidelines say?

My initial thoughts: It’s not worth writing re-usable code at the lowest levels (e.g. I have some in-line code which adds a “’s” to the end of a string), there would be far too much of this code to even sift through and find that someone has already done it. It’s also not worth writing re-usable code at the top-most level i.e. the application because your customer reporting application would end up being genericised into a SQL client – useless to most users.

Main barriers to re-usable code: You can’t re-use it unless you know it exists; Trust – It’s been done but do you trust it?; Initial time taken to make the code generic/re-usable (and to document it).


Solution

  • You can spend a long time trying to make something reusable, without anyone reusing it. So I usually follow the maxim that I only make something reusable when it's going to be reused (there are a few exceptions that will stand out).

    Often it's only when you come to reuse something that your client says "I want it to do the same, except..." or similar. It's only at that point that you understand which part of your reusable code is reusable, and what needs to be parameterised (e.g. via strategy patterns or similar)

    Consequently I don't tend to regard code as reusable unless it's really been reused :-)