The Tyrant Fears the Code Poet
During the earliest stages of my nontraditional software engineering education, I would often sit down to code and place my computer on a table covered with books of poetry. I loved coding but drew my power and sustenance as a Black woman from the words of poets like Jamila Woods, Jericho Brown, and Fatimah Asghar. The apparent contradiction between my interests always left me with a tiny itch, somehow, but I couldn’t quite put my finger on what the feeling was trying to tell me. I went on improving my coding skills while amassing poetry collections until one day, during a routine dive down some random internet rabbit hole, I stumbled upon precisely what I needed. I’d discovered the solution to that peculiar itch: code poetry. The tools for a robust engineering and artistic medium were right in front of my face, and I had finally found the connection!
Code poems are a type of writing that combines traditional poetry with computer code. These poems, written in various coding languages, may or may not run as executable programs. This discovery filled me with excitement, both because I understood the challenge of learning to code as an adult, and because my previous career had involved educating girls and gender-nonconforming youth in technology and engineering. I immediately recognized the familiar pairing of art with science, technology, engineering, and math (STEM). This pairing is a combination that research shows leads to increased participation, higher racial and gender diversity, and improved retention within STEM fields.
Now that I’m a professional engineer, I can say that writing code poetry has only become more important to me. Approaching coding with a poetic lens sparks my creativity, improves my mastery of coding languages, and helps keep me emotionally grounded in a technical environment where I am a minority of a minority. Plus, it’s just super fun.
To run the poem, click the green “run” button at the top of the page. To interact with this code and make your own changes, simply click the “fork” button to the left of the “run” button. This will copy the poem into an editor where you can make changes to the code yourself. Note that the lines that start with
// are comments that the machine does not run.
Let’s walk through a poem
To dive deeper into a code poem, we will use another poem, “Awareness(person)”. You’ll see that the poem itself is 29 lines long and produces 2 lines of output when it is run. I will dissect the components of this poem, which can all be customized and reused as building blocks as you create your own code poetry.
console.info() is a piece of code for creating output that prints whatever you put in the parentheses. Make sure you use quotes when you want it to print a string of words! This line is what causes my poem to print “Welcome,” as it begins to run.
let the first time you use it. After that, you can use just the variable on its own throughout the rest of your code.
This is a function. A function is a set series of operations (sort of like tasks) that are performed on a given input. This input is referred to as a “parameter.” Our example function has a name:
Awareness() and a parameter:
person. This function has several operations inside of it, so we’ll look at each step-by-step.
We see more variables here. They are all set to empty strings of words because we want to reset their values to other words later on.
Now we create another variable to hold the result of our function. We give the
Awareness function an input of our
anAndroid Object. It will perform the operations that we laid out then set the result to equal our
Lastly, we print out the result!
Try renaming the variable
anAndroid throughout the code and see what happens. Play with making changes to different words, but remember that you have to change the name of a variable or a function anywhere that it shows up in order for the code to run properly! For example, if I only change
anAndroid on line 3, but not on line 29, I will get this error when I try to run my code:
If you come up with any other errors, copy and paste them into a search engine to find solutions to your error! This is a valuable problem solving tool that coders use every day.
You did it!
Yes, that was a lot for a beginner code poem, so congratulate yourself for getting through it! Now have fun playing with these examples and using the pieces to craft your own poem. The example poems run, but the most important thing to remember is that
you do not have to make poetry that runs in order to be a code poet!
You can search through the documentation that I referenced throughout this article to find pieces of code that inspire you and put them together to form your poems. Please post links to any poetry that you create in the comments. I’d love to see what you all come up with!
This article was originally published here via Medium.