Growing Object-Oriented Software, Guided By Tests (chapter 16)

Feb 19, 22

This chapter is adding a new feature, where we introduce a little concurrency. Man, it is Java heavy :D

Here are my key takeaways:

  • As always, write a test first.
  • When refactoring, also see if the test failure messages can be made more clear.
  • If possible, try and extract things out of the main method. Will make things easier to test!
  • Try using a custom ‘defect’ exception to check where you have goofed up.
  • Tests can be a really good way to pick up off-by-1 errors before they get buried in code.
  • We may not have access to the full UI design upfront - while we wait, we should be able to roughly mock it out to test the functionality, just remember to stay flexible (and feedback ideas where appropriate).
  • Name methods to reveal their intent (the principle of least surprise!)
  • Continually challenge your approach to tease out better naming/abstractions.
  • Be careful when testing concurrent code.

Summary:

  • Make steady progress: TDD will help to drive your design forward in a structured way.
  • Working does NOT equal finished. Aggressively refactor once the tests are passing to help future maintainers (YOU!).
  • It’s better to refactor while you still have the context in your mind, don’t put it off (you will forget what the code is supposed to do!)