Thursday, January 29, 2009

Sudoku Solver in Glimmer

Dave Hoover recently experimented with writing a Sudoku solver in Ruby, so Joseph Leddy and I decided to slap a Glimmer cover on top of it. We pair-programmed on writing it test-first following the Model View Presenter pattern.

Here is how the user-interface looks like:

I'll provide more details once I've committed the code to the Glimmer repository.

Wednesday, January 28, 2009

About My 2008/2009 Vacation

I've been wanting to blog about this for a while, so here it goes.

I spent my Christmas vacation this year in Dubai, and I got to see a lot of interesting things, such as the world's new highest tower (higher than CN), one of the world's largest malls (slightly larger than Edmonton's), a 7-star hotel that looks like a sail, an indoor skiing/snowboarding hill, palm artificial islands, and a hotel that is partially underwater and has a massive aquarium.

Best of all, through a friend of mine who works in technology in Dubai, I got to go to a programming user group meeting that had Matt Mullenweg from WordPress/Automattic.

Here are some photos from the trip:

Highest tower in the world (Burj Dubai)

Atlantis Hotel partially underwater at the head of the palm artificial islands

7-star hotel that looks like a sail (Burj al Arab)

Foggy skyscrapers

Indoor skiing/snowboarding hill

Me and a snowboard on the indoor hill

User group meeting with Matt from WordPress

Wednesday, January 14, 2009

Easily Typable

For the Rubyists of us, I created a new mixin module called EasilyTypable:

I am pasting the README for it over here:

Easily Typable


Often when working with models that belong to an inheritance hierarchy,
it is useful to verify if a particular model is of a certain type to
perform some behavior specific to it. For example, this is needed when
the view needs to handle a special rendering case when encountering a
certain type.

The call typically made to accomplish the task is:

Often, to do so in a more readable fashion, developers add a more
English-like method that hides the details of type checking:

Writing such methods gets repetitive after a while, so an easier way
to get these methods automatically is to mixin the EasilyTypable

When mixed into classes in an inheritance hierarchy, each class gets
"certain_type?" methods for its type and all of its subclass types.


require 'rubygems'
require 'spec'
require File.dirname(__FILE__) + '/../lib/easily_typable'

class TypeA
include Obtiva::EasilyTypable

class TypeB < TypeA

class TypeC < TypeB

describe "Obtiva::EasilyTypable" do
it "should add type_a? method to TypeA object" do be_true
it "should add type_b? method to TypeB object" do be_true
it "should add type_b? method to TypeA object" do be_false
it "should add type_c? method to TypeC object" do be_true
it "should add type_c? method to TypeA object" do be_false
it "should add type_c? method to TypeB object" do be_false

Keep in mind that this is no substitute for good Object-Oriented design and is not an excuse to type-check everything in your code instead of letting behavior live in the models or rely on patterns like Strategy and State.

The type checking methods are simply useful in cases where type-related behavior really should not live on the model to maintain its cohesion and avoid strong coupling. An example of that is View logic that depends on the type of the model, but should not live in the model.