True, even if beauty is in the eye of the beholder

| 0 Comments

"I'll bet you that from ten feet away I can tell if a program is bad. I might not guarantee that it is good, but if it looks bad from ten feet, I can guarantee you that it wasn't written with care. And if it wasn't written with care, it's probably not beautiful in the logical sense."

Charles Simonyi

The quote is from an interview with Charles Simonyi; via Joel's discussion forum.

I've been a believer in judging code quality by 'the look' for a while now. I've never seen code that's been messily or inconsistently presented that's been structurally sound. Messy code is often due to maintenance rot, multiple programmers or people who just don't care, but whatever the cause if the code is ugly on the outside it tends to also be broken.

One of the first things that I tend to do when taking over such a codebase is to make it look nicer. Apply common structures so that idioms look like you'd expect them to. Once this is done it's easier to see patterns in the code and spot duplication and strangeness. Duplication is much easier to spot if the code is structured in a common way and when you're used to reading code that looks a certain way you can often spot bugs just by seeing unfamiliar shapes in the code.

Of course this kind of massive change often upsets the "don't change anything but the line you're fixing" crowd; who get upset when they get a complicated diff out of the version control system. I find the best way to do this kind of clean up is to insist that that's all we do. We clean up the code and change the structure but we don't fix anything, it's all about layout. Then we check that in and only then do we make changes that affect the actual code that executes...

And as for the people who say that it doesn't matter, well, they're just wrong, and if they don't understand why they're wrong they should just stop writing code... ;) I find code that is unstructured or structured in an unfamiliar way is harder to read and comprehend; the more thinking that I have to do to fix a bug or make a change the more chance there is that I'll make a mistake. I find that code that is structured in 'the normal way' conveys information in the patterns of the code; the block structures and space conveys meaning in the same way that well chosen variable names do.

Of course the main problem is that often beauty is in the eye of the beholder...

Leave a comment