Saturday, January 03, 2009

Codebase - Asset or Liability?

We've all had occasion to provide a size of the codebase we're working on for a project, whether for management, or for our own resume, and there is a natural tendency to make the KLOC large - it sounds more impressive to work on or manage a large codebase then a smaller; a project that has lots of code sounds more solid, more reliable.

But there is one school of thought that holds a large codebase as a liability - it is harder to shift it; it has more inertia.  And there is some merit to this; a large codebase means that there is greater chance for errors (statistically, at the very least), a greater chance for unwanted coupling, and more places where code has been unwittingly duplicated.  So it behooves developers to minimize code, as described here.  On the other hand, less code doing the same stuff means you've got denser code, and you are at risk of being clever.  Clever code is bad because it obscures its intent, and the next developer to support the code may not be as smart as we are (or like to think we are).

So this means we've got tension between making the code simple, and making it small.  The low-hanging fruit of this is reducing redundancy - it's not hard to understand that all I/O is being done through your library functions, for instance.  The next best step is to use standard libraries where possible - they have the benefit of being available elsewhere, so your next set of developers are likely to have used them before.  A third strategy is good naming - if reading the name does not give you the right idea of what the code does, it will confuse someone later on.

Beyond these steps, you are faced with needing to consider the density of the language you use.  The current trends are towards more "advanced" languages like Python and Ruby, which cover much of the ground C/C++ do, but with less cruft, and with nice things like built-in data structures that are easy to use.

Technorati Tags --
, , ,

No comments: