May 2008

Hooked on Synthesis

Synthesis is an incredibly powerful tool, but until the Ruby Tuesdays meeting in the ThoughtWorks office last night I didn’t really grasp what it does.

It’s actually quite simple, but it changed the way I think about tests and mocks.

Say you have a Foo and a Bar, and they need to talk to each other so that your system can fly on pink unicorns. In fact, you expect the instance of Foo to tell an instance of Bar to frobble, giving it an instance of Baz to play with, and then, when the frobbling is done, Foo gets an integer back, and the rest is some complex logic that we won’t get into now (flying pink unicorns is difficult, as well as getting ahold of one). In a less noisy language:


bar.expects(:frobble).with(baz).returns(10)
foo.fly_pink_unicorn()

No problem there, and it should be fairly quick to make that a green bar. The problem starts when I rename frobble to frob in Bar but forget to change it in Foo. That test/spec/example/whatever we call it these days will still pass, as the expectation is still valid, and foo fulfills it nicely. It’s then up to you to figure out that this expectation has gone bonkers in the first place, and fix it.

What Synthesis does is to tell you that you forgot that. That’s it. Nice readable error message that tells you “hey, Bar doesn’t know about frobble, why did you ask it to do that?”, and fails the test. That opens a great big can of rainbows: when you don’t have to validate every assumption about your mocks anymore, suddenly what people usually call integration testing isn’t as necessary – you can have confidence in your system without having to write tons of fiddly set-up code or double-checking those interactions by hand.


General

Comments (0)

Permalink

Making OpenCV prettier

So while I’m on what ThoughtWorks calls the beach, which is the really nice place to go when you’re not assigned to a project, I’ve been playing with OpenCV, a lovely opensource library originally developed by Intel. It’s got a gigantic set of really interesting features related to real-time image manipulation and especially around real-time motion detection and face, hand and body recognition. If you’ve never played with computer vision, I highly suggest giving it a try. It’s tons of fun – and you get to brag about actually knowing what the hell a cascade of boosted classifiers working with Haar-like features means.

While I’m at it, I’ve been building a very small set of wrappers to make it all look a bit more OO (and probably a lot easier to read and write). As the README says:

This project has been set up only as a way of representing the knowledge the authors have gathered about OpenCV and is not intended to be a complete set of OO wrappers for the library – but contributions of any kind are definitely welcome.

Still, I’d much rather see code like:

currentFrame.sub(initialFrame).threshold(thresholdAmount)

than…

sub = cvCreateImage(...)
cvSub(currentFrame, initialFrame, sub)
result = cvCreateImage(…)
cvThreshold(sub, result, thresholdAmount, 255, CV_THRESH_BINARY)

But then maybe that’s just me.

Oh, while I’ve got your attention – doesn’t Apple make or sell those external Firewire iSights anymore? I managed to get ahold of one, and they’re lovely. Now that pretty much every Mac laptop has a built-in camera, maybe there’s no point, but they’re still incredibly useful in these kinds of setups.


General

Comments (1)

Permalink