54
Shall I C ompare Thee to a Line of C ode?

Shall I Compare Thee To a Line of Code? (with presenter notes)

Embed Size (px)

Citation preview

Shall I Compare Thee to a

Line of Code?

Lauren Scott

Developer at Brad’s Deals RailsBridge Chapter Lead

Chicago, IL

@devdame devdame.com

…and poet.

- That’s me reading Dylan Thomas’s Fern Hill at Fern Hill in Wales! - left home at 15 to go to boarding school - about 8 formal years of instruction - got my BA in creative writing with a focus in poetry - published in many literary journals

- surprisingly, it turns out poet isn’t a career - so I had to find something else - programming was a good step because it’s both logical and creative - and unlike poems, people actually pay you for writing code NOW: How many of you have read any poetry? (should be all of you!) How many of you would say you like poetry? How many of you have read poetry outside of mandatory English class? How many of you have written poetry? Well, let’s do a poetry run-down!

Poetry Run-Down• poem

The Poem by George Oppen

A poetry of the meaning of words And a bond with the universe

I think there is no light in the world but the world

And I think there is light

Poetry Run-Down• poem

• lineThe Poem by George Oppen

A poetry of the meaning of words And a bond with the universe

I think there is no light in the world but the world

And I think there is light

Poetry Run-Down• poem

• line

• line break

The Poem by George Oppen

A poetry of the meaning of words And a bond with the universe

I think there is no light in the world but the world

And I think there is light

<br> tag!

Poetry Run-Down• poem

• line

• line break

• stanza

The Poem by George Oppen

A poetry of the meaning of words And a bond with the universe

I think there is no light in the world but the world

And I think there is light

Poetry Run-DownForm Poems

• set structure or pattern

• eg: sonnet, limerick, haiku

• SOMETIMES have a rhyme scheme

vs Free Verse• no constraints • no rhymes

required! • most poetry

written today

- it’s not that free verse doesn’t include its own structure, rhyme, or attention to sound - these elements still shape the free verse poetry, but the structure of them is not predetermined

- these things originated in form poetry for very specific reasons - particularly, to make things easier to memorize in a time where literary knowledge was an oral tradition and memorization was how things survived - think about music—there are patterns that help us recognize and remember songs, such as verses and choruses, rhyming lyrics, repetition of melodies. - Time signatures! How key are those to us remembering music?

and it’s not as stuffy as you think

- antiquated! not useful! not descriptive of US! - a relic of the past but no! - you don’t have to love “bluebird poetry” to love poetry - even I get bored with that shit

HeatHere in the electric dusk your naked lover tips the glass high and the ice cubes fall against her teeth. It’s beautiful Susan, her hair sticky with gin, Our Lady of Wet Glass-Rings on the Album Cover, streaming with hatred in the heat as the record falls and the snake-band chords begin to break like terrible news from the Rolling Stones, and such a last light—full of spheres and zones. August, you’re just an erotic hallucination, just so much feverishly produced kazoo music, are you serious?—this large oven impersonating night, this exhaustion mutilated to resemble passion, the bogus moon of tenderness and magic you hold out to each prisoner like a cup of light?

by Denis Johnson

- no bluebirds, right? - and if you still think that’s stuffy, then oh boy there is ALSO some poetry out there for YOU

So, what about programming?

Now that you know a thing or two about poetry let’s jump into it’s connections with programming! You might already have noticed the big one:

Language

- Both poetry and programming are ways of creating meaning from language. - Language is the creative medium - And when I say creative, I don’t necessarily mean that I think all of our programs are going to be as “creative” as a poem, or a painting, or any piece of

“art”. - I’m talking about the act of creating something new. We are using our medium—language, in this case—to make something that serves a certain

purpose. - Whether that purpose is tangible (like ordering pizza for delivery) or intangible (like conveying the devastation of losing a loved one) is irrelevant in this

context - Either way, we are attempting to address our purpose in language - And of course, with language comes … syntax!

–Oscar Wilde

“I have spent most of the day putting in a comma and the rest of the day taking it out.”

Syntax

- read quote - obviously, syntax is a big part of programming - and it’s something that poets are keenly attuned to as well - both uses of syntax require a huge attention to detail to make sure that something as small as one punctuation mark is the right one to use at the

moment

- syntax changes everything! - explain oxford comma - but this example is just concerning actual grammatical rules - in poetry, you don’t have to be grammatically correct - but the way that you put your sentences together really MEANS something - every decision you make regarding syntax changes the reader’s impression of the poem. - if you don’t want the poem’s voice to be formal or authoritative, for example, you might eschew capital letters or excessive punctuation. - a run-on sentence can create a feeling of anxiety or urgency

White SpaceThe negative space around your

words

(The joy of proper indentation!)

