Monday, July 9, 2012

Keeping code alive

There is a great bit by Joel Spolsky dating back to year 2000:
Old code has been used. It has been tested. Lots of bugs have been found, and they've been fixed. There's nothing wrong with it. It doesn't acquire bugs just by sitting around on your hard drive.
Joel also recognizes three types of issues with old code (architectural problems, inefficiency, ugliness), which he recommends be addressed without fully rewriting your software by refactoring, optimizing, and prettifying.

At Orbeon, as we are working very hard on releasing Orbeon Forms 4.0, we have taken an approach of careful migration and refactoring. When we need to do more than trivial changes to old JavaScript or Java, we often start by moving some of that code to CoffeeScript or Scala, respectively. This has lots of benefits:
  • Low risk. It's not a rewrite from scratch. (In the case of Java to Scala we even get help from tools to perform an initial migration.)
  • Revisited code. In the process, we re-read the code and are forced to understand it again. Sometimes we add new comments to unclear code, or even fix obvious mistakes.
  • Smaller, more expressive code. We are moving to better languages after all.
  • Future proofing. This sets things up for more refactoring in the future. (In fact, we often perform some refactoring right away.)
Little of this would be possible without a stack of great, modern technologies which includes ScalaCoffeeScriptLESS, and jQuery, none of which existed back when we started working on Orbeon Forms. We consider ourselves lucky to have them!

No comments:

Post a Comment