Readit News logoReadit News
nivertech · a year ago

  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 positioning urself at the center of a pixel or at the pixel's origin?

Almost 2 decades ago I designed an hierarchical IDs system (similar to OIDs[1]). First I made it 0-based for each index in the path. After a while I understood that I need to be able to represent invalid/dummy IDs also, so I used -1 for that. It was ugly - so I made it 1-based, & any 0 index would've made the entire ID - invalid

---

1. https://en.wikipedia.org/wiki/Object_identifier

umanwizard · a year ago
Why do you write “you” as “u” here? I don’t want to be rude, but it’s very jarring to see juvenile txt-speak in a serious discussion.
Brian_K_White · a year ago
I want to be rude.

The mix of "The same consideration applies to coordinate systems:" and "r u positioning urself..." in the same message is ridiculous to me and I can't take anyone seriously who speaks like this.

It's not illegal or immoral, but it is at the very least, demonstrably distracting from their own actual substantive point. Here we all are talking about that when they otherwise had a perfectly good observation to talk about.

Everyone is jumping on your use of the word "serious" as though you meant serious like cancer instead of just not texting ya bro bout where u at tonite, as though there are only two levels of formal and informal, the two extremes.

If this is so casual and we are txting, then why did they use punctuation and no emojis? Ending sentences with periods is verbal abuse now, so, I guess we're not txting after all? Pick a lane!

ziddoap · a year ago
>a serious discussion

hardly. this is an informal internet forum of mostly anonymous people chit chatting about random stuff instead of working.

theoreticalmal · a year ago
“serious discussion” notwithstanding, I thought the “u’re” was particularly interesting. Why not “ur”? “u” is obviously easier to write, so why worry about properly contracting it? Just interesting imo
jghn · a year ago
Not sure if it's the case here but over the decades I've observed there's a cultural aspect here. When I've had colleagues from the Middle East and/or South Asia I've found they're much more likely to use `u` and `r` colloquially than western counterparts.

This could be what you're observing. Or perhaps they just like the aesthetics.

flobosg · a year ago
I fully agree, youmanwizard.
sunshinekitty · a year ago
it’s not that serious
phanimahesh · a year ago
U are u man wizard. It's probably slightly jarring to see u r instead of you're, but I did not even notice it at first glance.

Like the sibling comment says, we're all semi anonymous internet folks talking about mostly not serious things.

Deleted Comment

brianzelip · a year ago
maybe on a mobile?
the_andrei · a year ago
u must be fun at parties
nivertech · a year ago
I dare u to correct sama’s tweets ;)
Tagbert · a year ago
I have started using “u” in my posts as there are a surprising number of sites that block or delay for approval posts that use “you”. They seem to feel that posts with “you” are too often inflammatory. It is very frustrating when you use grammatical “you” as I just did and suddenly your post is stuck in limbo.
jonahx · a year ago
> Seriously, it all depends on whether u're counting the items themselves (1-based) or the spaces btwn them

I've never heard the distinction stated this way. It's clarifying.

jacksnipe · a year ago
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.
JadeNB · a year ago
> 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.

It is, but it need not be. In the category of pointed sets with endofunctor, (Z_{\ge 1}, 1, ++) and (Z_{\ge 0}, 0, ++) are isomorphic (to each other, to (Z_{\ge 937}, 937, ++), and to any number of other absurd models), so either would do equally well as a model of Peano arithmetic.

cbolton · a year ago
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.

jmkr · a year ago
+1 for peano arithmetic club.

I never realized it was controversial. I think I've always included 0 in the nat numbers since learning to count.

But there are some programming books I've read, I want to say the Little Typer, or similar, that say "natural number" or "zero". Which makes actually confuses me.

Deleted Comment

bmacho · a year ago

      Numbering should start at π (2025) (umars.edu)
It's funny because pi is the joke compromise between 0 and tau, the circumference of the unit circle, and the period length of the trigonometric functions.

