Books + Head First C# + Lab 1 Solution
I’ve been reading through the new Head First book Head First C#
which appeared on Safari just before Christmas. I’ve been a fan of the Head Fist books ever since reading their best selling Head First Design Patterns book. This particular book is aimed at beginners / hobbyists so I’m not exactly the target audience but hey it covers C# 3 so its got to be worth at least a skim.
I was pleased to see they’ve added a new feature to the head first series namely lab sections. There are 3 lab sections in the book which are basically specifications for mini games, the idea being the reader creates the games using their newly acquired C# skills. I though this was a great idea and having a lot of spare time in front of my laptop over the Christmas (due to a very sore ankle) I did the first of the labs “A day at the races”.
I used the lab as an exercise in Behaviour Driven Development (BDD) which I’d recently read about here and here. I also got to try out a Test Data Builder I’d read about here. Now I’m not convinced I hit the nail on the head with the BDD as my solution wasn’t created in a test behaviour first manor. This was mainly due to the fact the book provides you with the shell of a solution to keep things nice and simple for beginners. Never the less it was a good fun doing the lab it’s a great way to try out new techniques.
All in all the BDD experience was pretty good not sure about the code duplication in the context setup but you got to love the way the descriptive contexts and method names combine to read like a sentence:
Also the Test Data Builder is a really flexible way to create test data using a fluent interface which again is really easy to read:
myGuy = new GuyBuilder().WithName("Joe").AndCash(50).Build();
You can download the solution here.