Code as she is wrote

Warning This article was written over six months ago, and may contain outdated information.

There is a famous Portuguese-English phrasebook, published in the 19th Century, with the title “English As She Is Spoke”. It contains many unintentionally hilarious translations of words and expressions, including such familiar phrases as “that are the dishes whose you must be and to abstain”, and “I not make what to coughand spit”. The author, Pedro Carolino, had the best of intentions in producing this book, but suffered from one major drawback: he didn’t speak English. The book was apparently translated from an earlier Portuguese-French phrasebook, using a French-English dictionary.

The reason I bring this up is that I think this is a fairly common problem in coding. Many people know how to write code in order to get a result, but they don’t know the language at hand in enough depth to realise that the result doesn’t always make sense.

I’m experiencing this on a site I’m working on at the moment; the code I’ve inherited is overly verbose, repetitive, sometimes head-scratchingly confusing, and has quite frequent errors. The site functions, but it’s a long way from being optimal.

A case in point: there was a CSS file over 12,000 lines long, largely because the author(s) didn’t understand CSS well enough. For example, there are some fourteen different styles of button, each with a unique class name, each of which repeats the same basic styles. Grouping all of the common styles under multiple selectors — or even better, creating one more class to cover all of the shared styles — would have made this much more manageable.

The CSS problems are in performance and maintainability, but some of the HTML caused basic errors of accessibility and usability; for example, I saw these used in a form:

<div class="label">Foo</div>
<a href="#" class="button submit-button">Submit</a>

The label isn’t a label, and isn’t associated with an input field. The button isn’t a button, so the form wouldn’t work without JavaScript, and wouldn’t submit through keyboard entry. They should, of course, have been like these:

<label for="foo">Foo</label>
<button type="submit">Submit</button>

This isn’t a quibble over semantics; these aren’t just simple mistakes; this is a fundamentally incorrect use of the language. But to the author who knows no better, because it ‘works’, there’s no problem.

Just to be clear, I’m not blaming the developers who made this site, or any others who make the same mistakes; I’m sure (or, at least, I hope) they were well-intentioned and thought they were doing a good job. But people are unaware of the limits of their own knowledge; this is a documented part of the Dunning-Kruger effect.

Like Carolino, the authors of bad code don’t understand that what they have produced isn’t right. With Carolino’s book the reader suffered from problems in communication, despite believing they were speaking English correctly. With bad code, the website visitor suffers reduced accessibility, constrained ease of use, and poor performance.

Comments are closed.