News for hackers. Stuff that matters.
Re:Getting Back to Smalltalk by ootachi on Friday December 30, 2011 @12:23PM (#3408284)
"The first element of an array is index 1, not index 0. Which, honestly, makes more sense."

No, it really doesn't. This is a constant headache in Lua too. See Dijkstra's comments on the subject here: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EW...

Re:Getting Back to Smalltalk by gecko on Friday December 30, 2011 @01:50PM (#3408620)
Smalltalk actually has two different ways to address things: as sequences, and as streams. Sequences are 1-based, and streams are 0-based. This is designed to model what you intuitively do in real life. As a picture:

    |  1  |  2  |  3  |  4  |
    +-----+-----+-----+-----+
    0     1     2     3     4
Think of a ruler. The ruler starts at zero, but you don't refer to the first inch as inch zero; it's the first inch, or inch 1. But if you want to delineate the inch, you do indeed say from the beginning of the ruler (i.e., 0) to the first inch marker (i.e., 1).

I'm not going to tackle whether Djikstra was right or wrong, but merely to point out that there's more to Smalltalk's indexing than meets the eye.

For what it's worth: I'm not a professional Smalltalk dev by any stretch of the imagination, but I've written enough Smalltalk to tell you that you very rarely deal with the indices, anyway. Nearly all Smalltalk code ends up just using comprehensions to navigate collections. Of the remainder, they're such trivial cases that the 1-based indexing is intuitive and does not bother me the way that it does in, say, Lua or really old Turbo Pascal programs where some coder got a bit too slap-happy on arbitrarily bounded arrays.

Re:Getting Back to Smalltalk by mmphosis on Friday December 30, 2011 @08:25PM (#3409799)
Math vs. Language.

I don't refer to the first inch of a ruler as inch 0 or inch 1, I refer to it as the first inch.

There are two things being described which I think is a set up for confusion and the many off by one errors that I've seen as a result.

    1. Coordinate.
    2. Interval.
The origin of a graph using the Cartesian coordinate system is usually 0,0, not 1,1.

But, in my list of 2 items, I index with 1 and 2, not 0 and 1. But, be sure that the first item is 1.0 not 1.1 and the second item is 2.0 not 2.1.

Re:Getting Back to Smalltalk by fractallyte on Friday December 30, 2011 @12:53PM (#3408381)
I'm struggling to find Dijkstra's argument sufficiently compelling to conclude that zero is the 'most natural number'. It's a conclusion based on his aesthetics (plus an anecdotal story).

The natural numbers are generally considered to start at 1. Therefore, to people in general, such a system makes more sense.

Re:Getting Back to Smalltalk by r00fus on Friday December 30, 2011 @02:00PM (#3408667)
Agreed. The fact that arrays were simple memory-offsets making zero-index easier for low-level programming doesn't make it easier for humans who historically prefer 1-indexing.

Zero is not a "natural" number, in fact many societies / civilizations never even understood or used zero in arithmetic [1].

[1] http://en.wikipedia.org/wiki/Roman_numerals

Re:Getting Back to Smalltalk by technomancy on Friday December 30, 2011 @02:20PM (#3408742)
> in fact many societies / civilizations never even understood or used zero in arithmetic

Yeah, but those societies were uniformly terrible at math.

Re:Getting Back to Smalltalk by gaius on Friday December 30, 2011 @02:34PM (#3408790)
There are Roman bridges still standing, and Roman roads still in use.
Re:Getting Back to Smalltalk by fractallyte on Friday December 30, 2011 @02:37PM (#3408804)
Therefore, with the concept of 'zero' in mind, I'm going to revisit the parent statement:

If I hold up my fingers to indicate elements in an array, zero fingers means the array is empty. One finger is then, naturally, the first item: of index 1.

Counting elements starting at zero (for the first element) is still unnatural...

Re:Getting Back to Smalltalk by joe_the_user on Friday December 30, 2011 @04:38PM (#3409196)
No, there really are no any societies that "terrible" at math, only societies that have evolved more sophisticated math than others - the smartest member of given society will certainly use the concepts the society has evolved correctly.

And you only need 1...N to order N bins and their contents.

Re:Getting Back to Smalltalk by ths on Friday December 30, 2011 @04:07PM (#3409101)
During my math undergrad, the natural numbers were always assumed to start with 0, the rationale being that the natural numbers should enumerate the cardinalities of all finite sets (the empty set, of course, being finite). I guess it depends on one's background.
Re:Getting Back to Smalltalk by joe_the_user on Friday December 30, 2011 @04:34PM (#3409180)
There wasn't such consistency in my math undergrad or masters programs. Further, the Peano postulates definitely involve the natural numbers starting at 1.

Of course, most programmers don't have math degrees and I'd suspect that most people indeed think 1st element of an array starts at 1.

Re:Getting Back to Smalltalk by stesch on Friday December 30, 2011 @05:10PM (#3409292)
No? You really want to discuss array starting indexes here, too? WTF? We have the end of 2011, get over it!

ARGHL!