Fun Driven Development and Result Driven Development

I decided to add a few double Ds to my old list. First up is FDD as in Fun Driven Development. FDD is when you only focus on what is fun at the moment. This may sound great but probably also leads to a number of unnecessary features just because they were fun to implement. You should have fun developing but don't let the fun drive you...

Second is RDD; Result Driven Development. This is a technique I've started to use lately that works very well for me when writing tests. Actually it works well for all code but I tend to forget it as soon as I'm done writing a test. Have to focus better I guess. So what is Result Driven Development? The idea is to always start with the result when you write a new function. That is; the first line you write in a new function should be the last line of the function returning the desired result. This does not mean a hard coded value (as you might assume if familiar with TDD) but rather to write the desired code.

For unit tests this is pretty straight forward. You first write the assert you want. And then you start filling in the missing pieces. When implementing the function being tested you do the same; start with the desired result and then fill in the blanks. For example consider a function that is supposed to return a new price after applying VAT and discounts. The first line you write should look something like this:

1: double CalculatePrice(double price)
2: {
3: return price * (1+vat) * (1-discount);
4: }

Then fill in the blanks:

1: double CalculatePrice(double price)
2: {
3: Customer customer = this.Customer;
4: State state = States.customer.State;
5: vat = state.VAT;
6: discount = customer.Discount;
7: return price * (1+vat) * (1-discount);
8: }

I think this method helps me writing code that is easy to understand and focusing only on the things I need.

Comments (1)

  1. sid says:

    Great approach

Skip to main content