People like to say that code is poetry.

Programmers say it. Technology companies put it on office walls. Someone has almost certainly printed it on a mug and sold it for €19.95.

The comparison initially makes sense. Poetry and code both arrange language according to rules. A small change in syntax can alter the meaning of an entire line.

There is, however, an important difference. A poem will not refuse to open because you forgot a semicolon.

Still, the comparison deserves more than a place on office merchandise.

Every Language Has Its Grammar

Poets work within rules of syntax and form, even when their intention is to break them. Programmers face a similar constraint: the machine needs to understand what has been written.

Every programming language has its own grammar. Python insists on clean indentation. JavaScript is more relaxed, although it occasionally behaves like someone who says, “Don’t worry, I understand what you mean,” before doing something completely unexpected.

Within those rules, code develops rhythm. A loop creates recurrence. A condition interrupts it. Variables carry meaning from one line to the next, while functions prevent the entire program from becoming a 4,000-line stream of consciousness written by someone who has not slept since Tuesday.

A well-written function can possess the compactness of a haiku. It does exactly what it needs to do and leaves little behind for the next developer to untangle.

A badly written function resembles the kind of experimental poem that is mysterious to everyone except its author. Six months later, it may also be mysterious to the author.

Code Makes Things Visible

A poem creates an image in the reader’s imagination. Code can place one directly on the screen.

Behind every website or mobile application sits a set of instructions telling elements where to appear and how to behave. A designer imagines a button changing colour when someone moves a cursor over it. A developer translates that behaviour into code. The browser renders it, and the user clicks the button without noticing any of this before complaining that the page took half a second too long to load.

Code can also produce images whose beauty is inseparable from the rules behind them. Fractals and generative artworks emerge from calculations repeated at a scale no person would attempt manually. A short equation can produce elaborate branching forms or spirals that appear almost organic.

The computer performs every calculation exactly as instructed. The creative work lies in choosing the rule and recognising when its output has become interesting.

Engineering does not suddenly turn into art at that moment. The two simply become difficult to separate.

Abstraction Works Like Metaphor

A metaphor gives an abstract idea a form we can recognise. Programming abstractions perform a similar task.

A programmer creates classes and functions to represent parts of the world in a form the computer can process. A customer becomes an object. A purchase becomes an event. A shopping basket becomes a data structure that, unlike a real basket, can disappear completely because someone deployed an update late on Friday afternoon.

These abstractions make complicated systems manageable. Once something has a name, programmers can organise it and define how it should interact with the rest of the system.

The abstraction is never the thing itself, however. A class called Customer might contain a person’s name and purchase history. It cannot explain why that person spent 45 minutes comparing two nearly identical kettles before buying neither.

Some behaviour remains resistant to modelling. This is probably fortunate for both programmers and customers.

Every Coder Leaves a Trace

Emily Dickinson became known for her dashes. Edgar Allan Poe cultivated a somewhat darker atmosphere. Programmers reveal themselves through variable names and comments.

One developer documents the reason behind every unusual decision. Another believes that good code should explain itself. Somewhere in the same repository, a third has created variables named x, new_x and final_x_v2, leaving future colleagues to reconstruct their meaning like archaeologists working through the remains of a vanished civilisation.

These habits create a recognisable style. Some programmers compress an operation into one elegant line. Others expand it so that every step remains visible. A developer who enjoys recursion may solve a problem by asking a function to call itself. Another developer remembers the first time this produced an infinite loop and quietly chooses a different approach.

Code therefore carries evidence of the person who wrote it. It may not reveal the programmer’s soul, but it usually reveals their tolerance for documentation.

The Fibonacci Sequence, With Some Qualifications

The Fibonacci sequence begins simply:

0, 1, 1, 2, 3, 5, 8, 13…

Each new number is produced by adding the two numbers before it.

Fibonacci numbers appear in some patterns of plant growth, particularly in the arrangement of leaves, seeds and petals. They are often associated more broadly with shells, spirals and artistic composition, although popular accounts sometimes make the relationship sound more universal than it is. Nature has never signed an exclusivity agreement with Fibonacci.

A Python function can generate the sequence like this:

def fibonacci(n):

numbers = []

current, next_number = 0, 1

while len(numbers) < n:

numbers.append(current)

current, next_number = next_number, current + next_number

return numbers

The function begins with two values. Each pass through the loop records the current number and calculates the one that follows.

Its structure is easy to trace because every line develops from the state created by the previous line. Remove one operation or change its order, and the sequence no longer grows as intended.

That resemblance to poetry is more convincing than the usual slogan. A line gains meaning partly from what came before it. Repetition establishes an expectation, while a small variation moves the work forward.

The difference is that Python will complain immediately when the structure fails. Readers of poetry may wait until the review appears.

Writing a Fibonacci Poem

The relationship can also work in the opposite direction. Instead of describing code as poetic, we can allow mathematics to determine the structure of a poem.

One approach is to write lines whose syllable counts follow the Fibonacci sequence:

1, 1, 2, 3, 5, 8…

For example:

Sun.

Grow.

Bright day.

Leaves unfold.

Spring whispers softly.

The garden remembers the light.

The poem expands according to the same numerical pattern as the sequence. Each line receives a little more room than the one before it.

This does not guarantee great poetry. Mathematics can provide a form, but it cannot prevent the result from becoming a carefully organised weather report.

The same limitation applies to software. A program can be beautifully structured and still solve a problem nobody has.

The Bug in the Metaphor

Calling code poetry can become romantic very quickly.

Most programmers do not spend their afternoons contemplating an elegant algorithm while soft piano music plays nearby. They search for missing brackets and read documentation written for an earlier version of the framework. They also investigate why code that worked yesterday has developed strong opinions overnight.

Yet this everyday frustration may make the comparison more accurate.

Poetry does not arrive fully formed through inspiration. A poem is rewritten. Lines are removed because they sounded better in the writer’s mind than they do on the page. At some point, the writer may suspect that the entire piece should be abandoned.

Programming follows a recognisable pattern. An idea feels clear until it has to be translated into instructions precise enough for a machine. The first attempt reveals what the programmer failed to consider. The next attempt fixes one problem and introduces another in a location that appeared completely unrelated.

Both practices depend on revision because language exposes the gaps in an idea.

Code is not automatically poetry. Most of it has a practical job to perform, and much of it would prefer not to be examined as literature.

But occasionally, a difficult problem is reduced to a few lines that another person can understand immediately. Nothing is missing, and nothing has been included merely to appear clever.

At that moment, code comes close to poetry.

At least until someone updates a dependency.