Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Ignoring the fact that equating what "normal people" would think in contrast to what a trained professional would think in the context of said profession, 1-indexing leads to other problems.

foreach is great, until you need an index. When you do, 0-indexing is more natural. Take, for example, looping over an image.

  unsigned char *buf = get_image();
  for(int y = 0; y < height; ++y) {
    for(int x = 0; x < width; ++x) { 
      // simple
      unsigned char pixel = buf[y * width + x];
    }
  }
That doesn't work when y begins at 1. All of a sudden you need to add and/or subtract 1 everywhere to keep things in line. I used C here, but this applies to many languages in many different circumstances where an index/count is required.



Can't edit now, but I meant to say:

"Ignoring the fact that equating what "normal people" would think in contrast to what a trained professional would think in the context of said profession isn't always an apt comparison..."




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: