Code is Poetry. It’s a phrase found in WordPress’s footer that should be true but often isn’t. At 9rules somebody asked if code really is poetry–I say that not all code is poetry, but all code should (and can) be poetry.

In this multiple-part series I’ll be taking a look at some specific code examples and showing how to turn bad and/or ordinary code into something even Shakespeare would drool over. But before we can do that, we’d better see what poetry is and how code could possibly fit this definition.

Defining Poetry

First I checked dictionary.com for a definition, since that seems to be a pretty good place for definitions:

3. A piece of literature written in meter; verse.
4. Prose that resembles a poem in some respect, as in form or sound.
6. A quality that suggests poetry, as in grace, beauty, or harmony: the poetry of the dancer’s movements.

Not a ton of help, though “meter,” “form,” “grace,” and “harmony” tend to stick out. Now lets see what Wikipedia says:

Poetry (Greek ποίησις poesis, literally “creating”) is a form of art in which language is used for its aesthetic qualities, in addition to, or instead of, its ostensible meaning. Poetry has a long history, and early attempts to define poetry, such as Aristotle’s Poetics, focused on the various uses of speech in rhetoric, drama, song and comedy. Later attempts focused on the deliberate use of features such as repetition and rhyme and the emphasis on aesthetics to distinguish poetry from prose. Now a days contemporary poets, such as Dylan Thomas, often identify poetry not as a literary genre within a set of genres, but as a fundamental creative act using language.

Poetry often uses condensed forms and conventions to reinforce or expand the meaning of the underlying words or to invoke emotional or sensual experiences in the reader, as well as using devices such as assonance, alliteration and rhythm to achieve musical or incantatory effects. Poetry’s use of ambiguity, symbolism, irony and other stylistic elements of poetic diction often leaves a poem open to multiple interpretations.

Now that’s more like it. This applies to code as well–good code has visual form, is condense, “expands the meaning of the underlying words,” can be used with “multiple interpretations,” and is just plain good-looking. Call me a freak, but I can honestly say that I’ve looked at code before and thought, “Dang, that’s beautiful.”

Back to Code

When code is poetry, you can tell what’s going on within it by a simple glance. It’s resourceful, it’s inspiring, and it works.

The next part in this series will focus on visual form within code, so stay tuned. swan