new Smalltalk programmer's thoughts

Laurence Rozier laurence.rozier at gmail.com
Mon May 1 17:22:54 UTC 2006


On 5/1/06, Hans-Martin Mosner <hmm at heeg.de> wrote:
>
> 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.
> >
> >
> http://en.wikipedia.org/wiki/Array 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" :-)


So true. The admonition "remember arrays start at zero" is repeated
countless times in most literature. You see this in just about every article
or book on most modern languages. If it were so "natural" to count groups of
things from 0 people wouldn't need to be reminded constantly.

Regards,
Laurence

Cheers,
> Hans-Martin
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060501/cc8c4add/attachment.htm


More information about the Squeak-dev mailing list