Oh Microsoft…How I Love Your Pretty Little Lies…
Mostly, I do business software. That may seem surprising since I work for the Space Telescope Science Institute and we not only operate Hubble for NASA but we’re also working on the James Webb Space Telescope, which is the project I’m deeply involved in at the moment. So you might think the work I do here is all sciencey and stuff and it mostly is, but not in the flight engineering sense of it. I do business software, and science like everything else has to account for its money and time. So as it turns out, a lot of my work still revolves around Microsoft products, and doing traditional business client-database applications. The other day I was tweaking something I’d done in Excel VBA (Visual Basic for Applications…a product Microsoft hasn’t upgraded in decades, probably because there is so much legacy stuff out there in their business user base). It was your basic fetch some data from a backend database server and feed it to Excel and let Excel make tables and charts out of it for management to ponder. And I needed to do something that I figured I could use a custom document property for. Which I could, but not exactly in the way Microsoft’s documentation said I could.
You run into this phenomena quickly in this trade: The Documentation Lies. Or more charitably, it is out of date. The documentation is buggy. The documentation is written by people who write software and hate writing documentation. If religious fundamentalists had to actually use passages in the bible like we software developers have to use the documentation and example code snippets we’re provided with maybe they’d stop waving that thing at everyone, and try a little figuring things out for themselves like we’re always doing…desperately at times. Oh you’re worried about the second coming are you? Let me show you my project’s Gantt chart…
See…I hate using Magic Numbers…
In programming, a “magic number” is a value that should be given a symbolic name, but was instead slipped into the code as a literal, usually in more than one place.
It makes the code hard to understand, which makes it hard to maintain. This is something a programmer is wise to avoid, even if it’s code you are nearly certain only you will be maintaining. Time passes, the universe expands, and you open a code file you haven’t touched in years to make a small change and you’ve forgotten what ThisWorkSheet.CustomProperties.Item(1).Value referred to. Better to write it ThisWorkSheet.CustomProperties.Item(“GetsGraph”).Value. And lo and behold the documentation says I can call that property with either a numeric value (the property index) or a string value (the property name). But it does not actually work that way.
Let it be said Microsoft is hardly the only culprit here. My first experience with this sort of thing happened right at the starting gate of my career as a software developer many many moons ago, when I was a youngster doing volunteer work for a gay BBS system (before the Internet Tubes came along) and I was asked to write a system for a local gay activists organization to generate welcome letters and membership funding letters and mailouts and so forth. They had a licensed copy of Ashton-Tate’s dBase IV which back then was the powerhouse database system for PCs. It was working my way through the dBase documentation while trying out their code snippets I had the displeasure of finding out that computer documentation will lie though its teeth at you and laugh at your pain and suffering. In those days I hurled many a programming book across the room. Nowadays I glance at the time and do a quick rough calculation of how many minutes until Happy Hour.
So I got through my little difficulty the other day by creating a sensibly named numeric constant that I can pass in lieu of actually passing the value of the name of the custom property whose value I want to check. That’s what we call in the business a kludge, because I’m not certain the property I want will have that index value Every Time. I think it’s likely since I’m the only one maintaining this code, for now, and I only have that one custom property in there. But what happens when someone else gets into this code? Okay…I’ve commented my useage of the property. But maybe the next update to Excel changes the starting index from 1 to 0? Surprise!
Oh well. So I get things working to a close approximation of my satisfaction. Then I sit back and I ponder the Five Stages of Software Development…
Denial: Oh I probably just forgot to close a parenthesis somewhere.
Anger: Oh F*ck Me…that is a COMPLETELY LEGAL FUNCTION CALL!!!
Bargaining: Maybe if I use single quotes instead of double quotes…
Depression: I should have gone to art school…
Acceptance: My software tools are buggy, the vendor is shady, the next upgrade cycle will probably depreciate my entire code base, but the bar at Rocket To Venus is open late.