Slashdot Mirror


Zuckerberg To Teach 10 Million Kids 0-Based Counting

theodp writes "'Why do programmers start counting at zero?' wondered Mike Hoye, questioning the conventional programming wisdom. Code.org will soon introduce the practice to a hoped-for audience of 10 million schoolchildren as part of Computer Science Education Week's Hour of Code. In a tutorial created by engineers from Microsoft, Google, Twitter and Facebook that's intended to introduce programming to kids as young as six years old, an otherwise breezy lesson featuring look-ma-no-typing Blockly and characters out of Angry Birds and Plants vs. Zombies, a Mark Zuckerberg video introducing the concept of Repeat Loops includes an out-of-place JavaScript example that shows kids it's as easy as 0-1-2-3 to generate 4 lines of lyrics from Happy Birthday to You by using zero-based numbering with a For-loop and ternary If statement. Accompanying videos by Bill Gates on If Statements and basketball star Chris Bosh on Repeat Until Blocks show the Code.org tutorial is still a work-in-progress. That's no big deal, since CSEdWeek has pushed back the delivery date for final Hour of Code tutorials from its prior little-time-for-testing due date to Dec. 9th, the first day of a five-day period during which teachers are expected to deliver the lessons to 10 million students."

2 of 295 comments (clear)

  1. They don't. by skywire · · Score: 4, Informative

    Iterating through offsets beginning with zero is simply not counting. The writer is confused.

    --
    Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety.
  2. Re:We don't by vux984 · · Score: 4, Informative

    It is quite true though that the 0-based thing is entirely an artifact of C (and of course languages that cribbed its syntax).

    Its not an "artifact of C" its an artifact of reality.

    If you allocate 10 bytes at address X, then:

    the first one is going to be at address X, the second one is address X+1, etc.

    The x[y] syntax then reduces to address x + y

    And so x[0] is the byte at x, x[1] is the byte at x+1, etc.

    Now you could 1 base the indexes, where x[1] resolves to address of x, but the implementation of that is:

    x + 1 - 1, and x[y] in general becomes x + y - 1

    That's an extra subtraction instruction on every single array access.

    For larger datatypes it becomes:

    x + y*sizeof(type) for zero based and
    x + (y-1)*sizeof(type) for one based arrays

    That's going to be true for any language, and the question is posed to every language designer: either the programmer counts from zero, or every array access in the language has a subtraction added to it.

    For C, which is designed to be a bare bones close to the hardware language the decision was a nobrainer, but even for higher level languages its always a choice between a performance hit, or using zero based indexing.

    Another wrinkle is that if you use 1 based indexing, then x[0] is undefined.

    Another wrinkle is that if you use 1 based indexing then the maximum length of an array was reduced by 1.

    No. Ada begins iterating wherever you tell it to. You can index your arrays from -100 to 0 if you like.

    I don't deny that it's useful, but Ada does that by effectively adjusting all the indexes to zero based behind the scenes.

    "Thinking that's a feature of programming is a sure sign of a inexperienced programmer."

    No, only an inexperienced programmer would not understand that zero based indexing is the 'natural' indexing, and that anything else requires extra processing.