Enum's start at 0? 
Author Message
 Enum's start at 0?

Just curious, but is there a reason enumerated type's POS values
start at 0 instead of 1?

----------------------------------------------------------------------------

Southwest Research Institute (SwRI)
San Antonio, Texas



Sat, 17 Jun 1995 22:36:42 GMT  
 Enum's start at 0?

Quote:
>Just curious, but is there a reason enumerated type's POS values
>start at 0 instead of 1?

Just like everything else in computing. ASCII characters, for example,
run from 0 to 127, not 128. You can represent 0..127 using one less bit than
1..128.

Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman
co-chair, SIGAda Education Committee

Professor, Dept. of Electrical Engineering and Computer Science
School of Engineering and Applied Science
The George Washington University
Washington, DC 20052 USA
(202) 994-5253 (voice)
(202) 994-5296 (fax)

"Americans want the fruits of patience -- and they want them now."
------------------------------------------------------------------------



Sun, 18 Jun 1995 11:38:42 GMT  
 Enum's start at 0?

|> >Just curious, but is there a reason enumerated type's POS values
|> >start at 0 instead of 1?
|> >
|> Just like everything else in computing. ASCII characters, for example,
|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
|> 1..128.
|>
   All right... then why do string indices start at 1? :-)

     Tim
--

 Software Technology R&D                     (215) 648-2475
 Paramax Systems Corporation                 FAX: (215) 648-2288
 PO Box 517, Paoli, PA 19301



Sun, 25 Jun 1995 06:00:07 GMT  
 Enum's start at 0?

[stuff deleted]

Quote:
>|> >
>|> Just like everything else in computing. ASCII characters, for example,
>|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
>|> 1..128.
>|>
>   All right... then why do string indices start at 1? :-)

Beats me. Anyone out there have an authoritative answer?

Mike Feldman



Sun, 25 Jun 1995 10:59:29 GMT  
 Enum's start at 0?
I actually once had a list of reasons to start arrays at 0 vs 1, which I've
conveniently lost. In the spirit of starting a new one, I'll try to recall what
I can from the old list. An array that is a STRING probably has other special
properties.

Start at 1:
  'LENGTH is same as 'LAST
  Negated indexes are unique (I used this fact once in a program)

Start at 0:
  Mod works better (for hashing)
  Convient when doing work with 'polynomial-like' things

Rich

--
------------------------------------------------------------------------------
  Richard E. Pattis                     "Programming languages are like
  Department of Computer Science         pizzas - they come in only "too"
    and Engineering                      sizes: too big and too small."



Sun, 25 Jun 1995 15:57:02 GMT  
 Enum's start at 0?


   > >   All right... then why do string indices start at 1? :-)

   > Beats me. Anyone out there have an authoritative answer?

   Is there such a thing?  (I assume you don't want me to point to
Appendix C(17) and say because...)  There was a lot of debate on this
in 1981-1982, but as I remember it, it was more concerned with
replacing the subtypes NONNEGATIVE and NATURAL with the more standard
NATURAL and POSITIVE.  Once these were changed STRING changed to
match.

    I guess the real answer is that there was always an expectation
that for "normal" strings 'LENGTH = 'LAST and this requires that
STRINGs be based at one.

--

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...



Mon, 26 Jun 1995 03:40:57 GMT  
 Enum's start at 0?
Timothy M. Schreyer asks:
: ... why do string indices start at 1? :-)

A closet Pythagorean in the Ada design team got rational arithmetic
into the compilers; similarly, a disciple of Parmenides strove to
find the one in the many and upheld that what is not, is not.  Thus,
String indices start at 1, not in the void of 0.

Ada is the language for those who have love of wise programming, a
derived type of philosophers.
--
Magnus Kempe            "I have sworn ... eternal hostility to every form of



Mon, 26 Jun 1995 16:09:43 GMT  
 Enum's start at 0?

Quote:



>[stuff deleted]

>>|> >
>>|> Just like everything else in computing. ASCII characters, for example,
>>|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
>>|> 1..128.
>>|>
>>   All right... then why do string indices start at 1? :-)

>Beats me. Anyone out there have an authoritative answer?

>Mike Feldman

shouldn't beat you. Both are reasonable.

The first is considered and used more as an "offset".
Additionally it coincides well with age-old integer-to-byte
and vice versa representation.
This representation can well be adopted and is the most likely
fitting data format when talking to foreign hardware
(in the serendipiduous sense). Additionally, the compiler has
the minimum conceivable work.
I see no harm with that rule. I see the benefits.

The second is naturally used for indexing,
which would be extremely disadvantages with a 0 as first index,
when working on vector and matrix material,
especially for more-dimensional matrices.
Here, you do not think in offsets but in elements, e11,e12,e13,...

Peter Hermann

