performance kata by corey haines

I just watched a great video of a “performance kata” by Corey Haines. Highly recommended!

Watching Corey solve the kata differently than I would have done has taught me several new tricks. Notably spec -fs spec — I get a completely unreadable mess when I run that on my own code, so there’s some work to do there in terms of how I name my specs.

Also, my first instinct would not be to extract the do_replacement helper method. I noticed GeePawHill do that too during his Double Dawg Dare refactoring videos; so it’s common, and a couple of years ago I was doing it all the time. But recently I’ve tried to work the opposite way — if the tests need a helper, I take that as a sign that the API under test isn’t as developer-friendly as it might be. So I look for ways to DRY up the tests by making the test subject’s interface more fluid. The helper method approach certainly gets results more quickly, but I worry about the longer term maintainability of the code; maybe I shouldn’t; maybe I think too much instead of just doing TDD “as if I meant it”.

All of which means that performance kata are a fantastic way to share knowledge, develop new skills and hone techniques. Time for some more practice…

About these ads

5 thoughts on “performance kata by corey haines

  1. Hi, Kevin,

    Thanks for the great thoughts and feedback.

    I definitely agree that the test helpers are an indication of possible api problems. One technique that I use is to build test helpers in the specs, knowing that they most likely are production code waiting to find a place. :)

    • Yeah, you’re clearly much more relaxed than me. I have to sort it out immediately, preferably before it happens. When you’re over here for your UK tour maybe you can show me how to let go a bit more… :)

  2. Nice. I completely agree with your notion that need-for-test-helper is the scent of weak design. One of the things I’ve been thinking of doing for my next video set is an attempt to maximize all such ideas — the ones that fall out of TDD, that is — during a reasonably rich set of TDD videos. – GeePaw

  3. Kevin, I’ve been pondering Corey’s (excellent) video and your response for a week now. I agree that the use of test helpers if probably an indication of a lack of fluidity in the API, but I’m not a fan of absolutes so to say that would *always* be the case doesn’t sit right with me.

    I have noticed that when I create mock objects in my specs, helpers can be useful to make the construction of the mocks more fluid and easy on the eye. In some cases, that’s a sign that the objects I am mocking have an unclear interface but other times it’s simply a reaction to the fact rspec only provides a single, simple, way to construct mocks and sometimes you just need more.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s