Xref: utzoo comp.lang.modula2:670 comp.lang.misc:1123 Path: utzoo!mnetor!uunet!husc6!necntc!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.modula2,comp.lang.misc Subject: Re: 0-based/1-based arrays Message-ID: <2851@haddock.ISC.COM> Date: 3 Mar 88 02:45:00 GMT References: <7161@sol.ARPA> <2740@mmintl.UUCP> <4343@june.cs.washington.edu> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 18 Summary: rebuttal from a 0-based user In article <4343@june.cs.washington.edu> pattis@june.cs.washington.edu (Richard Pattis) writes: >I too detest 0-based arrays (and think 1-based arrays are better). In trying >to rationalize this choice, I came up the the following argument: When we >process arrays, we often need to know the size of the array and/or the >position of the last element. In 0-based arrays, these quantites are off by >one; in 1-based arrays they are the same. Hence, I think that people will >make fewer errors with 1-based arrays. When dealing with 0-based arrays, the appropriate concept is a half-open interval: the index for an N-element array comes from [0,N). I find that this makes things simpler than with 1-based arrays, because half-open intervals can be abutted without having to adjust by one. (I.e., [0,N) U [N,P) = [0,P).) I very seldom need to know the position of the last element. Instead, I use the position of the first element beyond the array. Always use postincrement and/or predecrement to traverse it; everything works out fine. Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint