When Coding Standards Hurt Quality

Most of my work is on code that has “initialize all local variables at declaration time” as part of the coding standard. I’ve never been a big fan, but I’m very reluctant to get into coding-standard arguments (probably as the result of having had to enforce them for so long) so I just let it go. The other day, Rusty Russell offered up a better reason to avoid this particular standard. The crux of the matter is that there’s a difference between a value being initialized vs. it being initialized correctly, and the difference is too subtle to define a usable standard. Sometimes there is a reasonable default value, and you want to initialize to that value instead of setting it in ten different places. Other times every value has a distinct important meaning, and code depends on a variable having one of those instead of a bland default. Does NULL mean “unassigned” or “no such entry” or “allocate for me” or something else? The worst part of all this is that required initializers prevent compilers and static-analysis tools from finding real uninitalized-variable errors for you. As far as they’re concerned it was initialized; they don’t know that the initial value, if left alone, will cause other parts of your program to blow up. If you need a real value, what you really want to do is leave the variable uninitialized at declaration time, and let compilers etc. do what they’re good at to find any cases where it’s used without being set to a real value first. If your coding standard precludes this, your coding standard is hurting code quality.

Rusty suggests that new languages should be designed with a built-in concept of undefined variables. At the very least, each type should have a value that can not be set, and that only the interpreter/compiler can check. This last part is important, because otherwise people will use it to mean NULL, with all of the previously-mentioned ambiguity that entails. The “uninitialized” value for each type should mean only that – never “ignored” or “doesn’t matter” or anything else. A slightly better approach is to make “uninitialized” only one of many variable annotations that are possible, as in cqual. Maybe some of that functionality will even be baked into gcc or LLVM (small pieces already are), providing the same functionality in current languages. Until then, the best option is to educate people about why it can sometimes be good to leave variables uninitialized until you have a real value for them.

My Android Experiment

A while back, I bought an Asus EeePad Transformer. A bit later I bought the base unit which has a keyboard and extra battery. I still love it. Being able to switch between landscape and portrait orientation on a whim is really awesome, because so many sites look so much better in one format. The battery life is phenomenal. I can get a full day of near-continuous use with the tablet alone, and the battery in the base is even bigger. It’s even smart about draining the base-unit battery to keep the built-in one as full as possible.

The last couple of days, I had to travel to NYC, so I decided to experiment with using this as my travel computer. I did bring another (small) laptop along just in case, but resolved not to use it – and I didn’t, except as a reserve battery for my MiFi portable wireless gadget. However, I have run into two serious limitations. One is that I can’t use it for presentations. Besides the fact that it physically has only a (mini) HDMI whereas most projectors are still VGA, I can’t find any decent software for presentations. I’ve looked at several apps and a couple of online services. They’re all awful. Is it too much to ask that a presentation program handle a simple two-level bullet list properly? Apparently. The other problem is that I can’t really use this thing for terminal sessions. The base-unit keyboard actually lacks an escape key. As a vi user, that’s crippling. I could use emacs instead, but the handling of the control key also seems a bit erratic. I tried using the on-screen escape key in ConnectBot, but eventually settled on using Hacker’s Keyboard instead. While I was able to get some work done (Gluster guys: that’s how I did the quorum-optional patch) it was certainly not very pleasant. I’d like to avoid solutions that require rooting the device, but I might have to resort to that.

I still love using the EeePad at home, and in meetings. I just might not be able to use it as a road machine and that makes me sad. Maybe the software situation will improve over the next year or so.

To The Cloud . . . And Beyond!

You might not have noticed, but I just moved. As part of my ongoing project to consolidate my various web “properties” I upgraded and updated my Rackspace cloud server (which I’ve been using for two years), and put nginx + php_fpm + mysql on it to serve my websites. It probably wasn’t the best idea to do the move on the same day I posted something as inflammatory as my last post – there was some virtual-memory tuning I’d forgotten, and I did get bitten by the uber-stupid “OOM Killer” under the Hacker News load – but it all seems to be working out otherwise. One of the nice things is that I can resize my server any time I expect a similar spike, then shrink it again when the spike’s over. If I were really motivated I’d do it all automatically, but I don’t have that kind of spare time.

So, as usual, please let me know if you see any glitches. One of the things the traffic spike did for me was show that normal stuff is working, but some stuff around the edges might still need tweaking. I know FTP access and image links to womb.atyp.us (in old posts) aren’t working. Anything else?