Friday, July 24, 2009

Software Code Re-use

One of the holy grails for software development is to build something that will be used again by somebody else, saving the development time it would take to write it over again. Instead of re-inventing the wheel you get the efficiency of just grabbing a wheel off the shelf and using it. Inside of a small project with a small number of developers (perhaps even just one) this is usually easy to achieve. Once the project grows or there is a different project with similar needs it gets more complicated.

Software is still much of a craft than it is an engineering effort. Developers identify very strongly with their work and often believe that even though there is an existing block of code that basically does what they need that they can do it better. A combination of "not invented here" and a need for a slight change often results in yet another implementation of code to do something with text values, for example.

Sometimes this occurs directly in the face of existing code, out of developer hubris, but often it comes from ignorance of the platform that is being worked on. Chances are very good that a modern framework like Java, PHP or .NET already has defined in their frameworks code that does most of the things that you need. In a worst case you can often use something that is "almost there" and just add the couple of things you need without having to rewrite it all.

Regardless, software re-use is an ongoing are of interest for many organizations, both as producers and consumers.

So far, the best use of "re-use" of code has been with services rather than libraries (above the very basic libraries built into languages). The re-use has been best with things like web servers, database servers, etc. and not necessarily specific blocks of code that make up parts of the services. This is because a service creates a clear boundary. It defines for you up front what it will accept and what it will return or otherwise cause to happen. It is of no importance to the user how the work is accomplished, it is accomplished.

The UNIX ideal of "small and sharp" tools also cleaves to this ideal, whereby small command line utilities that do only one thing but do it very well can be chained together to create useful applications.

In a wider sense this is called a "stack", where different services and glued together to provide an overall environment / platform. For example, the LAMP stack (Linux, Apache, MySQL and PHP) is credited with a large amount of the innovation that occured on the internet because all four components were FOSS and were in use by large groups of developers.

Additionally, if you lived in any one of the components you did not have to worry about any of the others.

A web developer in PHP does not need to know how to program the C code that makes Linux work, nor the low level routines of Apache of MySQL. They can concentrate on building web applications using PHP and just depend upon the other items to work together. The same kind of re-use of code through services is found in many other cases also.

The techgnostic approach to re-use is to stop before you write a large pile of code and determine if what you need already exists. Writing and maintaining code is very expensive. If you can leverage something that already exists and has been used by other and has been tested to be good you can deliver a lot more value much more quickly than rolling your own.

No comments: