TDD is All About Reducing Accidental Complication
- The Mythical Man-Month
- Complication, not complexity
- The cost of a feature is dominated by the accidental complication
- Your design sucks -> TDD to the rescue
- Think about what you want to do
- Write a test
- Ask yourself "How much does this test suck?"
- simpler tests
- smaller tests
- Run the test and watch it fail
- Stop writing too much code
- Write just enough code to make it pass
- Refactor a bit now
- Refactoring is how you reduce accidental complication
I think this is the best explanation for why TDD can help with designing better software:
- TDD is never about writing some tests to prove our application is running correctly.
- Instead, TDD is all about reducing the accidental complication
we add to our application.
- Thinking about what you want to do and writing a test for that help you think deeply about your design decisions.
- Rethinking about the tests helps you rethink about that.
- Running the test and watching it fail makes sure we are not writing meaningless code.
- Writing just enough code to make it pass is the hardest part. Because we as developers tend to show off our intelligence and always try to solve multiple problems at once. And sometimes finding the minimum code to pass a test is much harder than the obvious solution.
- Refactoring makes sure we will think again about our design after learning more knowledge about our domain from the previous phases.