2024 Public Training Schedule
December 9 – 12, 2024 – Agile Analysis and Design Patterns
Half-Day Sessions
(c) 2024 To Be Agile
Using tests to drive development in TDD concertizes abstract requirements making them easier to understand and work with. This is a very powerful way of solving software problems while at the same time creating maintainable code. Here are seven strategies for solving problems test-first:
1. Think outside-in
Before solving a problem we must first understand it. Seeing the problem from the outside looking in is often the best place to start. This helps us understand the “big picture” and gives us a context for understanding how each piece interfaces with the rest of the world.
2. Create tight contracts
A key to well-encapsulated software is having tight contracts with well-defined responsibilities. This helps us focus on defining a useful interface that hide implementation details and decouples code from the rest of the system.
3. Separate knows from unknowns
Usually, problems have parts that are known and parts that are unknown. The goal is to expand the known and contract the unknown so all aspects become known. The first step is to identify the areas that are unknown so they can be explored and then find the right questions to ask to help eliminate unknowns.
4. Fake it the first time
Creating a fake or obvious implementation for the first test of a new behavior let’s you create a second test so you have two examples to generalize from. Generalization is always easier with multiple examples.
5. Try to fake it a second time
For really difficult problems it might be helpful to fake it a second time so you have three tests to generalize from. However, it can be a lot of work to fake something a second time and it’s usnally much more work to fake something a third time than to just create a robust implementation.
6. Remove redundancy
Redundancy in code hides the truth. By eliminating redundancy in code we often gain insights into the true nature of the problem we’re solving and that helps us find more elegant and comprehensive solutions.
7. Generalize
Whenever possible, look for the generalized solution to a specific problem. This can lead to a better solution that will fit in more situations so code is easier to extend and repurpose. It also makes code easier to read and understand.
Solving problems is a central part of programming. TDD provides a disciplined way of solving problems in code while building maintainable solutions. This helps us think about programming problems in ways that give us traction and helps us build good solutions.
Previous Post: « Seven Strategies for Building Smaller
Next Post: Seven Strategies for Creating Better Names »