Forgot your password?
typodupeerror
Programming Education

Zuckerberg To Teach 10 Million Kids 0-Based Counting 295

Posted by Soulskill
from the why-not-mix-things-up-and-start-at-pi dept.
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."
This discussion has been archived. No new comments can be posted.

Zuckerberg To Teach 10 Million Kids 0-Based Counting

Comments Filter:
  • They don't. (Score:5, Informative)

    by skywire (469351) * on Friday November 15, 2013 @08:48AM (#45432095)

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

  • Re:We don't (Score:2, Informative)

    by Anonymous Coward on Friday November 15, 2013 @08:57AM (#45432163)

    Exactly. The element count of an array where only index [0] is populated is still 1.

  • by Andover Chick (1859494) on Friday November 15, 2013 @09:04AM (#45432213)
    It is an indicator of a shift off the first position.
  • by Millennium (2451) on Friday November 15, 2013 @09:07AM (#45432251) Homepage

    Programmers don't count starting at zero. They index items in collections starting at zero, because it makes certain actions more convenient when you're working at a very low level. But when it comes time to count the items, they start at 1 like everyone else.

  • by Anonymous Coward on Friday November 15, 2013 @09:27AM (#45432463)

    If you are going to teach idiomatic loops, do it correctly. It's not

    for (i=0; i<=3; i++)

    but

    for (i=0; i<4; i++)

    Note that in the second, idiomatic version your actual number of lines appears.

    Note also that the two conventions are strongly related. [utexas.edu]

  • Re:They don't. (Score:4, Informative)

    by CastrTroy (595695) on Friday November 15, 2013 @09:28AM (#45432475) Homepage
    Speaking of iterating, I almost never need to write a loop that uses an integer index. All the programming languages I use have a "For each" construct that works with just about anything you'd want to iterate over. No more worrying about off-by-one bugs, and other such associated problems. I have trouble recalling the last time I actually used the For(i =0.... syntax.
  • by StormReaver (59959) on Friday November 15, 2013 @09:31AM (#45432495)

    I started reading the article linked to in, "start counting at zero", and stopped halfway through. I feel sorry for anyone who reads that article, but isn't a programmer (hell, even if they are programmers), as it is self-contradictory crap:

    From the article:

    Itâ(TM)s not about [pointer math] because pointers and structs didnâ(TM)t exist....So I found [the person who originally decided to start array indices at zero] and asked him [why he started array indices at zero].

    Then the father of zero-index arrays said:

    ...if p is a pointer p+1 is a pointer to the next word after the one p points to.

    He then goes on to admit that zero-index arrays are the most efficient means of calculating memory addresses, and brushes aside his self-contradictions by saying that the "why" is more important than the "how".

    Which means, as should be obvious to everyone, that zero indices are the most natural way to express pointer arithmetic; internally to your language runtime if your language doesn't support pointers, or externally if pointers are programmer-facing.

    The author of this article needs to brush up on computer fundamentals before self-publishing his absurd opinion pieces on computer fundamentals. Zero-index arrays are "conventional programming wisdom" because they have always been the easiest way to calculate memory addresses.

  • Re:We don't (Score:4, Informative)

    by tlambert (566799) on Friday November 15, 2013 @11:54AM (#45434285)

    No. The creators of C were not terribly concerned about the extra compilation time - they were concerned about generating efficient code and representing it efficiently in the source.

    Yes. But what made C such a universal language was the incidental fact that this made the compiler easier to implement.

    Except the first machines C ran on didn't have an "add unity to memory" instruction unless you got out the wire wrap tools and made one, so this excuse doesn't work.

    The real reason is that variables and arrays actually take up memory, and if you understand this fact, then you will naturally gravitate toward using a 0 offset, whereas if you don't, then you probably learned programming using a language that hides the underlying memory allocations from you. Which is why anyone who wants to claim they are a programmer should learn at least one assembly language, so that they understand that memory is just that free stuff, and that you actually have to allocate backing store for variables.

  • Re:We don't (Score:5, Informative)

    by vux984 (928602) on Friday November 15, 2013 @12:34PM (#45434781)

    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.

"Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken

Working...