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

41 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 wonkey_monkey · · Score: 3, Funny

      This press conference is over.

      --
      systemd is Roko's Basilisk.
    2. 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
    3. Re:They don't. by bsDaemon · · Score: 2

      Why would programming want to meet kids as young as six years old?

    4. Re:They don't. by CastrTroy · · Score: 3, Informative

      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.

      --

      Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
    5. Re:They don't. by Anonymous Coward · · Score: 2, Funny

      This press conference is over.

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

      I was at 0 Main Street.

      "The corner of 0th and Null" was the joke you wanted.

    6. Re:They don't. by Joce640k · · Score: 2

      Bill Gates still uses BASIC and Mark Zuckerberg uses its bastard offspring (Python). You have to excuse them for not knowing about any data structure other than the integer-indexed array.

      --
      No sig today...
    7. Re:They don't. by camperdave · · Score: 2

      Why would programming want to meet kids as young as six years old?

      Because marketing thought it would be a good idea, and management agreed?

      --
      When our name is on the back of your car, we're behind you all the way!
    8. Re:They don't. by jc42 · · Score: 2

      There are plenty of software documentation sets, tutorials, etc, like this one (selected at random), that have Step 0, Step 1, etc.

      And that example illustrates the usual reason for starting with step 0: The "zero" step is determining your initial state before you start doing anything. In this case, it's determining whether you should bother going on to step 1, which is pretty common. It's also common to use step 0 to list the material needed by the task.

      Probably the most common real-world example is cooking recipes, which typically start with a list of ingredients. That "step" is typically not numbered, but sometimes the actual "steps" to create the food are numbered starting with 1. Or they're just in separate paragraphs, since numbering them isn't actually very useful to carry out the task. In any case, the ingredient list is usually typographically different than the rest of the recipe, and is a description of the required initial state, so it's natural to call it "step 0".

      --
      Those who do study history are doomed to stand helplessly by while everyone else repeats it.
    9. Re:They don't. by i+kan+reed · · Score: 2

      That's the reason we do thinks bitterly and with a ton of resentment, not why we want to do things.

  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 Anonymous Coward · · Score: 2, Informative

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

    2. Re:We don't by aaribaud · · Score: 3, Insightful
      I beg to differ on two accounts:
      • A. Maybe you don't, but that does not apply to "programmers", only to an imaginary set of "programmers" which you consider yourself a member of.
      • B. Iterating is not necessarily entirely different from counting.

      After all, the whole calculus thing stems from the latin for "small stone", which was the way to count livestock, by enumerating them. Start with no stone in hand; pick one stone per animal when you lead them some place; drop one stone per animal when you take the animals back; make sure you have no stone left, none missing either when all animals have passed. IOW... count from zero up, and then back to zero. :)

    3. Re:We don't by T.E.D. · · Score: 3, Insightful

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

      Its a more useful language that way.

      It is quite true though that the 0-based thing is entirely an artifact of C (and of course languages that cribbed its syntax). Thinking that's a feature of programming is a sure sign of a inexperienced programmer.

    4. Re:We don't by alexhs · · Score: 2

      Reading the comments, many people are confused.

      If this can help people doing less off-by-one errors ;) : cardinal vs ordinal vs nominal.

      Depending on the language, an element in an array is referenced by either its ordinal value (1st element, 2nd element), or the cardinal value corresponding to an offset, that is, a difference counted in elements between the start of the array (1st element) and the considered element (0 position between requested element and start element, 1 position between requested element and start element).

      Nominal values are used in enumerations and map/dictionaries (sets of key-values).

      --
      I have discovered a truly marvelous proof of killer sig, which this margin is too narrow to contain.
    5. Re:We don't by tlambert · · Score: 3, Informative

      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.

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

    7. Re:We don't by vux984 · · Score: 2

      Everything you've listed is *an artifact of C*, at least in the context of the gamut of languages also thus far mentioned.

      Everything is an artifact of the hardware. The fundamental properties of the computer itself. C is just closer to the hardware. Its not artifacts of C its artifacts of the hardware.

      You're too stuck in C-think to realise how different other languages are, and how Algoloid-specific your knowledge is.

      I've worked with LISP and ML and Smalltalk and XSL and SQL... but that's beside the point. I'm not stuck in C-think. I'm "stuck" in assembler and binary think; you know the actual hardware itself. Registers and opcodes, where memory itself is just an array of cells. You mistake it as "C-think" because C is quite close to the hardware, but the point is that zero based counting is not an aritfact of C, its an artifact of the hardware itself, its reflected in C because C is close to the hardware.

      What is "allocating" and "an address" in LISP? Or in Forth? Or in prolog?

      The further from the hardware you get the less of it you see. But LISP uses zero based counting (AREF, CHAR). And numbering conventionally begins with zero in Forth too.

  3. 10 million? by sootman · · Score: 2

    So, is that (dec) ten million kids or (dec) two million?

    --
    Dear Slashdot: next time you want to mess with the site, add a rich-text editor for comments.
  4. 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.
  5. It's not a count, it's an offset by Andover+Chick · · Score: 3, Informative

    It is an indicator of a shift off the first position.

  6. Counting versus Indexing by Millennium · · Score: 3, Informative

    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.

  7. Re:Why do programmers start counting at zero? by Ihlosi · · Score: 2
    It's a "C" thing

    No, it's actually an assembly language thing, where you access array elements by base address and offset. Your first element sits at offset zero. C is merely a wrapper for assembly that's suffering from various wardrobe malfunctions.

  8. Make women *what* you? by JamieKitson · · Score: 2

    Are those YouTube features personally tailored?

    Also I'm pretty sure that theodp is breaking the Flickr T&Cs by linking directly to the image.

  9. Counting is an algorithm by swm · · Score: 2

    Counting is an algorithm, like long division or the use of logarithmic tables--in this case an algorithm for assessing the exact numerosity of a set of objects. It consists of reciting a memorized stretch of blank verse ("one, two, three, four, five, ...") while uniquely pairing each foot in the poem with an object in the spotlight of attention, without skipping an object or landing on one twice. Then, when no object remains unnoticed, you announce the last foot you arrived at in the poem as the numerosity of the set.

    This is just one of many possible algorithms for ascertaining numerosity. In some societies, people pair up the objects with parts of their body, and I know several computer programmers who count like this: "Zero, one, two three, four. There are five."

    --Steven Pinker, The Stuff of Thought, p. 141

  10. We should by trinaryai · · Score: 3, Insightful

    The biggest mistake in teaching mathematics is learning to start counting at one. That's fine if the only math ever learned is basic arithmetic; but higher order concepts including fractions, algebra, and number sets beyond whole numbers become much more difficult as a result. Why do we start counting at zero? Because zero is "Origin". When we count, what we are actually doing is this: I have zero. Adding one, I have one. Adding one, I have two. Adding one, I have three. Etc. By using zero as our origin, we can teach arithmetic using the integer set, rather than the whole number set. We can teach that the minus sign just means a change of direction, and that addition and subtraction are actually the same thing. So addition/subtraction is nothing more than repeated counting - a shortcut. Multiplication and division are repeated addition. Fractions are just another way of expressing division. Exponents/roots are repeated multiplication. "If you can count, you can do math. Everything else is a shortcut." Counting from zero allows us to teach euclidean coordinates / geometry as an extension of what students already are familiar with, rather than something new. Why do we start counting at zero? Because zero is "Origin".

  11. That "birthday loop" has the wrong upper end by Anonymous Coward · · Score: 2, Informative

    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.

  12. The Article Is Self-Contradicting by StormReaver · · Score: 3, Informative

    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.

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

  14. Re:They don't. - They really don't. by Jane+Q.+Public · · Score: 3, Insightful

    We don't start counting at 0. Our compilers do.

  15. I disagree by wcrowe · · Score: 2

    I think introducing zero-based counting to older children is a good idea. For younger children, this is a mistake.

    "You have ten fingers Zoe."

    "No I don't. I have nine. See? 0,1,2,3,4,5,6,7,8,9 -- 9!"

    Teaching young children zero-based counting, before they can count is like teaching them the Greek alphabet before they learn their ABCs.

    --
    Proverbs 21:19
  16. When running laps by nayrbn · · Score: 2

    We often say that immediately after starting to job on the track we are on first lap. Then we reach our second, then our third, and so on, updated each time we cross the starting point. But I hate this and would much rather start with zero. Does anyone else feel the same way? I liked to say to myself, "I've completed no laps," then "I've completed one lap," and so on, instead of "I'm on my first lap," and "I'm on my second lap." Better to count what one has already done instead of what one plans to do.

  17. It's actually only 9,999,999 kids.... by tekrat · · Score: 3, Funny

    Because you have to start counting kids from ZERO.
    Don't you guys read your own articles?

    --
    If telephones are outlawed, then only outlaws will have telephones.
  18. There are 10 types of people in the world by safetyinnumbers · · Score: 2

    Those who count from 0 and the other 10 types.

  19. Re:Simple: Because computers do. by BitZtream · · Score: 2

    That hasn't been true for 30 freaking years. Stop repeating crap your tired old, hasn't worked with a real computer in the past 2 decades, crap professor spewed at you.

    What processor takes more than 1 cycle to test a value other than 0? Educate me, please.

    --
    Persistent Volume manager for Kubernetes - https://github.com/dwimsey/openshift-pvmanager
  20. Re:They don't. - They really don't. by fatphil · · Score: 2

    > I start counting at zero. "I have zero bottles of Mt. Dew, it is time to go to the store."

    In that instance, you're counting down the number of bottles left. And zero is the value at which you *stop* counting.

    --
    Also FatPhil on SoylentNews, id 863
  21. Not only that, but he misses the point entirely by sladman.returns · · Score: 2

    The author of exple.tive thinks that it's all about execution, efficiency, which his sources clearly indicate it's not -- but he's so hung up on execution efficiency being the most important thing in his mind that he doesn't even realize what his sources are saying. It's actually all about ease of programming. The logic of offsets is easier to follow when indexing from zero. Full stop. (That said, as others have mentioned, people still count from one.)

  22. In related news ... by PPH · · Score: 2

    ... Zuckerberg To Chop One Finger Off 10 Million Kids.

    Just to enforce counting from 0..9.

    --
    Have gnu, will travel.
  23. judging world's smallest self-replicating program by raymorris · · Score: 2

    There was a contest for the smallest program that produces as output its own source code. Count the characters in the winning entry, which follows:

  24. Re:Simple: Because computers do. by JesseMcDonald · · Score: 2

    What processor takes more than 1 cycle to test a value other than 0? Educate me, please.

    You can often do away with the extra test altogether when you're comparing against zero, provided the decrement operation sets the condition bits. It's also fairly common to have dedicated counters and "decrement and branch if not zero" opcodes. If you're comparing against a non-zero constant, and the compiler doesn't optimize the comparison away, that's at least one extra instruction and one extra cycle in the body of the loop. In optimized code the space required for the extra opcode can be just as important as the time to perform the extra arithmetic.

    Counting up from 0 to 99 in PowerPC assembly:

    li r3, 0
    loop:
    ...
    addi r3,r3,1
    cmplwi r3,100
    bne loop

    Counting down from 100 to 1:

    li r3, 100
    loop:
    ...
    addi. r3, r3, -1
    bne loop

    or even

    li r3, 100
    mtctr r3
    loop:
    ...
    bdnz loop

    --
    "The state is that great fiction by which everyone tries to live at the expense of everyone else." - Bastiat
  25. Re:Yeah, but you're ruining a traditional joke by maxwell+demon · · Score: 2

    If all you want to do is to test for equal/not equal, you don't need a subtraction. You can just do a bitwise comparison.

    Of course the way you'd do it in hardware is to xor the corresponding bits and test the result against zero, so at the fundamental level you're right. But the circuit is so simple that I'd expect it to still finish in one cycle, so a processor implementing that would not necessarily be slower in comparing a value to zero than in comparing two values to each other.

    However usually the processor, when doing arithmetic, already does certain tests anyway, and one of those tests you get "for free" is the test for zero. So in many cases (especially in the case of loops), the test for zero needs zero additional instructions; it's part of the loop arithmetic anyway.

    --
    The Tao of math: The numbers you can count are not the real numbers.