Code sober, debug drunk

Code sober, debug drunk

The main reasons I write tests are:

  • reduced cognitive load,
  • improved communication with my peers,
  • ability to sleep at night.

Testing allows me to split hard problems into chunks small enough to fit in my head. I'm young, but with every passing year as a software engineer more and more often I wonder whether these chunks are becoming smaller because I'm getting better at my craft or because I'm losing the ability to hold and process large, complex ideas. Yes, I know I'm a bit paranoid.

  1. Writing code is easier than reading it.
  2. If your code is hard to write now it will be almost impossible to read later.

This is a paraphrase as I can't find the original quote, but I think it sums up the issue pretty well. Structure your code in a way that a more tired, less focused, "drunk" version of you would understand.

Tests help with this because they make the intent behind the code more obvious. First, test cases document the use cases. What's more important is that the code written following TDD tends to be simpler and less abstract.

The simpler and more boring the code is, the more satisfied I am with my work.

If we're working together, the last thing I want to do is to make your life harder. It's in the interest of both of us to be able to focus on something more rewarding than untangling spaghetti – such as, you know, building stuff.