New Perspectives On Web Design

(C. Jardin) #1

CHAPTER 2 Writing Maintainable, Future-Friendly Code


Something interesting happens in a developer’s mind when given a
blank slate. It feels like there are no rules, as you are no longer constrained
by previous work. You start dreaming about how wonderful things could
be and how your work is so much better than what came before it. What
you fail to realize is that creating something from scratch means that
you’re writing future legacy code. Your code will be given to someone else
to look after, and so it’s now on you to prevent the creation of yet more
horrible code.
One of my mentors told me that there are very few developers who
can effectively start from scratch and build up a project. In the exuberance
of creation you are far more likely to forget the basics and take shortcuts
to get the job done. In fact, many rewrites represent the beginning of the
familiar legacy code spiral:


  1. Code is rewritten.

  2. Authors of the rewritten code are present to answer questions.

  3. Team works more effectively with new code.

  4. Authors of the new code begin to leave.

  5. Questions emerge as to how parts of the code work.

  6. More and more parts of the code become magic.

  7. Development slowed by lack of understanding.

  8. Developers become frustrated and declare they can’t work with this
    code for much longer.

  9. Go to #1.


Even though rewriting is something that developers love to do, refac-
toring often achieves positive results more quickly and without thrusting
the team back into the legacy code rewrite loop.
You can, of course, effectively rewrite code if you come at it with the
proper perspective. Whenever you write new code you should think five
years into the future and of how someone else is going to pick up where
you left off. Think about the trouble you’ve had while working with legacy
Free download pdf