Posts tonen met het label Event. Alle posts tonen
Posts tonen met het label Event. Alle posts tonen

dinsdag 20 september 2011

Another Code Retreat and some TDD as you meant it

Saturday I had the honor of attending another code retreat hosted by Agile Minds at Qframe.  This code retreat was a bit special to me as we were only with 6 men.  Though it was a small code retreat, it was the best one I’ve attended so far!  

We did a total of 5 sessions so no luck breaking the world record ;-) Every session was pretty intense.
The main thing that I’ve learned from this code retreat is that TDD as you meant it can be allot more useful than I initially thought.  Let me first in layman’s terms explain to you what it is.

The most important thing in TDD as you meant it, actually in TDD in general is to have NO design plans up front.  Your mind must be clear of any predefined design choices!  The main focus is to let your test drive you design.  

Then what is the difference with just normal TDD?  Well in TDD as you meant it you actually have no choice then to let the design flow out of your tests.  This is because you write the actual implementation code inside your test.  Here is a small example in function of Conway’s Game of Life:

1. The first step is to write one failing test:

[TestMethod]
public void ALivingCellCanDie()
{
    object cell = new object();

    // implementation code comes here

    Assert.IsNull(cell);
}

As you can see in this method we don’t assume anything.  We didn’t assume that the cell would be a Boolean, there is not Game object, no Grid object, no Cell object, no design what so ever.  We are just testing the fact that the notion of a cell can die.

2. Make the test pass by writing the implementation code in the test:

So our test is red, now we can implement it.  The implementation would become:

[TestMethod]
public void ALivingCellCanDie()
{
    object cell = new object();

    cell = null;

    Assert.IsNull(cell);
}

That just looks like rubbish don’t it?  Well yeah… but keep in mind we have nothing at this point, and the first 2, 3 to 4 tests will look silly but then the patterns start emerging :-)

3. Create a new implementation function by:
               1. Doing an extract method on the implementation code
               2. Move the implementation code into an existing implementation method

Since we don’t have an existing method we’ll extract a new one:

[TestMethod]
public void ALivingCellCanDie()
{
    object cell = new object();

    cell = Die();

    Assert.IsNull(cell);
}

private object Die()
{
    return null;
}

4. Only create new methods in the test class

This is important because you’re not sure up front where these methods belong.  You might think that the Die method could belong to some kind of assassin object, but maybe another test will convince you that it doesn’t! 

5. Only create implementation classes to provide a destination for the extracted methods.

After a while when you keep doing this you’ll might notice that some methods belong to each other, at this stage you can start creating an implementation class for them.  But be sure that you have enough proof that shows you that these implementations belong to that object.

6. Populate implementation classes by doing move method from a test class into them

You should only move the methods out of your test class.  There shouldn’t be any need to adapt the methods so they fit inside this object.  When you feel the need for changing the implementation code then you might be doing too much.

7. Refactor as required

At this stage you might have some cleaning up to do, then this is the time to do it.  You have green tests so you’ll always be sure that your code works.

I must admit that at first this is a very bitter pill to swallow. It’s slow and tormenting but in the end you’ll produce very clean, testable and loosely coupled code. Understandably this might be too difficult and slow to use in a production environment and I know that when you’re on a deadline this could prove to be too much overhead.  But I encourage people that have some spare time left to try this out.  It will provide you with a new angle to tackle your problems and you’ll probably end up with a design you never expected.

I’ve enjoyed this code retreat allot and will probably subscribe to more of them.  If you’re interested then register here.  

Big thanks to Erik and Adrian for hosting the code retreat!

Till next time :-)

dinsdag 9 augustus 2011

Code Retreat Agile Minds

This Saturday I’ve had the pleasure of attending a code retreat hosted by Agile Minds.  The hosts were Erik Talboom and Adrian Bolboaca.  In case you don’t know what a code retreat is, here is a quick explanation:

A code retreat is an event where a bunch of geeks… euh fellow developers come together to spend their united time coding.  You get 45 minutes to code the assignment which is Conway’s Game of Life.  It might seem boring implementing the same problem over and over but I guarantee you that no implementation of this problem is ever the same. 

The goal of the event isn’t to finish the task at hand but to write the cleanest code possible.  For us developers this is hard to grasp because we have the urge to deliver. But delivering a final product is at the bottom of the priority list here.  

The assignment has to be coded in pair.  After every 45 minutes you have to switch pairs.  This makes it even more interesting because every time you start a new session, you are forced to reconsider your implementation with the ideas of the person you’ve paired up with.  It’s not allowed to pair up with someone twice so you’ll always have a different angle to tackle the problem.

At the start of the event Erik gave us a few recommendations.  He said that you’re not obligated to follow them but it’s strongly recommended that you do so.  One of the recommendations was that you write your code in a TDD fashion.  I’ve had some practical experience working test driven but I didn’t know you could take it that far.  One of the eye openers was TDD as if you meant it.

