Counting from zero
Ralph Johnson
johnson at cs.uiuc.edu
Tue May 2 04:46:12 UTC 2006
We certainly don't want to add complexity without necessity. But that
is not the reason to avoid "countZero".
In general, if your Smalltalk program knows whether the lowest index
of a collection is 1 or 0 then there is probably something wrong with
it. Use enumeration protocol. Say do: and collect: instead of
whileTrue:. If you need to iterate over the index of a collection,
use keysAndValuesDo:
I bet that in a typical month of Smalltalk programming, I don't ever
need to know whether arrays are indexed starting from 1 or 0. That is
a low-level implementation detail. Arrays are low-level
implementation details. Program at a high level!
-Ralph Johnson
More information about the Squeak-dev
mailing list
|