Python "why" questions

Martin Gregorie martin at address-in-sig.invalid
Fri Aug 13 19:53:56 CEST 2010


On Fri, 13 Aug 2010 19:14:44 +0200, Thomas Jollans wrote:

> "Where it all started" is that 0-based indexing gives languages like C a
> very nice property: a[i] and *(a+i) are equivalent in C. From a language
> design viewpoint, I think that's quite a strong argument. Languages
> based directly on C (C++, Objective C, ...) can't break with this for
> obvious reasons, and other language designers/implementers imitated this
> behaviour without any good reason to do so, or not to do so. In
> higher-level languages, it doesn't really matter. 1-based indexing might
> seam more intuitive.
>
In a higher level language 1-based indexing is just as limiting as 0-
based indexing. What you really want is the ability to declare the index 
range to suit the problem: in Algol 60 it is very useful to be able to 
declare something like:

	real sample[-500:750];

and Algol 68 went even further:   

	flex [1:0] int count

where the array bounds change dynamically with each assignment to 
'count'. Iteration is supported by the lwb and upb operators which return 
the bounds of an array, so you can write:

	for i from lwb count to upb count do....


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |



More information about the Python-list mailing list