bmacho · a year ago
I think we can pretend now that anyone talking about pi is just being sarcastic? It is such a random and useless number, a perfect candidate for a funny meme
pfortuny · a year ago
Actually, the duality arises from counting (there can be 0 items) and ordering (there is only a 1st item), conceptually. Which is why the year 2000 can and cannot be the start of the 3rd millenium, for instance.
somat · a year ago
Dates and times are prime examples of modular systems that make the most sense when they start at 0. but most commonly start at 1. Think how stupid it is that the day start at 12 hours then goes back to 1 hour, at least 24 hour clocks do away with this absurdity.

My personal take is that we should not let one short sighted decision 1500 years ago to mess us up and the first century covers from years 0 to 99 and the 21 century 2000 to 2099

https://madeofrome.com/how-was-it-made/how-did-we-choose-the...

I have a database where I tried keeping once per year periodic events(like birthdays or holidays) as postgres intervals, so number_of_months:number_of_days_in_month past start of year or effectively 0 based month-day. this looks weird but solved so many calculation problems I kept it and just convert to more normal 1 based on display. and a shout out to postgres intervals, they do a heroic job at tracking months, a thankless job to program I am sure.

xeonmc · a year ago
Fun fact: the words Ordinal and Cardinal respectively derives from Ordering and Counting.

So Ordinal quantities represent the ordering of coordinates and can be negative, while Cardinal quantities describes the counting of magnitudes and must be positive.

You can transform between ordinal domains and cardinal domains via the logarithm/exponential function, where cardinal domains have a well-defined “absolute zero” while ordinal domains are translation-invariant.

jonahx · a year ago
I don't follow the distinction you're making. The number line is ordered and contains a 0....

The GP's explanation seems more fitting for the year 2000 ambiguity. Are you measuring completed years (celebrate millenium on NYE 2001) or are years the things happening between 0 and 1, 1 and 2, etc (celebrate on 2000, because we're already in the 2000th "gap")?

bmacho · a year ago
Can you elaborate? What duality, and how?
01HNNWZ0MV43FF · a year ago
That makes sense for the ID system or a database, but for arrays in a language I still prefer starting at 0. It makes frame buffers easier easier to index
nivertech · a year ago
I prefer thinking from the first principles, and not according to the current computer architecture fashion.

And BTW that ID system was used in the system processing PBs of data in realtime per day back in the early 2000s, so it’s not that it was super-inefficient.

littlestymaar · a year ago
> The former uses natural numbers, while the latter uses non-negative integers

In fact “natural numbers” is ambiguous, as it can both contain zero or exclude it depending on who uses it.

See https://en.m.wikipedia.org/wiki/Natural_number

throwway120385 · a year ago
The center of the debate is that outside of pure mathematics numbers and number systems can only be signifiers for some physical or conceptual object. It is the signified object that determines the meaning of the number and the semantics of the mathematics.
y42 · a year ago
I totally disagree, but it's only my opinion and probably not scientific at all.

From a logical point of view I think it's totally unnatural to start at 1. You have 10 diffferent "chars" available in the decimal system. Starting at 1 mostly leads to counting up to 10. But 10 is already the next "iteration". How do you explain a kid, who's learning arithmetics, that the decimal system is based on 10 numbers and at the same time you always refer to this list from 1 to 10.

goatlover · a year ago
I think it's totally natural to start counting at 1, because you start with one of something, not zero. How do you explain to a kid that although they're counting objects, the first one is labelled zero, and that when they've counted 10 objects, they use the number 9?
nivertech · a year ago
Decimal system is simply a notation chosen by Humans to communicate and preserve information, it’s not a Law of Nature.

Also you use a circular reasoning.

patrickthebold · a year ago
The reminds me of the pain I felt seeing how the blacktop was painted at the local elementary school:

They had a 6 x 6 grid with 26 letters, then the digits 1-9, then an extra X to fill in the space left over. :facepalm:

