Why numbering should start at zero (1982) - <AUTHOR> https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html <comment><USER2> Depends on whether you're measuring or counting.

The article mentions Mesa's interval syntax, which gave programmers all the possible options:

[1..100] (0 .. 101) [1 .. 101) [1 .. 101)

were all the same interval, 1 to 100 inclusive. Bad idea. Great way to get off-by-one errors.

Another bad idea from that era - Wirth's insistence that you shouldn't be allowed compile-time arithmetic in Pascal. Like.

        const
            tabsize = 100;

        var
            tab: array [0..tabsize-1] of integer; { NOT ALLOWED }

No, you had to have a separate named constant for "tabsize-1", and it couldn't be initialized as "tabsize-1", either.

<comment><USER3> _"Bad idea. Great way to get off-by-one errors."_

I would think that depends on whether that gets taught at schools early in life.

Intervals that are closed at the low and open at the high end also are convenient when using zero-based indexing (you want an easy way to express 0,1,2,…,n-1, and if you're used to the notation [0,n) is nicer than [0,n-1])

I would think overloading the meaning of the various parentheses makes parsing and generating clear error messages harder, though (but not as hard as when one would follow ISO 31-11 and allow such things a _]3,7]_ for an half-open interval excluding 3, but including 7)

I think the desire to not overload parentheses with yet another meaning is why 'Modern' languages tend to use an infix operator for ranges, e.g. '1 to 5' or '1...5', with Swift having the half-open variant '1..<5' (IMO ugly, but clear, so I guess one would get used to it).

<comment><USER4> > 'Modern' languages

After having many fencepost errors, I finally came to the conclusion that all my code shall henceforth be zero-based. I'm much happier not having those errors anymore. I.e.:

       for (i = 1; i <= N; ++i)

The <= is always a huge red flag for me, and I rewrite it as:

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

and add a `1` in the body if I must.

<comment><USER5> Any specific reason to use _++i_ over _i++_? I always use the latter but only out of habit. I've rarely seen code with the former (your idiom).

<comment><USER4> It's just better form. Also, if `i` is a struct with an overloaded postinc operator, it can be more expensive.