I’ve already done a code retreat once hosted by my employer, but this code retreat was different in several aspects.  The people in this code retreat were total strangers to me (except for one colleague of mine). I found it very interesting to pair up with people you’ve never seen before because you didn’t know what to expect from them.  It was also different in the way that this code retreat was language agnostic, meaning it didn’t matter what your preferred language was. There were people doing java, ruby, C#, python, etc.  I loved this aspect of the code retreat as it gave me the chance of trying out Ruby and Python, languages I’ve never done before.

It surprised me that there were a few people who had difficulty grasping the concepts of a code retreat.  They were stuck with the notion of delivering a final product and didn’t seem to be able to get their heads around the fact that a code retreat does not equal a coding dojo or programming contest :-). Though I think at the end of the day everyone had a fair idea of what to do.

It was really fun participating in this code retreat and I’m certainly joining the next one.  The learning experience was awesome.  Some of the stuff I’ve kept in the back of my head is:
  • Let TDD drive your design
  • Doing TDD will help you archive other solutions for your problem instead of the predefined one in your head
  • Everyone has a different angle for the same problem.  Combining insights can deliver promising results!
  • Having 2 keyboards is very useful when programming in pair
  • I’ve got to try out ruby
  • Python is one damn ugly language
Certainly take a look at the website of Agile Minds and join us next code retreat (recursion joke...)!

vrijdag 29 april 2011

Techdays belgium

This week I went to techdays in Belgium and here is a small wrap-up:

The content was in my opinion less advertising then last year.  This could be because there are fewer technologies in the pipeline this year, but I found it a nice change then the usual: ‘this is our product and it’s the best’ – talks.  The main topics / technologies this year were NuGet, ASP.NET MVC 3, Silverlight, Windows Phone 7 and Windows Azure.  Off course there were also some other talks about the trend of programming languages and sharepoint, but the majority of the talks involved the previous mentioned technologies.

Some of the memorable talks were:

The keynote:
The keynote was given by Scott Hanselman.  I’m normally a big fan off Scott, but I didn’t like the keynote very much.  Normally, they talk about what’s in store in general, but this time it was more off a NuGet and ASP.NET MVC talk which he was going to show in another talk anyway... 

Silverlight, WP7 and some other stuff stirred not blended or whatever…:
The next talk I followed was the ‘Silverlight, windows Phone 7, windows azure, JQuery,… shaken, not stirred’ session.  It was a nice showcase of an existing application but nothing more.  I did not learn anything new, nor was there anything to learn.  The speaker showed us an application in which they’ve used RIA services in combination with Windows Phone 7.  It was nice to see how they’ve also managed to create an ASP.NET MVC frontend and a web UI using JQuery Mobile.

Silverlight 5:
Afterwards I followed the Silverlight 5 talk by Jeff Prosise.  I enjoyed his talk.  Not only is Jeff Prosise a very good speaker, the content he delivered was nice to.  Silverlight 5 seems to contain some very promising features like Markup Extensions, Text Improvements, Databinding enhancements (finally we can use relative binding to ancestortype!)  and some very impressive 3D rendering abilities.  He also demoed how the composition thread works and how it is used.  In all, I enjoyed his talk.

ASP.NET MVC 3 – Deep Dive:
Very nice talk by Hadi Hariri.  It was a bit out of my league because I’m not really that experienced with ASP.NET MVC but still he explained it well.  I laughed out loud when he made the remark: Partial classes is blasphemy …  and so is regions =D. 

NuGet in depth:
Scott Hanselman presented this talk in his usual comical way.  He showed us how to create your own NuGet package in a very original way.  He coded up a class and compiled it using nothing else but a dos prompt.  Immediately the day after I installed NuGet to get to play with it.  I really recommend everyone to use this tool.

Demystifying the .NET asynchronous Programming Landscape:
A talk given by Bart De Smet, a very clever man.  He showed how event driven async operations tend to lead to programmer faulths and showed us how to program asynchronously without the need to radically change your code.  He did this by explaining the new Async and Wait keywords.  I found it a real shame I did not see his Linq to everything talk, but I’m sure to watch it online later.  I encourage people to got to his VISUG talk next week.

Tips and Tricks and Techniques for Building Killer Silverlight Applications:
Another talk by Jeff Proise.  I learned quit a bit in this talk and I’m certain I’ll be able to apply half of it in the project I’m currently assigned to.  The talk was mainly about how to split up your XAP and download assemblies and load them in the appdomain on the fly.  He also showed some pitfalls when doing this (for example the compiler inlining short methods).  I enjoyed the talk and I found it for me to be one of the most educative talks on techdays (mainly because I’m a SL developer).

The other talks I did not follow or weren’t interesting enough to mention.   
Until next time ;)