In case you missed it, the awesome Globay Day of Coderetreat occurred on December 3rd. The amount of fun I experienced was unexpected and impressive! I learned some things too. Read on to find out what.
(Also, don’t worry if you missed the code retreat, sad kitten has some good news for you at the end of this post.)
I managed to make it out to Knoxville where they held the most awesome code retreat. Congrats to Brian Friesen for putting together such an excellent event.
For those not familiar with code retreats, you pair program with six different people under different constraints during each session. You delete all code between sessions. And you only work on one problem, Conway’s Game of Life.
You can’t code Game of Life in forty-five minutes. Or you can, if you’re really really good. Or if you’ve done it five times before in the same day and you skimp on tests and still probably not even then.
Sometimes you’re the teacher, sometimes you’re the student. Enjoy both!
C# is looking cooler and cooler. But not cool enough to pull me away from Ruby. (Sorry .NET recruiters. You can stop emailing me now. Seriously. Stop.)
How to make proper use of equality in ruby to generate a unique collection of items.
Let’s talk about number four!
Most of the attendees were C# developers. I was the lone ruby hold out and convinced a couple of my fellow attendees to give ruby a try. They were enjoying the ruby exploration and implementation until we hit a little snag.
I wanted to get a Set of a Point class instances. Given an array of Points, I wanted ruby to spit back out only the unique items. Overriding == didn’t work. Overriding .eql? didn’t work either. Neither did any combination thereof. Gah, this was extremely frustrating.
After a precious wasted 10-15 minutes I, mildly embarassed, threw in the towel. We moved on.. and of course, did not finish implementing GoL in ruby.
The C# devs were still impressed with ruby but I couldn’t let it go. During the lunch break, I spent some time (another 10-15 minutes) googling and came up with:
See it in action here. I based the code on a nice module implementation of equality and further discussion of equality in ruby.
The key is to override both #hash and #eql?.
Upon further reflection, my chagrin at ignorance of implementing equality in arbitrary Ruby classes was misplaced. The point of a code retreat is to practice, to get better. To learn from one another. Sometimes, even when you’re the teacher, you’re still the student. That’s one of the reasons we love code reviews so much at Highgroove).
Have you gone to a code retreat? If so, what did you learn?
p.s. Oh, I almost forgot. The great news for those of you who missed it, or want to again, is that I’m hosting a code retreat in Athens in 2012. Come check it out!