Newsgroups: comp.lang.ada
Subject: Re: Enum's start at 0?
Summary:
Expires:

Sender:
Followup-To:
Distribution:
Organization: ica2
Keywords:

- Show quoted text -

Quote:



>[stuff deleted]

>>|> >
>>|> Just like everything else in computing. ASCII characters, for example,
>>|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
>>|> 1..128.
>>|>
>>   All right... then why do string indices start at 1? :-)

>Beats me. Anyone out there have an authoritative answer?

>Mike Feldman

Newsgroups: comp.lang.ada
Subject: Re: Enum's start at 0?
Summary:
Expires:

Sender:
Followup-To:
Distribution:
Organization: ica2
Keywords:

- Show quoted text -

Quote:



>[stuff deleted]

>>|> >
>>|> Just like everything else in computing. ASCII characters, for example,
>>|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
>>|> 1..128.
>>|>
>>   All right... then why do string indices start at 1? :-)

>Beats me. Anyone out there have an authoritative answer?

>Mike Feldman

shouldn't beat you. Both are reasonable.

The first is considered and used more as an "offset".
Additionally it coincides well with age-old integer-to-byte
and vice versa representation.
This representation can well be adopted and is the most likely
fitting data format when talking to foreign hardware
(in the serendipiduous sense). Additionally, the compiler has
the minimum conceivable work.
I see no harm with that rule. I see the benefits.

The second is naturally used for indexing,
which would be extremely disadvantages with a 0 as first index,
when working on vector and matrix material,
especially for more-dimensional matrices.
Here, you do not think in offsets but in elements, e11,e12,e13,...

Peter Hermann



Mon, 26 Jun 1995 23:25:39 GMT  
 Enum's start at 0?

Quote:



>[stuff deleted]

>>|> >
>>|> Just like everything else in computing. ASCII characters, for example,
>>|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
>>|> 1..128.
>>|>
>>   All right... then why do string indices start at 1? :-)

>Beats me. Anyone out there have an authoritative answer?

>Mike Feldman

shouldn't beat you. Both are reasonable.

The first is considered and used more as an "offset".
Additionally it coincides well with age-old integer-to-byte
and vice versa representation.
This representation can well be adopted and is the most likely
fitting data format when talking to foreign hardware
(in the serendipiduous sense). Additionally, the compiler has
the minimum conceivable work.
I see no harm with that rule. I see the benefits.

The second is naturally used for indexing,
which would be extremely disadvantages with a 0 as first index,
when working on vector and matrix material,
especially for more-dimensional matrices.
Here, you do not think in offsets but in elements, e11,e12,e13,...

Peter Hermann



Mon, 26 Jun 1995 21:25:48 GMT  
 Enum's start at 0?

Quote:



>[stuff deleted]

>>|> >
>>|> Just like everything else in computing. ASCII characters, for example,
>>|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
>>|> 1..128.
>>|>
>>   All right... then why do string indices start at 1? :-)

>Beats me. Anyone out there have an authoritative answer?

>Mike Feldman

Newsgroups: comp.lang.ada
Subject: Re: Enum's start at 0?
Summary:
Expires:

Sender:
Followup-To:
Distribution:
Organization: ica2
Keywords:

- Show quoted text -

Quote:



>[stuff deleted]

>>|> >
>>|> Just like everything else in computing. ASCII characters, for example,
>>|> run from 0 to 127, not 128. You can represent 0..127 using one less bit than
>>|> 1..128.
>>|>
>>   All right... then why do string indices start at 1? :-)

>Beats me. Anyone out there have an authoritative answer?

>Mike Feldman

shouldn't beat you. Both are reasonable.

The first is considered and used more as an "offset".
Additionally it coincides well with age-old integer-to-byte
and vice versa representation.
This representation can well be adopted and is the most likely
fitting data format when talking to foreign hardware
(in the serendipiduous sense). Additionally, the compiler has
the minimum conceivable work.
I see no harm with that rule. I see the benefits.

The second is naturally used for indexing,
which would be extremely disadvantages with a 0 as first index,
when working on vector and matrix material,
especially for more-dimensional matrices.
Here, you do not think in offsets but in elements, e11,e12,e13,...

Peter Hermann



Mon, 26 Jun 1995 22:06:20 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Beginner's 'enum' question

2. Can't start vw30 [was: Can't start vwnc30]

3. Can't start vw30 [was: Can't start vwnc30]

4. enum to throw isn't arbitrary?

5. Parameter 'handshake source' in DIO Start

6. RC=457 from 'START ...'

7. RC=457 from a 'START ....'

8. CICS 'START' Question

9. Help: 'AttributeError: wm_title' Error starting IDLE

10. Q: how to get pid of 'start'ed process (WNT, os.system)

11. integers which start by '0'

12. [auto_execok] 'start' is NT builtin

 

 
Powered by phpBB® Forum Software