pansa2 · a year ago
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration." — Stan Kelly-Bootle
boothby · a year ago
Python supports a third way: start at -1. And if you think about it a little (but not too much) then there's some real appeal to it in C. If you allocate an array of length n and store its length and rewrite the pointer with (*a+=n)=n, then a[0] is the length, a[-1] is the first element (etc) and you free(a-a[0]) when you're done. As a nice side effect, certain tracing garbage collectors will never touch arrays stored in this manner.

Upshot: if you take the above seriously (proposed by Kelly Boothby), the median proposed by Kelly-Bootle returns to the only sensible choice: zero.

TOGoS · a year ago
He was right. If the first fencepost is centered at x=0 and the second at x=1, and you want to give the rail in-between some identifier that corresponds to its position (as opposed to giviung it a UUID or calling it "Sam" or something), 0.5 makes perfect sense.

In computer programming we often only need the position of the gap to the left, though, so calling it "the rail that starts at x=0" works. Calling it "the rail that ends at x=1" is alright, I guess, if that's what you really want, but leads to more minus ones when you have to sum collections of things.

edbaskerville · a year ago
I can't find a reference, but I have a vague memory that in original Mac OS X, 1-pixel-width lines drawn at integer locations would be blurred by antialiasing because they were "between" pixels, but lines drawn at e.g. x = 35.5 were sharp, single-pixel lines. Can anyone confirm/refute this?
kps · a year ago
First person to get a postgraduate degree in CS. I still miss his satirical writing.
Aransentin · a year ago
Perhaps ideally we'd change English to count the "first" entry in a sequence as the "zeroth" item, but the path dependency and the effort required to do that is rather large to say the least.

At least we're not stuck with the Roman "inclusive counting" system that included one extra number in ranges* so that e.g. weeks have "8" days and Sunday is two days before Monday since Monday is itself included in the count.

* https://en.wikipedia.org/wiki/Counting#Inclusive_counting

davidgay · a year ago
> At least we're not stuck with the Roman "inclusive counting" system that included one extra number in ranges* so that e.g. weeks have "8" days

French (and likely other Latin languages?) are not quite so lucky. "En 8" means in a week, "une quinzaine" (from 15) means two weeks...

MITSardine · a year ago
Hmm, "en 8" makes sense to me in that you're using it to reference the next Whateverday that is at least 8 days apart from now.

If we're on a Tuesday, and I say we're meeting Wednesday in eight, that Wednesday is indeed 8 days away.

Now I'm fascinated by this explanation, which covers the use of 15 as well. I'd always thought of it as an approximation for a half month, which is roughly 15 days, but also two weeks.

To partially answer the other Latin languages, Portuguese also uses "quinze dias" (fifteen days) to mean two weeks. But I don't think there is an equivalent of the "en huit". We'd use "na quarta-feira seguinte" which is equivalent to "le mercredi suivant".

01HNNWZ0MV43FF · a year ago
It is definitely my engineer myopia, but octaves in music should be called dozens
feoren · a year ago
Music only settled on 12 equal tones after a lot of music theory and a lot of compromise. Early instruments often picked a scale and stuck with it, and even if they could produce different scales, early music stuck to a single scale without accidentals for long stretches. Many of these only had 5 or 6 notes, but at the time and place these names were settling down, 7-note scales were common, so we have the 8th note being the doubling of the 1st.

