Sometimes, code is poetry

function codeAsPoetry()
    sometimes( code, "is", poetry )

    if code == poetry then
        it = is.made.with( "restraint" )
        
        simplicity = is( "valued" )
        code( isReused( "to achieve" ), simplicity )
        
        ironically( "this program, I would argue, is not poetic" )
    else
        sometimes( "it", "isn't" )
        
        -- I wouldn't call this poetry
        
        local this = "\112\114\105\110\116\040\034\092\110\073\032\119\111\117\108\100\110\039\116\032\099\097\108\108\032\116\104\105\115\032\112\111\101\116\114\121\092\110\034\041\059\112\114\105\110\116\040\034\116\104\105\115\032\105\115\032\109\101\115\115\121\034\041\059\112\114\105\110\116\040\034\092\116\111\118\101\114\045\099\111\109\112\108\105\099\097\116\101\100\034\041\059\112\114\105\110\116\040\034\092\110\092\116\092\116\121\101\116\032\111\098\115\099\117\114\101\100\092\110\034\041"
        
        if we( run( this ) ) then
            we( get( something ) .. " out" )
        end
        
        but( "it", "isn't", pretty() )
        
        -- this hides its meaning, like poetry often does
        -- but there is no ambiguity to the computer
    end
end

Poetry and programming share many similarities. Similar to how a more profound effect can be made with fewer words in poetry, simplicity is the key to cleaner code. Code is a method of communication; not only telling the computer which instructions it should execute, but telling other people who may work on the program what it is supposed to do. There are an infinite number of ways to tackle any problem, and the task of the programmer is to find an elegant solution which is easy to follow but also efficient in terms of computing.

I tried to illustrate some ways in which poetry is similar to programming by writing a poem in a programming language called Lua. My group members suggested I create a poem that is also code, and I was inspired by some of the entries to a contest about poetry written using code. I was unfortunately not able to be as elegant as they were in the construction of the program. The above code is the poem part, but will not run on its own. It requires a significant framework to define the various functions used in the poem part. I guess this could be a testament to programming's major difference from poetry. Everything needs to be spelled out explicitly; the computer does not try to interpret meaning.

The full program is below. I'll leave it as an exercise to the reader to execute the program: I suggest using this online interpreter. The code can just be copy-pasted in. Make sure to execute it a couple of times, because it doesn't always output the same thing.

math.randomseed( os.time() )

local code = "code"
local poetry = "poetry"

local function sometimes( arg1, modifier, arg2 )    
    local output = "sometimes " .. arg1 .. " " .. modifier
    
    if type( arg2 ) == "string" then
        output = output .. " " .. arg2
    end
    
    if modifier == "is" then
        if math.random( 0, 1 ) == 1 then
            code = arg2
        end
    elseif modifier == "isn't" then
        io.write( "\n" )
    end
    
    print( output )
end

local it

local is = { made = {} }
function is.made.with( arg )
    print( "it is made with " .. arg .. "\n" )
end

local isMetatable = {}
function isMetatable.__call( index, ... )
    local arg = ...
    print( "simplicity is " .. tostring( arg ) )
    

    code = function( ... )
        print( "code " .. table.concat( { ... }, " " ) )
        io.write( "\n" )
    end
    
    return "simplicity"
end

setmetatable( is, isMetatable )

local simplicity

local function isReused( arg )
    return "is reused " .. arg
end

local function ironically( text )
    print( "ironically" )
    print( text )
end

local run = load

local function we( arg )
    if type( arg ) == "function" then
        arg()
        return true
    elseif type( arg ) == "string" then
        print( "we " .. arg )
    end
end

local something = "something"

local function get( arg )
    return "get " .. tostring( arg )
end

local runNext

local function pretty()
    runNext = function()
        io.write( "\n" )
        print( "this hides its meaning, like poetry often does" )
        print( "but there is no ambiguity to the computer" )
    end
    
    return "pretty"
end

local function but( ... )
    print( "but " .. table.concat( { ... }, " " ) )
    runNext()
