Diving for Perls - the poetry of programming
Good code is pure poetry, the elegant exposition of the perfect solution for a given problem. Bad code is an impenetratable nightmare, clumsy in shape and confused in purpose. A well-written computer program is a poem and depends for its effect on precision of syntax and a close understanding of the language in which it is written. Good code looks right, smells right, falls well on the page, fits together with other code, and slots into place.
Good code looks right even when you don't know the purpose for which it was written. This is something that every good programmer knows. Good code just works, and even when it fails, is easy to fix. Code that doesn't feel right at a glance is almost certainly better rewritten from scratch, or you'll never get to the end of the problem.
Is code really like poetry? The hypothesis depends upon the programmer's willingness to see his or her work as a creative process. Richard Gabriel, who carries the splendid job title of 'Distinguished Engineer' at Sun Microsystems, holds both a Doctorate in Computer Science and an MA in Poetry. His work at Sun Microsystems involves researching "the architecture, design, and implementation of very large systems, and development techniques for building them."
He advocates a programme that offers a Master of Fine Arts in software, similar to the university programmes that offer MFAs in creative writing. "Traditions of computer science and software engineering have tried to turn all aspects of software creation into a pure engineering discipline, when they clearly are not", he says. "The MFA in software would begin to repair this error."
As someone who writes both code and poetry, Gabriel says that: "When I am writing poetry, it feels like the centre of my thinking is in a particular place, and when I am writing code, the centre of my thinking feels in the same kind of place."
Walking on one-legged stilts
The idea that computer programming has a relationship to the arts, or the even more controversial belief that creative programming should be taught as an arts subject, is not new. Lovers of science and mathematics have traditionally seen a mysterious beauty in the configuration and symmetry of numbers that is similar to the poet's feel for the texture and colour of words, or the painter's feel for the harmony and sound of paint. And poetry, the assemblage of words into a form that conveys meaning through rhythm and sound, is essentially mathematical even when it says it isn't.
Every form of poetry depends upon a reference to a structure that is as formal as the constructs of a computer programming language, or of a piece of music. The traditional forms, ballads or sonnets, have obvious constraints of metre and sound, and the good poet has a veritable armoury of tricks and techniques that are purely technical and transcend the apparent substance or matter of the poem. Poetry is not the preserve of the mystic and the seer, nor the possession of maiden aunts and the lumpen bourgeousie. Free forms of poetry may claim to have escaped the rules of form or metre, but are just as dependent on the sound and rhythm of words and our expectations of their meaning, even in the absence of formal structure - in much the same way as John Cage's representation of silence in his famous piece, 4'33", depends on the audience's expectations of a performance for its realisation as a piece of music.
Good poetry is often the triumph of technique over substance. A poet such as Dylan Thomas, who was a master of the word trade, often sacrificed substance for effects, rhythms, incantations and repetitions, that were the perfection of a technique that could weave wonderful effects, and seem like magic, even if the final product of poems such as 'Now, say nay' appear to be relatively meaningless. (Thomas himself said of this poem to Vernon Watkins that "so far as he knew it had no meaning at all.") On the other hand, such techniques are capable of conveying a meaning above and beyond the poet's immediate intention, as is shown by the popularity of Thomas's work with the public - a ranking it hasn't always shared in the world of literary criticism, where many critics dismiss Thomas as a showman.
The most famous example of a poet understanding the runes of his art is Rimbaud's 'Vowels', where he gives every vowel a colour and a metaphor that describes the vowel's effect:
Black A, white E, red I, green U, blue O
Brought down to their bones these techniques, which have always been used in story telling, in casting spells and political oratory, are as formal as any used in programming, and depend upon a similar knowledge or intuitive understanding of the tools of one's craft or art. Poetry relies as much on the shape, texture, rhythm, and smell of words as it does on formal meaning. The craft of poetry, like the craft of programming, depends upon a fine understanding of the uses and abuses of language and syntax. The programmer may not profess to higher emotions, but precision and elegance are as much a foundation of the good programmer's art and craft as they are of the poet's.
Yet how many programmers go in search of the great hacks of the past, and learn from them? Programming languages are not developing as fast as they might, or we would have left the repetitious tasks behind. The programming class is lazy in its adherence to imperfect solutions. Much of this is engendered by the market where employers demand programmers with experience in this or that language, (and never wonder that understanding the mechanics of one language is not so different to understanding the mechanics of another), or because the research departments of many universities (from which the majority of these languages arose) have been corralled into the service of corporations, and proprietary interests push software users into an inhibited and narrow universe... but one thing that good programmers share with professional writers, artists, musicians and poets is an obsessive attention to the detailed cause and effect of what they do....
Computers have only been with us for half a century, but artists and poets were quick to see the potential of computer languages and code as material for their art. As early as 1962, OuLiPo (Ouvroir de LittÃ©rature Potentielle, or "Workshop of Potential Literature"), a Paris-based group of writers founded by the radical author, Raymond Queneau, and the mathematician, FranÃ§ois LeLionnais, were looking for new vocabularies for art. Other well-known members were the Italian Italo Calvino who won a Nobel Prize for Literature, Marcel Duchamp and Harry Matthews. OuLiPo's declared purpose was to expand literature by borrowing formal patterns from other domains such as mathematics, computing, logic or chess.
The OuLiPo writers specialised in producing works that played with the conventional rules and constraints of medium and language - "Chinese boxes. Constraints of vocabulary and grammar, constraints of the novel (divisions into chapters, etc.) or of classical tragedy (rule of the three unities), constraints of general versification, constraints of fixed forms (as in the case of the rondeau or the sonnet)."
The first OuLiPo Manifesto proposed "anaglyphic poems, texts that are transformable by projection, etc. Other forays may be imagined, notably into the area of special vocabulary (crows, foxes, dolphins, the Algol computer language)." But it was 10 years or more before LeLionnais and NoÃ«l Arnaud first published poetry written in Algol computer code.
OuLiPo declared itself to be interested in "developing new possibilities unknown to our predecessors... Cent Mille Milliards de poÃ¨mes or Boolean haikus." As such they predated by twenty years or more the digital artists of the present who use code and code output to generate art that is sometimes random by design and is sometimes constrained by random design.
Perhaps the most extreme of the OuLiPo writers was Georges Perec, whose work has ranged from a novel that excluded all words containing the letter "E", to the longest palindrome ever written, "Ã§a ne va pas san dire", which contained more than five thousand words, and a 466 word short story in French where the only vowel allowed was "A". The term for a work that excludes a particular letter, in Perec's case the novel 'La Disparition' which excludes the letter "E", is a lipogram, so 'La Disparition' is a lipogram in "E". Most remarkably, Perec's works are entertaining and credible works in their own right, irrespective of the constraints and word play at their heart.
The OuLiPo writers and their brethren can can be seen as direct antecedents of the digital artists and poets of the present.
Using program code as poetry itself took off in the Perl community in the early 90s. The first Perl haiku was written by Larry Wall, and its genesis is described in Sharon Hopkins paper 'Camels and Needles: Computer Poetry Meets the Perl Programming Language'. These days several forums exist for people to display their adventures into Perl code poetry, and like all forms of poetry, much of it is banal and uninspired, but there is also much to admire.
When it comes to aping the trick of writing poetry in code, the poet may be limited by the scope for adventure in the language itself. The languages of southern Europe may be called the romance languages, and may contain within them the seeds of poetry, but how can we know who are specialists in one language? Nobody would ever mistake Cobol for a language of romance. Nobody ever wrote a poem in Cobol, and few would ever find Cobol a language that offered creative possibilities. Programmers with little experience of Cobol would see it as a language that leaves scant room for imaginative scope. The Cobol programmer who dreams of code and poetry should probably look elsewhere, (although I stand to be corrected), but can take solace in the knowledge that poems have been written in its equally aged siblings, Algol and FORTRAN. Even Perec would find it diffcult to create plausible literature using Cobol as his starting point. But we can dream and learn.
Music is maths
Both mathematicians and computer programmers will habitually talk of the elegance or otherwise of any particular solution. What is meant by an elegant solution depends, of course, on an aesthetic or subjective evaluation of of the code or equation, just as much as it does on the rightness of the answer. In his 'Passages from the life of a philosopher', Charles Babbage, the creator of the first mechanical computing machine (if you discount the abacus), quoted Elias de Joncourt's 1762 quarto. 'On the nature and Notable Use of the Most Simple Trigonal Numbers', in which de Joncourt asserted:
"The Trigonals here to be found, and nowhere else, are exactly elaborate. Let the candid reader make the best of these numbers, and feel (if possible) in perusing my work the pleasure I had in composing it. That sweet joy may arise from such contemplations can not be denied. Numbers and lines have many charms unseen by vulgar eyes, and only discovered to the unwearied and respectful sons of Art. In features the serpentine line (who starts not at the name) produces beauty and love; and in numbers high powers and humble roots give soft delight. Lo! the raptured arithmetician! Easily satisfied, he asks no Brussels lace, nor a coach and six. To calculate contents his liveliest desires, and obedient numbers are within his reach."
An assumption of modern education is that Art and Science are mutually exclusive disciplines, as if a man who paints shouldn't know how things work, and the man who counts should have no taste for art or music. Everyone is qualified, but few are educated in the classical sense, with a rounded education in the liberal arts. Students of software engineering and design, like others in the engineering disciplines, are taught the mechanics of their craft, but not the art, and would benefit from the kind of lateral thinking that the arts demand.
It hasn't always been so. Music was once taught as a science, one of the four disciplines of the Oxford quadrivium, alongside arithmetic, geometry and astronomy. Music, it was understood, had much to teach about the study of harmonics and harmonic principles, and the study of the motion of the planets and stars, or the "music of the spheres".
Brian Capleton tells us that as late as 1746 William Tans'ur defined a "Master of Musick" in 'A New Musical Grammar' as someone who "must not only be a grammarian, but also a Master of Letters and Languages, in order to unfold what is locked up in the Closets of the Learned - He must be an Arithmetitian and able to explain Numbers, and even the Misteries of Algebra; and also a Geometrician, to evince a great variety, the Original of Intervals, Consonant and Dissonant..."
That music and the science of numbers are related is indisputable, whether we are talking about the characteristics of rhythm, or the primary intervals in Western music. Music is imbued with mathematics. As many avant garde and classical composers have proved, it is possible to compose music that is aurally satisfying on purely mathematical principles, and all music can be broken down into harmonic structures that contain an inherent numerical consistency. Pierre Boulez, the radical 20th century French composer, began his career as a mathematician, and failed the pianist's entrance examination to the Paris Conservatoire, but "viewed composition as a form of aesthetic research and demanded that it be conducted on stringently scientific (that is, logical) lines."
The assertion that code and poetry have a relationship beyond a mutual reliance on language and syntax is controversial only because many programmers think they know what poetry is, and know that they don't like it, and many poets, or fans of poetry, don't understand the art of programming, and don't want to know anyway. These tribal divisions are less excusable in a world where the intersection between technology and the arts is closer than it ever was. We thrive on media, multimedia, music, tv, video, and pretend that we don't.
If we understand programming as an art form we gain a wider perspective on tackling solutions that are adaptable to changing realities, new hardware and other less predictable eventualities. If we see programming as merely functional we take a short term view, and the code does not live beyond its immediate purpose. The future will be populated with machines and if we don't inform the vision of where we are going from the perspective of art and culture, the prospect is at once both dull and frightening.
Helicopters and submarines
The separation between art and science is a relatively recent phenonemon. Renaissance man took an interest in everything around him. Leonardo da Vinci is as famous for his invention of the helicopter and the submarine as he is for painting the Last Supper and the Mona Lisa. When Lewis Carroll published 'Alice in Wonderland' in 1865, Queen Victoria was so enchanted she asked that his next book be dedicated to her. He obliged by dedicating 'An elementary Treatise on Determinants With their Application to Simultaneous Linear Equations and Algebraic Geometry' to her. The 'Elementary Treatise' was published in 1867 under his real name, Charles Dodgson.
Code and poetry have a long, if sometimes tangential, relationship that can be traced back to the beginning of computing. The first programmer of Babbage's Analytical Engine was Ada Augusta, Countess of Lovelace, who was the offspring of the short-lived marriage between George, Lord Byron, the most popular poet of the Romantic Age, and the heiress Annabella Milbanke, whom Byron called his "Princess of Parallelograms". Annabella MilBanke was an amateur mathematician and scientist. Byron left for Italy in disgrace, because of his incestuous relationship with his half-sister Augusta, when Ada was one week old, and never set eyes on her again. He died in the Greek War of Liberation when she was eight years old.
Despite, or because of, her lack of a relationship with her father, Ada grew up with an equal love for both science and poetry. According to Betty O'Toole, her biographer: "In her thirties, Ada wrote to her mother: 'If you can't give me poetry, can't you give me poetical science?' Her understanding of mathematics was laced with imagination, and described in metaphors."
A century after her death, Ada gained the rare distinction of having a computer language named after her. She was also a pioneer for the role of women in science. Male geeks would do well to remember that the first hacker was not only extraordinarily talented, but also a woman...
Lost in bits
Good code may be poetry but the truth remains that all computer technology is built on a sequence of on and off switches. The programmer's job is to build them in the right order. There is no mystery to this. Computer programs are not, except in the most remarkable circumstances, the work of geniuses who are above the flow, or somehow apart.
But if you are an artist you can build the commands of your chosen language into elegant structures that provide elegant solutions to a given set of problems. That is the main aim of most good programmers, to make a program which is a small work of art - the best expression of the best solution. And that is why programming computer code, in the right environment, can be a creative and satisfying task, or indeed, why so many programmers freely contribute their time and code to GNU/Linux and other free software projects in such abundance.
As the digital poet David 'jhave' Johnston says of Richard Stallman: "Why not label his programming work poetry and call it art? It is socially compassionate, extraordinarily intellectual, and devotedly imaginative. In the way that a Bach sonata is constructed, so too these massive operating system programs are interleaved and interwoven symmetries evocative of structural beauty. Writing a work of the size of GNU is comparable to the achievements of Dostoevsky. And unlike the contemporary artistic model of individual authorship, the open source movement is a collaborative environment, these are truly creations of collectives."
Programmers as poets - David 'jhave' Johnston
Music, mathematics and philosophy - Brian Capleton
Camels and Needles: Computer Poetry Meets the Perl Programming Language
The Poetry of Programming - interview with Richard Gabriel