You Are WRONG About 0 Based Indexing

  Рет қаралды 288,648

ThePrimeTime

ThePrimeTime

Күн бұрын

Recorded live on twitch, GET IN
Reviewed Video
• Why you're wrong about...
By: TJ DeVries | / @teej_dv
My Stream
/ theprimeagen
Best Way To Support Me
Become a backend engineer. Its my favorite site
boot.dev/?prom...
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
/ theprimeagen
Discord
/ discord
Have something for me to read or react to?: / theprimeagenreact
Kinesis Advantage 360: bit.ly/Prime-K...
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))
turso.tech/dee...

Пікірлер: 2 100
@catastrophicblues13
@catastrophicblues13 4 ай бұрын
This is why you should use -1 based indexing like DreamBerd.
@NewSchattenRayquaza
@NewSchattenRayquaza 4 ай бұрын
Ma man here is cooking some world peace right here
@CEOofCulturalMarxism
@CEOofCulturalMarxism 4 ай бұрын
Or BS
@Dekharen
@Dekharen 4 ай бұрын
Whenever I feel bad I go and read the dreamberd specifications 😆
@NithinJune
@NithinJune 4 ай бұрын
literally
@Sameer.Trivedi
@Sameer.Trivedi 4 ай бұрын
Number line starts at -infinity that's the only correct way of indexing.
@MrRobix13
@MrRobix13 4 ай бұрын
Man doing live reactions, he won.
@fus3n
@fus3n 4 ай бұрын
Actually kind of weird... i feel like he is trying not to put effort into this place, everyone came to see him give advice and stuff after all, i am sure he got permission for these videos or the youtuber doesn't mind anyways, but... yea... you could have at least make one presentation for this.. doesn't matter ig, everyone will gobble whatever's showed to them
@rodrigohmoraes
@rodrigohmoraes 4 ай бұрын
​@@fus3n most (all?) of his content is reaction, what did you expect him to do? A circus show?
@ciziadevos
@ciziadevos 4 ай бұрын
@@fus3n nobody forces you to stay in the damn room, or on this damn video, if you don't like it
@fus3n
@fus3n 4 ай бұрын
​@@rodrigohmoraes No, i expected him to do what usually happens in these kinds of conference/meetups or talk videos how many times have you see this kind of videos where the guy literally reacts to a youtube video? We could say they didn't expect to go there just to see someone react... it feels effortless as if they wanted to do that they could just watch his videos, as you said which is fine too.
@fus3n
@fus3n 4 ай бұрын
@@ciziadevos Yes... and i said nothing about him forcing anyone to watch this or be in that room...
@mgdotdev
@mgdotdev 4 ай бұрын
Imagine going to a conference in person, to see a speaker lecture in person and still watching a recording
@jsonkody
@jsonkody 4 ай бұрын
.. still watching IRL react video :D
@ChristofferLund
@ChristofferLund 4 ай бұрын
This format is insane, yet for me on KZbin it's exactly the same as it was
@jarylsim1973
@jarylsim1973 4 ай бұрын
Conferences? Is that what they call real life Twitch?
@blackspitit
@blackspitit 4 ай бұрын
conference? it seems more like a comedian to me. A conference is not with a video.
@heyrim72
@heyrim72 4 ай бұрын
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.
@porky1118
@porky1118 3 ай бұрын
But nobody actually calls it 0. It's usually E.
@DJKav
@DJKav 3 ай бұрын
We use the same notation in the UK.. Ground Floor / Floor 0. Then it could be 1st Floor. Or at my local hospital, -1 (A+E, Radiology) / 0 (Ground Floor, Main Entrance / 1st Floor / 2nd Flor / 3rd Floor / 4th Floor Hospital is built on a slight incline, so A+E is still on the ground, but the rest of the main hospital extends above it, level with the upper ground.
@markus.schiefer
@markus.schiefer 3 ай бұрын
True, and works well for elevator buttons, but if you tell me that it never caused confusion during conversations, you must be living in a bubble. ;-)
@AntsanParcher
@AntsanParcher 3 ай бұрын
@@porky1118 That's merely a matter of notation.
@cybernetic-ransomware1485
@cybernetic-ransomware1485 3 ай бұрын
@@porky1118 exept elevators
@Ekitchi0
@Ekitchi0 4 ай бұрын
As a French where the ground floor is floor 0 and the first floor up floor 1 and the first floor down is -1 it makes me smirk to hear Americans defend indexing starting at 0 ;p
@dwigtschrude
@dwigtschrude 17 күн бұрын
North America starts with a ground floor too
@unknownunknown5730
@unknownunknown5730 9 күн бұрын
@@dwigtschrude In the US the "ground floor" is typically called the "first floor"
@dwigtschrude
@dwigtschrude 9 күн бұрын
@@unknownunknown5730 weird because almost every elevator that floor has a G with a star next to it, instead of a 1
@ZingsVideos
@ZingsVideos 4 ай бұрын
0 makes sense because it's an offset. If you want someone to stand still, you don't tell them to walk 1 mile.
@spacecadet2926
@spacecadet2926 4 ай бұрын
Never thought of it like that. Makes sense
@jhny0
@jhny0 4 ай бұрын
very good analogy
@mAcCoLo666
@mAcCoLo666 4 ай бұрын
I guess that started with c, c++ and pointers. When you think of items 1 would make more sense.
@samuelswatson
@samuelswatson 4 ай бұрын
The whole point is that 0 makes sense when your index is functioning as an offset, and 1 makes more sense when it isn’t.
@SkyyySi
@SkyyySi 4 ай бұрын
That makes sense for as long as you think about arrays as memory addresses, rather than lists (as in, like, an actual list). So basically just a rephrasing of the "0-based indexing is right because pointer arithmetic" argument
@Lolimov
@Lolimov 4 ай бұрын
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.
@powercore2000
@powercore2000 4 ай бұрын
I felt that ending in my soul man. It was a beautiful message to end on.
@ChristofferLund
@ChristofferLund 4 ай бұрын
I think him having gone through what he’s done is a big reason why he is successful and why I enjoy watching him. Keeping it real.
@Kane0123
@Kane0123 4 ай бұрын
Could hear it as soon as he started choking up - I would have bailed asap. Bro did some real man shit right here.
@raq1024
@raq1024 4 ай бұрын
Damn that ending hit hard and made a great point. Salute to Prime.
@joelperpetua3929
@joelperpetua3929 4 ай бұрын
man almost quoting the bible at the end "What will it benefit a man if he gains the whole world yet loses his life?"
@chi_said_hi
@chi_said_hi 4 ай бұрын
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.
@DominikPlaylists
@DominikPlaylists 4 ай бұрын
yes, there are very many good arguments for 0-based in math, but there are way more for 1-based. I vote we look at the top 1000 most useful formulas in computer science, math, physics and chemistry that have an index and then decide which one is easier.
@nikitatimaev5297
@nikitatimaev5297 4 ай бұрын
​@thetukars this will make unreadable code.
@hobe4576
@hobe4576 4 ай бұрын
​@@nikitatimaev5297true therefore a must-have feature for ... VBA!
@thomasmaughan4798
@thomasmaughan4798 4 ай бұрын
@@DominikPlaylists "and then decide which one is easier." Done! Zero based is easier.
@dimitralex1892
@dimitralex1892 4 ай бұрын
dude... you cannot tell people to analyse if its better for them to use 1 or 0 and then when someone says "ok, zero it is" tell them "no my friend you are wrong, both can be useful"...
@aes0p895
@aes0p895 4 ай бұрын
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).
@MasterHigure
@MasterHigure 4 ай бұрын
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.
@username7763
@username7763 4 ай бұрын
C++ can be flexible about that. It is perfectly possible to create an array class that uses 1-based indexing. This isn't commonly used because it is unexpected in the language.
@MasterHigure
@MasterHigure 4 ай бұрын
@@username7763 I didn't mean it was physically impossible to do. I meant not a lot of languages do it, and it seems like a terrible idea.
@jongeduard
@jongeduard 4 ай бұрын
0 is the origin. Very simple. This is true in Math with the x, y, z axis, and used as a system in many areas of science like physics And this is true in computers with indexing in memory, in arrays. 1 based counting is for humans, practical when numbering things in real life. That's all. I prefer the 0.
@Forty8-Forty5-Fifty8
@Forty8-Forty5-Fifty8 4 ай бұрын
I prefer languages with strict rules that make it annoying to do things the non-standard way. There are so many different plausible ways that this could theoretically be implemented and I don't want to have to think of all of them when all someone had to do was write i+1 when that is what they need.
@NickMak-m2c
@NickMak-m2c 4 ай бұрын
@@jongeduard 0 is not the origin, zero actually represents nothing. "1 based counting is for humans" it's for computers too, it's actually multiplication that uses the zero, because you're multiplying addresses, and the first address has to equal the first address plus the number of bits until the next address * 0. 365 + 64*0 = 365 (first address) 365 + 64*1 = 429 (second address) and so on In representation, there is no reason to start it with zero, it confuses how math is done in the rest of programming, which is done the normal way where 1 = 1. 0 + 0 =/= 1 in computer math, it equals zero, computer math uses 0 as its normally used everywhere else, and this creates situations where you had to minus one from a calculation that equates to an index position. I see a lot of different reasons why people claim 0-start indexing is the way to go, and it all really is just justifying something people are used to, but if you wanted a more correct representation it'd start with 1. If we switched the norm now it'd cause a lot of chaos for something that a minus 1 or a plus 1 is all it takes to even out.
@primbin_
@primbin_ 4 ай бұрын
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]
@Akronsus
@Akronsus 4 ай бұрын
oh nice. that is even better than the "it makes sense as an offset" argument, since yours shows that 0-indexing makes sense for every enumerated data
@georg9899
@georg9899 4 ай бұрын
I think for higher dimensions [x][y][z] would be a better way to index the array. In this case both 1-based and 0-based indexing would be more intuitive than doing the calculations for the offset manually.
@maidenlesstarnished8816
@maidenlesstarnished8816 4 ай бұрын
​@georg9899 I believe you misunderstood the comment. They're not referring to the indexing syntax. They're referring to the logic for computing the index.
@z278z
@z278z 4 ай бұрын
(grid - 16 - 256)[x + y * 16 + z * 256] Arrays should start at index -1, so 3d arrays should start at index (-1, -1, -1)
@xpusostomos
@xpusostomos 4 ай бұрын
All you're telling me is that your language is brain dead and doesn't support multiple dimensional arrays natively
@tinnguyen5055
@tinnguyen5055 4 ай бұрын
0 base array works great with modulo arithmetic.
@spacelem
@spacelem 4 ай бұрын
In Julia, you have mod and mod1 functions. If you need n and not 0, just use mod1 instead.
@Daniel_WR_Hart
@Daniel_WR_Hart 3 ай бұрын
I never appreciated 0-indexing until I tried making a circular array
@MarcCastellsBallesta
@MarcCastellsBallesta 3 ай бұрын
I love your VLC-like profile picture!
@angeldude101
@angeldude101 3 ай бұрын
Minor problem, the vast majority of languages are broken by default for this, at least for negative indexes. Using unsigned values already takes an unrelated modulus unless the list itself has a length that's a power of two, and if the index is signed, then the remainder operator is broken by design and you need to manually add the length of the array anyways in order to simulate a working modulo operator. If you're instead referring to counting past the end of the array and then looping back to the front, then there's no problem and the positive indexes actually have work modulo operators. Python is one of the few languages whose signed remainder isn't broken by design and it just so happens to also be one of the few languages that allows negative indexes to index from the end, where said modulo is performed automatically. (I don't know if it works when idx/length is outside of [-1, 1).)
@Enjgine
@Enjgine 3 ай бұрын
I invited 1 people and they both showed up. I asked them to divide into 1 groups and there was 0 people in each group.
@Oler-yx7xj
@Oler-yx7xj 4 ай бұрын
Tom Scott in his "bodge" video was using lua, it went exactly the way one would expect
@kezzyhko
@kezzyhko 4 ай бұрын
it went exactly the way zero would expect
@SkyyySi
@SkyyySi 4 ай бұрын
You would indeed expect that considering he also said he likes JavaScript
@Alfred-Neuman
@Alfred-Neuman 4 ай бұрын
@@SkyyySi What's wrong with Javascript? Don't you agree that everything should be re-written in Javascript? Just imagine for a second, computers could be sold with Chrome a the main operating system and you could open Windows in the first tab, and then maybe Ubuntu in your second tab and why not have Fortnite in the third tab? Etc... Of course we might lose like 1 or 2 percent in performance but at the same time it would solve every single problems we currently have with all the other programming languages! Easy programming for everyone, no more security bugs, no more viruses!
@xybersurfer
@xybersurfer 4 ай бұрын
@@Alfred-Neuman it sounds like you've only programmed in JavaScript, because you are asking what's wrong with JavaScript. while it's probably true that there would be less security vulnerabilities related to memory safety with everything written JavaScript, it won't eliminate all security vulnerabilities. do you remember that JavaScript was also vulnerable to Spectre and Meltdown? and it happens all the time that vulnerabilities are discovered and fixed in JavaScript engines. also i don't think JavaScript would be the best choice to write everything in, because of it's aggressive type coercion, which sometimes has resemblance to accidentally accessing the wrong memory in languages like C. not to mention all the other design mistakes in JavaScript that even TypeScript can't fix. vulnerabilities are not even always technical (like social engineering). so "no more security bugs" etc. is something you should be more careful with saying
@colefrankenhoff1428
@colefrankenhoff1428 4 ай бұрын
@@xybersurfer Way to mix the joke lmao
@asdfghyter
@asdfghyter 4 ай бұрын
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
@drdca8263
@drdca8263 3 ай бұрын
Yes! This makes music theory way more confusing. I pretty much have to convert what people say in whatever tutorial into 0 based before listening in order to understand it
@GlueC
@GlueC 3 ай бұрын
I can't believe how long I went without ever considering 0-based scales. I feel like there are other things that can be done with that. Whoah.
@p-y8210
@p-y8210 2 ай бұрын
Music theory is fucking bonkers.
@pokefreak2112
@pokefreak2112 4 ай бұрын
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.
@spacelem
@spacelem 4 ай бұрын
True, but you do rarely need to do that with 1-based languages. X[x,y] is right there.
@porky1118
@porky1118 3 ай бұрын
And the intuitivity issue can be fixed by fixing natural language and teaching children to count from zero from birth :)
@spacelem
@spacelem 3 ай бұрын
@@porky1118 we do count from zero. If there are no things, there are 0 of them. When the first thing comes along, there's 1 of them. In a race, once 1 person has finished, they are 1st. Nobody wears the "I came 0th" badge, unless it meant "there were zero people in between me and the finishing ribbon" which... is a pretty weird way to say you won.
@porky1118
@porky1118 3 ай бұрын
@@spacelem Yeah, indexing would be the proper term. But since the maximum index represents the count, it's just the same. But still, you'd still count the same way since you usually don't care about the indices. But calling myself the "zeroth" (I don't like the term) would make sense. If the rank is just the same as the number of people who are better than me, that's just more intuitive.
@spacelem
@spacelem 3 ай бұрын
@@porky1118 I think "intuitive" is very much subjective, as describing where you came in a race by how many people came before you does not sound at all intuitive to me. If you're doing a test, and you answer no questions correctly and score "0", that's not an ordering, then it really is counting and 0 is intuitive. Saying "I got 37/50" is intuitive. Describing where you came on the test relative to everyone else is not counting, it's ordering.
@thomassynths
@thomassynths 4 ай бұрын
Edgar Dijkstra wrote a great short paper explaining why 0-based is intrinsically better. Source: EWD831 "Why numbering should start at zero"
@FighterHayabusa
@FighterHayabusa 4 ай бұрын
I have to bring this one out from time to time to convince people. It's really well-written and reasoned.
@isodoubIet
@isodoubIet 4 ай бұрын
Insane that people are still debating a point that was conclusively settled in the 80s
@victotronics
@victotronics 4 ай бұрын
I drop that article in the class resources of almost everything I teach. He was so eloquent, thorough, and *right*.
@GabrielFury-mg8du
@GabrielFury-mg8du 4 ай бұрын
LOL, a 'short paper'? By today's standards it was a blog post on Medium: a long-winded trash take with petty stabs at contemporaries. The whole of the text embodies a thoroughly subjective opinion; If only 1982 had also held a medium with a 280 character limit he might yet have expressed his poorly formulated opinion that much quicker.
@jsonkody
@jsonkody 4 ай бұрын
I know it for years .. he's right when we talk about C He is wrong everywhere else.
@Rikaisan
@Rikaisan 4 ай бұрын
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
@NoVIcE_Source
@NoVIcE_Source 4 ай бұрын
at the end he was fully himself
@scythazz
@scythazz 4 ай бұрын
It is alittle bit weird isn’t it. Like people are saying that is what theu expected him to do but still… it feels just somewhat awkward.
@Forty8-Forty5-Fifty8
@Forty8-Forty5-Fifty8 4 ай бұрын
Honestly, these live audience streams go much better than my actual college lectures from the very few I have seen so far.
@JeremyAndersonBoise
@JeremyAndersonBoise 4 ай бұрын
He does that too, later in the video, this is just a piece of the event.
@سیدمرتضیموسوی-ث2ل
@سیدمرتضیموسوی-ث2ل 4 ай бұрын
In Persian, weekdays are zero-based. "shanbe", "yek shanbe" "do shanbe", .... yek means one. do means two, ...
@brainandforce
@brainandforce 8 күн бұрын
And Doshanbe is the capital of Tajikistan.
@dire_prism
@dire_prism 4 ай бұрын
In mathematics, even before computing, 0 based indexing for sequences has had a lot of use.
@johnathanrhoades7751
@johnathanrhoades7751 4 ай бұрын
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.
@rikschaaf
@rikschaaf 4 ай бұрын
Can we just agree on this: - in languages that start arrays with 0, let's call it an offset (or subscript if you're fancy) - in languages that start arrays with 1, let's call it an index That way, both can coexist. It even allows for languages with both.
@Valerius123
@Valerius123 4 ай бұрын
Hmm.. I like this idea. Worth thinking about.
@xpusostomos
@xpusostomos 4 ай бұрын
A proper language lets the programmer choose his indexes
@stefanalecu9532
@stefanalecu9532 4 ай бұрын
​@@xpusostomosso... Pascal? Which has been doing this for 54 years and counting?
@xpusostomos
@xpusostomos 4 ай бұрын
@@stefanalecu9532 I guess, I forget... Of course the right libraries in Java and C++ could pull it off too
@Asto508
@Asto508 4 ай бұрын
@@xpusostomos You can always create your own array object and define/override the [] operator, so virtually every modern language allows this by default
@lifeisfakenews
@lifeisfakenews 4 ай бұрын
"Lua is actually right" alr fine, ill hear you out but i doubt you will convince me
@jsonkody
@jsonkody 4 ай бұрын
I've spent a very VERY long time studying the historical reasoning about this topic, and TJ did not present the most significant points of why 0-based is not real indexing :/ He had some nice points, but he did not delve too deeply. Zero-based indexing can be understood as 'offset indexing', which is akin to measuring distances on a ruler starting from zero. It doesn't point directly to an element, but rather to the starting point of where the element is stored in memory. This method is efficient for data stored sequentially, as it doesn't require additional information about the size or location of each element. In contrast, one-based indexing, which I refer to as 'real indexing', naturally aligns with human understanding of order, where '1' points directly to the first element, making it more intuitive for directly referencing items, especially in mathematical and scientific contexts. So 0-based indexing is really necessary in low-level programming, but I consider it unnecessary in higher-level programming because there's absolutely no need for it-it's not real indexing, but rather offsetting in memory. Higher-level languages don't go so low in memory access; the language handles these things for you, so you could use normal indexing that points directly to elements (1-based). It’s too bad that almost everyone copied 0-based indexing from the C language, so now it's considered the 'normal' thing for programmers.
@isodoubIet
@isodoubIet 4 ай бұрын
@@jsonkody You didn't present any arguments either, calling your wrong preference "real indexing" doesn't really count. "But it's intuitive" that's the same wrong argument TJ made.
@JohnSmith-qy1wm
@JohnSmith-qy1wm 4 ай бұрын
The colloquial, lay understanding of the word "index" is (and always has been) a list of things. You don't normally number a list starting at 0. That is what they meant by "intuitive," and what "indexing" means in any other context. I agree with them on that. Their argument is that lua's 1-based indexing is correct for high-level languages, while 0-based indexing is necessary for low-level indexing. That's their argument. It's not particularly difficult to discern.
@isodoubIet
@isodoubIet 4 ай бұрын
@@JohnSmith-qy1wm "The colloquial, lay understanding of the word "index" is" Irrelevant, since we're talking about a technical term with a precise definition. This has zero to do with high level versus low-level. It's about the fundamental logic of programming and 0-indexing is just inherently superior regardless of what "level" one is programming at. As long as you're indexing into a list, you have to think about how many elements are in a (sub)list and in how to combine two lists. 0-indexing with half-open intervals is the _only_ convention where end-begin is the number of elements and where, if you split a list into two, the "begin" for the second sublist coincides with the "end" for the first sublist. It's why multidimensional arrays are so much better when zero-indexing, for example. We're talking an objective advantage in writing actual code, not whatever a bronze age peasant counting sheep would've considered intuitive.
@parityviolation968
@parityviolation968 4 ай бұрын
@@isodoubIet I wouldn't exactly describe the math and science based POV as bronze age peasantry, which was brought up by jsonkody and ignored by you when dismissing his comment. But I wouldn't agree with his point completely, either. In theoretical physics zero-based indexing is convention for tensors involving spacetime ... to this day, I still cant figure out the rationale behind that convention. I doubt it's as based as it's been for programming, though. Probably just some banal reason like spatial dimensions already had 1,2,3, so in order to treat time differently physicists opted for 0 instead of 4. I hope I'm wrong^^
@Oler-yx7xj
@Oler-yx7xj 4 ай бұрын
But have you seen a language in which it's possible to have an array indexed -69..69? How can you not love Pascal
@rupen42
@rupen42 4 ай бұрын
Fortran too!
@EngineerErik
@EngineerErik 4 ай бұрын
done that in Ada
@adissentingopinion848
@adissentingopinion848 4 ай бұрын
Damn, VHDL and Systemverilog inherited the Pascal goodness. It's strucutred as type var(7 downto 0). Yeah, you can choose your endinaness in these godforsaken HDLs.
@josefjelinek
@josefjelinek 4 ай бұрын
Ada handled that much better than Pascal IIRC, since in Ada you could for example define a stack allocated array with dynamic length, while Pascal had the range part of its type and very static... almost impossible to do anything more complex with those arrays alone. Even Go needs dynamic "slice" construct and its stack allocated arrays still cannot be dynamic length...
@__christopher__
@__christopher__ 4 ай бұрын
@@josefjelinek Extended Pascal had that too. It's just that this standard got rarely implemented (the only implementation I'm aware of is GNU Pascal).
@andyc8257
@andyc8257 4 ай бұрын
Such a crazy argument. Pascal sorted this years ago by letting you specify the upper and lower bounds, so you could have whatever made sense. Need indexes from 7 to 12, array[7..12]
@GoddamnAxl
@GoddamnAxl 4 ай бұрын
The man is turning reaction videos into live performance art… what an innovation 🤯
@beest_
@beest_ 4 ай бұрын
Tldr: instead of INDEX say OFFSET, because as human readable point of view we are mistaking index and our numeric counting. By this definition arrays must at ZERO based offset
@Deschutron
@Deschutron 4 ай бұрын
Offset is a great word for a zero-based index. Index is a great word for the number you say while counting and pointing at each item as you count it. "Subscript" is not a great word to distinguish from "index", or to specify that you're starting from zero, because the tradition of using subscripts comes from mathematics, where subscripts are used to write indices, and the indices usually start at 1.
@jnharton
@jnharton 4 ай бұрын
Or just accept that your array has a Zeroth position. Try looking up the definition of index some time. Index and indicator have the same latin root. Also, the array is indexed by numbers which refer to a position/element in the array.
@Gregorius421
@Gregorius421 3 ай бұрын
This is the way.
@biggerdoofus
@biggerdoofus 4 ай бұрын
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.
@isodoubIet
@isodoubIet 4 ай бұрын
This fake distinction between indices and subscripts was the most mind-meltingly stupid part of the video.
@ionarevamp
@ionarevamp 4 ай бұрын
This is because array subscripting is a *form* of indexing. It doesn't mean that it is the only logical form of indexing, that's the whole point.
@delta3244
@delta3244 4 ай бұрын
​​@@ionarevampSubscripting doesn't have the inherent meaning of x[y] ⇔ (*(x + y)) anywhere except in C (edit: and any other languages which _choose to_ ascribe that meaning), so it's a pointless distinction either way. It's also an incorrect distinction, so focusing on it does naught but obscure whatever point was being made.
@ionarevamp
@ionarevamp 4 ай бұрын
@@delta3244 Precedent and tradition ascribe a meaning regardless. I think if you failed to see a point, you either have no opinion on it or you weren't paying attention. In fact, I think you just stated the point but don't seem to believe that's actually what it was: 0-based indexing because of the specified array subscripting pointer math due to the specification in C is the only real reason 0-based indexing exists. If 1-based indexing occurred first, *that* would probably be seen as normal, but the sheer influential power and age of the C (and C-based) language(s)--to quote the video--"tricks us" into thinking that 0-based indexing is the correct way. It is implied that we really should just think about what is the most intuitive and elegant solution that empowers us to do more with fewer mistakes.
@delta3244
@delta3244 4 ай бұрын
@@ionarevamp It could be that the point of the example was to restate the point of the video without adding anything, as you assume it is. That point is easy to figure out: simply watch the rest of the video and ignore the example. If the example was meant to illustrate any finer/more specific point, it was lost in the glaring flaws of the example. I cannot say which is true, because the example was clearly meant to be insightful, but it merely _sounds_ insightful. If it _were_ insightful, it could communicate something more specific than the point of the video. It isn't insightful, and it cannot do so. It is clearly meant to be insightful, so for all I know, the speaker could be trying and failing to communicate something specific. Hence "whatever point was being made." (edit - grammer)
@ytdlgandalf
@ytdlgandalf 4 ай бұрын
My daughter knew very well at age 2 that when were doing a count down, shit happens at 0, not 1, so debunked.
@bjbboy71697
@bjbboy71697 4 ай бұрын
Prime: "For those that don't use neovim..." Also Prime: "That's odd, because the people who said they use neovim didn't raise their hand".
@dami-i
@dami-i 4 ай бұрын
function myArray(i) { return myArray[i-1]; } BOOM!
@daschewie
@daschewie 4 ай бұрын
C introduced the 0-based indexing. Most languages prior to C, and in the Algol lineage used 1 based indexing: Ada, Pascal, ALGOL 68, APL, AWK, CFML, COBOL, Fortran, FoxPro, Julia, Lingo, Lua, Mathematica, MATLAB, PL/I, RPG, R, Ring, Sass, Smalltalk, Wolfram Language, and XPath/XQuery
@isodoubIet
@isodoubIet 4 ай бұрын
Yeah and then most languages after C copied the C convention instead of the earlier "intuitive" one. Almost like it was _actually better_ or something.
@roadgeek123
@roadgeek123 4 ай бұрын
Also RPG
@MartialBoniou
@MartialBoniou 4 ай бұрын
Exactly!
@AM-yk5yd
@AM-yk5yd 4 ай бұрын
@@isodoubIet What's funny it's even makes sense in purely functional languages(think something like agda): just consider how you would implement getting a value from a list using Peano numbers. Most natural is "get-nth for 0 is the head of the list. For a successor of X, it's get-nth(X, tail)". In Peano numbers "one" doesn't even exists on its own (successor of 0 exist). When such system and C agree on something... Well, human intuition probably has serious skill issues.
@jongeduard
@jongeduard 4 ай бұрын
Fact. I have learned myself a bit of Fortran recently, just for fun, out of fascination. And I have also written Delphi Pascal and VB in my life. It's all either 1 based indexing or you can choose your own array bounds when declaring the array. But I think the C family languages made a good choice here. I really prefer the technical and mathematical correctness of the 0. 1 based counting is just nice for humans in daily life. Lua is a much younger language by the way, a lot newer than C for example, but it clearly choose to follow the old programming languages.
@Hobbitstomper
@Hobbitstomper 4 ай бұрын
In the late 90s, my teacher explained like this: "Don't think of indexing as regular counting. Think of the numbers used in indexing as symbols. Instead of numbers we could have used letters starting with A to Z and then AA to ZZ etc. just like in columns in spreadsheets. However since offset calculations need to be done under the hood to access specific parts of the array, the symbols A-Z would eventually need to be turned into numbers anyway. That is why it's more efficient to just use numbers in the first place. The reason we start with zero as a starting point is, because we want to use as many different symbols as possible using non-negative numbers, so we don't want to waste the symbol zero. Hence we start with the symbol zero. Historically this has its roots in memory addresses, where the lowest memory address also starts with zero, for the same reason, to use the lowest possible non-negative symbol. Because memory addresses already use zero-based indexing, it makes calculation of memory addresses and offsets more efficient if the array also starts with zero indexing. Additionally it aligns with mathematical concepts and simplifies certain algorithms and calculations." I always liked this way of thinking about it. It helps get over the confusion of thinking of indexes as regular counting.
@psyience3213
@psyience3213 4 ай бұрын
i dk i mean it's not a symbol anymore than 1 represents the abstract idea of a singular thing. It seems like a way of thinking about it that is wrong, but i guess could still help you use it correctly? The symbol is the variable for the array you're using which represents to beginning of the block of memory, and the subscript/index represents how many of, the type that array holds, you're adding to the beginning of the block. Like if you have a ruler with 10 inches on it, if you wanted to access the first inch of the ruler you would start at 0 and go up to 1, you wouldn't start at 1, 1 is the start of the second inch.
@RandomGeometryDashStuff
@RandomGeometryDashStuff 4 ай бұрын
I just think index as how many elements to skip
@gezenews
@gezenews 4 ай бұрын
Yeah the problem with this discussion is you could make them different fruit loop flavors and I wouldn't give a shit. These things are iterated over and if you screw up I can't think of a more obvious place than in an array index.
@javierRC82857
@javierRC82857 4 ай бұрын
It was a Performance convention, ok. Any other reason it's wrong
@NickMak-m2c
@NickMak-m2c 4 ай бұрын
It seems really dumb to me, whether I'm used to it or not. The fact that I always have to minus everything by one when I want it to equal the number of list items there are is unintuitive. I understand that the address in memory iterates over bytes or whatever (address 123 + 8 * 0 = 123, address 123 + 8 * 1 = 131, and so on...) and so the first address has to equal the actual number where the list starts if it's not a linked list (123 in this case), you don't need the interface to show that. Nothing else in the representation of the machine code is that close to the actual machine code, why should positions in an index? It should work like everything else does, first item, second item, third item, fourth item... And then in memory 123 + 32*0, 123 + 32*1, 123+32*2, 123+32*3
@TomMcGuire
@TomMcGuire 4 ай бұрын
I started my programming with Lua, starting at 1 made so much sense to me starting out UNTIL I dealt with time. Hours are 0 - 23 so I constantly had an off by 1 error which flew under the radar for about 3 weeks until I started running everything together. Threw me through a loop and I really see both sides of the argument from this.
@ElesharVermillion
@ElesharVermillion 2 ай бұрын
Because a clock measures an *offset* from the midnight. You don't really have "hour 0", you always have "hour 0 something". It's like the ruler measuring distance. All these are offsets, not indexes. But if you were to iterate over each hour, you would start by 1, meaning the hour *running* from 00:00 to 01:00.
@nolanfaught6974
@nolanfaught6974 4 ай бұрын
In mathematics, it's possible use any partially ordered set as an index. With this in mind, it's clear that the superior option is to index arrays using the space of Lesbesgue-measurable functions. Anyone espousing the value of integer-based indexing is clearly unable to appreciate the beauty of being able to index uncountably many things and is categorically wrong in every conceivable way
@drdca8263
@drdca8263 3 ай бұрын
What’s the poset you are defining on measurable functions?
@nolanfaught6974
@nolanfaught6974 3 ай бұрын
@@drdca8263 ordered using the L2 norm over a subset of R^n
@kjdavid
@kjdavid 4 ай бұрын
How old were you when you were just born? 1 year old? No. 1 month old? No. 1 day old? No. But you are in your first year, first month, first day. That is how I interpret this 0 indexing vs the first element.
@milanstevic8424
@milanstevic8424 3 ай бұрын
This is the correct analysis. Yes you can say that you're in your first day, decade, heck even your first life, this is because your index is below the limit. Counting actually works like this: 9 belongs to a first grouping of ten, while 10 belongs to a second grouping of ten, which by extension means that 0 belongs to a first grouping of ten. This indicates that 0 should be the natural start for counting, it's just skipped because we humans are sloppy. Here's another argument for our sloppiness, let's say we count all the numbers that belong to a second grouping of hundred. There are a hundred of them going from 100 .. 199, so there are exactly one hundred natural numbers in this set. However in the first grouping of hundred, there are only 99 natural numbers, because 0 is excluded. Makes very little sense. We also do this for the millennium counting which is sad, because years stubbornly begin at 1 AD, year 2000 is included in the 2nd millennium. But check this out: the "80's decade" is officially set to be the interval between January 1, 1980, and December 31, 1989. That means that the 90's began at Jan 1, 1990 and ended in Dec 31, 1999, HOWEVER the 21st century began on Jan 1 2001. This makes VERY little sense. We are sloppy to the bone.
@spacelem
@spacelem 3 ай бұрын
@@milanstevic8424 "This indicates that 0 should be the natural start for counting." It is though. If there are 0 things, we say there are 0. If there's 1, we say there's 1. When we have 1 thing, that is the 1st thing. If all the things line up in a row, the first thing in in position 1. There is no position 0, because says there are 0 things (e.g. a race is yet to be completed). There's nothing sloppy about it. In other words, you can absolutely count 0 things, but you can't give the position of a 0th thing, because there isn't a thing to assign a position to. As for dates... the interesting thing about 2000 was all the digits changing. 2000->2001 was a regular single digit change, which was boring. 80s are any date matching xx8x, this millennium is any date starting with a 2. We didn't call year 1 year 1 until years later anyway. Plus if you switch to the Holocene calendar, we account for an additional 10 millennia of human history, and this is the year 12,024, and before the year 10,001 (1 CE) was 10,000 (1 BCE). It's all approximate and arbitrary, so just enjoy the digits.
@porky1118
@porky1118 3 ай бұрын
​@@milanstevic8424 I think it comes down to the distinction of ordinal and cardinal numbers. Ordinal numbers (first, second, basically indices) should start with zero. The offset from the start. Cardinal numbers (1, 2, 3, basically counts/quantities) should also start with zero. But zero in this case means no elements. An array of length 0 doesn't have an element 0. And ranges should be inclusive at the start and exclusive at the end. And these should probably be different types, too.
@milanstevic8424
@milanstevic8424 3 ай бұрын
@@porky1118 Here's a trick question: if we know that the year 2000 belongs to the 20th century, to which decade of which century it belongs? It can't belong to the first decade of the 21st century (2000-2009), because it doesn't belong to the 21st century by definition. It can't belong to the last decade of the 20th century, because the 90s run from Jan 1st 1990 to Dec 31st 1999. Such a conundrum.
@porky1118
@porky1118 3 ай бұрын
​@@milanstevic8424 What's tricky about that? It obviously belongs to the 21st century (1-based). If there is a definition which doesn't put the year 2000 into the 21th century, it's just not such a good definition.
@Exilum
@Exilum 4 ай бұрын
That end speech should've been an entire video. Got me real emotional. Those people that skipped the end really missed something.
@ebmpinyuri
@ebmpinyuri 4 ай бұрын
It's actually the best part arguably
@Exilum
@Exilum 4 ай бұрын
@@ebmpinyuri I think it's definitely worth having its own video. The thing is a lot of people skipped without knowing that, because when it reached the end of the react and he started talking about something else they just clicked on the next video, unaware of what was to come.
@abenezerteshome520
@abenezerteshome520 4 ай бұрын
@@Exilum ​ @Exilum I even recorded that portion from the live stream , it's very impotant life lesson for a programmer
@skaruts
@skaruts 4 ай бұрын
Two crucial mistakes in his reasoning: first, he confused indexing with counting, and second, he completely neglected to consider that indexing math only works with 0-indexing. People often make these two mistakes. Let me explain: An array of 10 elements will still have a *count* of 10 elements (10 loop iterations) regardless of whether it's indexed from 0 or 1. Indexing and counting are very different things. The "first element" is a count, not an index. Index 0 points at the first element. The only thing that guy got right was the statement _"that's what "indexes" do: they point at things"._ But then he failed to realize that "counts" don't point at things, and are not the same thing as "indices" (the plural is "indices", not "indexes"). This mistake nullifies almost every argument he makes, because they're based on this premise that he got wrong. And what programmer doesn't think about indexing math? Indexing math (converting an index to X and Y coordinates and vice-versa) is what you use to access an element in a 1D array that represents for example a tile in a 2D grid of tiles for an RPG, or a voxel in a 3D chunk, or a cell in a 2D text buffer, or a quad slot in a data structure for sprite batching, etc, etc. Indexing math dictates that, even if your language is 1-indexed, many of your arrays *have to* be indexed from 0, or else the math won't work. In practice, you can have every array indexed from 0, but you can't possibly have every array indexed from 1 (which causes some problems in 1-indexed languages). And man... that "index finger" argument is just absolute nonsense. It sounds like a desperate attempt at having one more flimsy argument. Speaking from experience, though: I love Lua like no other language. But it's because I've been using it for some 5 years that I can say that 1-indexing is a perpetual rock in the shoe. It's not a deal breaker because Lua is otherwise an excellent language, but it only brings problems, error proneness and traps: - it expects loops to go from 1 to limit (inclusive), and so whenever you need 0 to limit-1, you have to not forget the explicit -1. This requires some extra attention to what you're doing, lest you forget it. - you need to be extra careful about using certain language tools, like *_ipairs, #_* or *_table.insert()_*, because they won't work with 0-indexing. - the language creates 1-indexed arrays by default, and you can't run away from it. This makes your code inconsistent, such that you have to pay extra attention to not get your index variables off by 1, or if you're using them across multiple arrays with different indexing, etc. - utility functions that deal with arrays are harder to make/debug, because you never know what users will throw in them, so you have to account for 0 and 1 base. Or if you don't account for that, then your functions won't work for every use case where they'd be needed. - you'll perpetually have to be considering when to let the language have it's way with arrays and when not to. And sometimes you'll get it wrong and have to waste time re-writing some code. - it's harder to port code to and from 1-indexed languages because you'll have to be extra careful to not break the algorithm you're porting by allowing 1-indexed arrays in it. And then if the algorithm doesn't work, you'll have extra stuff to double-check with extra attention. There's just no world where 1-indexing is the sane option.
@epiphaeny
@epiphaeny 4 ай бұрын
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).
@bgdgdgdf4488
@bgdgdgdf4488 Ай бұрын
I mean I think when you spent 10 seconds programming, 0 based feels perfectly natural to you
@filipenicoli_
@filipenicoli_ 4 ай бұрын
As comp.sci people would say: "There are 2 hard problems in computer science: cache invalidation, naming things, and off-by-1 errors." Coming from a hardware background, it's always worth remembering that 0x0 is a valid address. Also, when doing ASM, some architectures access data by referencing a base pointer with an offset (again, 0 is a valid offset). As C was conceived as some sort of portable assembly, it makes sense for C arrays to be 0-indexed. I believe there's no objectively good or bad approach as long as it has a consistent behaviour and doesn't suffer from performance penalties.
@henry_tsai
@henry_tsai 4 ай бұрын
Except 1indexing suffers inconsistency as soon as you go out of bound. Like if you want to assess the last n item, or if you want to address things prior to first entry.
@Asto508
@Asto508 4 ай бұрын
@@henry_tsaiWith 1 indexing, the last item on an n array, is literally array[n] and accessing elements outside the array is something that's pointless to begin with. If you're relying on hacks using this, you're doing it wrong.
@henry_tsai
@henry_tsai 4 ай бұрын
@@Asto508 See, the last (1) item is array[n] in 1 indexing, instead of array[n-(1)] in 0 indexing. Or if you want to access the last third item, it would be array[n-(3-1)] instead of array[n-3], 0 indexing is more straigh forward. (python outright allow you to access the last nth item with array[-n].) Also, if you're describing something in real life with an array, like date, and later on you need to expand the span of interest, you would find the ability to address out of bound elements really valuable.
@mek101whatif7
@mek101whatif7 4 ай бұрын
How does one end up working in hardware?
@filipenicoli_
@filipenicoli_ 4 ай бұрын
​@@mek101whatif7 You can try getting into FPGA or Electronics Engineering. What I meant was, based on my knowledge about hardware, 0-indexing makes sense, and it's not even because of memory availability.
@spectrecular9721
@spectrecular9721 4 ай бұрын
RAM traditionally works in 0's and 1's to indicate whether or not voltage exists. I always just figured the concept of 0-based indexing originally stemmed from this, because 0 would indicate the first of two existing options and is the default when there is no power
@-Kal-
@-Kal- 3 ай бұрын
Exactly! I got into programming with electronics and microcontrollers. 0 is the obvious number to count from in hardware. I do mostly high level stuff now. Maybe if I got started with high level I would think differently, but when I try to 'think like a computer' I start counting from 0 and 1 based indexing is annoying af. Thinking of the 0 as an offset is probably the best way to go about it.
@josefjelinek
@josefjelinek 4 ай бұрын
In "How JavaScript works" book Douglas Crockford introduced "zeroth", "wunth", "twoth", "threeth" as a clear indication and disambiguation of the indexing (does not help with fourth and on, but at that time it should be clear what is going on). He also did a survey and analysis of all known arguments for 0 vs 1 start index and it came out inconclusive in the end...
@Saiphes
@Saiphes 4 ай бұрын
If you start counting seconds, and you go "1, 2, 3" and stop, you'll have counted 2 seconds. My son counts from 0 (where it is) for knight chess moves too.
@brandongregori995
@brandongregori995 4 ай бұрын
That's why people count Mississippis. It makes no sense to stop at just 3 without the Mississippi part
@brandongregori995
@brandongregori995 4 ай бұрын
Also cadence as well. But it's a benefit when using a cadence to counting the current number of seconds
@Thurrak
@Thurrak 4 ай бұрын
That's only assuming that 0 has to be said to be considered. You could easily assume that you were counting from 0 but didn't say it because it's irrelevant to the purpose of what you are trying to do. When you say 5 you don't say 5.00 or 005 because the 0's are irrelevant.
@brentlio5578
@brentlio5578 4 ай бұрын
Depends on where people think every number system starts. The starting of a timing system is 0. The starting of a counting system is also 0. The start of referencing system is going to be 1. Because if the size of a referencing system is zero, then there is nothing to reference to, whereas timing and counting can have a size of 0 if it hasn't started or progressed enough for their first cycle.
@ValentineOficial
@ValentineOficial 4 ай бұрын
If you're counting seconds, it's easier to count downwards (3, 2, 1, 0) because you'll intuitively include zero as the stopping point
@AlwaysSunny-qu5zp
@AlwaysSunny-qu5zp 4 ай бұрын
First element is at the address you have, the index is just used as offset, so you get the first element with offset 0. This is the root of why the first element exists at index 0. If we'd have called it 'offset', and you would dereference your array providing an offset, would you accept that providing offset 0 yields the start of the array, which is the first element?
@hoppy6437
@hoppy6437 4 ай бұрын
Offset isn't the same thing except at 0. Offset 1 isn't the second element of the array, that's at offset 1 * sizeof(element). Offsets are more natural to a computer, and indexes are more natural to a human. Offsets are going to be awkward anyway, why not make indexes more intuitive for programmers?
@jsonkody
@jsonkody 4 ай бұрын
yep, finaly someone. Offsets are better for computer but indexes for people. Higher level langs should have 1-based indexes. Lower level langs like C make perfect sense for offsets because they work with memory. Also there may be the case of using offsets AND indexes in same language - Rust has also higher level concepts next to low level stuff. It's still compiled so indexing could be transformed to offsetting when elements have same size.
@AlwaysSunny-qu5zp
@AlwaysSunny-qu5zp 4 ай бұрын
@@hoppy6437 Where did I say that the offset must be one byte to get to the next element? And if I have a typed pointer, and increase it by 1, the pointer moves to the next element, because the size of the element is taken into consideration. Are you imagining a byte pointer to region of contiguous memory of otherwise typed elements that you increase by one, and then tell me that's wrong?
@AlwaysSunny-qu5zp
@AlwaysSunny-qu5zp 4 ай бұрын
@@jsonkody If the language truly creates an array (contiguous memory), it is very likely that the index involves yielding some offset internally (or otherwise it just pretends to provide an array - but an array is usually chosen because of their advantageous contiguous layout). I can agree a 1-based index could be a viable choice, though we've also had issues with the difference between 0-based and 1-based systems and so I also feel some advantage if it's just always the same.
@themetadaemon
@themetadaemon 2 ай бұрын
He's right. 1-based indexing is not only more natural, but it opens up the opportunity to store the count of items in the array at position 0. The perfect implementation.
@abauchu
@abauchu 4 ай бұрын
Those feels at the end... Thank you Prime for thinking with us about technical stuff, having fun while doing so, AND being a great human being. At least that's what I can see from your videos. Thanks for sharing your life's journey from time to time with us, and thanks for your sincerity, we need more of that on the internets
@upsidedownChad
@upsidedownChad 4 ай бұрын
Yooooooooo that Brazilian shirt is fire 🔥🇧🇷
@nyahhbinghi
@nyahhbinghi 4 ай бұрын
it is :)
@FinalEyes777
@FinalEyes777 4 ай бұрын
Programmer with a heart and a soul and able to share that? You're somethin special primetime. Glad to have found your channel which has indeed been inspiring me to keep trying.
@TheSoulCrisis
@TheSoulCrisis 3 ай бұрын
Agreed was so touching man.
@Yupppi
@Yupppi 4 ай бұрын
You know what's crazy? When talking about physics, we have so many things starting at x=0 when we make graphs out of data or phenomenon. So our first point is always at 0.
@xennial7408
@xennial7408 3 ай бұрын
Yes. 0 is where we are, so it's actually wrong to call an array index an index. The first block in memory is 0 steps away from the array start. Yes, that's programmer thinking and yes, you should have that thinking when programming. However, high level programming languages, that do not require memory / pointer operations, it's more non-tech human readable.
@kc3vv
@kc3vv 4 ай бұрын
If the origin address of an array would just be stored as the -1 address. Then accessing each element would still be one addition. Ofc this has the disadvantage of figuring out what to do with the first bite. Maybe we could have an array end pointer there or some other useful metadata.
@dany_fg
@dany_fg 6 күн бұрын
I like to think of this as the line of non negative numbers (0+) that you start at 0 and every entry added is 1 unit away from the 0 position, so it's a relative position.
@pweddy1
@pweddy1 4 ай бұрын
The notion that he is advocating for data not being stored contiguously means he wants to get cache misses as he reads enumerated data.
@aoeu256
@aoeu256 4 ай бұрын
Will computers in the future have the same kind of caches and centralized memory like von-neumann's 1945 model? I think we are going to go for a more "networked" model where cpus and memory are joined together in a network like in a cellular automata...
@Forty8-Forty5-Fifty8
@Forty8-Forty5-Fifty8 4 ай бұрын
​@@aoeu256 I was under the impression that von Neumann architecture has been the status quo since forever? What problem would this hypothetical networked model solve that cloud computing doesn't already do? It sounds like it would be an expensive to develop model that would not financially benefit the companies who are supposed to design it.
@NickMak-m2c
@NickMak-m2c 4 ай бұрын
No he is arguing for the representation of it, how much of what you program input into the machine level is what you entered? Unless your IDE is full of "001001110010100011101000110100" I'm going to guess very little. It's a matter of translating human-sense to machine-sense, and it is not really at all helpful for the human, in a high-level programming language, to remember the bytes are incrementing via multiplication with the index number.
@robmorgan1214
@robmorgan1214 4 ай бұрын
Count and index are different integer types... however, I'm a physicist. we invented the concept of potential... when you are forced to do calculus for a semester on your pointers before you even get to take the math classes that cover the prerequisite concepts I'll sympathize with this perspective. I wake up every day of my life off by one and bump into everything until the coffee and training kicks in.😂 Oh...and BTW iterators are the devil. Historical note: for several algorithms in memory limited numerical computations, it is sometimes significantly more efficient and faster to do computations in the address space rather than on the data itself hence we retain the choice of zero based indexing for these purposes. Symmetry about a zero index becomes an important mathematical property here.
@dasdos002
@dasdos002 4 ай бұрын
In physics, the “initial value” is indexed with 0 not 1. We say, “x naught” (x_0 or x[0]) because that’s where we START. It’s an indexing convention NOT a counting convention. TJ’s points about indexing and counting are moot point.
@Becoming-Human
@Becoming-Human 4 ай бұрын
In my opinion, one of the strongest arguments for 1 based indexing, at least in Python, would be the following logic, "In Python, if negative indexing starts at -1, then why _wouldn't_ positive indexing start at 1?"
@shaggygoat
@shaggygoat 4 ай бұрын
But Python negative indices aren’t able to address the end of the array so the last three single-element slices of array A would ideally by A[-3:-1], A[-2:-1], A[-1:0] but as zero is interpreted to mean the beginning of the array (so that the first single-element slice is A[0:1]), A[-1:0] has to be replaced with A[-1, len(A)] or A[len(A)-1, len(A)]. (Just as graphics coordinates typically address pixel edges instead of pixel centres, Python and C address element and slice boundaries.)
@Starwort
@Starwort 4 ай бұрын
Negative indexing actually starts at ~0 Also, adding one to a negative index gives you the next number in the sequence (wrapping around the end if necessary) - why should there be a hole in the valid indices at 0
@porky1118
@porky1118 3 ай бұрын
I could answer the question: The simplest way to implement negative indexing would be this: value = array[mod(index, array.length)] If you implement it like this, the first element wold still be 0, and the last element (using negative indices) would be -1, just like it usually is now. So that's why negative indexing starting with -1 is rather an argument for positive indexing starting with 0.
@titfortat4405
@titfortat4405 3 ай бұрын
This is actually a reason to start non-negative indexing at 0 if you think about how modular arithmetic works and how arr[-1] gives you the value arr[length-1]. But that's not just my opinion, that's the reasoning behind the python syntax/semantics.
@JoeJoeTater
@JoeJoeTater 4 ай бұрын
So, I learned a lot of math before I got into coding. In math, you just explicitly say what your starting index is each time, because sometimes it's more convenient to start at -1, 0, 1, 2, whatever. (In more advanced notations, like Einstein index notation, you don't even say what your starting/ending indices are. You work with placeholder indicies that each imply a loop over the entire range.) So, I think there's a lot of merit to the variable-first-index thing. I've written a lot of R, which is 1-based. Honestly, I ran into fewer off-by-one errors in R. Though, I think a lot of that is due to how R allows you to avoid using loops and explicit indices through vectorization. I think that's the real takeaway. Whether it's through vectorization, iterators, or whatever else, avoiding explicit loops is a good idea.
@DarkerStarSword
@DarkerStarSword 4 ай бұрын
Easy solution, just declare a map like this and use it to convert English to indices: {"first": 0, "second": 1, "third": 2, "fourth": 3, ...}
@therainman7777
@therainman7777 3 ай бұрын
And ~double the syntax needed every time you need to index into a collection for any purpose?
@DarkerStarSword
@DarkerStarSword 3 ай бұрын
@@therainman7777 Did the sarcasm really escape you?
@jordanhildebrandt3705
@jordanhildebrandt3705 14 күн бұрын
This is nightmare fuel 🤣
@tedlava
@tedlava 4 ай бұрын
When a baby is newly born, we don't start counting their age as being 1 year old immediately when they come out of the womb. All the age counters for every unit of time start at ZERO intuitively!! A recently born baby would be something like 0 years, 0 months, 0 weeks, and maybe 3 days old... However, it's common in human languages to omit saying the units that are currently zero, but they are still there and we all know mathematically that they are there.
@lucassatie
@lucassatie 3 ай бұрын
Except some cultures do start counting age at 1 from the moment of birth. Which I think is the problem: it's all about subjective perception. When I reference an element in an array, I prefer to reference it by its cardinal position so I prefer indexing at 1(e.g. "the first element"). But if you prefer thinking about it as an offset, then it makes more sense to start at 0 (e.g. "count of elements beyond the starting point").
@sillymesilly
@sillymesilly 3 ай бұрын
@@lucassatiedont care. Most countries start from 0. Because before you move the distance you start with is 0. It is not subjective, the baby did live for one year outside of the womb. A man standing did not travel 1 of any distance by standing.
@TPF00T
@TPF00T 3 ай бұрын
@@lucassatie The countries that start counting at 1 do so because they are counting the baby's age from conception. Presumably, they didn't know that it was exactly 9 months or they decided to simplify it. Keep in mind these countries also have their entire population get 1 year older every New Year, so they aren't exactly counting it mathematically anyway. It's just formality.
@lucassatie
@lucassatie 3 ай бұрын
@@sillymesilly dont care. You're explaining what an offset is which I already said makes sense to start at zero. A man standing did not travel 1 of any distance, but a man at the head of a queue is not 0th in line. Offset != position.
@cheerpoasting
@cheerpoasting 11 күн бұрын
Most of Asia starts as 1 and you turn 2 on new years
@Ninakoru
@Ninakoru 4 ай бұрын
If you think of it in a continued way (a simple ruler), makes sense, you start at 0, and at 1 you start with the next. The zero-based index always made sense for me, the only time I feel lightly challenged mentally is accessing a position of a string.
@Pyrosublime
@Pyrosublime 4 ай бұрын
true but when using a rule to mark lines for saw cuts for example 0 is at the edge of the time not the first marking point, in your case you would need a rule that starts at -1 so you can mark 0 as the first measure. Essentially its about how each person sees it and wants to use the scale and what makes sense to them. Looking at a 48 port network switch that starts at port 0 is trippy and having to explain to a trainee or management the documentation of why its port 0 and not port 1 is very challenging.
@mskiptr
@mskiptr 4 ай бұрын
@@Pyrosublime I have the exact opposite experience. It's so confusing whenever stuff is numbered from 1 and swaps to the next column | row | page at 11, 21, 31 and so on
@DF-wl8nj
@DF-wl8nj 4 ай бұрын
@@Pyrosublime It shouldn't be challenging at all. "Why does it start at 0?" "Because that's how the company made it". Conversation over.
@thomasslone1964
@thomasslone1964 4 ай бұрын
i think the concept is that the first item of the array should be the most often access item and with 0 in many script languages you can just not pass a value so it becomes nil which is treated as zero, also 0 is a number why not use it and have one more value for the maximum possible array size
@xpusostomos
@xpusostomos 4 ай бұрын
0 index is easy to think about the first position, but hard to think about the last character (n-1)
@meowrbius
@meowrbius 4 ай бұрын
Those who didn't watch the whole video, please don't skip the last 5 mins. It's the greatest life lesson from Prime ever. Clip that part and save it on your device. Everyone needs to remember that advice forever.
@gregdawe2786
@gregdawe2786 2 ай бұрын
We need to protect you at all cost. Like Prime , you just seem like such a good dude. I know you've made mistakes but as you point out in this video, thats what makes you better. Youve taught me so much and made me better AND provided lots of entertainment. Thank you for being THE PRIMEAGEN ♥️
@awesomedavid2012
@awesomedavid2012 4 ай бұрын
The problem is, he criticizes us for not liking 1-based indexing because it isn't familiar to us. Then he argues that 0 based indexing is bad because it isn't familiar to how we talk about ordinal numbers.
@dabbopabblo
@dabbopabblo 4 ай бұрын
The moment I realized he was doing a live reaction to a video during a talk I died laughing, this is way too meta😂😂☠
@xpusostomos
@xpusostomos 4 ай бұрын
A good programming language will never make you think about indexes, but when you insist on it, you choose the indexing, bottom and top value.
@juliencortes2666
@juliencortes2666 Ай бұрын
Base 0 : I can speak your language machine, don't worry. Base 1 : Machine, speak my language please. Hypothesis : the smarter one is the one that succeeds to speak both languages.
@OhMyShad
@OhMyShad 2 ай бұрын
Man! The final quick speech was something else, it went beyond work, skills, salary and bring us to the essence of why we push ourselves into this complex field! Being excellent but losing yourself in the long run is actually loss. Always keep in mind the people around you ❤
@asaad1022
@asaad1022 4 ай бұрын
When you enter a building and go up, do you start from the ground floor or the first floor?
@SandraWantsCoke
@SandraWantsCoke 4 ай бұрын
I live in a basement
@kirkanos771
@kirkanos771 4 ай бұрын
the ground floor, because in Europe we dont count floors, but stages. It's a NA perception i guess. But like imperial units, everything from NA is dubious.
@iraniansuperhacker4382
@iraniansuperhacker4382 4 ай бұрын
@@kirkanos771 its Europes fault really. All the retards you guys kicked out had no where else to go so they came to America. Compound that over 300 years or so and you got stuff like the imperial system
@kirkanos771
@kirkanos771 4 ай бұрын
@thetukars The second one. 0 is the engine. xD
@shaggygoat
@shaggygoat 4 ай бұрын
Americans count floors starting at 1 at ground-level but British count floors starting at 1 one storey above ground, which used to be just dirt and indoor farm animals. (The British system would fit nicely with −1 being the first floor underground.)
@FlyingOctopus0
@FlyingOctopus0 4 ай бұрын
By writing "-1" when you index, you can use 0 based indexing lika a 1 based indexing. Like this arr[3-1].
@therainman7777
@therainman7777 3 ай бұрын
lol did you really just share this as an insight? 😂 Sorry, not trying to be a jerk but it’s just kind of funny
@orthoplex64
@orthoplex64 4 ай бұрын
Subscript vs index is a distinction without a difference. EVERY realistic time that you need to do some amount of arithmetic to compute an index, 0-based requires no additional math, and 1-based requires subtracting 1 at the beginning and/or adding 1 at the end of the formula. The preference is not baseless dogma. Lay intuition and ease of accessing last element are the only benefits of 1-based indexing, and they're not much. In real world code, the times you need to specifically access the last element are few and far between, and programmers usually quickly develop a separate 0-based intuition.
@pedrosolorzano6020
@pedrosolorzano6020 5 күн бұрын
I remember trying to explain to my brother that when someone counts to 10 seconds, it's wrong to say "1, 2, 3..", if you do it that way, by the time you reach 10, you will have counted 9 seconds, you have to start at 0 to count 10 seconds ("0, 1, 2, 3..."), just like a timer would.
@RogerValor
@RogerValor 4 ай бұрын
My first language after basic was pascal, and it had 1-based string indexes, so most of the time you would define arrays as 1-based as well array[1..100] of integer it took me a long time to learn 0-based indexes, or the fact range() returns length-1 as maximum. for the for loop the only difference is, whether you use < or
@RenderingUser
@RenderingUser 4 ай бұрын
TJ the type of guy to say he's 6ft when hes actually 5 cause he like to start from 1
@jongeduard
@jongeduard 4 ай бұрын
Or just take the elevator, which is like an iterator. It brings you to the right floor without having to walk every step yourself.
@billeterk
@billeterk 4 ай бұрын
But you need to know which number to press
@jongeduard
@jongeduard 4 ай бұрын
@@billeterk Yeah, iterator analogy kind of stops there indeed. :P
@PasiFourmyle
@PasiFourmyle 4 ай бұрын
Thank you for sharing your wisdom and motivating words! 👏👏👏
@wojciechbojewski9442
@wojciechbojewski9442 4 ай бұрын
0-indexing is right for C, and optional for other languages (base of the legend of C - php, python and others). You don't teach kids counting from 0, as well as you don't teach a kid's poinmter's arithmetic in C.
@thomasmaughan4798
@thomasmaughan4798 4 ай бұрын
"You don't teach kids counting from 0" This becomes a challenge when you introduce the zero as the fulcrum of a number line. Now suddenly "1" is not the first number; in fact, on a number line there is no first number.
@bgdgdgdf4488
@bgdgdgdf4488 Ай бұрын
Maybe we should teach counting from zero. I mean when you start counting with one, you actually count 1 second too much. Because when you start saying "one", zero seconds have passed.
@James_D_Bartlett_III
@James_D_Bartlett_III 3 ай бұрын
Man, that took a hard left turn from a purely technical talk to passionate advocacy for self-care and spending quality time with your loved ones... And I am 100% here for it. Zero notes.
@thunder____
@thunder____ 4 ай бұрын
The way I've always conceptualized it (even before learning C, but learning C has only reinforced this) is that the index doesn't point to the data itself, it points to the space before the data. As anyone who knows C knows, the index is the number of elements to be skipped over to get to the memory address of the one you want. This also explains why things like string slices are non-inclusive; when I was first learning PHP, I was confused about why something like $string[0:5] wouldn't include the 6th character in $string when that character exists at index 5, but when I started thinking of it existing AFTER index 5, it immediately made total sense. It was a little bit of a learning curve, but with the thought process of looking at an index as the space between elements, I find it very easy and I don't even want to consider using a language like Lua, even if it has the endorsement of John Romero, someone I greatly admire.
@IdeaToGame
@IdeaToGame 4 ай бұрын
yo Brazil mentioned!!! suddenly caralho
@lookingforluck
@lookingforluck 4 ай бұрын
live reactions is wicked work
@softwaretechnologyengineering
@softwaretechnologyengineering 4 ай бұрын
No Hood. Unsubscribed.
@atomicman007
@atomicman007 4 ай бұрын
I had a class on this in college 2 semesters ago. This addition-asterisk-address magic actually makes sense (it's not magic, I get it) and it blew my mind that a[i] is same as a + i. One more thing was blown away recently, my eardrums while watching this video. Cheers
@ZenoDovahkiin
@ZenoDovahkiin 4 ай бұрын
"How do we show 1? With our index finger, what a coincidence!" -Anglos not understanding that there are cultural differences and the whole world doesn't work like their home town, exhibit 572984. There are lots of different ways different people count on their hands, including starting with your thumb (e.g. Germany), curled fingers being the "active" ones rather than the straight ones, and even counting using knuckles instead of whole fingers.
@user-cx5jj2yv3p
@user-cx5jj2yv3p 4 ай бұрын
Gigachad ending
@sk-sm9sh
@sk-sm9sh 4 ай бұрын
No because sometimes you just don't want to iterate the array in sequential order you want to build your own order of iteration. For instance maybe you have 2d matrix and you are iterating in a spiral that starts at center.
@mugiseyebrows
@mugiseyebrows 3 ай бұрын
In programming, we typically use an index to access elements in an array. The index represents the position of the element within the array, starting from zero. For example, if we have an array called `myArray` and we want to access the third element, we would use the index `2` (since arrays are zero-based). Although subscripts are sometimes used interchangeably with indices in programming, they are more commonly associated with mathematical notation or chemical formulas rather than array access. C spec is confusing by design because it was writen by dorks.
@phillipjoyce8825
@phillipjoyce8825 4 ай бұрын
A good practical example is age, 0 is your first year. Age points at the end of your year not the start A technical example is rendering textured polygons. The top left corner of your map is 0,0. If you're saying "get me that first texel" then you need to sample from texel (0.5,0.5) or else your sample is filtered with its neighbours. 0 points to the start of each item. 1 points to the end. If you want unambiguously the first item that's 0.5
@wtrflsh
@wtrflsh 4 ай бұрын
We start at 1 in our uni's pseudocode. Had multiple calculation issues because the range was always offset the first time. The advantage of 0 is it has no effect in algebra. You can do checks that - if the pointer is not moved(i.e. pointer value has no effect), it should still be at the start.
@minastaros
@minastaros Ай бұрын
Watch the byte: it absolutely makes sense that the last 8-bit number is 0xFF, therefore 0x00 the first that fits in a byte. Can't make a byte where the first value is 0x01 and the last 0x100.
@ChannelSho
@ChannelSho 17 күн бұрын
My mindset of 0-based making sense is because when you're addressing a memory location, all of the lines being logic 0 is still a valid memory address. And it doesn't make sense to call it address 1 when the physical value is 0.
@neshrammc
@neshrammc 4 ай бұрын
The difference between ordinals, indexes, and offsets. (Words are tricky; e.g. is an offset essentially an index, or is it the product of an index and some stride, or something else; your mileage may vary.) As for a real-world example of starting at 0: I have on many occasions, in many different places, seen elevators where the ground floor is labeled as "0".
@HarshColby
@HarshColby 4 ай бұрын
Crestron designed a bastardized language (SIMPL+) where arrays are 1 based, but if you say 0, it gives you the same element as index 1. When they were explaining this language to me, I just looked at the instructor and asked if they really use this language. Don't get me started on their "symbolic" representation (SIMPL) where they misuse and redefine a whole host of existing computer software terminology.
@pqnet84
@pqnet84 4 ай бұрын
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.
@treidex
@treidex 3 ай бұрын
this ^
@liviousgameplay1755
@liviousgameplay1755 12 күн бұрын
That 2nd to last problem is definitely a big thing that confused me when I started. Going from 1 to 0 was an easy jump, but doing it from the end of a length of something was more difficult, especially since sometimes you do -1 and sometimes you don’t.
@sercan9791
@sercan9791 4 ай бұрын
As someone who has fucked up in life and now is trying his hardest, I really appreciate you man. Knowing that you also made a bunch of mistakes before getting where you are gives me hope for my own future.
@stevenpike7857
@stevenpike7857 3 ай бұрын
Zero index is because of the binary nature of the computer. If it's 8 bits, for example, you start the position with all switches off: 0000 0000, and then increment by one: 0000 0001, 0000 0010, 0000 0011.... and so on. Moresoe, if you are accessing an array in memory, and it's starts at memory address 1001 0110, you simply add the index number to get your location of the data. First position is at 0000 0000. Want the second one? -- add the index 0000 0001 to the address to get it.
@TheBswan
@TheBswan 4 ай бұрын
"I had my head really far up index zero", and "I can only lose time from here on out," are hilarious and sobering respectively. This was a really nice talk. Thanks Mr. PrimeTimeagen
@rodionbykov
@rodionbykov 3 ай бұрын
In Adobe Coldfusion you have 1-based index and it plays nicely with 'find element in array', 'find occurrence in a string'. If not found, function returns 0, which can be interpreted as false. No need to play with -1 or some other tricks, 0=false, that's it.
@defenestrated23
@defenestrated23 3 ай бұрын
A great argument for 0-offset notation is languages that allow indexing from the end, like Python. What's the obvious index of the very last element? -1. If you 0-index, the absolute offset is just (length + index). If you have ten things, the last thing is at -1, 10-1=9, array[9]. How do you make this intuitive for 1-indexing? You can't use 0 for the last element, that's insanity, and -2 is the wrong direction, so it's still -1. Now the math is 10-1+1 = 10, 10-2+1 = 9, etc. You are adding 1 just to make up for the implicit -1 from starting at 1.
@jvapr27
@jvapr27 4 ай бұрын
In England the elevator uses zero for the ground floor. In the USA the 1st floor is the ground floor.
@bernardoquina
@bernardoquina 4 ай бұрын
The index of an array is a coordinate relative to the beginning of it. So if you want the very first element you go to the array memory location and add the index offset. It makes perfect sense to use 0 based indexing because the first element will be exactly where the array starts.
@cleptos972
@cleptos972 4 ай бұрын
You are such an inspirational person! Especially the end. Thank you!
@postblitz
@postblitz 2 ай бұрын
It's very easy to imagine a world without 0: - Think about roman numerals. They don't even use 0 as a digit anywhere and have no need to. - Infinity is not a number because it's a weird concept we "tend" toward. So is zero in many, many cases. - Math breaks down when dividing by zero, the only number where this happens. - As a position it makes no sense. The nothing position is a place that is nowhere. Why are you pointing to nowhere? Where is nowhere? Is it anywhere, everywhere or nowhere? Everywhere is someplace. - As a quantity it's the absence of quantity. You cannot multiply yourself out of it because you're taking what you have "nothing" and trying to make more of the same thing. - Incrementing out of the quantity of zero works because you're adding something upon nothing, no matter how much that is. It's very easy to imagine why zero exists also: - when you subtract a quantity with itself and end up with nothing, you do need a symbol to express that because empty space may be confusing.
@AsJimSeesIt
@AsJimSeesIt 3 ай бұрын
I use 0 based indexing outside of programming. When building a wall, you have your first stud at position 0. When planting crops, my first plant is at position 0. We just don't normally think of things in this way, but it is how things work.
@Tephr1te
@Tephr1te 3 ай бұрын
There is already another example of automatically reading/thinking of different numbers - whenever reading a 24 hour clock you see 15 and read 3, or you see 18 and read 6.
The Stockholm Syndrome of SQL | Prime Reacts
31:21
ThePrimeTime
Рет қаралды 141 М.
Why I Quit Copilot | Prime Reacts
35:56
ThePrimeTime
Рет қаралды 318 М.
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17
The Joker wanted to stand at the front, but unexpectedly was beaten up by Officer Rabbit
00:12
Why you're wrong about 0-based indexing
10:23
TJ DeVries
Рет қаралды 28 М.
Yes, we actually won
20:26
Theo - t3․gg
Рет қаралды 228 М.
C Is Not A Language Anymore
34:29
ThePrimeTime
Рет қаралды 225 М.
Scams In Software Engineering
31:44
ThePrimeTime
Рет қаралды 756 М.
Generative AI Has Peaked? | Prime Reacts
40:18
ThePrimeTime
Рет қаралды 223 М.
Is Computer Science still worth it?
20:08
NeetCodeIO
Рет қаралды 172 М.
ThePrimeagen On Running Linux
9:40
Tech Over Tea
Рет қаралды 253 М.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 1,1 МЛН
I Will Piledrive You If You Say AI Again | Prime Reacts
55:59
ThePrimeTime
Рет қаралды 306 М.
You Need Kubernetes?
27:59
ThePrimeTime
Рет қаралды 217 М.
My daughter is creative when it comes to eating food #funny #comedy #cute #baby#smart girl
00:17