Monday, February 25, 2013

FsCheck is great for for native code too!

I've just had call to write some good old-fashioned 'C' code recently, for use in an environment where my access to anything fancy like external libraries is limited. And a one part needs a simple transcoding function to take data in and manipulate it from the form convenient to provide into a form that's actually useful.

But of course, I want to test that bit before I start wiring it into place. There are, of course a whole slew of 'C' unit test frameworks out there, none of which I've used before, but really I wanted to just soak-test the algorithm quickly and simply, with a maximum of coverage and a minimum of distractions, so, I actually wanted a QuickCheck-equivalent tool that would "just work".

And this is where F#'s easy P/Invoke syntax (almost as simple as cutting and pasting out of the 'C' header file) and FsCheck were just the tools I was looking for -- write a property (or, in fact, a series of properties) that asserted that an input mapped by my function was the same as obtained using an equivalent .net library function already to hand as reference, invoke them with FsCheck.Check.Quick, and then TDD away, starting with the rough outlines as asserted by the early properties, and then filling in details as asserted by the later ones.


Sunday, February 24, 2013

Dear diary

After last week-end showing early promise of spring, with warm sunshine enough to be comfortable in a T-shirt outside, and thoughts turning to gardening, it's now gone back to grey and around freezing again, with three days of light snow flurries, though no perceptible settling.

At least the generally dry cold has meant that I've just had to wrap up well to continue the one day a week cycling to work (on average -- the 1st was washed out so I did the 7th and 8th). The downside of cycling in winter conditions has been picking up a lot of salty mud on the bike, and a chain that, despite drenching with GT-85, was often stiff in places after being parked a few days. That warm spell at least gave me chance to do a good clean and re-grease.

And the car is now at 8008 miles.

Recent Reading

Exaltations by Richard Garfinkle

A strange, almost indescribable, and most inventive meta-fiction, as a narrator of lives gets tangled, along with some of his subjects, into the machinations of the archetypal Quest. And as a tale about telling (or Telling), it scatters the seeds for a small library's worth of tales in passing. As airy ephemera, just to decorate one short scene, we are shown the three different-yet-similar versions of the Trojan War and the founding of Rome that spin from Paris' choice of which goddess to give the apple of Eris; and none of that is really important.

This time, the ending is satisfying if understated, rather than just fading out.

Star Carrier by Ian Douglas

Somewhat a change of pace, a good solid hard mil-SF trilogy that shows that the John Campbell school of SF still lives, as the US Space Force squares off against an ancient Galactic Empire, intent on subjugating the human race.

A solid page-turner of space battles and some seriously alien races in a purely relativistic setting with Alcubierre warps (handwaving away the engineering details involved).