Live data from Hacker News

Numbering should start at zero (1982)

cs.utexas.edu

271–280 of 309 posts

Re: Numbering should start at zero (1982)

#271
post #171

Earlier quoted context omitted.

I always thought: - Offset: 0-based - Index: 1-based

That sounds reasonable at first, but humans are messy and so the distinction is not always clear. For example, in music we use numbers for the notes of a scale (G is the 5th of C, because in the C major scale: C=1, D=2, E=3, F=4, G=5, A=6, B=7). The numbers are clearly indices for the notes of the scale. But we often think of stuff like: what's the 3rd of the 5th -- that is, get the note at the 5th position (G in our…

Music doesn't count, it has its own numbering.

Re: Numbering should start at zero (1982)

#272
post #256

Earlier quoted context omitted.

Okay, fair enough. I stand corrected.

I didn't intend to be correcting you. You weren't factually incorrect about anything; you just have different objectives than Lua's designers.

I mean, I was incorrect that Lua wasn't intended to be used by beginners/non-programmers.

Re: Numbering should start at zero (1982)

#273
post #208

I'll upvote this Djisktra note every time it appears. :-) It settles the discussion of array numbering. F*ck off Visual Basic, MS Javascript, and all the languages that said you should start with 1.

Matlab, Fortran, Julia, R, SAS, SPSS, Mathematica, and the whole field of mathematics. F*ck off all mathematicians, what do they know about counting?

Yeah, they didn't even manage to get the circle constant right.

Re: Numbering should start at zero (1982)

#274
post #38

Consider n real numbers a_0, ..., a_{n-1}. That's not very elegant.

That's only because you insist on explicitly mentioning the last element, which you can only do when the sequence is finite and non-empty (more generally, when it is indexed by a successor ordinal). So your choice of notation is not only inelegant, it cannot even express all possible sequences.

Re: Numbering should start at zero (1982)

#275

Numbering should start at π (2025) (umars.edu) Seriously, it all depends on whether u're counting the items themselves (1-based) or the spaces btwn them (0-based). The former uses natural numbers, while the latter uses non-negative integers For instance, when dealing with memory words, do u address the word itself or its starting location (the first byte)? The same consideration applies to coordinate systems: r u pos…

Zero is a natural number. It is in the axioms of Peano arithmetic, and any other definition is just teachers choosing a taxonomy that best fits their lesson.

There is no consensus on that, and it's not just about teachers. It depends on the mathematical field and tradition. It usually starts at 1 in German, at 0 in French due to the influence of the Bourbakis, and in English I think it's more field-dependent.

The original formulation of Peano started at 1.

Re: Numbering should start at zero (1982)

#277

Earlier quoted context omitted.

Yes, but Python is not math. This is a syntax-feature we are talking about, math is here just a tool, not the purpose. And it's also not running on hardware, but multiple layers higher.

Python already has the best design (fewest tradeoffs) in this small area. You're proposing to break the expectations of millions and break offset math while you're at it. Not very compelling if you ask me.

I'm proposing nothing. I'm pointing out a flaw, for me. Nobody will change this at this point. Nobody should change it at this point. There is no benefit in this, just harm.

Re: Numbering should start at zero (1982)

#278

Earlier quoted context omitted.

It's at least as valid, in fact more so, to say that I was distracted by something they decided to say. There is no objective way to assign all blame for the tangent to just us or just them, however the closest you can come is to say that whoever speaks first is more responsible for their unprompted speech than responders are for their reactions. They chose their reactions, but they are not reactions in a vacuum, the…

Both reactors and reactees have equal opportunity not to speak. A reactor who reacts simply to nitpick provides much less to a conversation than a reactee with interesting thoughts expressed unusually.

ur both rite

Re: Numbering should start at zero (1982)

#279
The question arises when people get confused between a cut and span. These two are opposite concepts, and they make up a continuum, and they define each other.

So, it depends on what you understand as "numbering". If it is about counting objects, the word "first object" refers to existence of non-zero number of objects. This shows why the first one can't be called as zero, as zero is not equal to non-zero.

If the numbering is about continuous scale such as tape measure, then the graduations can start with zero. But still the first meter refers to one meter, not zero meters.

It looks silly when people have their book chapters numbering to begin with zero. They have no clue whether the chapter refers to a span or a cut. Sure, they can call the top surface of their book cover as zero, though. But still they can't number a page as zero.

The use of zero index for memory location comes from possible magnetic states of array of bits. Each such state is a kind of a cut, not a span. It's like a graduation on the tape measure, or mile stone on the side of the road. So it can start with zero.

So, if you are counting markers or separators, with zero magnitude, you can start at zero. And when you count spans or things of non-zero magnitude, you start at one. If you count apples, start at one. If you count spaces between apples start at zero.

Re: Numbering should start at zero (1982)

#280
post #47

1 or 0-based index... I recently picked up Lua for a toy project and I got to say that decades of training with 0-based indexes makes it hard for me to write correct lua code on the first try. I suppose 1-based index is more logical, but decades of programming languages choosing 0-based index is hard to ignore.

Interestingly, it also poses great challenges for LLMs. GPT-4 can translate Perl into Python almost flawlessly, but its Lua is full of off-by-one errors.

Haha, then my lua code is reaching LLM code quality...
Post reply on HN