Most beginners still start out thinking in one scale at a time (except perhaps Guitar, which sorta has its own system that's more efficient for playing basic rock). So thinking about music as having 7 notes over a base "tonic" note, plus some allowed modifications to those notes, is still a very useful model.

The problem is that these names percolated down to the intervals. It is silly that a "second" is an interval of length 1. One octave is an 8th, but two octaves is a 15th. Very annoying. However, it still makes sense to number them based on the scale, rather than half-steps: every scale contains one of every interval over the tonic, and you have a few choices, like "minor thirds vs. major thirds" (or what should be "minor seconds vs. major seconds"). It's a lot less obvious that you should* only include either a "fourth" (minor 3rd) or a "fifth" (major 3rd), but not both. I think we got here because we started by referring to notes by where they appear in the scale ("the third note"), and only later started thinking more in terms of intervals, and we wanted "a third over the tonic" to be the same as the third note in the scale. In this case it would have been nice if both started at zero, but that would have been amazing foresight from early music theorists.

* Of course you can do whatever you want -- if it sounds good, do it. But most of the point of these terms (and music theory in general) is communicating with other musicians. Musicians think in scales because not doing so generally just does not sound good. If your song uses a scale that includes both the minor and major third, that's an unusual choice, and unusual choices requiring unusual syntax is a good thing, as it highlights it to other musicians.

mdiesel · a year ago
I think we should call them doubles
Animats · a year ago
> At least we're not stuck with the Roman "inclusive counting" system that included one extra number in ranges* so that e.g. weeks have "8" days and Sunday is two days before Monday since Monday is itself included in the count.

Yes, we are. C gives pointers one past the end of an array meaningful semantics. That's in the standard. You can compare them and operate on them but not de-reference them.

Amusingly, you're not allowed to go one off the end at the beginning of a C or C++ array. (Although Numerical Recipes in C did it to mimic FORTRAN indices.) So reverse iterators in C++ are not like forward iterators. They're off by 1.

[1] https://devblogs.microsoft.com/oldnewthing/20211112-00/?p=10...

taco9999 · a year ago
> C gives pointers one past the end of an array meaningful semantics

Nelson Elhage wrote about an alternate interpretation: https://blog.nelhage.com/2015/08/indices-point-between-eleme...

zajio1am · a year ago
Note that 'first' and 'second' are not etymologically related to one or two, but to 'foremost'. Therefore, it is would make sense to use this sequence of ordinals:

first, second, twoth, third, fourth, ...

or shortened:

0st, 1nd, 2th, 3th, 4th ...

Deleted Comment

mjevans · a year ago
In terms of another thread the item is the "rail" between the "fence posts". The address of the 'first' item starts at 0, but it isn't complete until you've reached the 1.

Where is the first item? Slot 0. How much space does one item take up* (ignoring administrative overheads)? The first and only item takes up 1 space.

windward · a year ago
Who knew those bodybuilders were such history buffs?
spookie · a year ago
A day needs to finish before you count the next one. It makes perfect sense.
roenxi · a year ago
The 1980s were not a particularly enlightened time for programming language design; and Dijkstra's opinions seem to carry extra weight mainly because his name has a certain shock and awe factor.

It isn't usual for me to agree with the mathematical convention for notations, but the 1st element of a sequence being denoted with a "1" just seems obviously superior. I'm sure there is a culture that counts their first finger as 0 and I expect they're mocked mercilessly for it by all their neighbours. I've been programming for too long to appreciate it myself, but always assumed it traces back to memory offsets in an array rather than any principled stance because 0-counting sequences represents a crazy choice.

tetha · a year ago
I've heard the statement "Let's just see if starting with 0 or 1 makes the equations and explanations prettier" quite a few times. For example, a sequence <x, f(x), f(f(x)), ...> is easier to look at if a_0 has f applied 0 times, a_1 has f applied 1 time, and so on.
branko_d · a year ago
0-based indexing aligns better with how memory actually works, and is therefore more performant, all things being equal.

Assuming `a` is the address of the beginning of the array, the 0-based indexing on the left is equivalent to the memory access on the right (I'm using C syntax here):

  a[0] == *(a + 0)
  a[1] == *(a + 1)
  a[2] == *(a + 2)
  ...
  a[i] == *(a + i)
For 1-based indexing:

  a[1] == *(a + 1 - 1)
  a[2] == *(a + 2 - 1)
  a[3] == *(a + 3 - 1)
  ...
  a[i] == *(a + i - 1)
This extra "-1" costs some performance (through it can be optimized-away in some cases).

goatlover · a year ago
But then again Fortran proceeded C, is known for being very performant, and is 1-based by default.
hn_throwaway_99 · a year ago
The comment you are replying to essentially said exactly that:

> but always assumed it traces back to memory offsets in an array rather than any principled stance because 0-counting sequences represents a crazy choice.

pwdisswordfishz · a year ago
> Dijkstra's opinions seem to carry extra weight mainly because his name has a certain shock and awe factor

So you claim this is just an appeal to authority and as a rebuttal you give appeal to emotion without being an authority at all?

> the 1st element of a sequence being denoted with a "1" just seems obviously superior

> I'm sure there is a culture that counts their first finger as 0 and I expect they're mocked mercilessly for it by all their neighbours

> 0-counting sequences represents a crazy choice

5G chess move.

personalaccount · a year ago
> The 1980s were not a particularly enlightened time for programming language design; and Dijkstra's opinions seem to carry extra weight mainly because his name has a certain shock and awe factor.

Zero based indexing had nothing to do with Dijkstra's opinion but the practical realities of hardware, memory addressing and assembly programming.

> I'm sure there is a culture that counts their first finger as 0

Not a one because zero as a concept was discovered many millenia after humans began counting.

Aardwolf · a year ago
For math too, 0-based indexing is superior. When taking sub-matrices (blocks), with 1-based indexing you have to deal with + 1 and - 1 terms for the element indices. E.g. the third size-4 block of a 16x16 matrix begins at (3-1)*4+1 in 1-based indexing, at 2*4 in 0-based indexing (where the 2 is naturally the 0-indexed block index).

Also, the origin is at 0, not at 1. If you begin at 1, you've already moved some distance away from the origin at the start.

venusenvy47 · a year ago
Just speaking anecdotally, I had the impression that math people prefer 1-based indexing. I've heard that Matlab is 1-based because it was written by math majors, rather than CS majors.
shiandow · a year ago
In mathematics, if it matters what index your matrix starts on then you're likely doing something wrong.

Besides, in the rare cases where it does matter you're free to pick whichever is convenient.

sham1 · a year ago
Zero-based counting works better with modular arithmetic. Like

  arr[(i++ % arr.length)] = foo;
Is certainly nicer than the equivalent in one-based subscripting

  arr[(i++ % arr.length) + 1] = foo;
(The above is actually wrong, which helps the idea)

I'll concede that it's not all that significant as a difference, but at least IMO it's nicer.

Also could argue that modular arithmetic and zero-based indexing makes more sense for negative indexing.

tmtvl · a year ago
But on the other hand,

  last := vector[vector-length(vector)];
is nicer than

  last := vector[vector-length(vector) - 1];
so in the end I'd say 'de gustibus non est disputandum' and people who prefer 0-based indexing can use most languages and I can dream of my own.

Quekid5 · a year ago
Yes, negative indexing as in e.g. Python (so basically "from the end") can be incredibly convenient and works seamlessly when indexes are 0-based.
xandrius · a year ago
What culture would that be? Because I was under the impression that counting "nothing" generally makes little sense in most of the practical world.
silotis · a year ago
Pretty much any algorithm that involves mul/div/mod operations on array indexes will naturally use 0-based indexes (i.e. if using 1-based indexes they will have to be converted to/from 0-based to make the math work).

To me this is a far more compelling argument for 0-based indexes than anything I've seen in favor of 1-based indexes.

pwdisswordfishz · a year ago
Forget multiplication, even addition becomes simpler.
arnsholt · a year ago
Both are fine, IMO. In a context where array indexing is pointer plus offset, zero indexing makes a lot of sense, but in a higher level language either is fine. I worked in SmallTalk for a while, which is one indexed, and sometimes it made things easier and sometimes it was a bit inconvenient. It evens out in the end. Besides, in a high level language, manually futzing around with indexing is frequently a code smell; I feel you generally want to use higher level constructs in most cases.
noneeeed · a year ago
I've always appreciated Ada's approach to arrays. You can create array types and specify both the type of the values and of the index. If zero based makes sense for your use, use that, if something else makes sense use that.

e.g.

  type Index is range 1 .. 5;
  type My_Int_Array is
     array (Index) of My_Int;
It made life pretty nice when working in SPARK if you defined suitable range types for indexes. The proof steps were generally much easier and frequently automatically handled.

tdeck · a year ago
Many BASIC dialects had this too, which could make some code a bit easier to read e.g.

    DIM X(5 TO 10) AS INTEGER
I recall in one program I made the array indices (-1 TO 0) so I could alternate indexing them with the NOT operator (in QuickBASIC there were only bitwise logical operators).

fweimer · a year ago
On the other hand, if you receive an unconstrained array argument (such as S : String, which is an array (Positive range <>) of Character underneath), you are expected to access its elements like this:

    S (S'First), S (S'First + 1), S (S'First + 2), …, S (S'Last)
If you write S (1) etc. instead, the code is less general and will only work for subarrays that start at the first element of the underlying array.

So effectively, indexing is zero-based for most code.

nivertech · a year ago
I think lower..higher index ranges for arrays were used in Algol-68, PL/1, and Pascal long before Ada

At least in standard Pascal arrays with different index ranges were of different incompatible types, so it was hard to write reusable code, like sort or binary search. The solution was either parameterized types or proprietary language extensions

Deleted Comment

ninalanyon · a year ago
Pascal has it too.
myfonj · a year ago
I found it devastating that there are no distinct agreed-upon words denoting zero- and one-based addressing. Initially I thought that the word "index" clearly denotes zero-base, and for one-base there is "order", "position", "rank" or some other word, but after rather painful and humiliating research I stood corrected. ("Index" is really used in both meanings, and without prior knowledge of the context, there is really no way to tell what base it refers to.)

So to be clear, we have to tediously specify "z e r o - b a s e d " or "o n e - b a s e d" every single time to avoid confusion. (Is there a chance for creating some new, terser consensus here?)

pansa2 · a year ago
AFAIK "offset" (i.e. from the beginning of the array/file/etc) is commonly used to indicate a zero-based index.
TOGoS · a year ago
I like this. I feel like "offset" hints at the reason for starting at 0. "How far do you have to offset your feet (from the beginning of whatever space we're talking about) before you're touching the thing in question?" If it's the first thing, you don't have to move at all, so zero offset
aero142 · a year ago
I humbly submit '1ndex' and 'ind0x', or '1dx' and 'i0x'.
pixl97 · a year ago
While most people ran screaming from programming assembly aero142 thought it was a rather swell idea.
wasabi991011 · a year ago
Pronounced "one-dex" and "in-dox"?
xandrius · a year ago
I always thought:

- Offset: 0-based

- Index: 1-based

moefh · a year ago
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 example) and then get the 3rd of that note (the 3rd of G is B). But note that B is the 7th of C major, not the 8th you'd get from adding 5 and 3.

The problem, of course, is that we ended up using the numbers as offsets, even though they started as indices.

naasking · a year ago
Index is ambiguous. I think "Offset" and "Itemized".
Rygian · a year ago
I think that "zero-based" and "one-based" expressions are the distinct agreed-upon "words" and they are terse enough.

I can suggest "z8d" and "o7d" otherwise. (/jk)

weinzierl · a year ago
I don't think "index" by itself should imply any starting value. After all many induces start at higher numbers and then you'd have to invent words for 2-based, 3-based and so on as well.
inkcapmushroom · a year ago
Maybe we can call it 0ndex and 1ndex. Really rolls off the tongue.
otikik · a year ago
Zerodex and onedex?
scoofy · a year ago
I mean, I think "ordinal" and "zordinal" would work.
xeonmc · a year ago
or Ordinal and Cardinal, meaning ordering and counting respectively
lupire · a year ago
"offset" and "ordinal".
zajio1am · a year ago
Ordinals in math also start at zero. It is just common people accepted zero for cardinals and but not (yet) for ordinals.