DEV Community

Cover image for Poetry in Code
Boris Orekhov
Boris Orekhov

Posted on

Poetry in Code

Poetry in Code: When Code Becomes Poetry

Have you ever written poetry in Java? Or C++? It turns out there’s a whole genre at the intersection of programming and poetry — code poetry. Not just poems about computers or programmers, but actual executable programs that are also poetic texts.

Ten years ago I published a paper proposing a method for analysing such works. Here are the key ideas — I think the dev.to community will find them interesting.


What is it?

Imagine writing code in Java, Python, or even CSS — it runs and works. But at the same time, the source code itself reads like a poem: rhythm, metre, imagery.

Here’s an example from Habr (2013):

if (newGame) resources.free();

s = FILENAME + 3;

setLocation(); load(s);

loadDialog.process();

try { setGamerColor(RED); }
catch(Exception e) { reset(); }

while (notReady) { object.make();
  if (resourceNotFound) break; }

byte result; // change to int!

music();

System.out.print("");
Enter fullscreen mode Exit fullscreen mode

This Java code can be compiled and executed. And when read aloud, it follows a strict trochaic tetrameter. The author deliberately arranged the accents so that the rhythm aligns with the poetic metre.


How to classify such works?

In the paper I proposed three main analytical criteria:

1. Programming language choice

  • High‑level languages (Python, PHP, Perl) — closer to humans, accessible to a wider audience.
  • Low‑level languages (assembly) — elitist, requiring deep expertise.
  • Dead languages (Pascal, Cobol) — like Latin poetry, archaic.

Example from a Stanford poetry slam (C++):

class For_every {
public:
  void ngular(){cout << endl << "I";};
  void que(){cout<<"f";};
  void ng(){cout<<"w";};
  void ghting(){cout << "d";};
  void ving(){cout << "e";};
  void on(){cout << " n";};
};

int main() {
  For_every i;
  i.ngular(); i.quet(); i.ng();
  i.ving(); i.ghting();
  i.vidual(); i.on();
}
Enter fullscreen mode Exit fullscreen mode

Thanks to variable names (i, us) and method names, the sequence produces a phrase: "I fought we will surely seperately" — the theme of “I vs. we”.

2. Functional load

What does the program do? Even if pragmatically “useless”, the program’s intended behaviour matters.

Example: an infinite loop in C as a metaphor for addiction:

void addiction() {
  int mind = 1;
  while (true) {
    mind = mind + 1;
    if (mind < 0) break;
  }
}
Enter fullscreen mode Exit fullscreen mode

An infinite loop is usually considered a bug, but here it becomes an artistic device.

3. Dependence on natural language

Can code poetry avoid relying on English? That’s the holy grail. Most authors use English words as variable names — e.g., an SQL query:

INSERT your hand INTO mine
SELECT restaurant FROM nearby
WHERE you would LIKE to date;
Enter fullscreen mode Exit fullscreen mode

This is essentially English wrapped in SQL syntax. But if one could express meaning purely through the programming language itself (without borrowed natural language) — that would be a new art form, understandable to any developer regardless of their mother tongue.


Not just “normal” languages

At the Code Poetry Slam (Stanford, 2013–2015), even non‑Turing‑complete languages like CSS or lists of HTTP status codes are accepted.

For example:

201 created
200 OK
100 continue
303 see other
302 found
409 conflict
403 forbidden
520 origin error
...
Enter fullscreen mode Exit fullscreen mode

These are Apache web server response codes. But arranged like this, they evoke a lyrical mood — reminiscent of human life with its errors, redirects, and successes.

Or CSS:

.ocean {
  color: cornflowerblue;
  pitch: high;
  overflow: visible;
}
.boat {
  color: firebrick;
  transform: rotate(94deg);
  float: none;
}
.rescue-team {
  visibility: visible;
}
Enter fullscreen mode Exit fullscreen mode

That’s already a narrative about a capsized boat and a rescue team.


Poetry in Code

What’s next?

I think this practice is more than a hype. Behind it are:

  • therapeutic relief (programmers unwind through creativity);
  • carnivalisation of professional language;
  • the search for new expressive means.

Of course, when the element of contrast wears off, the wave may subside. But for now, such texts keep appearing, and a subculture has already formed around them. Over time, researchers will amass a whole corpus of “poetic programs”.


Link to the full paper

If you want to dive deeper, here’s the PDF (in Russian, but with an English abstract and plenty of code examples):

🔗 https://nevmenandr.github.io/portfolio/assets/pdf/21.pdf

APA citation:

Orekhov, B. (2016). Stikhi v programmnom kode: sovremennyy opyt i metodika analiza [Poetry in program code: Contemporary experience and analysis methods]. Kritika i Semiotika, (2), 94–101. https://nevmenandr.github.io/portfolio/assets/pdf/21.pdf

BibTeX citation:

@article{Orekhov2015programmpoetry,
  title = {Стихи в программном коде: современный опыт и методика анализа},
  author = {Орехов, Борис},
  year = {2016},
  journal = {Критика и семиотика},
  number = {2},
  pages = {94--101},
  issn = {2307-1737},
  keywords = {poetry discourse, poetic text analysis, programming languages}
}
Enter fullscreen mode Exit fullscreen mode

Let me know in the comments — have you ever tried writing “code poetry”? Or do you know other examples? 👨‍💻📜

Top comments (0)