Review: Refactoring HTML

Refactoring HTMLThere’s nothing more dispiriting than being stuck with maintaining an old website with hundreds of pages of rubbishy “Netscape 4″-era code. There can be an overwhelming number of things which need fixing or updating. You may well be tempted to think it not worth trying to improve things incrementally and instead plan for a major redesign at some indeterminate point in the future – which maybe you’ll never get the time or the money to undertake.

If you find yourself in this situation, then Elliotte Rusty Harold’s book Refactoring HTML: Improving the design of existing web applications will be a good antidote to “wait for the redesign” paralysis. The book encourages taking a gradual approach to converting your website to a modern standards-compliant state, rather than trying to do everything at once. I think this is a great area to write a book about, since it fulfils a need a lot of website managers will have. Designing and building new sites is fun and there are an awful lot of books available about this creation process. Maintenance and incremental improvement of old sites is distinctly unsexy in comparison and gets much less shelf-space.

The book is a compendium of stuff, most of which you’ll probably already know you should be doing. It’s arranged with subjects listed in a cookbook fashion – covering why you want to make each change, potential trade-offs and the mechanics of how to carry out each improvement. The first chapter is an introduction to the subject of refactoring, which is a programming concept that may be new to a lot of web designers.

“Refactoring is the gradual improvement of a code base by making small changes that don’t modify a program’s behaviour, usually with the help of some kind of automated tool. The goal of refactoring is to remove the accumulated cruft of years of legacy code and produce cleaner code that is easier to maintain, easier to debug, and easier to add new features to.” From “Refactoring HTML”

In the second chapter, there is a thorough overview of automated tools you can use for refactoring. A lot of the information here is going to be of more use if you’re a programmer. However, the discussion of regular expressions should be of use to anyone who has to deal with outdated HTML code. It’s backed up by an appendix which provides a beginner’s guide to regular expressions. Throughout the book there are specific regular expressions supplied for fixing particular problems which will be hugely useful to non-programmers like me who find writing their own regular expressions a pain.

Chapters 3 and 4 cover all the aspects of well-formedness and validity in HTML documents. The author is sensibly not insistent upon validation for its own sake and on several occasions gives examples of times when it may be pragmatically better to go for an invalid option. He also points out where the standards don’t actually make much sense – the rule that block quotes can’t be within paragraphs is one example discussed which has always really annoyed me.

Chapter 5 covers layout, with some discussion of replacing table layouts and frames-based layouts with CSS. However this is definitely not a design-oriented book and its CSS advice is limited to providing some basic layouts and advising that CSS is ‘very much a technique for full-time professionals”.

The book continues with a nice-to-see chapter on accessibility and a section on web applications. The latter includes an interesting section on Web Forms 2.0 types as well as solid advice on older topics, like when to use POST or GET and the need to escape all user input. Finally, there’s a chapter on content which – like the section on layout – is pretty basic. Still, it’s nice to see an emphasis on the need for correct spelling in a book that seems to be aimed primarily at coders.

Refactoring HTML as a whole is certainly useful for anyone managing a badly-coded site, especially if they haven’t thought much about ways to semi-automate testing and improvements.

Refactoring HTML: Improving the design of existing web applications by Elliotte Rusty Harold is published by Addison-Wesley.

Leave a comment

Your comment