new Smalltalk programmer's thoughts

Hans-Martin Mosner hmm at
Mon May 1 11:03:08 UTC 2006

Wolfgang Helbig wrote:

>The last sentences are purely speculative and Dennis might shed some light on 
>them. But it is not speculative that Smalltalk is the only programming language 
>that allows indexed variables and forces the programmer to use one as the first 
>index. If you find another one let me know.
> lists BASIC and Fortran as having 
1-based array indexing, and it even discusses some of the relative 
merits of and arguments for 0-based and 1-based array indexing.
Which one is more natural is a matter of personal taste and opinion. In 
most everyday programming situations I consider the 1-based approach 
much more natural, but the low-level stuff where you're addressing 
hardware is definitely an exception which can be handled pretty well by 
implementing a specialized arrayed class which does 0-based indexing. 
Having learned BASIC as a first language in school, I found C's 
convention of 0-based indexing pretty awkward, until I realized that C 
is mostly a kind of portable assembly language which lets you get close 
to the hardware. It's not a language I would consider well suited for 
expression my thoughts in a program...
The question is: do we want to let hardware characteristics dominate our 
way of thinking? I at least don't. When I've got 5 elements in a 
collection, I want the first at index 1 and the fifth at index 5. When 
I'm using Integers, I don't want to think about 16 vs 32 bits, signed vs 
unsigned etc.
The argument about loop bounds is somewhat related. I've seen quite some 
beginner's C code which did "for (i=0; i<=10; i++)" to address a 
10-element array :-) Seasoned C programmers don't do that anymore, but 
it tells me a bit about what is "natural" :-)


More information about the Squeak-dev mailing list