Monday, August 6th, 2007

Sometimes you are truly better off starting from scratch

By Joel Nagy

Reuse, Reuse, Reuse is a typical mantra these days, leaving me to wonder if any new ideas are ever written. Now of course I’m being a little sarcastic here, but it seems that the call to reuse code and use as much free code as you can get your hands on is the norm these days. I believe that there are very valid reasons to not only start from scratch but building certain code bases in-house.

The reasons why we often opt for prefab code (or previous incarnations) instead of coding from scratch are varied: our urge to rush to market, hesitation to throw away code, etc. Sometimes we feel that it would be a waste to not reuse old code, or even “why waste our time writing code that someone else already wrote?” Some good reasons why you should write from scratch:

  1. Maintenance: Plugging 20 odd libraries from 20 separate sources into a single project can become a maintenance nightmare as they might try to step on each other and may not have been written with the most optimized or clean code.
  2. Adding Features: Adding features to some prefab code bases can make the code unmanageable as hacks get frequently introduced to solve a simple issue.
  3. Scalability: Do you know for a fact that the old code or the plugged in library will scale? Do you have the time to perform a thorough code walk through of the new code?  If you do you might actually have time to write new code.
  4. Use the Right Tool (screwdrivers don’t make good hammers): Using old code (especially from legacy platforms written with older languages, such as non-web languages used in a web platform) will result in trying to leap hurdles that newer languages were designed to perform.
  5. Learning: There’s nothing wrong with trying to figure out how to accomplish a task on your own, in the end you’ll be rewarded with the new knowledge and firm understanding of how the code you are using actually works.

Don’t take these reasons as “you should always” write from scratch, but sometimes it’s just better than using <insert code here> into your next project.

3 Responses

  1. 8/6/2007
    Chris D Said:

    Great post, Joel. I agree completely, especially when it comes to an area like web development, where codebases are usually not monolithic monstrosities.
    I’d also like to point out a place where Joel Spolsky disagreed with you, and later showed himself to be a little off the mark: in “Things You Should Never Do, Part I” (written April 6, 2000), he tears into Netscape for rewriting it’s browser after netscape 4.75 – calling it the ’single worst strategic mistake’ a company could make.
    Of course, we know that after a while, the mozilla suite became pared down into one of the best browsers around, Firefox, and although I can’t see alternate realities, I doubt it would be as popular if they had stuck with the Netscape 4.75 codebase and built off of it.

  2. 8/10/2007
    Avi Flax Said:

    Chris, that’s an interesting example. Sure, the new codebase that Netscape developed turned out to be quite good, and quite valuable – but it didn’t save the company.
    Also, I’m not sure the question of “rewrite or refine?” is directly applicable to Joel’s post, which is more about “use an existing implementation or roll your own?”

  3. 8/10/2007
    Tim Said:

    I think the value of writing your own solution, even if it’s inspired by that of others, is that you as the developer really internalizes the solution (your #5 above.) This shows itself, and usually pays huge dividends, when some of your other points come into play, namely looking for bugs later, trying to add a new feature or scaling the app. One other point is that an existing implementation often isn’t written in the same style as yours, or that of your company (therefore making maintenance on it later again more difficult.)
    There are certainly places where off-the-shelf or borrowed code can pay-off in a big way, but in a strategic area that I’m committing to long-term, I generally prefer the developers that are going to have to maintain the code to have written it.

Leave a Comment