You Are WRONG About 0 Based Indexing

preview_player
Показать описание
Recorded live on twitch, GET IN

### Reviewed Video

### My Stream

### Best Way To Support Me
Become a backend engineer. Its my favorite site

This is also the best way to support me is to support yourself becoming a better backend engineer.

MY MAIN YT CHANNEL: Has well edited engineering videos

Discord

Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
Рекомендации по теме
Комментарии
Автор

This is why you should use -1 based indexing like DreamBerd.

catastrophicblues
Автор

Imagine going to a conference in person, to see a speaker lecture in person

and still watching a recording

mgdotdev
Автор

Fun fact already on minute two.

In Germany we are actually counting floors starting with a a zero floor. "Erdgeschoss": ground floor, "1. Etage" is up one level from ground floor (and now I am already confused what it is in English). So 0 based index systems have been working well for a couple hundred years.

heyrim
Автор

The concept of 'nothing' or 'zero' definitely existed. They just didn't have agreement on how it worked in math (or a system to use it effectively).

aesp
Автор

Prime at its Prime. I felt the emotions in the end. This is a man truly talking about what is important to him and he does not hide his feelings about this. I admire this fucking guy.

Lolimov
Автор

0 makes sense because it's an offset. If you want someone to stand still, you don't tell them to walk 1 mile.

ZingsVideos
Автор

0 base array works great with modulo arithmetic.

tinnguyen
Автор

my favorite example of 1-based indexing is used where it makes zero sense is intervals in music. if you add together two third intervals you get a fifth interval. 3+3=5. 5+4=8.

the first interval, the unison, is a zero offset

asdfghyter
Автор

1-based gets nasty the moment you need to do any index arithmetic.
Like let's say you have a pixel array of WxH pixels and you need to generate an index given x and y. With 0-based thats just "x + W * y", while with 1-based it becomes "x + W * (y-1)"

I can't think of any code where 1-based is better beyond it being slightly more intuitive for beginners.

pokefreak
Автор

The problem with 1-based is that when you do modulo and integer divide operations, there's a missmatch in indexing. Like if you have an array of 20 items and you want to associate them evenly for like 1000 elements, you'd do items[i % items.length()], this way, it'll always be contained within items. But with 1-indexing, item[40 % 20] = item[0], which would error out.

chi_said_hi
Автор

1-based indexing is significantly worse for higher dimensional arrays.

If I have a cubic 3-dimensional grid of width 16, its way more intuitive to index it like this (0-based):
grid[x + y*16 + z*256]

As opposed to this (1-based):
grid[x + (y-1)*16 + (z-1)*256]

primbin_
Автор

I don't know how I feel about live reactions, it's just...
If I ever go to a Primeagen event, I would like him to talk about something himself, just like the course he made for Frontend Masters

Rikaisan
Автор

in C the third element of an array is not at a+2, it is between a+2 and a+3. The address point at the start of the object. x[n] refers to the object that is in the memory range between addresses x+n and x+n+1. Once you start giving addresses to the gaps between bytes and not to the bytes themselves everything makes a lot of sense.

pqnet
Автор

I do a lot with SQL. It’s 1 indexed. I think it makes sense for the stuff you do with SQL.
For anything that needs math, actual locations, modulus operator, etc., I am all for 0 index.

Also, thanks for the closing thoughts! No one looking at you now would guess what you had to go through to get to where you are.

johnathanrhoades
Автор

"Lua is actually right"
alr fine, ill hear you out but i doubt you will convince me

lifeisfakenews
Автор

Tom Scott in his "bodge" video was using lua, it went exactly the way one would expect

Oler-yxxj
Автор

As soon as he mentioned the c specification I paused to look it up. C99, c-11, and c-17 all refer to square brackets as subscripting operators, but also refer to the elements of an initializer list as being "indexed". Further, c-2x (since at least August 2022) has all that plus the explicit mention of 0-indexing in relation to bits in the stdbit.h section. Also _Lua_ stores the array portion of tables in an actual c array.

..Counter-ackshually-d.

biggerdoofus
Автор

I was coding many years in Matlab (1-based index) and now programming in C++ (0-based, you know...). 1-based index feels indeed more natural for counting, but 0-based index is MUCH more convenient when you do modulo operations. With 1-based indices, you basically always convert your index to a 0-based index, do the modulo operation and than convert it back to a 1-based index. So annoying.... The counting "issue" with 0-based can be fixed relatively easy with ranged-base loops (or STL algorithms).

epiphaeny
Автор

As a mathematician, some times it's more sensible to start a sequence at 0 (such as a geometric sequence, where the index tells you the power of the common quotient), some times it's more sensible to start a sequence at 1 (such as the harmonic sequence where the index tells you the denominator).

It's the fact that programming languages can't be flexible about it that's the real issue here.

MasterHigure
Автор

Edgar Dijkstra wrote a great short paper explaining why 0-based is intrinsically better.
Source: EWD831 "Why numbering should start at zero"

thomassynths