end

local function readPoem( name, author )
    print( name .. " by " .. author )
    io.write( "\n" )
    
    local poem = _G[ name ]
    if type( poem ) == "function" then
        poem()
    end
end

function codeAsPoetry()
    sometimes( code, "is", poetry )

    if code == poetry then
        it = is.made.with( "restraint" )
        
        simplicity = is( "valued" )
        code( isReused( "to achieve" ), simplicity )
        
        ironically( "this program, I would argue, is not poetic" )
    else
        sometimes( "it", "isn't" )
        
        -- I wouldn't call this poetry
        
        local this = "\112\114\105\110\116\040\034\092\110\073\032\119\111\117\108\100\110\039\116\032\099\097\108\108\032\116\104\105\115\032\112\111\101\116\114\121\092\110\034\041\059\112\114\105\110\116\040\034\116\104\105\115\032\105\115\032\109\101\115\115\121\034\041\059\112\114\105\110\116\040\034\092\116\111\118\101\114\045\099\111\109\112\108\105\099\097\116\101\100\034\041\059\112\114\105\110\116\040\034\092\110\092\116\092\116\121\101\116\032\111\098\115\099\117\114\101\100\092\110\034\041"
        
        if we( run( this ) ) then
            we( get( something ) .. " out" )
        end
        
        but( "it", "isn't", pretty() )
        
        -- this hides its meaning, like poetry often does
        -- but there is no ambiguity to the computer
    end
end

readPoem( "codeAsPoetry", "Julian Montague" )

Comments

  1. This is a really cool interpretation of our suggestion to write a poem in code. You obviously know what you're doing and/or did an impressive amount of research, and the end result is very interesting and kind of beautiful. Good job!

    ReplyDelete
  2. Brilliant, Jujubes. I like the amount of effort you put into this coding project, and the different options of poetry lines is pretty clever. It'd also be interesting if you made a random word generator or something that created poetry from a pool of random words, but I like the explicitness of this poetic code.

    ReplyDelete
  3. Wonderful solution to this problem, Julian. I like the way you highlight the connections and similarities between poetry and code ("simplicity is the key to cleaner code"), and also the salient differences ("Everything needs to be spelled out explicitly; the computer does not try to interpret meaning"). Reading your code and then running it through the translator, I was brought to mind of my brief stint with coding, when I took a couple of high school programming classes (in BASIC and Pascal). I enjoyed writing programs, but I was always amazed at how much time and energy it took to create a relatively simple result. I guess that's another difference between poetry and code, since it's possible to write a very small amount of poem and create a major, complex effect. But only if the poem is really great...

    ReplyDelete
  4. This Poem was in a foreign language to me the first time i read it, it took several tries to interpret what some of it meant. This depth creates a fascinating work of art, with hidden meanings only the author understands immediately. For some reason the list of the ascending numbers created a poetic rhythm in my head as i read through them, i have no idea if that was intentional but it was fascinating!

    ReplyDelete
  5. This poem was fascinating to read. I enjoyed how Lua's syntax and semantics were (ab)used to create something the reads a bit like english, and I also enjoyed the tangled web of control flow of the implementation.

    ReplyDelete
  6. Julian,
    I can definitely tell the time and effort that you put into this blog post and I think it really payed off. I like the way that you play with the syntax and your creative approach. Thanks for sharing this with us!

    ReplyDelete
  7. I love how you decided to use coding language to write poetry, especially how you emphasized the parallel needs to achieve simplicity in both code and art. I also really like that you allow readers to interact with the poem by putting it into an online interpreter. Awesome work!

    ReplyDelete
  8. This is great. I've never heard of the programming language called Lua, but this is definitely impressive. Even though it's something I've never seen before, there are a ton of similarities with other coding languages. This is an aspect of computer programming, which could also be an aspect of poetry.

    ReplyDelete

Post a Comment

Popular posts from this blog

Promiscuous Poetry

Science? Poetry.

Write a poem without the letter E. Write an explanation without the letter S.