Ruby Haiku: Code is Poetry

73

By melbel

This is a collection of three poems, ooh a trilogy! Each poem is a haiku.

Ruby I

Matsumoto's child

dynamically typed

OOP language

Ruby II

Written in Ruby

object oriented code

everything is beautiful

Ruby III

Beautiful Ruby

downloading gems (libraries)

code is poetry

Implementation of Ruby Haiku

line_of_code = [
  "Written in Ruby, object oriented code, everything is
    beautiful",
  "Matsumoto's child, dynamically typed, OOP language",
  "Beautiful Ruby, downloading gem (library), code is
    poetry"]

def write_poetry(line)
  puts line
  puts
end

line_of_code.each do |something_beautiful|
  write_poetry(something_beautiful)
end

About the Poems

I decided to make a somewhat nerdy poem. I ended up with three and couldn't pick my favorite, so I'm sharing them all.

This is actually something of an offshoot of another Ruby poem I wrote, which I could not publish as it's kind of floating around the Internet. However, I think these three actually turned out better than that first one I'd written.

I decided to write these poem using the rules of haiku as it is a Japanese form of poetry. Since Ruby was created by Yukihiro Matsumoto in Japan, I felt it was appropriate. I decided to include this information in one of the poems, so I started the first line of "Ruby I" with "Matsumoto's child."

Code Poetry Is a Thing?

Yep! Coding poetry is a hobby for some programmers. The rules of code poetry state that the code must be both poetic (in some way) and must run. Definitely bonus points if the way in which the program runs is related to or adds to the idea behind the poem itself.

Code poetry that doesn't actually run is just a poem, but still pretty cool!

About the Implementation

I had to write this code because I think it better conveys the idea that writing in Ruby is like writing poetry.

In the code, I have three strings (pieces of text) and each one is a poem. All the poems are put in an array (kind of like a list), which I named line_of_code.

I created a method in this code. A method is kind of like a verb in a program. It's the part of the program that does specific things. I named my method write_poetry. What I made this method do is print whatever words I tell it to on the screen, with a space in between each line.

Then, I write the actual code that makes everything work, starting with "line_of_code.each do |something_beautiful|". Here, I am telling my program to go through the list, one item (or poem, in this case) at a time with something called an iterator. Most people name their iterator "i" for iterator, but I decided to name it "something_beautiful".

Not Just Ruby, Perl Too

The programming language that's perhaps the most famous for code poetry is Perl. In fact, the poem Black Perl by Larry Wall is sheer genius! The poem is something that a non-programmer would enjoy, but it also runs* which is seriously awesome!

*Programming languages are constantly updating and growing. When the poem was first released in 1990, it ran. However, Perl has grown since then (we're on Perl 6 now, the poem was written in Perl 3)

On the next line, I have "write_poetry(something_beautiful)" which is where I'm telling the program that I want to use my method (the program's "verb"). Like the English language, verbs need information. For example, the verb "run." You can't just have a sentence that says "Run." Run where? How should I run? Run away from zombies? Or run to them?

In a program, you need to give your verb some information. The verb here, write_poetry, is getting it's information from what is called a parameter, in this case something_beautiful. Something_beautiful is the current item on the list/array. So, this would mean write_poetry using something_beautiful.

I chose to use an array because this is a collection, however small, of poetry and I thought that this would kind of convey how writing a line of code is like writing poetry.

While in the actual poems above, each part is on its own line, when run through my program, each poem is on one line.

Comments

Savva Pelou profile image

Savva Pelou Level 2 Commenter 6 months ago

this is really clever stuff, i am a fan!

jenubouka profile image

jenubouka Level 8 Commenter 6 months ago

Huh! Cool info Melbel, your poems were awesome

molometer profile image

molometer Level 8 Commenter 6 months ago

OMG

I have found someone who is a bigger Nerd than me.

What Genius.

I am in awe of your explanation and the poetry was pretty cool too.

I like the way this whole thing hands together so well to the history of ruby and it's creator.

I am in the presence of a true master.

Well done. I loved it.

voted up loads of buttons

melbel profile image

melbel Hub Author 6 months ago

Wow, everyone! Thank you! These comments are among some of the nicest things anyone has ever said to me! I appreciate the compliments. :)

I'm glad you liked the poems. :)

Sunshine625 profile image

Sunshine625 Level 8 Commenter 5 months ago

Outstanding Haiku and detailed information Melanie!:)

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    • No HTML is allowed in comments, but URLs will be hyperlinked
    • Comments are not for promoting your Hubs or other sites

    Please wait working