Refactoring HTML

Improving the Design of Existing Web Applications

by Elliotte Rusty Harold

In just over a decade the web has gone from a technology with promise to major part of the world's infrastructure. It's been a fascinating time and many useful resources have been built in the process. But as with any technology we've learned as we go how best to use it, and the technology itself has matured to help us use it better.

However complex a web application, it finally hits the glass in the form of HTML - the universal web page description language. HTML is a computer language, albeit a very limited and specialized one. As such, if you want a system that you can evolve easily over time, you need to pay attention to writing HTML that is clear and understandable. But just like any computer language, or indeed any writing at all, it's hard to get it right first time. Clear code comes from writing and rewriting with a determination to create something that is easy to follow.

Rewriting code carries a risk of introducing bugs. Several years ago, I wrote about a technique called Refactoring which is a disciplined way of rewriting code that can greatly reduce the chances of introducing bugs while reworking software. Refactoring has made a big impact on regular software languages. Many programmers use it as part of their daily work to help them keep code clear and enhance their future productivity. Tools have sprung up to automate refactoring tasks, to further improve the workflow.

Just as refactoring can make a big improvement to regular programming, the same basic idea can work with HTML. The refactoring steps are different, but the underlying philosophy is the same. By learning how to refactor your HTML, you can keep your HTML clean and easy to change into the future, allowing you to make the inevitable changes more quickly. These techniques can also allow you to bring web sites into line with the improvements in web technologies, specifically allowing you to move towards supporting XHTML and CSS.

Elliotte Rusty Harold has long had a permanent place on my bookshelf for his work on XML technologies, and a place in my libraries for his open source software for XML processing. I've always respected him as a fine programmer and writer. With this book he brings the benefits of refactoring into the HTML world.