<comment><USER5> Yeah, but why is it better form (I am coming from Java where it shouldn't make any difference)?

<comment><USER4> It's better form to not ask for a characteristic that you don't need.

For example:

1\. increment x

2\. take the value of x, then increment x

(1) is better form if you don't need the value of x.

<comment><USER5> I just checked in Java, it is:

1\. increment x, then take the value of x

2\. take the value of x, then increment x

Both are expressions in Java returning a value. My C is very rusty but I remember it being the same in C.

</comment></comment></comment></comment></comment></comment></comment></comment><comment><USER6> Python follows convention the first convention, just as Dijkstra recommends. Mostly this worked-out well except for the case of descending sequences.

With half-open intervals, that case proved to be cryptic and error-prone, so we added reversed() to flip the direction of iteration. That allowed people to easily bridge from the comfortable and common case of looping forwards. Instead of range(n-1, -1, -1) we can write reversed(range(n)).

<comment><USER7> I was intrigued to see how this worked out in practice for Python 3, where range returns an iterator rather than a list— like, would reversing the iteration require allocating the whole list in memory?

        $ python3 -c 'print(reversed(range(10)))'
        <range_iterator object at 0x7fdb53ae96f0>

It turns out that reversed() only works on objects that expose the __len__ and __getitem__ methods:

[https://www.python.org/dev/peps/pep-0322/](https://www.python.org/dev/peps/pep-0322/)

If you try to use reversed() with your own generator it will fail with "TypeError: argument to reversed() must be a sequence", until you wrap the generator invocation in an explicit list().

Very nice.

<comment><USER8> Alternatively the object can expose a __reversed__ method, which is why reversed(range(10)) is a "range_iterator object" rather than a "reversed object".

</comment></comment></comment><comment><USER9> The first time I read this, I was ready to be convinced and left disappointed. His entire argument is based on avoiding "the pernicious three dots."

What's so pernicious about them? They are short, clear, unambiguous, easy to type. Why don't we just get our computer languages to understand what "2, 3, ..., 12" means? Is there any other argument to start counting at 0 other than not defining a range using the three dots? If not, maybe starting at 1 (like everyone does outside of computing) is the better option.

<comment> crooked-v > Why don't we just get our computer languages to understand what "2, 3, ..., > 12" means?

Some languages already do: for example, in Ruby you can use (-5..-1) to get [-5, -4, -3, -2, -1]. It's lazy evaluation, so you can even do stuff like:

        Infinity = 1.0/0.0
        (1..Infinity).step(2).take(5) #=> [0, 2, 4, 6, 8]

<comment> mark-r I remember seeing a rather convincing argument that 1.0/0.0 should not be infinity, but zero.

<comment><USER10> This is how Pony handles division. There's a good summary of possible motivations here: [https://www.hillelwayne.com/post/divide-by- zero/](https://www.hillelwayne.com/post/divide-by-zero/)

<comment><USER10> I pasted the wrong link above, but my mobile app isn't letting me edit it. This is the link that describes their reasoning: [https://tutorial.ponylang.io/gotchas/divide-by- zero.html](https://tutorial.ponylang.io/gotchas/divide-by-zero.html)

</comment></comment></comment></comment></comment><comment> 0-_-0 Lots of people have a strong opinion on this: Ones that say that 0-based indexing is the only logical way of things, and ones that don't see what the fuss is about and prefer 1 because that's how we count objects. I suspect the people in the first category did some low level programming that needed to do arithmetic on indices. For example, let's say you want to take a string "abc" and repeat it until the length is 10, getting "abcabcabca". Assuming some Python-like language you would start with:

        a = "abc"
        b = [" "]*10

With 0-based indexing you would do:

        for i in range(0,10):
          b[i]=a[i%3]

In a 1-based language that becomes:

        for i in range(1,11):
            b[i]=a[(i-1)%3+1]

So you need to shift the index twice. This is because modulo arithmetic needs 0 to form a ring. As a result, in situations where the difference between 0 and 1 based indexing makes a difference it's ususally 0-based indexing that leads to simpler code.

<comment><USER8> Dijkstra makes, I think, a stronger argument, particularly given that in languages like C, (-2) % 3 == -2 rather than 1 as it should.

<comment><USER11> This used to be unspecified behavior. C99 then codified this wrong behavior.

Assume positive b for a moment. We want a * (a/b) + (a%b) = a. If a%b is to always be within [0..b), then a/b has to round toward -infinity. C99 instead chose round towards 0.

<comment><USER12> Don't you mean we want "(a/b) + (a%b) = a"?

<comment><USER13> > We want a * (a/b) + (a%b) = a.

> Don't you mean we want "(a/b) + (a%b) = a"?

No, they mean " _b_ * (a/b) + (a%b) = a". (Also I'm not convinced that's actually useful, but that's a different discussion.)

<comment><USER12> Ha - you're correct of course. I saw the a^2 term and thought that can't be right. Note to self - before attempting to correct others, check the "correction".

</comment></comment></comment></comment></comment></comment><comment><USER14> Very subjective and context specific argument.

Some things are more naturally numbered from 1, others from zero. Fence posts versus fence spans.

Pointer arithmetic is a great example of a situation well adapted to 0 based numbering, and was quite relevant to many programmers when this was written. However, far fewer programmers nowadays interact with raw pointers directly.

Personally, I run into more cases where I'd rather have 1 based numbering than zero, but your mileage may vary. It's valuable to have a language which can support both.

<comment><USER15> > However, far fewer programmers nowadays interact with raw pointers directly.

It doesn't have to be literally a memory pointer to run into the same phenomenon. For example, offsets into a file. I can think of an example when I was doing work on a file format, and 0 based indexing certainly helped simplify some logic.

<comment><USER14> Correct, I was merely pointing out that the main motivator of Dijkstra's argument is not nearly as relevant as it was when this was written.

I have no idea what indexing style is more appropriate to the hypothetical 'average' programmer, but I find myself preferring mostly 1 to N the most, followed next by -N to N and finally 0 to N.

As I said originally, your mileage may vary, but I think it's important that we use languages where many different indexing styles can be supported ergonomically, and in a way that avoids silly errors due to using the wrong index style.

Type systems and generic functions help a lot with this. I think of it a lot like say, signed versus unsigned integers. Multiple useful ways of looking at the same bitwise data. Type systems generally save us from nasty errors with the various types of integers. They can do it with arrays too.

<comment><USER16> Do you have any examples where 1 to N is a more convenient numbering?

<comment><USER14> What are the second to fifth elements of the array A?

        A[2:5]

I find that much much more convenient and user friendly than the alternative.

</comment></comment></comment></comment></comment><comment><USER17> In the business domain one is often counting and tracking explicit things: widgets, contracts, customers, complaints, pizzas, etc. When counting, you almost always start with 1. "1" fits the domain more naturally, and if you deviate, you'll likely spend code converting between the end-user's view and the code's view. The translation layer creates risk of errors and more code. Maybe weather forecasting or space probe orbit calculation is different, but 1 better fits biz. Dijkstra was not (primarily) a business domain coder. (Smarter languages, like Pascal, allow you to define the range, although I'm not sure if it has dynamic upper ranges.)

<comment><USER18> I think you'd still start counting those things from 0, because it's a convenient and natural way to express that you don't have complaints, widgets or pizzas.

Or, I suppose, you could start counting at 1, but use an optional type and use None for that case. But that makes doing arithmetic on those numbers ("widgets per pizza") harder than if you'd just used 0 to begin with.

<comment><USER17> I think you are mixing up indexing and default value setting. They are roughly related, but only roughly.

<comment><USER19> Hum, no. He is using a generalized version of counting that works for 0 items too.

A computer should start counting from 0, there's no reason to special case the empty set.

<comment><USER20> Humans should too for the same reason.

Lets consider a measuring tool for fluids which is based on volume. What is a useful range for the index on the side that measures the currently non-air capacity?

Many such devices, E.G. a measuring cup I've got at home in the kitchen, use a series of tick marks within a bounded scale of accuracy range ] with marks on both the top (of course) and also the bottom (it looks nice).

While 0 isn't expressly labeled on many scales, it is part of the inclusive range by implicit nature. Thus as you point out the case of 0 units, and 'empty set' are one and the same in this real world example.

<comment><USER21> You forgot to explicitly mention that bottom mark on your measurement cup is indeed 0, and without it you could measure "at least this volume of fluid".

<comment><USER17> That doesn't change anything that I see. Indexes and counters are usually not used for "continuous" metrics such as liquid quantities. And again, the biz domain typically does not count fractional quantities, at least not in an indexed way.

It's not a _practical_ problem for most coding. If you disagree, can you demonstrate a problem caused by indexing arrays starting at one in a _typical_ code situation/scenario?

</comment></comment></comment></comment></comment></comment></comment><comment><USER22> The syntax I always want but no language I know of supports:

        for 1 <= i <= 10:
            do stuff

        for 0 <= i < 10:
            do stuff

        for 1 <= i < j <= 10:
            do stuff

(In the last case, the exact order in which the 45 iterations happen should maybe be left unspecified; at any rate, it would be bad style to depend on it.)

Downward iteration:

        for 10 >= i >= 1:
            do stuff

Obviously this doesn't cover every case of "arithmetic for loop" that would be useful: sometimes you want a stepsize that's neither 0 nor 1. I'd be quite happy with a language in which I had to do that using a more general iterate- over-an-arbitrary-sequence construction; I'm tempted by options like

        for 100 <= i <= 1000 where i%3==1:
            do stuff

but it's probably too clever by half; either you only support the simple "specify the value of the variable mod something that doesn't change while iterating" case, in which case users will complain that some obvious generalizations fail to work, or you support arbitrary predicates, in which case you have to choose between making the "easy" cases efficient and the "hard" cases not (in which case users will be confused when what seem like small changes have drastic effects on the runtime of their code) and making all of them inefficient (in which case users will be confused by how slowly their code runs in some cases).

<comment><USER23> You may enjoy Common LISP's looping: it's a whole minilanguage where you can say stuff like

        (loop for i from  1 upto   10 ..)
        (loop for i from  1 below  11 ..)
        (loop for i from 10 downto  1 ..)
        (loop for i from 10 above   0 ..)
        (loop for i from 3.5 to 7.5 by 0.25 ..)

It does much more than that, I should mention; it's a whole mini-language/DSL (like format).

<comment><USER22> Not only _may_ but _do_ ; I like Common Lisp a lot, and while some people complain that LOOP isn't lispy enough I personally do like it.

But it doesn't have the elegance of just specifying the inequalities you want your loop variables to satisfy :-).

</comment></comment></comment><comment><USER24> "Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."

\-- Stan Kelly-Bootle

<comment><USER25> I made a Python library that implemented this and gave a talk about it at PyCon: [https://www.youtube.com/watch?v=yC9m2GInXqU&feature=youtu.be...](https://www.youtube.com/watch?v=yC9m2GInXqU&feature=youtu.be&t=330/)

<comment><USER26> Gave me a good laugh, thanks for this :)

[https://github.com/travisjungroth/Compromise](https://github.com/travisjungroth/Compromise)

</comment></comment></comment><comment><USER27> On the assembly language level, you have compare instructions. These subtract, and throw away the result, but leave the flags.

Many CPUs have a flag that is automatically raised if a value is 0.

This means you don't have to execute a compare instruction to test if a value is 0, because the "Zero" flag will be set as soon as the 0 value is loaded.

That means you can load a value, and directly go to a BEQ (which is really shorthand for "if zero flag = 0") and save a few cycles by avoiding the CMP instruction.

So this is why numbering starts at zero. Testing if your list is empty, which is probably a common thing if you loop through each element, is slightly quicker.

<comment><USER8> A disappointingly large number of comments on this article are by people who inexplicably offer weaker arguments than Dijkstra's.

</comment></comment><comment><USER28> In scientific-oriented languages (R, MatLab, Julia, Fortran, &tc.), array indicies tend to start at 1. I think it is a culture thing. Software engineers prefer 0. Scientists prefer 1.

<comment><USER29> The scientists can do what they want until they start using computers, then they should listen to the software engineers.

<comment><USER30> This is silly. Different domains have different needs. If you think of arrays as pointer + offset calculation, and your only for loop has an explicit index increment in it, then starting at 0 is natural. If you are a systems programmer then a language targeting you should accommodate that.

If you are anyone who doesn't want to care (too much) about how things are implemented, then it's a lot less error prone to mark the 1st element of an array a[1]. Having taught and written fairly complex scientific code in both 0 and 1 indexed languages, there really is no good reason to do anything else.

        for a in array[3:6]

Should iterate over the third to sixth element of the array.

<comment><USER29> I dunno man, it's Dijkstra's essay. He has a pretty good reputation.

</comment></comment></comment></comment><comment><USER31> I'd like to have a keyboard with a 0 (zero) to the left of the 1 (one) digit.

<comment><USER20> Learn to enter numbers with the 'ten key' 'num pad' on the right... or possibly buy a full-sized keyboard.

</comment></comment><comment><USER32> Discussed in 2018: [https://news.ycombinator.com/item?id=17765034](https://news.ycombinator.com/item?id=17765034)

2016: [https://news.ycombinator.com/item?id=13186225](https://news.ycombinator.com/item?id=13186225)

2015: [https://news.ycombinator.com/item?id=9761355](https://news.ycombinator.com/item?id=9761355)

2009: [https://news.ycombinator.com/item?id=777580](https://news.ycombinator.com/item?id=777580)

</comment><comment><USER33> I'm usually a start-at-zero guy, except if I'm implementing matrix routines... going from the 1-based indexing from the math theorems to 0-based code is so tedious in order to ensure the translation is correct.

</comment><comment><USER34> I totally agree with this. However, I'm trying to teach my 1 year old how to count. He's got 1, and 2 down, and we're working on 3 (He can say the numbers 1 to 10, I'm talking more about the concept of numbers). I would love to get him to understand 0 too, but I'm not sure how.

<comment><USER35> > _He 's got 1, and 2 down, [...] He can say the numbers 1 to 10_

That's extremely amazing for a kid that is exactly one years old, rather than, say, 1.x years old for high values of x.

<comment><USER25> Seems like a very technical way to say "almost 2".

<comment><USER36> Consider P₁ ∈ H and P₂ ∈ G where H is the set of HN posters, and G is the set of persons in the general population. Let p(P U) be the probability that a person, P, will produce an utterance, U, using mathematical terms and/or notation. Let q(U) be the probability that U will be better understood in mathematical terms than in plain language.

For any U, p(P₂ U) ≤ q(U) < p(P₁ U)

</comment></comment></comment></comment><comment><USER37> There's not much reason in a high-level language to start at 0. Humans reason about iteration in terms of the natural numbers.

<comment><USER11> That doesn't help: mathematicians have two definitions for "the natural numbers", one starting at zero, and one at one.

<comment><USER38> The languages designed for scientific computing, which make heavy use of math libraries, start at 1.

</comment></comment></comment><comment><USER39> Great to see this at position 1 on Hacker News

<comment><USER40> It deserves to be at position 0.

<comment><USER38> Position 0 doesn't exist.

<comment><USER40> No, you just need to subscribe to HN Gold to see it.

</comment></comment></comment></comment><comment><USER41> The worst is google sheets API, which uses Javascript-based 0-indexing for some functions, but Excel-based 1-indexing for other functions. Nightmare!

<comment><USER20> It's trying to replace/inter-operate with Excel, so it has to maintain backwards compatibility; bug for bug, including design bugs.

I couldn't tell you offhand if the logic you speak of is distinct to Sheets or if it's Sheets maintaining the same interfaces other spreadsheet software defined for those macro names long ago.

</comment></comment><comment><USER42> Counting a physical process, so you have to allocate space. 0 is that allocation, and as you move along the number line, you update that space (using "add 1"). Note that you only update the space at discrete intervals, which has surprisingly deep implications.

Having a kid I've been thinking a lot about counting, and what it really is. It seems totally wrapped up in repetition, and so I'm wondering if teaching counting as a function of, say, circular motion doesn't give a better intuition than the usual "count this clump of things" approach. (Counting clumps requires the person to simultaneously introduce an ordering and then implement a kind of internalized repetition as they point and count rhythmically. My kid seems to struggle with the ordering part, and no wonder: N objects have N! orderings.)

</comment><comment><USER43> Please note that "counting" there is really "indexing", as in 1st, 2nd, etc. Apart from indexing in programming languages, some commenters in this thread seem to have an idea of counting (indexing) real things from zero, as if it solved the -1 problem easily. But that is a natural offset between a quantity and a position. We could in theory rename our ordinals one backwards like: zeroth, first, second, and so on. But that would shift the meaning temporarily, and 0th would become new 1st. With new counting in mind, for an empty set [] count is 0, for [x] count is one and an ordinal for x is "zeroth", -1 again dammit.

Between 0 and 10 there is 10 one-sized intervals touching 11 connecting/borderline points (integers). You cannot make this fact go away, no matter which language you choose.

</comment><comment><USER44> If the author had contemplated this sentence before writing this pained and narrow-minded treatise: "Why thinking should start before writing", engineers would be slightly more capable of interacting with and designing for other human beings. Numbering is highly domain specific -- the concept of zero is not always relevant. And sometimes the lay perspective has primacy over others. I remember the intense arguments engineers had regarding when the new millennium was to start. There weren't celebrations on New Year's 2001 that could compete with the scale of those for the year 2000.

</comment><comment><USER45> Worst than starting at 0 or 1 is two give the option. In old Visual Basic the "Option Base" statement change the indice for a whole module. I had to debug code program with a mix use of code with indice starting at 0 and 1.

</comment><comment><USER46> I (almost) always fall victim of one-off errors in competitive programming when working with counting numbers in range. Sticking to convention like 2 ≤ i < 13, as Dijkstra observed for Mesa programmers, sounds like a good idea.

</comment><comment><USER47> I need help with this. I intuitively count with starting at one.

In a for loop, if we start with 0, then the terminating condition is i less than n.

However, ifvit starts at 1, then the terminating condition is i less than or equal to n.

What mental trick do you use to remember that?

<comment><USER48> n is n steps ahead of 0,and thats what < checks for.

</comment></comment><comment><USER49> One thing that's nice about it is that you can use a positive difference as an array index directly. This is nice when you want to store a function of the "distance" between two things, e.g. potential[] = {-10, -5, -3, -2.2, ...}; ... potential[r1-r2]. It also works nicely with modular arithmetic as '0-_-0 mentions in their post. More generally this corresponds to the array being a function from the natural numbers to some other values, and this function can only start at zero if the arrays start at zero. But if you want a function that starts at 1, you can just set x[0] = invalid().

</comment><comment><USER50> Nice quote at the end...

"In corporate religions as in others, the heretic must be cast out not because of the probability that he is wrong but because of the possibility that he is right." Antony Jay

</comment><comment><USER51> « Exclusion of the lower bound forces for a subsequence starting at the smallest natural number the lower bound as mentioned into the realm of the unnatural numbers »

There's a parallel argument for being inclusive in the upper bound: it lets you specify a range which is the entire size of your integer type.

I can see that that might seem like a poor trade for losing the ability to represent an empty range starting at zero, but it seems a shame he didn't mention that this is the tradeoff you're making.

</comment><comment><USER52> The only reason to count from zero is for the sake of array processing -- given a pointer to an array, the first element will be at pointer plus zero. That's significant for low-level code as it avoids an extra add one operation.

However for high-level programming, starting at one has advantages. For instance what index to use to represent insertion of an element at the beginning? Being able to use zero for this is cognitively easier.

<comment><USER17> That convention seems confusing to me, especially one new to the convention. If you need an explicit "insert at the start" operation, then do something like "x.insertAtStart(y)" instead of "x[0] = y".

<comment><USER53> This is typically built into a language as "x.unshift(y)"

<comment><USER17> "unshift" is not very intuitive in my opinion, but let's not get bogged down with API naming design.

</comment></comment></comment></comment><comment><USER54> One detail that I always liked about zero-based arrays is that it makes for loops look nicer, using `i < length` instead of `i <= length`.

</comment><comment><USER48> A recent study has found the number of '+1's and '-1's in a codebase is around 15 times higher if you use 1 based indexing.

<comment><USER55> I'd love to see the citation?

Also I wonder if it's highly dependent on whether the domain is largely algorithmic (e.g. video codecs) or business logic (e.g. supply chain).

And how much is simply the language being "misused", e.g. writing "<= n - 1" rather than "< n".

<comment><USER48> It was an app I wrote, probably in algorithmic category. But even in business code, I very rarely see off by one problems that would be easier to handle in 1 based indexing.

> e.g. writing "<= n - 1" rather than "< n"

Wouldn't such errors further increase the ratio?

<comment><USER55> I'm sorry, the "recent study" was "an app I wrote"? Sorry, but unless I'm misunderstanding... that's not a study. And the whole point of a study is to back up assertions like "I very rarely see" so they aren't just opinion subject to all the normal human biases we all have.

But if you ran such an analysis across public GitHub repositories per-language and wrote the results up in a blog post, I'm sure HN would love to see it. Definitely front-page material.

<comment><USER48> It wasn't a serious comment. I thought it was obvious from the tone.

> But if you ran such an analysis across public GitHub repositories per- > language and wrote the results up in a blog post, I'm sure HN would love to > see it.

I'll see what I can do. I do have some repos in sight that could be used for it.

But even then this won't be as straightforward as you say since different languages have different applications (eg cpp for games, julia for scientific computing). This would require writing the same code in both indexing patterns and then comparing them.

</comment></comment></comment></comment></comment><comment><USER56> While I agree with the conclusion, i think he could have expanded it even more. Not everyone has as developed aesthetic sense. Measuring, counting, combinatorics, indexing, arithmetic with ranges.

95% of cases it does not matter or make things more elegant or simple, but when it does it's always zero-indexing that is more elegant.

<comment><USER57> No it doesn't. One indexed means it equals counting. First person = index 1.

</comment></comment><comment><USER58> At the end of the day they are both great and they both suck depending on context. I use 0 based when programming and 1 based pretty much everywhere else.

And in both cases I always run into an issue where I think, "This would be so much easier if we just started at [the other index]".

<comment><USER59> I use 0 based when programming in some languages, and 1 based in others. Everywhere else I use 1 based.

When I'm programming in 1-based languages, I'm almost always happy with that choice, because they're almost always languages designed for solving problems in a domain that were standardized on 1-based counting before Charles Babbage was born.

When I'm programming in 0-based languages, I'm sometimes very happy with that. Those times are when I'm working in C or C++ . When I'm using other languages, I don't care much maybe 1/3 of the time. And the majority of the time I still wish it were 1-based, because I'm using that language to solve problems in a domain that had standardized on 1-based counting before Charles Babbage was born.

</comment></comment><comment><USER60>
        Case: indexing an array in ASM, C, C++, Swift,…
        Case: using an offset
           0 <= i < N

        Case: indexing an array in Pascal, Ada, …
        Case: writing a math paper
        Case: talking with a non-programmer
           1 <= i <= N

</comment><comment><USER61> No: [https://hackernoon.com/dijkstra-is-wrong-and-so-am- i-f36e2fb...](https://hackernoon.com/dijkstra-is-wrong-and-so-am- i-f36e2fbd5ae4)

<comment><USER62> Silly article. Most of its points are actually arguments against JavaScript's type system and semantics, not zero indexing per se. (Consider how would they apply if we used letters for indexing, where there's no longer a superficially appealing zero value to special-case: 'We should use B-based indexing, because A is a falsey value in JavaScript! Also, now we can use A to denote missing elements!'.) Others are empty appeals to vaguely defined 'mathematics' that ultimately boil down to historical legacy.

It is true that most matrix theorems are formulated with 1-based indices. But mathematical notation is full of unfortunate historical accidents (like defining π to be _half_ the circumference of the unit circle), so one should be cautious when drawing inspiration from it. And for what it's worth, set theorists start ordinal numbers from zero, and each ordinal a half-open interval of numbers which precede it:

[https://en.m.wikipedia.org/wiki/Ordinal_number#Von_Neumann_d...](https://en.m.wikipedia.org/wiki/Ordinal_number#Von_Neumann_definition_of_ordinals)

</comment></comment><comment><USER63> Purely functional languages have no reason to 0-indexed arrays. Imperative languages that deal with for loops are more logically consistent with 0-indexed arrays. I think.

</comment><comment><USER64> 0 is the first number. 1 is the first number 1 unit from 0.

<comment><USER65> One is the first number. Until there is one of something there is no point to counting at all. Zero is a regression from one and only significant for the lack of that something which we started counting at 1.

<comment><USER66> But there absolutely is a point in setting out to count something when it turns out there is zero of that thing. If you don't know how many of something there is, but you know that this information is important, you will want to go out and count. If it's _really_ important, then you will likely want to keep records of the count every time you perform it. This is, of course, very important in commerce.

<comment><USER65> Oops, I was wrong. A count is a quantity.

This is numbering being talked about. Guy finishes a marathon in first place, he would be the zeroth runner and one runner has finished. Most people would intuitively like those numbers to line up.

Of course, when you build the natural numbers on a computer and use those as indices to arrays, it makes sense that the first index is zero. So the first (common usage) element would then naturally be called the zeroth element. This, of course, gives you the problem that array.size == x means that array.last_index == x - 1 and all the off by one errors that entails.

<comment><USER66> Sure, but I don't think anyone's complaining about how you would assign race completion position labels in a programming language. Surely you would do something like this:

        // Start the position at one, because that's how we
        // assign number labels to finishers in a race.
        let position = 1

        // Create a callback that will assign a label to
        // each competitor when that competitor finishes
        // the race.
        let assignLabel = (competitor) => {
          competitor.label = position
          position = position + 1
        }

        // Begin the race, and pass it a callback that will
        // be run each time a competitor finishes the race
        // (in the order they finish).
        race.begin(assignLabel)

Note that this "label" really is just a label. It happens to be an integer here, but we could also use a library that outputs English strings like "first", "second", "third", etc. This debate is focused more on how elements in an ordered collection are _accessed_.

</comment></comment></comment></comment></comment><comment><USER67> In the case of lists/arrays, it's because we count the number of shift. It's what I always thought. I see analogies with Turing machine.

</comment><comment><USER68> It does, ask any shepherd, accountant, quartermaster, etc. It has a well defined meaning and use over the centuries which for hysterical reasons of economy it took on a second meaning equal to physical 1. Luckily it's the only case in computing where established meanings in base ten were changed to fit a base 2 world.

<comment><USER57> 1 and 0 have the same meaning in both bases

<comment><USER68> CPU0 would disagree, for example. A non technical person might be forgiven for thinking a system that says CPU0 has no CPUs, when in fact it has one, again, for example. Many logical objects start their enumeration at zero and increment from there. There are four rings of operation in Intel CPUs, but they are labeled ring 0 through 3.

<comment><USER57> I'm sorry but you don't understand what number base means

[https://en.m.wikipedia.org/wiki/Radix](https://en.m.wikipedia.org/wiki/Radix)

Nothing to do with starting number. And base 0/base 1 makes no sense.

<comment><USER68> I'm sorry, but you clearly haven't heard of unary, or base 1, which is probably the earliest counting system which 1 is 1, 2 is 11, 3 is 111, etc. Tallymarks. You are correct base 0 would make no sense, however.

But yes please explain to me the very thing we're talking about which is exactly what I was referencing when pointing out that using 0 as an identifier rather than a value is moderately counterintuitive.</comment></comment></comment></comment></comment>


Supply chain analysis of iPhone 5c cases and the pencil marks hidden inside them - <AUTHOR> https://theprepared.org/features/production-marks <comment><USER2> I don't know if I've ever read such a long piece filled with so many interconnected details, but ultimately telling no coherent story.

It's like a modern crackpot conspiracy theory, but told in iPhone land.

<comment><USER3> This is what I was thinking/ further reading the article confirmed. Takes 'I digress' into a new dimension. Had to abort midway through.

</comment></comment><comment><USER4> > When computerized management first came to the shop a half century ago, the > limitations of memory were so severe that early bills of material could not > be recorded as single data entities. The solution was to break them into > component parts, such that each part or subassembly became an individual > bill with an individual shop order. As the scale of these subassemblies > grew, the shop was now relegated, in the words of Richard Lilly, to the > "business of making parts instead of products."

Can someone ELI5? Been a programmer and computer history dilettante for 35 years but don't know what this lack of memory condition caused.

<comment><USER5> The author thanks that if a list of parts doesn't fit on one page, that the second page has to be produced by a different factory.

He see seems to conflating complexity of manufactured products with complexity of BOM documents.

</comment></comment><comment><USER6> TL;DR

> The precise meaning of the messages my students found scrawled in their > iPhone 5c is something only workers or managers at the Wuxi factory could > definitively determine.</comment>


Why Being a "Big Fish in a Small Pond" Is Bulls**t - <AUTHOR> https://medium.com/@garyvee/why-being-abig-fish-in-a-small-pond-is-bulls-t-dba1e2a6c953

<comment><USER2> Wow, just a truly narcissistic and overall terribly written piece of utter drivel.

<comment><USER3> Well, that has always been Gary's style. He's the Tom Peters of our time: always full of "you-can-do-it" motivational speeches, but zero substance.

I guess it works for some. After reading his book, I think I'm vaccinated.

<comment><USER2> This article was the first thing I've read by the guy. I've never posted before just to say I didn't like something around here (don't need any extra down votes with my already low rep), but like you said zero substance.

I'm all for shooting for the stars, but if we have the attitude that the world is a big game and there is only one ultimate winner then that just makes everyone else unhappy losers. Personally, I like to be happy, so I think of the advice of "Big Fish in a Small Pond" more along the lines of doing the very best that you can do and find life satisfaction in your achievements, otherwise you may die a very unhappy person. Life is too short for that.</comment></comment></comment>


The Twilight Years of Cap'n Crunch (2007) - <AUTHOR> http://online.wsj.com/public/article/SB116863379291775523-_EQCu93LyjSommsN6J7qiCozuu8_20070122.html?mod=blogs

<comment><USER2> A quote from the article: "Mr. Draper received permission from the sheriff's office to attend a computer fair in 1979 in San Francisco, where the program, named after the cult film "Easy Rider," was a hit. It became Apple's first word-processing program. When IBM launched its first PC, it also chose EasyWriter, over competition from other programmers, including a young Bill Gates."

I have the real story, and the author should have talked to me. After my program Apple Writer (<http://en.wikipedia.org/wiki/Apple_Writer>) replaced Easy Writer and became Apple's default word processor, someone from IBM called me up and asked me to write a word processor for their PC.

I asked "What business terms?" The IBM guy, taken aback that a programmer would switch into business mode so quickly, said, "Okay, you get $100K in royalties, after which we own the program."

I thought for a minute, then said, "100K, okay, umm, that's 15 days of Apple Writer royalties right now. I think you'll need to do better than that." But IBM wouldn't budge, and that ended the negotiation.

Later I heard they offered Draper the same deal and he accepted. Rumor has it that the PC version of Easy Writer was really terrible and didn't last long. Later, Draper supposedly remarked, "They asked for a hundred thousand dollar word processor, and I gave them one."

<comment><USER3> IBM really were messed up in 1979 weren't they? Skimping that badly on the default word processor is just insanity.

<comment><USER2> The reason was that IBM looked on their PC as an "entry system", a silly, unimportant introduction to their primary business, mainframes. It's important to realize that IBM didn't see the potential of personal computers -- they thought they would be another passing fad like quadraphonic sound. So they slapped together a really minimal computer, nothing at all remarkable, only hoping to attract people to their main business. They just had no idea what was going to happen, or how the world would look on their PC, given that they were IBM.

That's the real reason why older desktop machines are so crappy. That's the reason why IBM wasn't able to compete against their own imitators. And IBM's contemptuous attitude toward their own PC is one of the main reasons Apple was able to introduce the Macintosh to an adoring public. It really was spectacularly better than the original IBM PC.

</comment></comment></comment><comment><USER4> his time in the bay area rave scene in the late 90's/early 00's earned him a creepy reputation, mostly due to his fondness of doing "energy work" with shirtless teenage boys.

<comment><USER5> This can not be under-emphasized. I was in my late teens/early 20s at that time and a lot of my friends who were nerds and into the rave scenes had stories that started with "Oh wow, I met Captain Crunch at a rave, we'll get to hang out soon!" and ended with "You are sweaty, you should take off your shirt!" or "Do you want an energy transfer massage?"

I think his preferences are his own business, but using his reputation to approach a bunch folks much younger than he is and otherwise uninterested, probably had a lot to do with ruining any social capital that he had.

There's a very legitimate discussion that needs to happen about ageism in the industry, but age is not the sole issue in the case of Captain Crunch.

<comment><USER6> I first met him in '00 (I think). He came up right after I played a live techno set in a warehouse in Oakland, and I second this. As someone who grew up on 2600, my excitement for meeting Draper quickly turned to backing away once the topic of an energy transfer massage came up.

</comment></comment></comment><comment><USER7> Not a single mention of energy massages. I'm disappointed.

For those unfamiliar, it's really hard to explain just how strange the guy is in print. He's out there.

<comment><USER8> LOL yes, yes yes. I've heard stories of people who met him while staying at the HHH in Brooklyn.

<comment><USER7> Is the HHH even still a thing? I'd been to a few parties there back in the day and knew a few of the folks that lived there but haven't heard mention of it in years.

</comment></comment></comment><comment><USER9> _"Mr. Draper several years ago developed some Internet-security equipment and started a company. Some clients were interested, but the company foundered when one of its executives, a fellow raver, made off with much of the money from investors, say Mr. Draper and another executive, John Johnson."_

I remember back in 2001, seeing Draper speak at University of Illinois about his "CrunchBox" security appliance. I got the vibe that he was just repackaging some open source software on it and putting his name on it.

I never really heard anything more about it after that talk, though - I guess this explained what happened.

</comment><comment><USER10> I don't think the article captures quite what "obsessive" means when you're talking about Captain Crunch.

This does.

<http://www.webcrunchers.com/stories/esq-art.html>

</comment><comment><USER11> I met the captain a few times when I was living in California. Weird does not even start to describe him. I was part of the party scene in San Francisco at the time, and heard how he was banned from certain parties because of inappropriate massages. I treated that as rumor until now, when I read different comments specifically about his special massage techniques.

</comment><comment><USER12> I think if I had a great deal of money, I'd skip flying first class a few times per year and "tenure" guys like John by giving him a few $k/month and telling him to go work on whatever he wanted.

Just seeing what he came up with each year would be far more entertaining than another beach vacation somewhere.

<comment><USER13> Some friends and I muse about what it would take to create a home for people like John during their twilight years. Its very challenging. There aren't a lot of high tech jobs that pay pensions, and the retirement money is very unevenly distributed around.

Not a lot of folks think about that now, but someday, maybe sooner than we would like, some icon of computing history is going to get rousted out of a homeless shelter on national TV. I don't look forward to that day, not at all.

</comment></comment><comment><AUTHOR> This passage really strikes me, because he is happy, though his life seems so tragic, so emblematic of the dark side of technological obsession. It's a bittersweet mixture of a "there but for the grace of God, go I" feeling and a simultaneous admiration for the purity of his life's focus. It makes me reflect on my own life:

"Mr. Draper's unusual behavior, such as shouting at anyone smoking anywhere near him, could wear on fellow workers and employers. 'He was not a self- starter, or associated with all the companies springing up back then,' says Mr. Wozniak. 'But, actually, John is one of the happiest guys I know, no matter what his situation seems.'"

</comment><comment><USER14> "I'm blacklisted, man, a permanent menace to society, I guess,"

No dude, you're just old, in an industry with entrenched ageism. Just like the other accomplished engineers in the story living in mobile homes, couchsurfing, and living in a bus. Not a lack of skill or relevance, so much as an excess of gray hair.

Imagine the same story if he went for management instead of engineering, he'd be a CEO somewhere, greatly loved for his eccentricity, etc.

<comment><AUTHOR> Although I have grey hair, and it does seem to reduce the number of job offers, I think a lot of those couch-surfing engineers have other issues besides hair color.

Capt Crunch would likely do better if he bathed regularly, washed his clothes, and stopped shouting at people whose behavior he doesn't like (and hapless waiters who bring him substandard bacon). And then there's that pesky criminal record.

<comment><USER15> It's all self-justifying fantasy on Draper's part, and passive aggressiveness. He's a crazy old coot with dreadful personal hygiene who never brushed his teeth or took a bath, with an inflated sense of his self-importance to go with his disgusting habits, in addition to a predilection for "working out" with young men.

Years ago one friend of mine went to a conference Draper was at. During a break he went outside for a smoke, well away from the building. Draper left the building through the same door, saw him smoking, and did his "I'm going to scream at you now" act.

My friend had _no idea_ who he was, and as a result almost punched Draper in the face.

Then there's his criminal record. But to Draper it's all a persecution complex. He doesn't have enough sensitivity as a human being to understand why many people didn't want to work with him at any age.

<comment><USER16> I got one of those offers to "work out" with John. I remember putting on my shoes, headed for the door to join him, and something stopped me. To this day I listen to my hunches and gut feelings. I'm not always right, but I think I was that time when I decided to stay home.

</comment></comment></comment></comment><comment><USER17> Wow, some of you guys are impressing me with how much you're struggling to suppress your raging homophobia in this thread.

I realize the need for some techies to look down on people who won't assent to their brand of whatever for a chance to climb the ladder of temporary success. Draper's more widely known and admired than most of you will ever be. So I guess you gotta do what you gotta do. (which probably doesn't involve hanging out with Woz)

<comment><USER18> Who are you referring to? Could you provide a link?

I don't see anything in these comments that looks like homophobia. Maybe they deleted it.

</comment></comment><comment><USER19> Back at defcon last year he ended up joining a game of Cards Against Humanity that I was playing. He's an interesting guy for sure, and it's nice to be able to say that I hung out with him for a bit, but he wore out his welcome pretty quickly. He wasn't being rude or disrespectful - he just acted like an old man who had seen a _lot_ of shit. Felt bad for him...</comment>


What should I buy my CTO for his Birthday? - <AUTHOR>

Using a throwaway because we normally chat through my normal handle. Any suggestions? <comment><USER2> Nice bottle of Bourbon. Can't go wrong (unless he is a friend of Bill Ws)

</comment><comment><USER3> A livescribe pen?

</comment><comment><USER4> a Chumby One</comment>


Soma, Spice and Substance D: A History of Drugs in Science Fiction - <AUTHOR> http://motherboard.vice.com/read/soma-spice-and-substance-d-a-history-of-drugs-in-science-fiction <comment><USER2> Dick also wrote mesmerizingly about Can-D and Chew-Z in "The Three Stigmata of Palmer Eldritch".

And of course there was Stelazine from "Faith of Our Fathers", which was actually an anti-hallucinogen.

The 10 Greatest Mind-Altering Drugs and Drinks in Science Fiction : [http://www.therobotsvoice.com/2009/04/the_10_greatest_mind-a...](http://www.therobotsvoice.com/2009/04/the_10_greatest_mind- altering_drugs_and_drinks_in.php)

"While the drug of choice for author Philip K. Dick ran the gamut of uppers, his 1965 Nebula-nominated novel The Three Stigmata of Palmer Eldritch featured two distinct hallucinogens: Can-D and Chew-Z. Can-D is used by colonists to "translate" themselves into the Barbie-style "Perky Pat" layouts where they either become Perky Pat or her boyfriend, Walt. While in this shared- hallucination, users can leave behind their dismal existence and act out an idealized, "swell" version of life on Earth. P.P. Layouts, the company behind Perky Pat, is also the manufacturer of the "illegal" Can-D. P.P. gets some competition when Palmer Eldritch is rescued from a crash on Pluto and returns with an alien drug known as Chew-Z. Like Can-D, Chew-Z transports the user into an alternate reality but the difference is that Eldritch plays puppet master to these hallucinations. The book spirals in and out of reality and hellish hallucinations until the memorable last trip."

<comment><USER3> "The Three Stigmata of Palmer Eldritch" is a fascinating book, as so much of P.K. Dick's stuff is.

Another interesting drug, or rather drug system, is the one used by enhanced Culture people in Iain M. Banks' amazing novels. People are modified to the extent that they can secrete a number of different drugs at will, or "glanding", which allows them to get high/drunk and sober again among other things.

</comment></comment><comment><USER4> So many great examples to choose from. PKD might have been the most creative in this area - Can-D is one of his most striking creations, but another interesting one is KR-3 in Flow My Tears, The Policeman Said.

<comment><USER5> Not to mention the Mood Organ in Do Androids Dream of Electric Sheep.

[https://law.stanford.edu/2012/11/01/lawandbiosciences-2012-1...](https://law.stanford.edu/2012/11/01/lawandbiosciences-2012-11-01-biosci- fi-do-androids-dream-of-electric-sheep-philip-k-dick-1968/)

</comment></comment><comment><USER6> Another great one was Nuke from Robocop.

<comment><USER7> Don't forget Slo-Mo from Dredd!

</comment></comment><comment><USER8> meh, 1984 just used alcohol

and the article completely misses the coffee references in Dune</comment>