comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Default array base index
Date: Mon, 28 Jan 2008 09:02:51 -0800 (PST)
Date: 2008-01-28T09:02:51-08:00	[thread overview]
Message-ID: <1c61f7eb-f922-4805-9e04-0bb70f0c2cc6@i7g2000prf.googlegroups.com> (raw)
In-Reply-To: 1497d552-b826-4477-a181-4962a6d38c8c@i12g2000prf.googlegroups.com

On Jan 27, 11:20 am, Scott Burson <FSet....@gmail.com> 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






  parent reply	other threads:[~2008-01-28 17:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-27 19:20 Default array base index Scott Burson
2008-01-27 19:36 ` Dmitry A. Kazakov
2008-01-28  4:29   ` Scott Burson
2008-01-27 20:40 ` (see below)
2008-01-28 17:02 ` Adam Beneschan [this message]
2008-01-28 18:50   ` Dmitry A. Kazakov
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox