From mboxrd@z Thu Jan 1 00:00:00 1970 From: doug@cs.dartmouth.edu (Doug McIlroy) Date: Wed, 07 Jun 2017 22:27:05 -0400 Subject: [TUHS] Array index history Message-ID: <201706080227.v582R5D9056395@tahoe.cs.Dartmouth.EDU> > Who started this? Why was the change made? Arrays in Fortran and Algol were indexed from 1 by default, but Algol (IIRC) generalized that to allow first:last declarations. NPL used first,last for the SUBSTR operation. But first,last begets off-by-one errors. The successor slice begins at last+1. The formula for the position of 1-indexed a[i,j] is a mess. First,length is much cleaner: the successor begins at first+length. I convinced the committee of that, so when NPL became PL/I, first,length was the convention. Zero- indexing is also a clean first,length notation. BCPL, where a[i] was synonymous with rv(a+i), had it. Dennis, who knew a good thing when he saw it, took it over. Dijkstra, too, often inveighed against 1-indexing, and opined that zero was the true computer-science way. 1-indexing certainly came into programming languages from the math tradition for matrix notation. Of course in math series are often indexed from zero, so one may pick and choose. Off hand I can only think of one CS context where 1 comes in handy: heapsort. Doug