Programming by Wishful Thinking

Coderetreat: Programming by Wishful Thinking

Blog post series

This blog post is part of a series about coderetreat sessions.

Purpose

This session introduces the concept of top-down approach of Test Driven Development for a new feature.
By following the steps you will be able to understand how to add thin top-down features that you can show very fast to your customers. Many of the features will work, even though you will not have a fully functional system, just because you have used stubs or fakes for the parts of the system that are not yet implemented.

Programming by Wishful Thinking

Concept

You want to implement a feature using Test Driven Development starting from the user interface. We call this kind of development top-bottom, as opposed to bottom-up, when you start from the database.
Let’s say your system is brand new, and you need to start from somewhere. Because you want to be Agile, your first feature needs to be a vertical slice from the user interface to the data layer. You want to receive feedback as soon as you can from your stakeholders on the new feature.
How do you do that?
One solution: Programming by wishful thinking.

The first step is to find the scenario you want to focus on. This means that the business is very clear and you can do a vertical slice of the requirements.

Once you know what you need to do, you write an acceptance test. For that you need to implement the top and the bottom layer. This test will fail until you have implemented the last unit test.

You start writing unit tests from the top layer (user interface) to the next layer (maybe a view or a model). If you need any information you create an interface or a function and create a stub. That stub will give you all the information you need. This is where you are doing some wishful thinking. Whatever you need and don’t have, think that you have it and write a stub for it. Working in this way will give you the opportunity to focus on the vertical slice, from the top layer to the bottom. Don’t get distracted implementing anything else, just write a stub.

You continue to write code like that, writing tests on each layer until you reach the bottom layer. When the last test is implemented, the acceptance test should pass. This is when you can show your new scenario to someone for feedback.

Outcomes

You will be able to understand better what top-down Test Driven Development is. Another important outcome is that you can understand one of the ways of doing Evolutionary Design.

You can develop a product with a fast feedback cycle by using this method. Once a feature is finished you can show it to your stakeholders. They will come with improvement feedback that you can act upon.

Remarks

The top-bottom Test Driven Development approach is very appropriate for web development. You pass through all the layers and write the needed tests, add the needed functionality. Nevertheless top-bottom is not that useful when writing algorithms, there I would recommend you to try a bottom-up approach to Test Driven Development.

 

During all the steps you are taking incremental design decisions:

  • When writing the acceptance test you design the top and bottom layer
  • With each unit test you design bit of each layer
  • With each stub you design the interaction with future collaborators that are not yet implemented

The design evolves with each step you take. This is why I call this way of working Evolutionary Design.

 

When working in this way you need to have solid skills of business analysis, software design, TDD, and testing.

History

I know about his session idea from Corey Haines. Thanks Corey for telling me about this way of working.

During a few of the coderetreats I facilitated I presented this concept as a constraint. The fastest pair was when a tester was pairing with a programmer.

Code Cast

Somewhere in the future there will be a code cast showing this method of writing code.

Contact

Feel free to contact me to find more about methods of evolutionary design.

Subscribe

If you want to receive an email when I write a new article, subscribe here:

Subscribe for new articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation