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."

6 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.
    1. Re:They don't. by ackthpt · · Score: 4, Funny

      This press conference is over.

      The press conference began at 0 PM, where were you?

      --

      A feeling of having made the same mistake before: Deja Foobar
  2. We don't by Anonymous Coward · · Score: 5, Insightful

    Why do programmers start counting at zero?

    We don't. We start indexing at zero (in some languages), because that's usually the offset of the first useful location in an array (ie, addr + 0).

    1. 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.

  3. Copyrights! by sootman · · Score: 5, Insightful

    Careful there, Z -- that might count as a "public performance" of Happy Birthday. I know you're rich, but the payment for and audience of 10 million might be kinda high.

    --
    Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
  4. Counting From Zero Actually Makes more Sense by physicsphairy · · Score: 4, Insightful

    Even well into adulthood, people are still confused by, e.g., the difference between "the early 1700s" and "the early 17th century" (which is actually the 1600s). Turns out, whether you like it or not, the first place value of 10^2, 10^3, 10^4, etc. you count through is always the 0th one. It's only in the very specific circumstance of counting the 10^1 place and when all the other 10^x place values are zero that the 0 gets skipped. Why not be consistent?

    Besides being more consistent, I also think it is more intuitive (barring the fact that we are culturally inducted into thinking that it isn't). If you were counting *backwards,* say, starting with ten cookies and removing one cookie off a plate each time, it would be perfectly intuitive to you that you should count down to zero cookies, taking the very last cookie off the plate. The zero cookie limit is enforced by physical reality, while the one cookie limit is enforced by your arbitrary decision to interrupt your process of removing cookies and leave one cookie on the plate. Likewise, in the reverse process, you should also start your counting at an empty plate.