We're hiring!

We're actively seeking developers & designers for our new Detroit location. Learn more

Learning to Program

This month I’ve been working through Chris Pine’s Learn to Program, a book intended for programming newbies like myself. Pine uses the Ruby language to teach elementary programming principles like variables, arrays, and classes. After reading several chapters and conveniently not doing the exercises, I decided I better open up Vim and experiment.

The first program I wrote asked the user (me) for my first, middle, and last name, and then repeated them to me in all caps. After several variations in this realm, I decided to try one of the more interesting challenges in the book: write a program that prints the lyrics to “99 Bottles of Beer on the Wall” using the while technique in Ruby.

After several painful failures, I began looking around the web for solutions. It wasn’t long before I discovered an entire site dedicated to the problem, http://99-bottles-of-beer.net/, which at the time of this writing contains versions in 1348 languages. There are 9 solutions to the problem in Ruby alone. Looking through these, I was ready to slam my aluminum unibody closed (carefully, I didn’t opt for the solid-state drive) and give up. All the samples included classes, something not yet covered in my book. I was having trouble parsing out the interplay of Fixnum and String instances in the code, let alone calling new classes.

The situation didn’t improve when I asked my developer colleagues for help. This exercise piqued their interest immediately, as it combined two popular things here at AO: Ruby and Beer. One suggested using the alias_method method to change puts to slam, a good joke to a niche group of programmers, perhaps, but it was not exactly pedagogically helpful. I was also informed of downto, but I wanted to use the toolset I had learned in Pine’s book. Finally, at around 6pm on a Friday night, I was able to get the program to run. Here’s a slightly cleaned-up version of the code:

The else initially threw some of my colleagues. Why did she call out a separate line for the last stanza? The answer – the product of a liberal arts education – is grammar. I simply couldn’t have one bottles of beer on the wall.

This entry was posted in Reviews and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted September 23, 2010 at 12:23 pm

    Q5ysBo cipzpshvfpvy, [url=http://vwiitgkdowdc.com/]vwiitgkdowdc[/url], [link=http://vsspojbgasil.com/]vsspojbgasil[/link], http://knvoykwtspjz.com/

  2. Earl Everett
    Posted September 23, 2010 at 12:23 pm

    Marissa,

    Did you test your code thoroughly? Unfortunately, the code review has revealed a bug. And a mortifying one at that. ;-)

  3. Ezra
    Posted September 23, 2010 at 12:23 pm

    lol, I love it

  4. Paul
    Posted September 23, 2010 at 12:23 pm

    Wanting to remove that _s_ means you are a UX designer at heart!

  5. Justice
    Posted September 23, 2010 at 12:23 pm

    class Object; alias_method :slam, :puts; end

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">