Why Refactor HTML?

May 28th, 2008

Here’s part 2 of the ongoing serialization of Refactoring HTML, also available from Amazon and Safari.

How do you know when it’s time to refactor? What are the smells of bad code that should set your nose to twitching? There are quite a few symptoms, but these are some of the smelliest.

Smell: Illegible Code

The most obvious symptom is that you do a View Source on the page and it might as well be written in Greek (unless, of course, you’re working in Greece). Most coders know ugly code when we see it. Ugly code looks ugly. Which would you rather see, Listing 1.1 or Listing 1.2? I don’t think I have to tell you which is uglier, and which is going to be easier to maintain and update.

Read the rest of this entry »

Refactoring HTML: Chapter 1

May 27th, 2008

Over the next week or two I’m going to serialize the first two chapters Refactoring HTML here. Of course, if you don’t want to wait you can always buy it from Amazon or read it online on Safari. And with that brief commercial announcement out of the way, let us begin:

Refactoring. What is it? Why do it?

In brief, refactoring is the gradual improvement of a code base by making small changes that don’t modify a program’s behavior, 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.

Technically, refactoring never actually fixes a bug or adds a feature. However, in practice, when refactoring I almost always uncover bugs that need to be fixed and spot opportunities for new features. Often, refactoring changes difficult problems into tractable and even easy ones. Reorganizing code is the first step in improving it.

If you have the sort of personality that makes you begin a new semester, project, or job by thoroughly cleaning up your workspace, desk, or office, you’ll get this immediately. Refactoring helps you keep the old from getting in the way of the new. It doesn’t let you start from a blank page. Instead, it leaves you with a clean, organized workspace where you can find everything you need, and from which you can move forward.

Read the rest of this entry »

Linux 2008: Still Not Ready for Prime Time

May 25th, 2008

I’ve just spent a couple of hours installing and exploring Ubuntu 8.04. Bottom line: better but still not yet an adequate end user system. Here are the things that absolutely must be fixed before one can plausibly recommend Ubuntu to a non-developer end user (and since Ubuntu is the best desktop Linux out there, these are things that need to be fixed before one can recommend desktop Linux). In roughly increasing order of severity:
Read the rest of this entry »

Setting Up My Home Office

May 18th, 2008

I’m realizing that my productivity since I moved has been severely reduced by the setup of my loft here in Irvine compared to the office I had back in Brooklyn. Herewith are some resolutions and plans for fixing that. Suggestions are appreciated.

Loft office with shag carpet and Aeron chair, quite messy
Read the rest of this entry »

Spot the Bug Part 2

April 1st, 2008

Another future exam question: Identify the intermediate programming error in the following screenshot from a major web standards organization:

28 March 2008: Basic XML Schema Patterns for Databinding Version 1.0 - Last Call Ends NaN

What likely happened here, and how could it have been avoided?