You Are WRONG About 0 Based Indexing

Ғылым және технология

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/?promo=PRIMEYT
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-Kinesis
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/deeznuts

Пікірлер: 1 600

  • @MrRobix13
    @MrRobix1318 күн бұрын

    Man doing live reactions, he won.

  • @fus3n

    @fus3n

    18 күн бұрын

    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

    18 күн бұрын

    ​@@fus3n most (all?) of his content is reaction, what did you expect him to do? A circus show?

  • @ciziadevos

    @ciziadevos

    18 күн бұрын

    @@fus3n nobody forces you to stay in the damn room, or on this damn video, if you don't like it

  • @fus3n

    @fus3n

    18 күн бұрын

    ​@@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

    18 күн бұрын

    @@ciziadevos Yes... and i said nothing about him forcing anyone to watch this or be in that room...

  • @ZingsVideos
    @ZingsVideos18 күн бұрын

    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

    18 күн бұрын

    Never thought of it like that. Makes sense

  • @jhny0

    @jhny0

    18 күн бұрын

    very good analogy

  • @mAcCoLo666

    @mAcCoLo666

    18 күн бұрын

    I guess that started with c, c++ and pointers. When you think of items 1 would make more sense.

  • @samuelswatson

    @samuelswatson

    18 күн бұрын

    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

    18 күн бұрын

    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

  • @mgdotdev
    @mgdotdev18 күн бұрын

    Imagine going to a conference in person, to see a speaker lecture in person and still watching a recording

  • @jsonkody

    @jsonkody

    17 күн бұрын

    .. still watching IRL react video :D

  • @ChristofferLund

    @ChristofferLund

    17 күн бұрын

    This format is insane, yet for me on KZread it's exactly the same as it was

  • @jarylsim1973

    @jarylsim1973

    17 күн бұрын

    Conferences? Is that what they call real life Twitch?

  • @blackspitit

    @blackspitit

    14 күн бұрын

    conference? it seems more like a comedian to me. A conference is not with a video.

  • @Lolimov
    @Lolimov18 күн бұрын

    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

    17 күн бұрын

    I felt that ending in my soul man. It was a beautiful message to end on.

  • @ChristofferLund

    @ChristofferLund

    17 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    Damn that ending hit hard and made a great point. Salute to Prime.

  • @joelperpetua3929

    @joelperpetua3929

    17 күн бұрын

    man almost quoting the bible at the end "What will it benefit a man if he gains the whole world yet loses his life?"

  • @catastrophicblues13
    @catastrophicblues1318 күн бұрын

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

  • @NewSchattenRayquaza

    @NewSchattenRayquaza

    18 күн бұрын

    Ma man here is cooking some world peace right here

  • @CEOofCulturalMarxism

    @CEOofCulturalMarxism

    17 күн бұрын

    Or BS

  • @Dekharen

    @Dekharen

    17 күн бұрын

    Whenever I feel bad I go and read the dreamberd specifications 😆

  • @NithinJune

    @NithinJune

    17 күн бұрын

    literally

  • @Sameer.Trivedi

    @Sameer.Trivedi

    17 күн бұрын

    Number line starts at -infinity that's the only correct way of indexing.

  • @tinnguyen5055
    @tinnguyen505518 күн бұрын

    0 base array works great with modulo arithmetic.

  • @spacelem

    @spacelem

    7 күн бұрын

    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

    2 күн бұрын

    I never appreciated 0-indexing until I tried making a circular array

  • @chi_said_hi
    @chi_said_hi17 күн бұрын

    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

    17 күн бұрын

    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

    16 күн бұрын

    ​@thetukars this will make unreadable code.

  • @hobe4576

    @hobe4576

    15 күн бұрын

    ​@@nikitatimaev5297true therefore a must-have feature for ... VBA!

  • @thomasmaughan4798

    @thomasmaughan4798

    15 күн бұрын

    @@DominikPlaylists "and then decide which one is easier." Done! Zero based is easier.

  • @dimitralex1892

    @dimitralex1892

    14 күн бұрын

    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"...

  • @spectrecular9721
    @spectrecular97217 күн бұрын

    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-

    4 күн бұрын

    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.

  • @primbin_
    @primbin_18 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    ​@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

    17 күн бұрын

    (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

    17 күн бұрын

    All you're telling me is that your language is brain dead and doesn't support multiple dimensional arrays natively

  • @beest_
    @beest_18 күн бұрын

    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

    15 күн бұрын

    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

    12 күн бұрын

    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.

  • @rikschaaf
    @rikschaaf17 күн бұрын

    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

    17 күн бұрын

    Hmm.. I like this idea. Worth thinking about.

  • @xpusostomos

    @xpusostomos

    17 күн бұрын

    A proper language lets the programmer choose his indexes

  • @stefanalecu9532

    @stefanalecu9532

    17 күн бұрын

    ​@@xpusostomosso... Pascal? Which has been doing this for 54 years and counting?

  • @xpusostomos

    @xpusostomos

    17 күн бұрын

    @@stefanalecu9532 I guess, I forget... Of course the right libraries in Java and C++ could pull it off too

  • @Asto508

    @Asto508

    17 күн бұрын

    @@xpusostomos You can always create your own array object and define/override the [] operator, so virtually every modern language allows this by default

  • @Rikaisan
    @Rikaisan17 күн бұрын

    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

    17 күн бұрын

    at the end he was fully himself

  • @scythazz

    @scythazz

    17 күн бұрын

    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

    15 күн бұрын

    Honestly, these live audience streams go much better than my actual college lectures from the very few I have seen so far.

  • @JeremyAndersonBoise

    @JeremyAndersonBoise

    14 күн бұрын

    He does that too, later in the video, this is just a piece of the event.

  • @thomassynths
    @thomassynths18 күн бұрын

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

  • @FighterHayabusa

    @FighterHayabusa

    18 күн бұрын

    I have to bring this one out from time to time to convince people. It's really well-written and reasoned.

  • @isodoubIet

    @isodoubIet

    18 күн бұрын

    Insane that people are still debating a point that was conclusively settled in the 80s

  • @victotronics

    @victotronics

    18 күн бұрын

    I drop that article in the class resources of almost everything I teach. He was so eloquent, thorough, and *right*.

  • @GabrielFury-mg8du

    @GabrielFury-mg8du

    18 күн бұрын

    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

    18 күн бұрын

    I know it for years .. he's right when we talk about C He is wrong everywhere else.

  • @pokefreak2112
    @pokefreak211217 күн бұрын

    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

    7 күн бұрын

    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.

  • @Hobbitstomper
    @Hobbitstomper17 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    I just think index as how many elements to skip

  • @gezenews

    @gezenews

    17 күн бұрын

    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

    17 күн бұрын

    It was a Performance convention, ok. Any other reason it's wrong

  • @user-wr2cd1wy3b

    @user-wr2cd1wy3b

    14 күн бұрын

    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

  • @biggerdoofus
    @biggerdoofus18 күн бұрын

    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

    18 күн бұрын

    This fake distinction between indices and subscripts was the most mind-meltingly stupid part of the video.

  • @ionarevamp

    @ionarevamp

    17 күн бұрын

    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

    17 күн бұрын

    ​​@@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

    17 күн бұрын

    @@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

    17 күн бұрын

    @@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)

  • @Oler-yx7xj
    @Oler-yx7xj18 күн бұрын

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

  • @kezzyhko

    @kezzyhko

    18 күн бұрын

    it went exactly the way zero would expect

  • @SkyyySi

    @SkyyySi

    18 күн бұрын

    You would indeed expect that considering he also said he likes JavaScript

  • @Alfred-Neuman

    @Alfred-Neuman

    17 күн бұрын

    @@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

    17 күн бұрын

    @@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

    17 күн бұрын

    @@xybersurfer Way to mix the joke lmao

  • @MasterHigure
    @MasterHigure17 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    @@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

    16 күн бұрын

    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

    15 күн бұрын

    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.

  • @user-wr2cd1wy3b

    @user-wr2cd1wy3b

    14 күн бұрын

    @@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.

  • @meowrbius
    @meowrbius6 күн бұрын

    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.

  • @filipenicoli_
    @filipenicoli_17 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    @@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

    17 күн бұрын

    @@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

    17 күн бұрын

    How does one end up working in hardware?

  • @filipenicoli_

    @filipenicoli_

    17 күн бұрын

    ​@@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.

  • @lifeisfakenews
    @lifeisfakenews18 күн бұрын

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

  • @jsonkody

    @jsonkody

    18 күн бұрын

    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

    18 күн бұрын

    @@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

    18 күн бұрын

    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

    18 күн бұрын

    @@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

    17 күн бұрын

    @@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^^

  • @upsidedownChad
    @upsidedownChad18 күн бұрын

    Yooooooooo that Brazilian shirt is fire 🔥🇧🇷

  • @nyahhbinghi

    @nyahhbinghi

    8 күн бұрын

    it is :)

  • @Exilum
    @Exilum17 күн бұрын

    That end speech should've been an entire video. Got me real emotional. Those people that skipped the end really missed something.

  • @ebmpinyuri

    @ebmpinyuri

    17 күн бұрын

    It's actually the best part arguably

  • @Exilum

    @Exilum

    17 күн бұрын

    @@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

    17 күн бұрын

    @@Exilum ​ @Exilum I even recorded that portion from the live stream , it's very impotant life lesson for a programmer

  • @user-ib3gr9ov5j
    @user-ib3gr9ov5j18 күн бұрын

    In Persian, weekdays are zero-based. "shanbe", "yek shanbe" "do shanbe", .... yek means one. do means two, ...

  • @Oler-yx7xj
    @Oler-yx7xj18 күн бұрын

    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

    17 күн бұрын

    Fortran too!

  • @EngineerErik

    @EngineerErik

    17 күн бұрын

    done that in Ada

  • @adissentingopinion848

    @adissentingopinion848

    17 күн бұрын

    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

    17 күн бұрын

    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__

    17 күн бұрын

    @@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).

  • @FlyingOctopus0
    @FlyingOctopus018 күн бұрын

    By writing "-1" when you index, you can use 0 based indexing lika a 1 based indexing. Like this arr[3-1].

  • @JimmyBin3D
    @JimmyBin3D5 күн бұрын

    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.

  • @heyrim72
    @heyrim7216 күн бұрын

    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.

  • @TomMcGuire
    @TomMcGuire18 күн бұрын

    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.

  • @GoddamnAxl
    @GoddamnAxl17 күн бұрын

    The man is turning reaction videos into live performance art… what an innovation 🤯

  • @PasiFourmyle
    @PasiFourmyle18 күн бұрын

    Thank you for sharing your wisdom and motivating words! 👏👏👏

  • @abauchu
    @abauchu16 күн бұрын

    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

  • @Saiphes
    @Saiphes18 күн бұрын

    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

    18 күн бұрын

    That's why people count Mississippis. It makes no sense to stop at just 3 without the Mississippi part

  • @brandongregori995

    @brandongregori995

    18 күн бұрын

    Also cadence as well. But it's a benefit when using a cadence to counting the current number of seconds

  • @Thurrak

    @Thurrak

    18 күн бұрын

    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

    18 күн бұрын

    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

    18 күн бұрын

    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

  • @daschewie
    @daschewie18 күн бұрын

    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

    18 күн бұрын

    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

    17 күн бұрын

    Also RPG

  • @MartialBoniou

    @MartialBoniou

    17 күн бұрын

    Exactly!

  • @AM-yk5yd

    @AM-yk5yd

    17 күн бұрын

    @@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

    16 күн бұрын

    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.

  • @TheBswan
    @TheBswan17 күн бұрын

    "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

  • @ytdlgandalf
    @ytdlgandalf17 күн бұрын

    My daughter knew very well at age 2 that when were doing a count down, shit happens at 0, not 1, so debunked.

  • @Becoming-Human
    @Becoming-Human17 күн бұрын

    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

    16 күн бұрын

    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

    12 күн бұрын

    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

    Күн бұрын

    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.

  • @AlwaysSunny-qu5zp
    @AlwaysSunny-qu5zp18 күн бұрын

    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

    18 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    @@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

    17 күн бұрын

    @@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.

  • @yeran7017
    @yeran701717 күн бұрын

    Man this is such a great video. TBH I got so emotional on the last minutes. Such a great advice I heard in a long time. Thanks!

  • @cleptos972
    @cleptos97217 күн бұрын

    You are such an inspirational person! Especially the end. Thank you!

  • @robmorgan1214
    @robmorgan121418 күн бұрын

    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

    16 күн бұрын

    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.

  • @dabbopabblo
    @dabbopabblo17 күн бұрын

    The moment I realized he was doing a live reaction to a video during a talk I died laughing, this is way too meta😂😂☠

  • @johnathanrhoades7751
    @johnathanrhoades77518 күн бұрын

    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.

  • @wtfusernamecrap
    @wtfusernamecrap11 күн бұрын

    ❤️ Props for the ending. That took some guts. And you’re absolutely right.

  • @kjdavid
    @kjdavid15 күн бұрын

    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

    4 күн бұрын

    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

    4 күн бұрын

    @@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

    2 күн бұрын

    @@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

    2 күн бұрын

    ​@@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.

  • @sk-sm9sh
    @sk-sm9sh18 күн бұрын

    Many countries start counting building floors from "ground floor" (0th floor) and nobody finds it confusing. Pizza delivery guy who finished just 9 grades at school is able to deliver pizza to correct floor and doesn't get confused when he hears 1st floor he knows he needs to climb 1 floor to deliver pizza and he never gets it wrong. And here we have people who finished computer science degrees and struggle to get over the fact that array indexes start at 0.

  • @SecretMoose

    @SecretMoose

    18 күн бұрын

    I still find it difficult after I moved to an index 1 floor system. “Meet me on the 1st floor”, I always go up, they don’t.

  • @fullfungo4476

    @fullfungo4476

    18 күн бұрын

    Pizza delivery guys also don’t get confused in countries that count floor starting from the “1st floor”. A pizza delivery guys knows he has to count the floors he’s visiting. So he visits the 1st, the 2nd, the 3rd floor… until he is at the n-th floor. It makes just as much sense.

  • @sk-sm9sh

    @sk-sm9sh

    18 күн бұрын

    @@fullfungo4476 thing is it makes sense either way. One just needs to acknowledge the way it is done and to stop trying to shape the world to fit their brain and instead one needs to adapt their brain to the world around. Now which way is intrinsically better is a tricky case - of course both ways will have their own advantages and disadvantages - but if Dijkstra thought counting indexes from 0 is better then I'll take his word for it instead of some random guy in the right bottom corner who some 70 years later still struggle with it.

  • @sebastienpautot

    @sebastienpautot

    17 күн бұрын

    Counts vs indexes is such a non issue, indexes start at 0, counts start at 1

  • @StefanvanAalst

    @StefanvanAalst

    17 күн бұрын

    Nah, pizzas should be delivered to pianos.

  • @orthoplex64
    @orthoplex6415 күн бұрын

    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.

  • @ryanrobbins3846
    @ryanrobbins384617 күн бұрын

    I appreciate you brother! You are like one of those marine recruiters that imposed their will on unsuspecting youths in high schools and hooked them into the military... But you are using your power to fill the ranks in the greater geek-verse.

  • @FinalEyes777
    @FinalEyes77718 күн бұрын

    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.

  • @pweddy1
    @pweddy118 күн бұрын

    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

    16 күн бұрын

    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

    15 күн бұрын

    ​@@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.

  • @user-wr2cd1wy3b

    @user-wr2cd1wy3b

    14 күн бұрын

    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.

  • @DarkerStarSword
    @DarkerStarSword6 күн бұрын

    Easy solution, just declare a map like this and use it to convert English to indices: {"first": 0, "second": 1, "third": 2, "fourth": 3, ...}

  • @atomicman007
    @atomicman00717 күн бұрын

    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

  • @asaad1022
    @asaad102218 күн бұрын

    When you enter a building and go up, do you start from the ground floor or the first floor?

  • @SandraWantsCoke

    @SandraWantsCoke

    18 күн бұрын

    I live in a basement

  • @kirkanos771

    @kirkanos771

    18 күн бұрын

    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

    18 күн бұрын

    @@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

    17 күн бұрын

    @thetukars The second one. 0 is the engine. xD

  • @shaggygoat

    @shaggygoat

    16 күн бұрын

    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.)

  • @Ninakoru
    @Ninakoru18 күн бұрын

    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

    17 күн бұрын

    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

    17 күн бұрын

    @@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

    17 күн бұрын

    @@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

    17 күн бұрын

    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

    17 күн бұрын

    0 index is easy to think about the first position, but hard to think about the last character (n-1)

  • @Ekitchi0
    @Ekitchi015 күн бұрын

    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

  • @josefjelinek
    @josefjelinek17 күн бұрын

    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...

  • @user-nr4ju3qd9o
    @user-nr4ju3qd9o18 күн бұрын

    live reactions is wicked work

  • @vikiai4241
    @vikiai424117 күн бұрын

    The 'zero didn't exist as a concept historically' pop-meme is the kind of massively overblown nonsense that makes actual historians cringe in the same way that programmers cringe watching Hollywood representations of computer programming. It falls into the same category of 'modernism' that leads to ideas like 'those people 4000 years ago couldn't have possibly built those structures that I, personally, can't work out how they did it, so aliens [or (white) foreigners, before aliens became the contemporary go-to] must have done it for them." Of course people knew what it meant to have 'none of something' - it was a pretty common situation for most. And they certainly had no problem with the idea that if they had 5 of something and sold or lost 5 of them they had none left. Or if they had none and acquired five they then had five. What they lacked was a discrete written symbol for "0" . They could state or write the word "none" (in their local language) just fine. And there are plenty of written records from the times - including arithmetic - where this was exactly what they did. Even finger-counting starts at zero, even if you don't say the 'zero' out loud. If you don't believe me, ask a math-historian and I'm sure they will happily show you their clenched fist. Real-close-up! 😛 The moment anyone drags out the "They didn't know about zero" trope, I just switch off and bin them with the anti-vaxers, con-trailers, Bill Gates 5G Microchippers and the lady living in the apartment below me who watches Ancient Aliens unironically (nice enough lady, but I just let what she says on anything more intellectually advanced than long-weekend changes to bin-night wash right over me). ... Also, we do have a pretty good idea how they built those things - they left written instructions on how to do it - in so much detail we even know the pay-grades for the work forces involved. We just took a few hundred years of telling ourselves we knew better before we decided to just RTFM!

  • @thomassynths

    @thomassynths

    17 күн бұрын

    Even if it were true (it aint as you point out), modern schooling teaches people the concept of zero. There was a time when addition and multiplication wasn't figure out, yet that doesn't stop us from using it today. It's such a shoddy argument.

  • @fredgoodrum771

    @fredgoodrum771

    17 күн бұрын

    Perhaps, more as a novelty, numbers were used cardinally or ordinally, when there is something to count. Latin's closest approximation to a zero might be translated as null ("zero" as nullus, -a, -um). I suppose there might have been a philosophical or theoretical use for zero but not in practical terms aside from "I am all out of apples to sell."

  • @SimonBuchanNz

    @SimonBuchanNz

    15 күн бұрын

    The reason this "pop-meme" exists is not because the general public didn't know about the concept of none, but because a bunch of mathematicians had savage arguments about whether "none" was a *number* specifically (similar to the negative numbers vs numbers being used for reducing/subtracting another). So no, you're not wrong, it is a dumb idea to think that people didn't know what not having something was, but it's not out of nothing, and I think Prime here gets something of the meaning with (approx.) "I don't know how you think in a world without 0" - not saying they *didn't*, just that we don't understand what it's like to do it without 0.

  • @epiphaeny
    @epiphaeny17 күн бұрын

    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).

  • @JoeJoeTater
    @JoeJoeTater5 күн бұрын

    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.

  • @RenderingUser
    @RenderingUser17 күн бұрын

    TJ the type of guy to say he's 6ft when hes actually 5 cause he like to start from 1

  • @jongeduard

    @jongeduard

    14 күн бұрын

    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

    11 күн бұрын

    But you need to know which number to press

  • @jongeduard

    @jongeduard

    11 күн бұрын

    @@billeterk Yeah, iterator analogy kind of stops there indeed. :P

  • @bjbboy71697
    @bjbboy7169717 күн бұрын

    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".

  • @Yupppi
    @Yupppi17 күн бұрын

    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.

  • @josegabrielgruber
    @josegabrielgruber17 күн бұрын

    You know Prime, I'm extremely glad that you came to Brazil, it meant a lot to us, your story, your determination and your good humor it's something that we really appreciate. But still, I would prefer to start at 1

  • @IdeaToGame
    @IdeaToGame18 күн бұрын

    yo Brazil mentioned!!! suddenly caralho

  • @mayanksinha6136
    @mayanksinha613618 күн бұрын

    Dunno... Starting with zero makes sense.... Because if you are at 1 it means you have already gone to 1. We don't start walking from 1km, we start from 0km.

  • @marlonlom

    @marlonlom

    18 күн бұрын

    so, first versión must be 0.0.1 instead of 1.0.0 in production ?

  • @innocentsmith6091

    @innocentsmith6091

    18 күн бұрын

    This logic works for iterating, but doesn't really make sense when just looking at objects in a list.

  • @mayanksinha6136

    @mayanksinha6136

    18 күн бұрын

    @@marlonlom it usually starts at 0.0.1. That's the alpha, unless you write perfect code. If thats the case then you can do whatever you want.

  • @gooble1

    @gooble1

    18 күн бұрын

    Does a sequence begin with the first or the zeroth number?

  • @mayanksinha6136

    @mayanksinha6136

    18 күн бұрын

    @@innocentsmith6091 true but then again you iterate over arrays and list as well

  • @ssmith99
    @ssmith9917 күн бұрын

    Thanks for your advice at the end, I really needed that right now

  • @aeronwolfe7072
    @aeronwolfe707214 күн бұрын

    23:00 brother. THANK YOU for saying this stuff. Man, I freaking LOVE this guy. Thank you for everything you do man..... :)

  • @awesomedavid2012
    @awesomedavid201217 күн бұрын

    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.

  • @xpusostomos
    @xpusostomos17 күн бұрын

    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.

  • @thunder____
    @thunder____17 күн бұрын

    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.

  • @RogerValor
    @RogerValor17 күн бұрын

    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

  • @simulatrix
    @simulatrix18 күн бұрын

    One of the best arguments for 0-based indexing is time. The 1st second starts ticking at 00:00:00. Can you imagine if we started at 01:01:01?

  • @ThePlayerOfGames

    @ThePlayerOfGames

    18 күн бұрын

    🤯

  • @r6scrubs126

    @r6scrubs126

    18 күн бұрын

    but how is that a good argument when you're not dealing with time... you're dealing with a number of THINGS in a list. If there's 1 thing in the list, you'd call that item 1. Look I understand why it starts at 0 in lower level languages for the reason mentioned at the start of this video, but there's loaaaads of other things we've abstracted and simplified in higher level languages so why not this as well

  • @SilentFire08

    @SilentFire08

    18 күн бұрын

    Seconds are continuous while index is discrete so I don't like that argument

  • @pxolqopt3597

    @pxolqopt3597

    18 күн бұрын

    ​@r6scrubs126 indexing starting at 0 is not something complex enough to be abstracted

  • @jackdanielson1997

    @jackdanielson1997

    18 күн бұрын

    Right! A child isn't 1 when they are born, they turn 1 after 1 year. My bank account doesn't start at 1, clocks don't start at 1

  • @skaruts
    @skaruts17 күн бұрын

    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.

  • @andyc8257
    @andyc82579 күн бұрын

    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]

  • @neshrammc
    @neshrammc6 күн бұрын

    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".

  • @code_combatant
    @code_combatant17 күн бұрын

    I was introduced to programming in Pascal which is 1 based. It made sense to me, it had never occured to me that 0 based indexing was a thing. Later on i worked with java, javascript and python, all 0 based. It felt weird at first, then it just felt normal. And then i stopped using indexes for the most part, because iterators were better. I mostly agree with teej here. But i'll chime in. 0 based indexing is like implementation leaking into the public api interface. Every human will recognize 1 as being the first item, until theyre brainwashed by big C lol.

  • @ciano5475

    @ciano5475

    17 күн бұрын

    Beacouse C is just assembly with a new mask 🙂

  • @khhnator
    @khhnator18 күн бұрын

    holy shit, i was not expecting the brazilian soccer team shirt

  • @Bolpat
    @Bolpat15 күн бұрын

    I deliberately avoid using “n-th element” when talking elements in lists. I use “the index-n element”. Only exceptions are “first” and “last”, and maybe “second”. Everyone knows that “first” is index-0 and “second” is index-1.

  • @lezzbmm
    @lezzbmm17 күн бұрын

    21:00 it’s not JUST that 0 made sense as offset it’s also that in math we like to think abt the 0th, “initial” state (zeroth iteration (bc u haven’t iterated yet)), and then the first iteration, second iteration (third item), etc

  • @wojciechbojewski9442
    @wojciechbojewski944218 күн бұрын

    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

    15 күн бұрын

    "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.

  • @jsonkody
    @jsonkody18 күн бұрын

    I have thought about this concept a lot and know all the history of 0-based versus 1-based indexing. Ultimately, it all boils down to two philosophical approaches. The older, more intuitive, and easier method is 1-based indexing. I believe this is correct-it simply points at the index, meaning you count the elements from the start and determine at which count the index is. This is 'real' indexing. The other approach is more similar to a 'ruler' or 'offsets'. If you place your hand on a wall, the 'distance' is zero. As you measure a greater distance, it increases. In this approach, you aren't really 'indexing' or pointing to an element. You operate on a lower level, simply asking, 'Where in the memory does the element or the thing start?' or "Where the thing starts?". This is not indexing but can be used as indexing. It's too bad that almost everyone copied 0-based indexing from C because C was so popular, even though there was no reason for these higher-level languages to adopt it-on the contrary, the only reason for 0-based indexes in C isn't valid in these languages, and thus we lost the opportunity to use more intuitive and 1-based real indexes.

  • @sqlexp

    @sqlexp

    18 күн бұрын

    Have you ever tried mapping a multidimensional array to a 1-dimensional array? Everyone who likes 1-based indexing has skill issues.

  • @isodoubIet

    @isodoubIet

    18 күн бұрын

    With zero-based indexing + half-open intervals, you can always compose two intervals when the endpoints match, and the number of elements is always end - begin. This makes 0-indexing inherently and objectively superior. Try doing multidimensional arrays with 1-based indices.

  • @isodoubIet

    @isodoubIet

    18 күн бұрын

    PS: this argument is valid for all languages everywhere since it's an argument about the fundamental logic of programming, AFAIK first articulated by Dijkstra in the 80s. Surprising that someone who knows all the history of 0-based versus 1-based indexing wouldn't be familiar with it.

  • @EwanMarshall

    @EwanMarshall

    18 күн бұрын

    To be fair, there are a lot of underlying flat memory data structures at the bottom so it still ends up making sense under all those object layers in quite a few cases.

  • @iraniansuperhacker4382

    @iraniansuperhacker4382

    18 күн бұрын

    @@sqlexp Im literally doing this right now and I am confused as to why anyone would consider 1 based indexing sane. How is this even a debate?

  • @steves9250
    @steves925017 күн бұрын

    SAP’s ABAP language doesn’t have arrays in the normal sense. Instead it has internal tables so the first entry is at line 1.

  • @Misterz3r0
    @Misterz3r018 күн бұрын

    Zero-based indexing comes from the fact that values are stored in memory locations. The zero-th index of an array represents the memory location where the array starts and each additional index represents an offset multiplier against the size of the data type being stored. Instead of having to know the memory address of where the array starts and then having to add an offset to the starting location of an array to retrieve a value at a particular location in contiguous memory, we use a zero-based index instead. Zero-based indexing isn't meant for counting the number of items in an array, it's to facilitate referencing values stored in the array. Despite the analogy of home addressing that is often used to teach people about indexing, memory allocation and data storage doesn't correspond one-to-one with real-world, physical objects. Storage in memory has to take into account the different sizes involved with different types of data, and the different sizes obviously affect the memory addresses those values end up getting stored at. Whereas a house of any size can be assigned an address and wouldn't affect the address of the next house because we are counting discrete physical objects. If addressing was based on plot size, than houses would be addressed in the same way as zero-based indexing to make the life of the postman easier.

  • @user-cx5jj2yv3p
    @user-cx5jj2yv3p18 күн бұрын

    Gigachad ending

  • @sk-sm9sh

    @sk-sm9sh

    18 күн бұрын

    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.

  • @billybest5276
    @billybest527618 күн бұрын

    This may have been one of the nerdiest things I have watched yet lol. That ending though you almost made me cry :' ) your an inspiration to many Prime stay hard!

  • @HarshColby
    @HarshColby6 күн бұрын

    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.

  • @mduvigneaud
    @mduvigneaud18 күн бұрын

    TJ isn't lying, he's just confidently wrong.

  • @jsonkody

    @jsonkody

    18 күн бұрын

    why?

  • @mduvigneaud

    @mduvigneaud

    17 күн бұрын

    @@jsonkody Because: mathematics. The first element in a collection of elements has no elements before it.

  • @softwaretechnologyengineering
    @softwaretechnologyengineering18 күн бұрын

    No Hood. Unsubscribed.

  • @christianforler1476
    @christianforler1476Күн бұрын

    In C, it is super easy to switch between the subscript and index notation. It virtually supports both. 😁 Example in "modern C" (C99, C11, C17, C2x): #include int main() { char *subscript[] = { "first", "second", "third" }; char **index = (void*) (subscript-1); puts(subscript[0]); puts(index[1]); }

  • @tedlava
    @tedlava17 күн бұрын

    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

    Күн бұрын

    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").

  • @hamm8934
    @hamm893417 күн бұрын

    Ill say this: 1. Linear algebra is base 1 and those folks LOVE arrays/vectors more than anyone 2. I used to be a die hard base 0 fanboy until i used R, which is base 1. I will say, after the initial stage of getting used to it, I actually experience first hand how much more intuitive it is. Indexing =/= slicing, and this is what programmers are confused on. I’ll use whatever, but if im being honest, in my heart of hearts, i really think base 0 for indexing for higher level languages is almost an anti pattern. Base 1 for indexing is just so much simpler after you really give it a chance. Its like that sludgey feeling you get when you go back to the legacy part of a codebase after leaving it for a while. Its just a haze looming over your code.

  • @ineverknowdoyou

    @ineverknowdoyou

    17 күн бұрын

    Not to disagree or anything, but as ive never used a 1-indexing lang, 1-indexing feels like sludgy legacy code, it feels like a haze that hides my soul further from god. mostly a joke, i am just to hooked on 0-indexing (offseting?) to ever be able to convert. i think they are both about the same, but the positives of 0-indexing shine through when you have to do math with the index. imo

  • @HarisAzriel

    @HarisAzriel

    17 күн бұрын

    Can you please elaborate more about indexing =/= slicing?

  • @blaisepascal3905

    @blaisepascal3905

    12 күн бұрын

    Completly agree, I had the same experience. After learning Python I went to R and then Julia, both 1 based indexing. I believe it is related to the fact that they are both array languages with a strong focus on linear algebra. Furthermore, Julia is a pretty new programming language (2012) so it is not a old concept. As you say it is weird at the beginning but then you understand it makes perfect sens in many situation (like 0 based indexing).

  • @jsonkody
    @jsonkody18 күн бұрын

    you have: arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] Select sub-array from 3rd to 6th element (included) .. in 0-based (Python) and 1-based (Julia) langs: Python: selected = arr[2:7] Julia: selected = arr[3:6] Thats all I need to show you gentlemen. PS: I should add that another reason why Pythons way is co cursed in this comparison is that it uses half-open intervals which is common in 0-based languages and it has one obvious advantage in things like for cycles etc - you keep the value because higher is not included - it can be used to next lower.

  • @zimpoooooo

    @zimpoooooo

    18 күн бұрын

    Now start your Numbers from 0 🙂

  • @isodoubIet

    @isodoubIet

    18 күн бұрын

    Ok now tell me, how many elements are there in that list? ;)

  • @volodymyrchelnokov8175

    @volodymyrchelnokov8175

    18 күн бұрын

    it is [2:6] in Python, and it makes more sense than always having to say " (included)" in *informal* speech

  • @kirkanos771

    @kirkanos771

    18 күн бұрын

    What you win in clarity, you may lose in memory optimisation (atleast for interpreted languages) since the bytecode has to "minus one" everything.

  • @birthdayzrock1426

    @birthdayzrock1426

    18 күн бұрын

    would it not be 2:5 instead of 2:7?

  • @defenestrated23
    @defenestrated232 күн бұрын

    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.

  • @mgmchenry
    @mgmchenry4 күн бұрын

    I simply love lua. I've got decades with C# and Java. Before that, C and C++, but my first love was Pascal. I've spent time interfacing with lua from x64 ASM and being able to be comfortable in an interpreted language while in a debugger is amazing. Lua integrates with c so well. I have wasted so much time working around the 1 based index standard. Almost every algorithm just works with a zero base, but I have to slow down constantly and make sure I haven't messed it up. I still love lua but i don't know why this choice was made

  • @jsonkody
    @jsonkody18 күн бұрын

    Indexing should absolutely be indexed from one in high-level languages. 0-based indexing exists primarily because of low-level pointer arithmetic, which does not exist in high-level languages. I often felt alone with this personal belief. Sometimes, there are languages designed by people who are mathematicians, and they create languages with 1-based indexing (like Julia, for example). By the way, ultimately, there is nothing we can do about this issue in languages already using 0-based indexing, so we are stuck with it as it is.

  • @isodoubIet

    @isodoubIet

    17 күн бұрын

    " 0-based indexing exists primarily because of low-level pointer arithmetic," Nonsense, it exists because it's inherently superior. It's the one convention where end-begin gives the length of the interval and intervals compose when the end of the first matches the begin of the second. This is an overwhelming advantage and was settled by Dijkstra in the 80s. Anyone still thinking this has to do with pointers is just ignorant.

  • @Dan-codes
    @Dan-codes18 күн бұрын

    Teej is correct.

  • @TimothyWhiteheadzm
    @TimothyWhiteheadzm14 сағат бұрын

    The array index is just that, the index of an element in an array. When we count things we give the length, which is something different. All integer numbering systems must either point to the start or the end of the items and it just happens that our common language use is length which is the end of the item and it is easier in most cases to use length when labelling boxes, but it gets complicated if we want to do calculations on it and the start of boxes (zero based) can be more useful for calculations.

  • @justliberty4072
    @justliberty40724 күн бұрын

    I learned to code FORTRAN (66) in high school in about 1977. Keypunch, card reader, 132-column output, 1-based indexing.

  • @aes0p895
    @aes0p89513 күн бұрын

    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).

Келесі