Matt Ward has written a very nice article over at Smashing Magazine examining some of the similarities between code and poetry. It is an excellent article, but I must respectfully disagree. There are similarities between code and poetry, as Matt and others have seen, but these do not make code poetry (as claimed by WordPress’ famous tagline). Here are two reasons why:
A Categorical Difference
Following the ancients, we must distinguish between Craft and Art. Both are skillful endeavors that require mastery to do well, but they differ in purpose. Arts are pursued for their own sake, while crafts are pursued for the sake of utility.
Craft is done for the sake of some other goal. An excellent shoemaker, for example, is a craftsman because he creates shoes to be worn, and we judge a shoe’s excellence based on how well it serves its function. We never purchase a shoe just to hang on our wall. No, a great shoe is one that is comfortable, wears well, and looks great. A craft’s value and excellence lies in its utility.
Art, on the other hand, is done for its own sake. An excellent painter creates his paintings to be enjoyed in-and-of-themselves. There is no other purpose for his art. We judge a paintings excellence not on how well it sells beer (that would be commercial art, a craft), rather we judge its excellence based on how much we enjoy looking at it. In other words, an excellent painting is an enjoyable painting.
Code is craft. No one writes code so that the code itself can be enjoyed. It is written to perform some job. That is not to say that code cannot be beautiful. There is a distinct difference between beautiful and ugly code, but at the end of the day code is judged based on how well it performs its job. In fact, beautifully structured code that doesn’t work is worse than ugly, difficult to maintain, code that does. We can even say that beautifully structured code that doesn’t work isn’t actually “beautiful” at all, for the simple reason that it is flawed and doesn’t do what it’s suppose to do. The very question of what it means for code to be beautiful is bound up in the question of whether or not it fulfills it’s purpose.
Poetry is art, at least good poetry is. It is written to be enjoyed in its own right. Its beauty does not rest in utility but in itself.
The question of meaning
Code and poetry differ in many other more specific ways as well. But I want to deal with only one that Matt perceived to be a similarity: meaning. Matt argued that just as poetry has multiple levels of meaning, so code can impart varying meaning to content. He attempted to compare a poem’s literal and figurative meaning to some code’s semantic value.
He gave these two examples of HTML code to illustrate code’s ability to imbue content with different meanings:
<p>The Wasteland</p>
<h1>The Wasteland</h1>
I agree with Matt’s basic contention about this code: the displayed text is the same on both lines but the “meaning” is different. Obviously the first is paragraph text, and the second is a top-level heading. But these two lines are distinctly different lines. The one does not imply the other. One does not “figure” the other. Strictly speaking, considered as code, the content of each line is not the same. Each line can mean one and only one thing and it is different for each.
If this were not the case then code would be useless. Ambiguity in code is deadly. Just imagine the nightmare of trying to debug code in which a single line could be interpreted in 2 (or heaven forbid more) ways at the same time in the same context! But ambiguity is a strength in poetry. Ambiguity is poetry. The poet’s ability to give the same words multiple meanings at the same time is what makes a good poem good! Ambiguous figurative language is poetic language.
just look again at the example of poetry Matt provided. He quoted the following lines from Robert frost:
The woods are lovely, dark, and deep,
But I have promises to keep.
And miles to go before I sleep,
And miles to go before I sleep.
We could unpack the meaning of these lines for hours. What do the woods signify? Why are they lovely, but also dark and deep? Does sleep refer to death, or to the comforts of home, or both? We cannot derive the same joy from the lines of HTML code quoted above, nor would it be good if we could.
Code is not poetry. It can be excellent, beautiful even, but its beauty must be judged by a different standard than the beauty of poetry. Code is craft, poetry is art. Excellent code is certainly worthy of pursuit, laudable to master, but it will never be art. Speaking as one who loves to code, but hates to debug it, I’m thankful that is so.