Re: Default array base index



On Jan 27, 11:20 am, Scott Burson <FSet....@xxxxxxxxx> wrote:
Hi,

I just came across this Wikipedia page:

http://en.wikipedia.org/wiki/Comparison_of_programming_languages_%28a...

which claims that the default base index for arrays in Ada is 1. It
has been over 15 years since I have written any Ada, so my memory is
fuzzy, but what I recall is that there actually is no default: the
base index must always be specified explicitly when the array is
declared. However, it does appear that Ada culture leans toward the
use of 1 as a default (for example, the language numbers the
dimensions of the array from 1 in attribute expressions).

Do you agree?

There may be some small ways in which this is correct. For example,
the predefined type String is defined with "Positive" as the index
subtype, which means you can't define a String subtype that starts at
index 0. Of course, you can define one that starts at positive
integers larger than 1, but (without having read the article in
question) I suspect that this is part of a long-running debate over
whether it's "better" to start arrays and other sequences at 0 or 1
(as if there were one answer that fit every situation). At least
once, I've seen articles in SIGPLAN or other places where an author
decided to number the sections, subsections, sub-subsections, etc., of
his article starting with section 0 instead of the more traditional 1,
apparently for no good reason except to declare which side of this
debate he was on. So anyway, bases larger than 1 aren't really
relevant to this "culture" or stylistic issue.

Back to Ada, when I opened my Ada 95 RM to see if I could find other
predefined arrays, I did find this in A.9:

subtype Buffer_Type is
System.Storage_Elements.Storage_Array(1..Buffer_Size);

In general, though, I think the statement you quote is nonsense. As
you mention, Ada doesn't really have a default base, and programmers
are free to choose whichever one suits the problem more. In my own
code, when I don't have a particular reason to choose 1 or 0 as the
base, I tend to gravitate toward using 1, but I think that has less to
do with "Ada culture" and more to do with the fact that when I was one
year old and my mother started teaching me to count, she started with
"one" and not "zero". Also, we always number everything else starting
with "first", "second", etc.; ever seen a baseball game played with
"zero-th base", "first base", and "second base"? ("Who's on zero-
th?" "Yes."
"I mean his name." "Who." "The guy on zero-th." "Who." "The zero-
th baseman." "Who." Just doesn't have the same ring to it.) So it
isn't an "Ada culture" at all---it's the fact that using 1 seems more
natural, and that I get to use a language that gives me a choice,
rather than struggling with a low-level language like C that forces me
into unnatural behaviors like using 0 as the index base.

-- Adam



.



Relevant Pages

  • Re: A simple ADA puzzle (I havent the answer)
    ... >But this programmer does understand what arrays and types are, ... >just not how they manifest in Ada. ... >languages of the day. ...
    (comp.lang.ada)
  • Re: which language?
    ... > Many engineering and physics calculations use arrays as their ... Fortran compilers have implemented ... Ada provides very efficient arrays. ... > loop index to be changed in the body of the loop. ...
    (comp.programming)
  • Re: Ada 2005?
    ... component-on-demand abstraction, that is, unified notation for an externally ... arrays likewise may be ... between arrays and functions, supported in Ada). ... contest AI's propositions concerning all things except Object.Operation ...
    (comp.lang.ada)
  • Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... Ada arrays compare to C++ style arrays when the problem ... The language already provided what was needed, ... I've tried to picture the higher level of abstraction ...
    (comp.lang.ada)
  • Re: Teaching new tricks to an old dog (C++ -->Ada)
    ... Ada arrays compare to C++ style arrays when the problem ... The language already provided what was needed, ... I've tried to picture the higher level of abstraction ...
    (comp.lang.cpp)