Posts Tagged ‘learning’

Design Patterns study group

Sunday, January 17th, 2010

A new thing at Eden is we have started a study group and we are currently studying the Gang of Four Design Patterns book. I’ve read this before but i’ve not studied it. I guess i got an overview and thought to myself, “Well, i know where to look if i ever want to look up a pattern …” – Have i ever looked up a pattern since? No! ;)

So i’m really glad to be studying it this time and really getting to know the patterns properly so that i can use them readily whenever appropriate. It’s good to have the opportunity to discuss one pattern at a time in a group. Here’s a photo from the first study group last week:

Design Patterns Study Group

As part of my studying, i am implementing examples of the patterns in Ruby. Last week i coded the Factory Method example. It’s funny how i can skim over the code in the book and convince myself that i understand it, but coming to implement it for myself in a different language was a challenge. One that i thoroughly enjoyed, i have to say! :) I’m happy to say that i now fully understand the factory method!

I’ve also been writing tests to ensure the code works as i expect. This has been useful because i’ve learned about Test::Unit which was previously unknown to me. When i joined Eden i learned RSpec and Cucumber (or story_runner or whatever it was called back then). Other than that i’d never tested Ruby before.

This week i have been implementing sorting algorithms as strategies. I wasn’t too impressed with the code examples in the book for the Strategy pattern, largely because they left out all the code that actually differs between the strategies! So i decided to make up my own example. It has been good to refresh my memory on sorting algorithms at the same time as clarifying how the Strategy pattern works.

You can follow along with my workings on sermoa/ruby_design_patterns.

A testing framework

Saturday, November 28th, 2009

Enrique has amended my task so that i cannot use any existing testing framework, not even Ruby’s built-in Test::Unit. However, i must practice test-driven development! Ha ha ha!

So here i am trying to ponder how to write a unit testing framework. Which is actually really nice because i get to decide the syntax i would like to use, and maybe – just maybe – i’ll come up with something that suits me really well and i’ll use again.

Enrique pointed me to the Given specification framework which i like because it uses the BDD ‘given/when/then’ approach for unit-level specifications. I’m already used to this kind of format for Cucumber features. Effectively, we use ‘given/then/when’ for Rspec, but it’s not made explicitly obvious. My comments in this trivial example should make it obvious:

describe "example" do
  before do
    @counter = 1             #(given)
  end

  it "increments the counter" do
    @counter += 2            #(when)
    @counter.should == 3     #(then)
  end
end

Now i think i could make the ‘given/when/then’ more obvious, and i can also simplify it. I might actually change ‘then’ to ‘expect’, meaning i can do away with the ’should’ method. Effectively i’m saying that whatever is in the ‘expect’ block should return true, otherwise the spec fails. Here’s what i’m thinking of:

spec do
  given { @counter = 1 }
  when { @counter += 2 }
  expect { @counter == 3 }
end

I suppose this is what people call a DSL – a domain-specific language. That is the kind of language i’d like to use to write my specs. I’ve never written a DSL before, but i’m excited by the idea of being able to write specs like this, so i’m looking forward to giving it a go!

A little voice in the back of my head is telling me i’m going to have to finally understand ‘lambda’ properly. Lambda is one of those things that never sticks in my head. I can look it up when i need to and blunder my way to making it work, but i never really understand what it’s doing or how or why. I have a suspicion that i’ll be making extensive use of ‘lambda’ in my testing framework! :)

Apprenticeship

Wednesday, November 25th, 2009

I am pleased to say that today i have been offered an apprenticeship under Enrique Comba Riepenhausen and i have accepted! From this moment on we have entered into a formal mentor-apprentice relationship where i will learn as much as possible from Enrique, and Enrique will mentor me to become a better software crafter. I expect it to be hard work but very rewarding.

I am proud and honoured to have been given this opportunity. I am glad that it has become official because i need my learning to be accountable to somebody. I am great at starting new things but really bad at following them through. To be answerable to Enrique will be very good for me, and i know that there is a lot that i can learn from Enrique.

My first task is to write a wiki engine in pure Ruby, with no libraries other than a testing framework. So no Rails, no Sinatra, no Mongrel, no plugins. This is to teach me the real core of Ruby as a language, without relying on other people’s code for shortcuts.

I guess the first thing i need to figure out is how to make the application listen for HTTP requests. Which i can honestly say right now i don’t have the faintest clue! Let the learning begin!