Hate-Driven Development

Most development at Atomic gets done in Vim, but occasionally we get work that better fits the use of Visual Studio or IntelliJ IDEA. When we do, we take advantage of the intelligent code features of these IDEs. Despite occasionally feeling slower in .NET or Java than in, say, Ruby or CoffeeScript, one way to keep up the pace is with a technique we call Hate-Driven Development.

m not talking about this kind of HDD, where you hate the code. At Atomic, HDD refers to the editor hating you. Our sense of the word refers to the horror-inducing full-saturation red highlights that appear all over the code when you use instances of unknown classes or call methods that don’t yet exist:

By letting these hints guide the use of code helpers in the editor, you can drive a feature from failing test to completion with a lot less manual typing of overwrought syntax. The technique goes something like this:

  1. Write the test
  2. The class under test doesn’t exist; auto-create it
    • The method under test doesn’t exist; auto-declare it with infered parameter types
    • The collaborating objects aren’t available; inject instances or assign fields
    • Auto-create expected method stubs on collaborating objects, etc.
  3. Run the test
  4. The test fails
  5. Write the method
  6. The test passes

Getting used to letting go of future concerns and writing speculative code into tests takes practice. Once mastered, this approach lets me focus on what a feature needs to do, instead of all the “boilerplate” code I need to write before writing the feature and getting a passing test. HDD works even better when paired with interaction-based TDD and Presenter- (or ViewModel-) First patterns.

Fortunately, I don’t miss this intelligent hinting when I’m writing features in higher-level, dynamic languages. The need for boilerplate tends to be less anyway, so the process of speculating a test and then writing signatures to make the test fail isn’t as long-winded and repetitive.

Next time you are using a type-checked language or an intelligent editor like IntelliJ, try HDD. You might learn to love the editor telling you what to do next.

“Good. Use your aggressive feelings, boy. Let the hate flow through you.” – The Emperor

  • Karl says:

    At least in Visual Studio, go to Tools > Options > Text Editor > C# > Advanced. You can turn off the underline errors and live semantic errors; I believe there are similar options in IntelliJ. You can even turn off intellisense if you like. It also sounds like you may enjoy using the dynamic keyword in C# (new to C#4) . You may also benefit from writing your own Code Snippet functionality in VS to help speed the process along.

    • Karlin Fox says:

      Thanks for the tips Karl, but I hope I haven’t confused my point: I appreciate the underlines and live errors, as they inform my TDD process and guide the auto-creation tools to write the boilerplate for me as I add tests and features. And while I definitely use custom code snippets for boilerplate that isn’t built into the IDE (Guice annotations, for instance), I prefer to let the tools do as much for me as possible. When I have to write C# or Java, I want intentions and intellisense, etc. to make my TDD workflow smooth!

      Basically, I’m saying the “hate” is on the screen for a reason, use it! Give in to the Dark Side!

  • CSX321 says:

    This isn’t exactly the same thing you’re talking about, but it reminds me of how I tackled porting a project from Windows Mobile to Android. I just dumped it all in and kept fixing it until nothing was highlighted anymore. For this particular app, it worked great!

  • Richard says:

    No! What you describe is Love Driven Development… love the IDE and it’ll love you back

    Whatever you end up calling it, this is hands down the best way to write code.

    • Karlin Fox says:

      Richard, I like your term for it too. You hit the nail on the head that this is a great way to embrace the IDE and get the full benefit for it. We call it “hate” as a tongue-in-cheek anthropomorphism of the editor yelling at you about your incomplete code, and as a subtle jab at serious attempts to label every development technique with *DD. Love has a sweeter ring to it. Maybe we could provide a color scheme that makes it highlight in pink? ;)

      I’d like to think that JetBrains was looking at “tests first” as a use-case for these intelligent features but, even if they weren’t, I’m glad they’re adaptable to the practice.

      • Karl says:

        I think youre on to something with highlighting in pink. Theres a surprising amount of research out there on the effects color on our emotions and behavior, like This (PDF). A few tweaks to the color palette and you could go from Hate Driven Development to Sedative Driven Development ;) . Though being severely color blind myself, I’m not sure I would even be able to notice the change from red to pink.

  • Comments are closed.