Thursday, 14 May 2009

Writing: A case for code reuse

The May issue of ACCU's CVu magazine is hitting doormats right now, and contains my latest Professionalism in Programming column, called "A case for code reuse". I present a number of "re-use" cases (pun intended), and show a real use for your old code - as a tool to help you write better code in the future.

This is another excellent issue of CVu. Edited by Steve Love (don't ask how many beers contributed to his picture on the editorial page), there are some great articles on subjects including: distributed version control, job hunting, and the D programming language (this latter one contributed by Andrei Alexandrescu).

Friday, 8 May 2009

Const-correctness for documents

Const correctness is the art of using the type system of a static programming language (conventionally C or C++) to ensure that immutable objects are never modified, and mutable ones... can be.

It's a real boon to ensure program correctness. If you don't want your data fiddled with then you declare it (or any references you give to it) const, so that users of said data cannot change it. Note that you can give away a const reference to mutable data - in this case the user cannot change it, but the you may do so behind their back.

And now, in the Real World...

I'm getting fed up with the sloppy business practice of sending around copies of Microsoft Word documents as email attachments. Everyone does it. So it must be OK. Right?

No. It's cobblers. For a start, I don't have a copy of Word. I know that makes me rare, but there are a few freaks like me out there. Although Open Office is good, it's never perfect at rendering complex word documents.

However, I'm more worried about the distribution of a mutable document (the Word document itself). Sending a .doc to people who can modify it in ways that are not easily traceable, and then send it onwards is not ideal. If the document proudly proclaims that you are the author, then this should scare you rigid. Some muppet in marketing could change your text beyond all recognition - make it factually incorrect, but not change the author line - and then publish it to the world, making you look a total plonker in the process.

Ensure the const-correctness of your documents.

When you distribute any document that should not be modified by others, send around a PDF copy. OK, PDFs can be annotated, but those annotations are clear and cannot easily be mistaken for part of the original document. Of course, some devious idiot can make a convincing variant, but then a devious maintenance programmer could always const_cast your data's immutability away.

PDFs are the mainstay of const-correct document control.

Bonus points: yes, this is not entirely the same as my programming language analogue. In C or C++ a user could make their own copy of your const data and modify it themselves. Fair game. You can also give away a const reference to some data, but still change that data yourself. How would you do these things in the document? Perhaps consider a URL as your document reference?

Legacy Code: Learning to live with it

The slides from my ACCU 2009 conference presentation, Legacy Code: Learning to live with it, are now available from the conference website, here.

Click on {Slides} link to download a PDF copy. In the comfort of your own home, you too can enjoy theology, underwear, frogs, a shopping list or two, and a whole pile of dodgy code.

Monday, 27 April 2009

ACCU 2009: The aftermath

The ACCU conference is without doubt, the technical highlight of my year. A chance to put down the tools for a while, and spend time with other like-minded developers who care about crafting great code.

ACCU 2009 was last week. I'm now recovering! Every year the conference induces brain overload, and sleep deprivation. I never fail to learn exciting new stuff, to be encouraged to think new thoughts, and to meet interesting fellow developers.

I'm not going to provide an enormous writeup of this year's event here. There are many people who have done such a thing already in their blogs. If you didn't go, then no doubt they'll make very interesting reading.

This year, I learnt that going to bed before 4am does help with the delivery of your session the next day! Perhaps I was not as animated as usual, but I trust my session on Living with Legacy Code was useful.

It's a great technical conference, but it has a wonderful social aspect, too. This year spaces drunk tabs under the table (well, around it, at least) to settle an old score that a game of squash simple couldn't answer: which is God's One True Way To Format. And over the course of the event much money was raised for Bletchly Park, a suitable and very worthy cause.

My thanks go to the dedicated team of conference organisers and administrators, to every speaker, and to the delegates who made the event another incredible success. If you missed it this year, I highly recommend booking a place at next year's conference. I have no idea what the programme will look like, but I already know it'll be good.

Tuesday, 21 April 2009

Subversion, KDiff3, and Cygwin

Recently I've been doing work in a Windows environment, which is a bit of a culture shock for this Linux/Mac weenie.

As ever, I installed cygwin early on to make my life bearable. I'm not sure how I'd navigate without vim, grep and ctags. Are there actually any IDEs with genuinely useful code navigation?.

To make subversion usage the mirror of my Linux setup, I installed the excellent Windows port of kdiff3. My usual trick is to set a simple svn alias that involves kdiff3 when I need it. Something like:
alias sd="svn diff --diff-cmd kdiff3 -x ' -qall '"
(The nasty -x parameter is a workaround for some problematic kdiff3 invocations on Linux.)

However, the same trick did not always work under cygwin. From time to time, kdiff3 would complain that it could not find a file.

It turns out that this is a subtle problem where cygwin sometimes tries to convert filenames to DOS format before passing them to kdiff3.exe. When it does this, it fails and creates hybrid half-DOS/half-unix filenames. Handy.

The trick to make it work is to create a little kdiff3 wrapper script and use that, rather than kdiff3 directly. The magic rune you need to incant in the script is cygpath.

#!/bin/sh

LEFT=`cygpath -d ${6}`
RIGHT=`cygpath -d ${7}`
LEFT_NAME=${3}
RIGHT_NAME=${5}
/cygdrive/c/Program\ Files/KDiff3/kdiff3.exe $LEFT $RIGHT -L1 "$LEFT_NAME" -L2 "$RIGHT_NAME"

Monday, 20 April 2009

Speaking: Journeys (The loss of a child)

A few weeks ago I spoke at Cambridge Community Church with my wife in a talk entitled Journeys. We spoke about a particularly hard time in our life: seven years ago when we lost our beautiful 12 week old baby girl in a car crash.

Perhaps this is a slightly unusual (and somber) topic for this blog, but if you're interested in our deeply personal and unashamedly Christian viewpoint on the loss of a child, and the importance of our faith, the support of friends, and the church family then you can hear the pair of us speak here. We begin speaking about 24 minutes in.

In the talk we mentioned the song I played at Jess' thanksgiving service, and a few people have subsequently asked about it. If you'd like to listen, there's a rough version of it available to listen to on MySpace here.

Friday, 17 April 2009

Writing: Beautiful Architecture reviews

O'Reilly's Beautiful Architecture book has been out for a while now and has met some good reviews. May I draw your attention, for example, to the following review in the On Ruby blog, which gives an honourable mention to my chapter, A Tale of Two Systems:
Like most anthologies it has some chapters that different people will like or not. To me, some of the real winners are: Peter Goodliffe's "A Tale of Two Systems", ...
A little appreciation goes a long way :-)

Remember that all proceeds from the sale of this book go directly to charity.