keyboard special keys image
Experience, Information Technology, Thank You Sir May I Have Another

The getkey Trap

This topic came up on my Jed mailing list the other day and, once again, I got in touch with my inner Bill. Your inner Bill? Yes, that cranky old man who isn’t putting up with the world around him and wants it to be his way. The older you get the easier it is to find your “inner Bill.” In this case it fits because I have lived this death at least a hundred times over my career.

OpenSource allows pretty much any 8 year old with a keyboard to hurl code into a software repository without having read any books on programming logic or software design. Inevitably these 8 year olds tend to get involved with the fledgling projects “to leave their mark” but the truth is fledgling projects with only one or two contributors tend to never turn anyone away if the primary contributor doesn’t have an ego the size of Texas.

We went through this with the days of DOS. Back when we used to have magazines like “Programmer’s Journal,” “The C Gazette” and “The C User’s Journal” not to mention Bulletin Board Systems (BBS) where people shared code via both file uploads and echo mail it was the same story over and over. It seems like we had about as many languages being introduced back then as well. The difference is most were compiled languages, not scripting languages. Yes, real geeks wrote compilers for their languages _and_ made those compilers fit on a floppy.

You see, every beginner who wants to contribute something fundamental to a language or library ends up writing something called getkey(). The name will vary just a touch from language to language and library to library, but this will be a horribly simplistic routine. It will only return one octate or 8-bit byte. (Not all bytes on all processors have 8-bit bytes, some have 4-bit words.) Much of the industry quit using the term byte, instead using the term octate which was defined to be exactly 8-bits.

The student then “tests” their routine with the standard letters and numbers. They are overjoyed the thing works. Yeah, this is why every project needs a QA group and why TDD is a complete fraud. They don’t ever hit those other keys. You know, the function keys and those cursor navigation keys, let alone those special buttons for multi-media and such. Nope, their wonderful routine doesn’t get a key, it gets an octate and bad things happen when someone hits one of those other keys.

Oh, you can’t fix it. They have been returning a byte, or at best an int. Some of those keys have 3 and 4 octate sequences. There is no way to jamb them into the return value. Adding insult to injury this routine, by the time the flaw is “discovered and admitted” (OpenSource projects tend to just let bug reports rot rather than admitting there is a problem) too much existing code is out there expecting the limited return value. Some modules worked around the problem and others didn’t.

Usually the person involved in this debacle has already gone on to victimize other projects with the same debacle, continuing to spread their own special kind of joy in the Universe.