Yesterday I had occasion to implement a clone of an existing piece of software. It took me about 20 minutes, just by bolting together pieces of code I'd already written. This struck me as odd, not because it's unusual, but precisely because it isn't; I increasingly seem to be finding that when I want to write a program I usually have quite a few already-written bits and pieces that I can use to make the job easier. That's bits I've written, not including any third-party libraries.
Last week, someone told me that when he writes new programs, he often finds himself reaching for bits of code I've written which happen to be the right tool for the job. So I got to thinking: I must have written quite a lot of code in my time for this to happen so often.
So I've now gone through my source code directory on my main computer, catalogued everything in it, and counted how much there is. The result is a rather staggering two hundred and eighty thousand lines of code. That's around 280,000 lines of code that I've not only written, but still have and can re-use at need; it doesn't count stuff I wrote on Spectrums, BBCs, Amigas, strange CP/M machines my dad brought home from work, and suchlike.
280,000 is a hell of a number. I recently wrote 3000 lines of good working code in three days (while on holiday from work, so that was full time rather than evenings), and at the end of that time I could tell I'd achieved a peak of coding performance which I rarely hit at all, and I could also tell that I couldn't have sustained that rate for much longer than those three days. So 280,000 lines of code would have taken me the best part of a year to write, even if I'd been coding at that flat-out rate constantly! In fact this stuff is code I've written over about the last ten years, which makes it a believable figure; but even then, I have to take into account the fact that this is only code I've written on my own time, and doesn't count stuff I was employed to do or did as part of a university course. The bottom line is, I wonder how I ever managed to have a social life at all! :-)
Of those 280,000 lines of code, 150,000 are in programs I've actually released. A further 71,000 are in programs that are basically usable, perhaps lacking a little polish and full documentation or (in one case) unpublishable for copyright reasons, but not too far off being release-quality. That accounts for nearly 4/5 of the total, which is a rather satisfying thought; only about a fifth of my free-time coding output is seriously unfinished, flawed, abandoned or otherwise unusable. I call that a pretty good percentage: I was expecting a far higher proportion of write-offs.
Of course, now I find myself wondering whether I ought to polish up the 71,000 lines of nearly-releasable code for publication, just in case anyone might find it useful for something. Perhaps I should at least make a list of all the things I could publish if there were a sudden need for me to do so.