Chess TDD 39: Dipping a Toe into Complex Piece Movement
What I accomplish in this clip:
- Finished implementing the bishop acceptance tests.
- Introduced the concept of “capture move” and “non-capture move” to piece movement.
- Made some good headway on the pawn’s diagonal capture capability.
Here are some lessons to take away:
- I’ve mentioned this before in the negative a few times, but I’ll phrase it in the positive. If you’re going to do refactorings, even trivial ones like deleting a dead method, do it with a green test suite.
- Writing acceptance or integration tests, whether using them to drive design or not, tends to give you a good lesson in patterns of things that can go wrong. The specific example I’m referring to here is how I noticed that movement for the black pieces from higher numbered rows to lowered number ones tended to be a problem across pieces.
- Even if you’re not thrilled with a design, you can be productive and get things done with it when your test coverage is good since you won’t be afraid to change it later. This helps prevent “coders’ block” or “paralysis by analysis.”
- When you’re reasoning about implementation, allow yourself to stub out helper methods or methods on other objects that will ‘magically’ do what you want. E.g. if I were writing a “CookDinner” method, I might just declare “TurnOnStove()” and stub it out, to be implemented later. This practice of defining what before how can help you get toward the single responsibility principle.
- I won’t belabor the metaphor of tech debt, but having a really high degree of test coverage and a lot of small, modular methods in the code base lets you live with tech debt a little more easily in the short term. With a lot of crufty code around the problematic code, you’ll never want to touch anything when it comes time to pay it off. With lots of coverage and good code elsewhere, getting rid of the tech debt at a time that suits you is easier.