ChessTDD 18: RemovePiece and Housekeeping
In this episode, I managed to pry myself away at a slightly shorter length of recording time. You can seem me at the end wavering and and wanting to continue, but I know myself, and I’d have been hustling to wrap up under 25 minutes next thing I knew, so I thought I’d call it at a reasonable stopping point.
Here’s what I accomplished in this clip:
- Implemented RemovePiece.
- Made the public interface of Board a little nicer.
- Minimized the usage of the array in favor of readable abstractions.
Here are lessons to take away:
- Make yourself feel the pain of duplication. Around 3:15 I fought off the temptation to copy and paste the setup of another test class to the new one, but I retyped it instead. Copy and paste is like taking morphine and then walking on lava — you’re easing your pain when you should be letting it inform your actions to improve the situation.
- Having identical setup in multiple classes is a test smell that’s making subtle suggestions. Maybe the tests should be in a single class or, perhaps, there should be something in production code making that setup easy, if it’s really that common. (I view the alternative, a lot of helper code in tests, not to be a better option).
- At around 7:20, I did something subtle. I looked for references to Board’s _pieces array and looked to eliminate as many references to it as possible. The idea here is to minimize the use of a primitive abstractions in favor of the more descriptive ones I’ve created (GetPiece, RemovePiece, MovePiece).
- More compact isn’t always better. If you inline a variable, check for readability. The beauty of a robust test suite is that you can really whip things around to maximize readability and feel good that you’re not breaking anything.