- poets often talk about “white space”, the negative space that surrounds your words - it can have a profound effect on your poetry—the same words with different white space can mean different things - one of the first things you learn as a programmer is how to properly indent things so that other people can understand your code - and in the case of some languages, it’s key to the computer understanding it as well - in both fields, you get trained to have a gut response to how the white space in your work looks - which is WHY we can use it as a tool to help others understand our code - example of hard to understand code

- if you ever work with beginners, I’m sure you’ve seen this at some point - if a beginner was working on this and asked for help, it would take me so much longer to help her because the lack of white space obscures the

meaning of the code - what if we took away all of the whitespace? - like trying to read minified html or javascript - it’s just… not going to happen

- One of the very first similarities I noticed when I was starting out was how code often visually mirrors poetry. - You can see it here, where I’ve put some code from Rails up next to part of a Sylvia Plath poem. - I’ve blurred it so that we focus on form rather than content - You can see how the stanzas in the Plath poem look a lot like the methods in Rails - Much like the methods, the stanzas are separated from each other to separate thought

And here, looking at an e e cummings poem, you can see the different feel the white space can give you - without reading this, you might already have a feeling that the poem will be very different than the Plath poem on the last slide

Condensed Communication

- in both forms, you have something you’re trying to communicate with the reader through language, be it a human or a computer - a poem has an expected output just like a program does—it aims for something, whether it’s conveying an emotion or idea, or just giving the reader a

certain feeling - you can really think of a poem as a program - the reader enters the poemgram and we expect it to change them somehow - destructive method! - the difficult bit, of course, is the testing - and both of these forms strive for brevity - you’re trying to say the most with the least amount of words - more on that later! :)

Creativity Within Constraints

- When you come down to it, both poetry and code are about creativity within constraints - One of the biggest types of constraints in poetry is, when you choose to use it, form poetry.

Take a Sonnet

• 14 lines long

• Three quatrains (4-line stanzas)

• The volta—a logical turn

• One couplet (2-line stanza)

• All in iambic pentameter

“But soft! what light through yonder window breaks?”

(Elizabethan, not Petrarchan)

- Prosody—the study of meter and rhythm in poetry

And the rhyme scheme:———————-A ———————-B ———————-A ———————-B

———————-C ———————-D ———————-C ———————-D

———————-E ———————-F ———————-E ———————-F

———————-G ———————-G

sun red dun head

white cheeks delight reeks

know sound go ground

rare compare

- you’ve heard enough about them, now let’s take a look at one! - here’s one of my favorites by Shakespeare, the same one from this rhyme scheme example - pay attention to the logical progression of the poem—keep your eyes out for the volta!

Shakespeare’s Sonnet no. 130My mistress’ eyes are nothing like the sun; Coral is far more red than her lips’ red; If snow be white, why then her breasts are dun; If hairs be wires, black wires grow on her head.

I have seen roses damasked, red and white, But no such roses see I in her cheeks; And in some perfumes is there more delight Than in the breath that from my mistress reeks.

I love to hear her speak, yet well I know That music hath a far more pleasing sound; I grant I never saw a goddess go; My mistress when she walks treads on the ground.

And yet, by heaven, I think my love as rare As any she belied with false compare.

(read the dang poem) - so you can see how the form works for him here - the first three stanzas, he’s telling us about all the ways in which his mistress is not perfect - he’s riffing on the flowery love poems popular at the time that idolized the lover - but then the last couplet flips the arguments he’s been making - and he shows us that loving these imperfections is more honest than idealizing her - SO. you can see a LOT goes into the sonnet.

and it’s gotta be GOOD!

- it’s REALLY HARD fitting what you’re trying to say into this form - and if you think this is hard, a sonnet is a relatively simple form - there are SO MANY MORE and they get a LOT more challenging - like a heroic crown of sonnets! 15 sonnets, last one is first lines of first 14 in order - sometimes it can be extremely frustrating - it can be easy to start to hate the “form for keeping you back”

Rhyme & ReasonForms help you….

• organize thought

• pay attention to sound

• develop patterns and rhythms

• plain old get started

• and much more!

- but there’s a REASON for these forms - these things were developed and have stuck around because they give helpful guidelines and set you up with a structure that works - forms help you…… (bullets) - each form brings a different set of tools to the table that help you do all kinds of different things with your poem - your form is there to HELP you!

Challenges are FUN

- when i first started writing form poetry, I got really excited - like, write my college entrance essays in iambic pentameter in quatrains with end rhyme excited - everything was a PUZZLE! which you programmers know can be addictive - when you have a hammer, everything looks like a nail - it’s easy to get caught up in the low level challenges, like making a thought fit the meter and rhyme scheme, and forget the high-level challenges - like: should i be using this form? does it help this particular poem or idea?

Sound familiar?• Frameworks!

• Languages!

• Design patterns! (ABAB => MVC)

