Monday, January 18, 2016

Quickies: One For The Software Nerds

     I was searching through my archives for a piece I wrote on the 2004 presidential election, when I came across a bit of humor I’d almost forgotten. It originated as a comment at another blogger’s site. The other blogger, Michael Williams, had written about the importance of “bounds-checking your arrays,” a practice of some importance to those too benighted to grasp the inherent maleficence of arrays. I responded as follows:

     No, Michael. Never bounds-check your arrays. You cannot bounds-check that which you don't have. Arrays are inherently evil, and should almost never be used.

     The array is implicitly a point of program vulnerability. Bounds-checking is only one of the ills its flesh is heir to. He who programs with arrays will inevitably come to grief, either through a bounds violation, or a fencepost error, or a size-rigidity problem.

     Arrays are incompatible with the most important software-engineering breakthrough of our time, the principle that gave birth to object-oriented programming: Unite your data to the set of operations that can be validly performed on it, and forbid all others.

     When programming in any language that supports the dynamic allocation of memory, I avoid arrays, you should pardon the expression, religiously. Instead, I use keyed linked structures: either forward-and-backward linked lists or binary trees that can be searched by content, and which are organized in a fashion that conceals their nature and size from the "higher" application.

     Computer languages are shockingly inconsistent in their treatment of arrays. Whereas Pascal and Ada treat the array's dimensions as part of its data type, other languages do not. FORTRAN arrays start from 1; C and C++ arrays start from 0. BASIC arrays start from 0 and then throw in an extra element at the end, to the confusion of communications applications everywhere. And let's not discuss PERL arrays; my stomach simply isn't up to it.

     Applications written around arrays have caused much destruction. I once had a matrix mechanics job, a twelve-hour program that ran on a supercomputer, fail in the ninth hour because of an array problem. The great continent-wide communications crash of a decade ago was caused by a mis-defined array. Two major stock market recording debacles occurred because an array was undersized -- the same array in both cases, ironically enough.

     Our enemies know this. Soviet academicians pushed arrays right up to the end of the USSR. (Hoist on their own petard. Hah!) Stroll the streets of Paris and you'll see innumerable placards that say, L'arrai, c'est tres bon! Al-Qaeda has reportedly tried to popularize arrays in certain unnamed engineering colleges in Virginia and North Carolina, promising "extra virgins" to those who used them "effectively."

     Arrays are not attractive. I've lost count of the number of times a flirtatious single woman has asked me, "Are you a dynamic kinda guy?" (More than that was ultimately required, of course, but hey, we're talking principle here.)

     Several (admittedly disputed) statements of Christ condemned the array. When Peter denied Him thrice, the third occurrence caused a protection violation. You know what happened after that.

     Preserve the purity of your precious bodily fluids. Avoid the array at all costs. Don't let your friends bring arrays to your parties. If you see one coming toward you, cross the street. Make sure any candidate you support for public office has a firm anti-array stance.

     Despite all of this, you might ultimately have to get involved with an array, if only for maintenance purposes. If so, your Curmudgeon will pray for you. And always remember the Golden Rule Of Indexing:

Real Men Count From Zero.

     Ah, the memories!


  1. Ah,yes! I fondly remember how far above the fray I was able to fly because I knew the power of the List. Of course, it is possible to succumb to the Dark Side of the List as well, as one poor guy in the lab found out when he schlonged himself by creating a multiply-linked three dimensional array of – lists.

  2. Shouldn't you have followed longstanding tradition and titled your comment "Arrays Considered Harmful"?

  3. Arrays do the jobs linked lists aren't willing to do.


Comments are moderated. I am entirely arbitrary about what I allow to appear here. Toss me a bomb and I might just toss it back with interest. You have been warned.