This semester I'm studying event-driven programming using VB. My instructor, a veteran developer and programming instructor, was horrified to discover that VB has a feature neither he nor anyone else in the class had ever seen in any language -- even other dialects of BASIC: For the declaration of an array with a single subscript
*, such as
Dim thisArray(20) As Integer
VB creates an array of not 20 but
21 integer variables!
Why? The answer may lie in the concept that VB is intended not merely for experienced developers but casual programmers too. The implication here is that, for those of us who are accustomed to a first array member with a subscript of 0, we'll get what we expect, but those who would find the typical progression of subscripts (0)...(
n-1) bewildering and counterintuitive can have an array whose subscripts progress 1...
n. You see, to a non-geek,
thisArray(1),
thisArray(2), and
thisArray(3) naturally seem like they ought to be the first three elements in the array,
thisArray(20) ought the be the last one, and there should be no such thing as
thisArray(0).
Our good-natured classroom outrage at the zero-to-
n-minus-one convention yielded to some brief discussion of the tradeoff involved. In an era where Moore's Law makes processor power and speed and memory capacity cheaper all the while, it's evidently worth having a "throwaway" extra member in each array a programmer creates if only to placate the nontechnical VB user who doesn't want to think overmuch in terms of how a computer language really does its work under the hood.
----------------------------------
*I say "with a single subscript" because VB also permits interesting declarations such as
Dim thatArray (7 to 9) as Single
to consist specifically of
thatArray(7),
thatArray(8), and
thatArray(9).