On 5/1/06, Laurence Rozier laurence.rozier@gmail.com wrote:
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.
You're right; it's not natural to count from zero. All those people who used Roman numerals and similar systems before about the year 600 never thought of it once. It took hundreds more years for the zero to be in common use; many people simply didn't accept it as a number.
But even then, if they had wished to measured a distance, what number would have marked the beginning of their measuring tape? If they had thought to measure time, what number would represent the beginning of their measurements? How did their census takers report a home without children?
Although it's not necessarily natural to count from zero, there are good reasons to teach when, why, and how to count from zero.
Cheers!
--Tom Phoenix
Tom Phoenix wrote:
But even then, if they had wished to measured a distance, what number would have marked the beginning of their measuring tape? If they had thought to measure time, what number would represent the beginning of their measurements?
You're getting to the heart of the matter here - intervals are not entities. When you're measuring (macroscopically) continuous stuff like time and distance, it makes a lot of sense to let offsets start at 0, and to use half-open intervals. So the way from your origin (distance 0) to the first milestone (distance 1) is the first mile, although all points on it are labeled with a zero first digit. Or time: your first year in life was the one up to the day you became 1 year old. Then began your second year.
How did their census takers report a home without children?
Now that's a completely different issue. (Indivisible) entities are best counted with integral numbers starting at 1. If you have one child, you'd write down the number 1, naturally. Without the digit 0, you'd probably mark the field with something else which states that there is nothing.
Computer hardware (such as memory) can often be seen as almost continuous (or at least divisible) matter. Using half-open intervals to address it is very reasonable.
Smalltalk Arrays are mostly used like containers of discrete entities, which makes using 1-based indexes feel natural. But of course, if your goal is to model core or disk memory, 0-based addressing is most likely better.
Cheers, Hans-Martin
Tom Phoenix wrote:
On 5/1/06, Laurence Rozier laurence.rozier@gmail.com wrote:
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.
You're right; it's not natural to count from zero. All those people who used Roman numerals and similar systems before about the year 600 never thought of it once. It took hundreds more years for the zero to be in common use; many people simply didn't accept it as a number.
But even then, if they had wished to measured a distance, what number would have marked the beginning of their measuring tape? If they had thought to measure time, what number would represent the beginning of their measurements? How did their census takers report a home without children?
Although it's not necessarily natural to count from zero, there are good reasons to teach when, why, and how to count from zero.
Cheers!
--Tom Phoenix
Tom, your argument is a little misleading to me. You can use 0 as a number wherever you want in Smalltalk. So you can use zero to mark the beginning of a tape and to report the result of a census for a family without children.
An array should be use to store a collection of things (any of its values can contain zero even in Smalltalk). And calling the first element of an array 1 does make much more sense.
Most lower level programming languages start counting from 0 (for arrays) just because they're nearer to machine language and thus to the hardware. Smalltalk isn't anyway.
Ciao,
c.
On 5/1/06, Cesare Marilungo cesare@poeticstudios.com quoted me:
Although it's not necessarily natural to count from zero, there are good reasons to teach when, why, and how to count from zero.
Tom, your argument is a little misleading to me. You can use 0 as a number wherever you want in Smalltalk.
It looks as if you thought the subject of my posting had something to do with the design of Smalltalk. No; my posting was about counting from zero, a mathematical idea. This mathematical idea is discussed frequently in Smalltalk discussion groups, often by people who advocate changing the language and those who oppose it. But I was discussing it in the abstract, as a mathematical idea that's worth teaching all by itself, even if you don't want to use counting from zero for any particular purpose in your favorite programming language.
Sorry for the confusion.
--Tom Phoenix
squeak-dev@lists.squeakfoundation.org