- this might sound familiar to you all by now! - form poetry is really similar to some of our tools in programming - (go through list) - like form poetry, these are all things we’ve created to give ourselves helpful guidelines and make our code easier to write - but I’m sure we’ve all had times where we are really struggling against the form that we’ve chosen to write in

forest first, trees later

• is your form the right form?

• not every poem is a sonnet!

• not every app is MVC!

notice the red flags

- you might be tempted to change so many low-level things trying to get the darn thing to fit in there that… - you start to LOSE THE POSITIVE THINGS the form was supposed to provide for you - that’s when you should ask yourself: is this the right form? - it’s totally okay to break conventions sometimes and not follow every last rule strictly - but if you find you want to change EVERYTHING, particularly the more high-level thought structures of the poem, or the things that the language or

framework is particularly good at, what good is it doing you? would a diff form be better? - you have to trust yourself to make changes, but know how to recognize your red flags. - Get yourself into the routine of asking: why am I using this form?

okay, so then what?

- You pick your form! Or you go free verse! Or you pick a language and a framework and you get to writin’! - but then…

But what makes code and poetry good?

• Both are subjective

• People have opinions!

• Contextual creation is hard to teach

• But we have guidelines

- you & coworkers might debate about the best way to code something - and god knows there are a million opinions about everything programming related on the internet - when it comes down to it, it’s just hard to teach something that is going to change so much based off of the context, whether it be a line in the context

of a poem or a controller in the context of an app - BUT! We have plenty of guidelines in both fields that help us along the way. And one of the main ones that applies to both is:

Say a lot with a little

• Use just enough language to make yourself clear

• Make sure every word is necessary

• But what do we deem “necessary”?

- I told you we’d get back to this! :) - in both fields, people really like it when things are concise - you want to use just enough language to make yourself clear, no more, no less - one thing I ask myself a lot when I’m writing a poem is, “is this word necessary to the poem? will I lose something if I take it out? what have I gained by

putting it in?” - which is a great question! but first, we have to decide what we mean by “necessary”.

A balance of two factors:

fact & beauty

- it helps to think of it as a balancing act between what I’m going to call fact and beauty

Fact

• What the code does

• What the poetry means

(functionality / message)

what you say

- by fact, I mean the functionality of your code, or the “narrative”, so to speak, of your poetry - by narrative, i don’t mean that the poem needs a plot (lots of poems don’t have that aspect) but just the main things you’re trying to get across to the

reader - it’s what you say

Beauty

• The clarity of the code

• The “poem-y” parts of the poem

(readability / imagery)

how you say it

- by beauty, I mean the readability and human-consumption-friendliness of your code, and the imagery or “poem-y” parts of your poem - I’m making the assumption here that readable code is something you’re striving for, which I think most of us are - basically, this is how you say things NOW: let’s take a look at a poem famous for saying a lot with a little.

In a Station of the Metro

The apparition of these faces in the crowd; Petals on a wet, black bough.

by Ezra Pound

- Pound is able to convey a huge amount of feeling in just two lines. This is pretty much the favorite small poem of English majors everywhere. - so why is the balance so important here?

without beauty, fact can be irrelevant

- a poem that tells you what it’s about with no embellishment might be clear, but it loses its magic - a convoluted line of code that’s chained 15 methods long might work, but it is not only difficult for others to read, it can actually be painful - much like bad poetry. - so what if Pound had gone too far in stripping down the essence of his poem?

I Was In the Metro

I saw faces in the crowd; They were beautiful.

by Ezra “Just the Facts” Pound

- not only is this not particularly fun to read, but it’s also LOSING some of the meaning that it had before - we don’t get the full richness of the poem and all of the extra things that it conveyed with the beauty of its imagery - you can think of imagery and metaphor sort of like variables or methods - by referencing one thing, you have access to much more information - by itself, a method might not tell that much of a story, but in the context of your code it makes sense, it comes alive

but too much elaboration

loses focus

- if you go on and on with your imagery and flowery words, you are diluting the message your poem has - just like adding unnecessary comments and breaking your code up too much in the name of readability - if Pound hadn’t said only what he needed to, we could have ended up with this:

In a Dreary Station of the Metro

I was deep down in the Metro, looking at the crowd, and these faces appeared almost as if they were ghosts.

The metro was a dark cavern, the crowd a solid mass , but the faces were clear, delicate, fleeting, a brief moment of beauty in the otherwise dark world, like flower petals stuck to a slick black bough wet with rain.

by Ezra “Pile It On” Pound

much less impactful, right? - poetry also follows the rule of “don’t repeat yourself” - say it once and say it well, so you don’t need to say it again - and use the methods and variables available to you! - Pound didn’t need to go on about how he felt when he saw the faces in the crowd - he called on the included library of human experience and told us it was like petals on a wet black bough, which held the rest of the information we

needed

remember the human aspect

