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?

1 comment:

Peter Hartley said...

Surely attaching the document (in any format) is pass-by-value, sending a link is pass-by-const-reference, and sending a link to a Wiki page is pass-by-nonconst-reference?

But actually the reason why I thought I'd comment is that I like the way that the Google Ads contextual advertisements thingie has decided to attach to your post an advertisement for an product which claims to "Easily convert between PDF, Word, HTML, TXT or Excel"...