Think a little, code a little
Date: 2009-08-05 00:13:12

I recently came across an interesting post by http://weblogs.asp.net/fbouma/default.aspx[Frans Bauma] entitled 'http://weblogs.asp.net/fbouma/archive/2009/07/26/think-first-doing-is-for-later.aspx[Think first, doing is for later]' which was linked to from http://codebetter.com/blogs/jeremy.miller/archive/2009/07/28/incremental-delivery-and-continuous-design.aspx[Jeremy Miller's blog entry about incremental delivery and continuous design].

Right now I find myself in favour of Jeremy's approach which is more about writing some code and then getting some feedback on it and then writing some more code instead of spending a lot of time thinking before we write any code.

My colleague http://blog.brianguthrie.com/[Brian Guthrie] http://twitter.com/bguthrie/status/2930492906[referred to this approach on twitter] as '*think a little code a little*' which I think sums it up pretty well.

The example that Frans gives is centred around algorithms so I wonder whether a bit of up front design to work out that we understand the algorithm is necessary before trying to code a solution.

On the other hand something that we've noticed in particular at http://www.markhneedham.com/blog/2009/07/04/coding-dojo-19-groovy-traveling-salesman-variation/[coding dojos] is that putting an idea into code helps to *generate a rhythm of progress* which we've struggled to create just by talking about the way that we think we can solve a problem.

Even with algorithms I find that I understand them more easily once they are written in code rather than just spoken about conceptually or drawn out in pseudocode.

My current thinking is therefore that I'd prefer to spend a little time thinking and then get the idea into the code more quickly even if that means we make more mistakes and have to do a few iterations of the code to end up where we want to be.

The alternative is to spend much more time thinking up front and then maybe getting to the solution more quickly but maybe realising that our idea doesn't work once we get into the code which means we haven't got that http://www.markhneedham.com/blog/2009/07/20/coding-quick-feedback/[feedback as quickly] as we might have been able to.

A similar idea is discussed in http://domaindrivendesign.org/[Domain Driven Design] where Eric Evans points out that while a model that we come up with on the whiteboard may seem perfect that doesn't actually matter if we find out that the idea doesn't quite work when we try and put it into the code.

Uncle Bob has also written about the difference between http://blog.objectmentor.com/articles/2009/04/25/the-scatology-of-agile-architecture[no design up front and spending some time thinking about what we want to do] and while some of the activities that we would do while thinking through an approach would be similar to those Frans' identifies, I don't feel the planning would go into quite that depth.

There is definitely a need for some thought in the process, however - what I refer to as http://www.markhneedham.com/blog/2009/07/21/good-lazy-and-bad-lazy/[lazy coding] is the extreme of what happens when we don't think at all about what we're doing and that leads to code which is completely unmaintainable and very difficult for both ourselves and our colleagues to understand.

Often when we do this type of thing we like to refer to it as 'http://iancartwright.com/blog/2009/01/five-kinds-of-technical-debt.html[technical debt]' but I quite like the distinction http://twitter.com/unclebobmartin[Uncle Bob] has been making on twitter between technical debt and just http://twitter.com/unclebobmartin/statuses/3123307938[creating a] http://twitter.com/unclebobmartin/statuses/3111623316[mess].

I find the former is done as a result of us thinking about what we're doing and realising that we need to take on a bit of debt with a shortcut now and then fix it up later. The latter on the other hand seems to occur when we don't think about what we're doing and just do the easiest thing possible.

An idea which I do like from the post is the idea of documenting why we made a certain decision.

From my experience quite often that information just remains in the heads of the people who made the decision and then we are relying on their memory when we come across a bit of code in the future and want to know why it was written in a certain way. In http://www.markhneedham.com/blog/2009/04/25/pimp-my-architecture-dan-north/[Dan North's language] this would seem to be the job of the project sharman although I guess it wouldn't hurt to have some of that information written up on the project wiki as well.

I would still probably do that bit of documentation after we'd proved that the code actually worked rather than before writing any code which is what seems to be the approach.

I guess this approach does work for Frans so there is certainly some value in it from that perspective but from the projects I've worked on *working in smaller increments has worked more effectively for us*.