- Ultimately (if you work with other developers) your code isn’t just meant to be consumed by the computer—it’s also consumed by other people - By forgoing readability, you cut other people out of the equation. You’re not writing poems, you’re just journaling. - So maybe try approaching your code with that question I asked myself about my poetry: is each word necessary? and is there anything that’s not being

said? - and remember that readability can be just as necessary as function

so how do we teach the contextual?

- a lot of these “guidelines” we are talking about are fairly dependent on making gut decisions - it can be pretty difficult to teach people how to make the best decisions based off of their contexts - or even to agree on what the best decisions are when you KNOW the context! - there’s a lot we can learn from the way that poetry is taught

workshops

- the vast majority of a poet or writer’s education is spent in writing workshops - in a college program, you’ll be taking at least one of these at all times - the classes usually have a small number of students, think maybe 8 of them, and rely heavily on giving feedback to each other - when it’s your turn to be workshopped, you’ll give your poem or poems to the class the week before, and they read everything and mark it up with

comments and critiques - when you reconvene, you’ll read your poem out loud to the class, and then everyone discusses it - and then comes the terrifying part…

- for the first part of the discussion, you’re not allowed to talk - and by the first part, I mean it’s usually most of the discussion - you sit there while your classmates critique your poem, and you’re not allowed to jump in and explain anything or answer any questions - and oh man do they ever get it wrong sometimes. it is incredibly difficult to stay quiet. - but by not being able to reply, you are given a gift: you know what your poem says when it speaks for itself.

you won’t always be there

- because when your poem is out in a literary journal or a book, you will not be there to defend it. - You can’t give your readers the missing piece of information that makes them go “ohhh I get it now!” - So even if you don’t agree with the critique, which often you won’t, you still get some very valuable information: how people react to your work as it

stands by itself, not as it stands explained by you. - And with programming, if a bug comes up you might have moved on to the next job, you might be out of the office, you might have just forgotten what

you were thinking when you coded it, so you cannot rely on yourself being there to explain it

try being silent

- so what I’m suggesting here is difficult. - it’s even difficult for me! I find myself wanting to explain my decisions all of the time - I think a lot of it comes out of a fear that someone will mis-understand you and think that you don’t know the things you do - but if your code isn’t speaking for itself, it is valuable for you to stay silent, to listen, and to see if the way you are writing it is unclear to the people

around you - you can explain yourself later, and often you’ll need to, but allow yourself a moment to get that raw feedback - you might hear actionable pieces of information that you might have not heard otherwise

How to implement:• Implement workshop-style code reviews

• Stay silent in code reviews or on PRs until you’ve gotten your feedback

• Weekly lunch & learn, workshop style

• Start a Coder’s Workshop with friends

• Just embrace silence personally

- those of you who implement code reviews might already have something a little bit like this at your job! - and a pull request certainly is similar. - i suggest doing this in an environment where you tell the reviewers about it so that they don’t think you’re unresponsive.

- it can be easy to become attached to the things that we make - One of the hardest things I’ve had to overcome as a writer is thinking of my poems as “precious” - when you put a lot of yourself into the creative process, and you’re proud of what you’ve accomplished, it can become extremely difficult to change that

thing - our poems, or our code, become like our children—we refuse to think anything they do is other than perfect. we love and accept them as they are. - and when we think this way, our work stagnates

kill what you love

- what i’m going to say to you now is kill what you love - no, i don’t mean always - no, you don’t have to completely gut it - but be ready and willing to destroy things that are precious to you

- because you don’t know when that feature will be canceled - or if they’ll use your coworker’s implementation - or if you’ll get feedback you can learn and grow from

you != what you make

- the more you conflate yourself with the things you produce, the harder it’s going to be when you need to change them - remember that, although you might put a lot of yourself into what you do, your work is not YOU - and changing or destroying your work is not a sign of personal defeat - the majority of the most famous poems out there went through countless revisions—or, as we’d say, refactors - often, early drafts of the poems look nothing like what they end up like. if those poets kept their work precious, they never would have achieved the

things that they did.

before you go…

- I’m not the only one who’s made this connection

code {poems} code-poems.com

Code can speak literature, logic, maths. It contains different layers of abstraction and it

links them to the physical world of processors and memory chips. All these resources can contribute in expanding the boundaries of

contemporary poetry by using code as a new language. Code to speak about life or death, love or hate. Code meant to be read, not run.

- code {poems} was a project by some programmers in 2012 who noticed the similarities between programming and poetry - they gathered poems written in programming language from coders and artists alike - the programs don’t have to do anything, but they should be valid, compilable code - the book is available online at the Centre de Cultura Contemporania de Barcelona, and you should GET IT OMG

- a poem from the book, written by Jeffrey Knight

Lauren Scott @devdame devdame.com

thank you so much for coming out today! find me all over the internet as devdame