Read about:

Archive for November, 2009

Rediscovering my music


Years ago, I was torn between two passions. I had loved tinkering with computers and other electronic gadgets since I was as young as 10 (possibly younger!). But I also played the piano, taking lessons with my sisters and playing around with melodies and chords on the keys when I wasn’t practicing my lesson pieces.

That love of music carried into high school. I had stopped playing piano but in music class I picked up the clarinet quite quickly. I transferred to another school after grade 9 because the school I was in was planning to cut their music program entirely and I could not imagine being without it. At my new school, I was blown away when I heard the excellent performances of the senior jazz band and ensembles. I was fiercely determined to play with them but not many modern jazz arrangements called for a clarinet. So I learned to play saxophones.

At the same time, I continued tinkering with computers, teaching myself how to program because I wanted to program video games one day. An exhibit at the Ontario Science Centre featuring the “new” graphical web browsers, Netscape and Mosaic, inspired me to try my own hand at web publishing as soon as we were able to get connected to the Internet. In high school programming classes, I was well ahead of the curve, frequently finishing assignments meant to take hours in a matter of minutes.

And so, when I graduated from high school and decided I wanted to go to university, I had a difficult choice to make: which of these two things would I choose to focus on?
Read the rest of this entry »

Adventures in Ruby: When Constants Aren’t


I just squashed a bug that had me scratching my head for at least a good half-hour or so involving a class constant that kept on getting changed. Here’s the setup (anonymized so that I’m not exposing gooey proprietary secrets):

class WebTransaction
  # Base URL for transaction web service
  def transaction_url
    url = SERVICE_URL
    url < < "VAL1=foo"
    url << "&VAL2=bar"

The class is meant to represent a transaction being posted against a rather odd web service that actually uses GET rather than POST for posting transactions (bad web service!). In my actual code, the URL parameters appended to the SERVICE_URL base would be determined on a per-object basis but I’ve simplified it here.

Here’s the punchline: SERVICE_URL was changing! Calls to transaction_url would keep on appending more variables to it. If you’re particularly clever with Ruby, you’ve already figured out exactly why. But if you’re scratching your head like I was, here are some hints:

  • In Ruby, constants aren’t. In fact, they’re really no different from variables except for the fact that Ruby detects that variable names in all-caps are probably supposed to stay constant and warns if you try to assign to them.
  • <<, for strings, will append to the end of the string.
  • Ruby strings are mutable. That is, operations on a string variable will usually be done in place, rather than returning a new string. (Method calls, on the other hand, are a different story!)
  • Assigning a String variable to another String variable will assign the reference. That is, the two variables will be pointing at the same object.

Hit the jump to see the solution to this little mystery…
Read the rest of this entry »