An interesting essay on Code Quality by Hew Wolff, over at the Pragmatic Programmers, in their online magazine. The basic thesis is that ‘Good Code Tells the Truth’ (that’s the title). It resonated with me because a week or two back I was looking at an Access/VBA application (not one of mine!). The code in this application was, if I might be frank, dire:
- no indentation in a lot of procedures
- no splitting of long SQL strings over multiple lines (when I did reformat one, it ran to 8 lines)
- no useful comments at either module/form or procedure level
- form controls not renamed (one form had buttons called Command27, Command28, Command66, Command139 – see what I mean?)
- obscure variable names – for example, in one procedure, U3, D3, d4, SN3, FN3
- using 0 and -1 for False and True (why?)
- copy-paste-and-tweak repetition (e.g. to re-initialize a form).
The piece de resistance was a SELECT-INTO query that created a column using this expression:
So, arithmetic on Ids? As far as I can tell, this converts an Id value into -1 (presumably treated as True), but leaves Null values as Null, since arithmetic expressions involving Nulls equal Null. Is this a common Access programming technique? Even if it is, couldn’t it be wrapped in a function called something like NonNullToTrue (although this could not have argument or result types more specific than Variant).
This might (or might not) be a clever trick, but not considering the possibility of other people finding it confusing indicates of a poor approach to programming. What the essay mentioned earlier is saying, and what I’m agreeing with here, is that software development is as much about communication of a solution as it is about that solution just working.