Programmatic poetry

I was working on a WordPress plugin today that will allow users/developers to stop a javascript from running on a particular page.  That doesn’t sound very exciting, but it got me thinking about the WordPress adage “code is poetry”.  (Blame this on my recent initiative for going slow — I had this idea when I was taking the dog outside…)  I was thinking about the thought process behind that, about how good, semantic code should have a flow and be easy to read and understand.  The tabs and spaces certainly hint at poetry, but what if you took that a step further?

This led me to an interesting idea (hark!): what if you actually wrote poetry like code?  What if you wrote a story/novel like code?  Here’s my line of thinking…

There is a flow to writing code.  Often times it’s written in a quasi-stream-of-consciousness style as you add new functions as you think of them and are testing your program.  You’ll write a function that will tie into another function and call another function.  There are variables that come in and out of different functions and perform different actions.  When the code is complete, you have a finished product that can be executed and enjoyed.  There are parallels in storytelling.  Functions are storytelling elements — plot arcs, story lines, relationships — that tie into other functions (plot arcs, story lines, etc) and involve many different variables.  A variable in programming is a placeholder for a specific object (unit, text string, array of values) that holds a value that can be referred to later.  Variables can be static or they can be changed as new variables or values are added to them (or removed from them).  Variables, therefore, can be characters (or, possibly, a family of characters).

Here’s an example:

function story() {

    // introduce three main characters as global variables
    $tom = 'main character';
    $bill = 'friend of tom';
    $sally = 'love interest';

    function tom_flashback() {

        globals $tom, $bill, $sally;

        $sam = 'father of tom';
        $room = array($tom, $bill, $sally);

        function childhood($sam) {

            bad_stuff_happens($sam, $tom);


        if ( in_array($room, $sally) ) {

        while ( $sam != 'deceased' ) {
            $memory = childhood($sam);



…and so on.  What it becomes is a dynamic story outline that can continually be added to — new characters introduced, new plot lines added — in a non-linear way.  PHP (which I’m basing this from, but you could conceivably translate this into any programming language) is read from the top down, but in execution, it can jump around.  For example, tom_flashback would happen whenever that function was actually called.  The memory of bad_stuff_happens in $tom‘s childhood only persists as long as $sam is alive.  The argument() only happens when $sam and $bill are both in the same $room with $sally, in which case it’s always the same old thing (presumably there’d be a love_triangle() plot point in there somewhere).  So you’d build out this non-linear narrative, and maybe just write out the argument() portion.  Then later you could flesh out the $memory of $tom‘s childhood().

As a user, you’re typically unaware of the programming language under the hood, so none of this pseudocode would ever manifest in any way into the actual story.  When you go to finalize your story, you would piece together these different functions based on how they actually execute (e.g. the function is called), but when you’re writing it, you might write from the top down.

I’m interested in this idea because it’s absurdly nerdy and also because it is an actually feasible and functional method for outlining a story that could be as epic or as minor as you want it to be (but it seems like it would lend itself better to the epic side of things).  It also would allow you to focus on scenes rather than trying to conceptualize the entire story, so you could really just worry about certain parts and then piece them together later (when all the “functions” were written).  The only prerequisite, of course, is that you’re familiar enough with coding that you could write pseudocode all day long like the above.  Syntax errors don’t really matter, of course, and no one (other than yourself) is going to know if you never finished that bad_stuff_happens function, but the beauty is that you could continue to add to the “code” and just call that particular function much later in the story().

Anyway, that’s my brilliant new idea for a writing method.  I’d be interested in anyone’s reactions or suggestions.  I may or may not start using this for my own writing.

2 Replies to “Programmatic poetry”

  1. Hmm.. I am actually not familiar with this but it looks interesting and the idea is a lot more unique compared to others.. Anyway, I hope this is a big help for us..

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.