You Are WRONG About 0 Based Indexing

Поделиться
HTML-код
  • Опубликовано: 10 май 2024
  • 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,6 тыс.

  • @MrRobix13
    @MrRobix13 17 дней назад +1612

    Man doing live reactions, he won.

    • @fus3n
      @fus3n 16 дней назад +103

      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 16 дней назад +59

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

    • @ciziadevos
      @ciziadevos 16 дней назад +14

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

    • @fus3n
      @fus3n 16 дней назад +43

      ​@@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 16 дней назад +12

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

  • @catastrophicblues13
    @catastrophicblues13 16 дней назад +998

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

    • @NewSchattenRayquaza
      @NewSchattenRayquaza 16 дней назад +38

      Ma man here is cooking some world peace right here

    • @CEOofCulturalMarxism
      @CEOofCulturalMarxism 16 дней назад +1

      Or BS

    • @Dekharen
      @Dekharen 16 дней назад +20

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

    • @NithinJune
      @NithinJune 16 дней назад +2

      literally

    • @Sameer.Trivedi
      @Sameer.Trivedi 16 дней назад +16

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

  • @mgdotdev
    @mgdotdev 16 дней назад +212

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

    • @jsonkody
      @jsonkody 16 дней назад +10

      .. still watching IRL react video :D

    • @ChristofferLund
      @ChristofferLund 16 дней назад +22

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

    • @jarylsim1973
      @jarylsim1973 16 дней назад +9

      Conferences? Is that what they call real life Twitch?

    • @blackspitit
      @blackspitit 13 дней назад +1

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

  • @chi_said_hi
    @chi_said_hi 16 дней назад +110

    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 16 дней назад +12

      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 15 дней назад +12

      ​@thetukars this will make unreadable code.

    • @hobe4576
      @hobe4576 14 дней назад

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

    • @thomasmaughan4798
      @thomasmaughan4798 14 дней назад +3

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

    • @dimitralex1892
      @dimitralex1892 13 дней назад +1

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

  • @ZingsVideos
    @ZingsVideos 16 дней назад +1264

    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 16 дней назад +90

      Never thought of it like that. Makes sense

    • @jhny0
      @jhny0 16 дней назад +14

      very good analogy

    • @mAcCoLo666
      @mAcCoLo666 16 дней назад +48

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

    • @samuelswatson
      @samuelswatson 16 дней назад +99

      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 16 дней назад +59

      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 16 дней назад +362

    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 16 дней назад +11

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

    • @ChristofferLund
      @ChristofferLund 16 дней назад +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 16 дней назад +9

      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 16 дней назад +5

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

    • @joelperpetua3929
      @joelperpetua3929 16 дней назад +7

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

  • @tinnguyen5055
    @tinnguyen5055 16 дней назад +17

    0 base array works great with modulo arithmetic.

    • @spacelem
      @spacelem 6 дней назад

      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 День назад

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

  • @primbin_
    @primbin_ 16 дней назад +113

    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 16 дней назад +20

      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 16 дней назад +15

      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 16 дней назад +24

      ​@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 16 дней назад +6

      (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 16 дней назад

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

  • @beest_
    @beest_ 16 дней назад +105

    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 14 дней назад +7

      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 11 дней назад +1

      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 2 дня назад

      This is the way.

  • @Rikaisan
    @Rikaisan 16 дней назад +59

    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 16 дней назад +10

      at the end he was fully himself

    • @scythazz
      @scythazz 15 дней назад +6

      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 14 дней назад +2

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

    • @JeremyAndersonBoise
      @JeremyAndersonBoise 13 дней назад +1

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

  • @kjdavid
    @kjdavid 14 дней назад +20

    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 дня назад +1

      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 2 дня назад +1

      ​@@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 День назад

      @@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 День назад

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

  • @rikschaaf
    @rikschaaf 16 дней назад +174

    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 16 дней назад +3

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

    • @xpusostomos
      @xpusostomos 16 дней назад +8

      A proper language lets the programmer choose his indexes

    • @stefanalecu9532
      @stefanalecu9532 16 дней назад +5

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

    • @xpusostomos
      @xpusostomos 16 дней назад

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

    • @Asto508
      @Asto508 16 дней назад +1

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

  • @thomassynths
    @thomassynths 16 дней назад +199

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

    • @FighterHayabusa
      @FighterHayabusa 16 дней назад +15

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

    • @isodoubIet
      @isodoubIet 16 дней назад +42

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

    • @victotronics
      @victotronics 16 дней назад +7

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

    • @GabrielFury-mg8du
      @GabrielFury-mg8du 16 дней назад +14

      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 16 дней назад +2

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

  • @pokefreak2112
    @pokefreak2112 16 дней назад +10

    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 6 дней назад +1

      True, but you do rarely need to do that with 1-based languages. X[x,y] is right there.

    • @porky1118
      @porky1118 2 дня назад +1

      And the intuitivity issue can be fixed by fixing natural language and teaching children to count from zero from birth :)

    • @spacelem
      @spacelem 2 дня назад

      @@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 2 дня назад

      @@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 2 дня назад

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

  • @MasterHigure
    @MasterHigure 16 дней назад +43

    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 16 дней назад +1

      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 16 дней назад +3

      @@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 15 дней назад +3

      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 14 дней назад

      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 13 дней назад

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

  • @biggerdoofus
    @biggerdoofus 16 дней назад +39

    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 16 дней назад +12

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

    • @ionarevamp
      @ionarevamp 16 дней назад +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 16 дней назад +1

      ​​@@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 16 дней назад +1

      @@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 16 дней назад

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

  • @Hobbitstomper
    @Hobbitstomper 16 дней назад +36

    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 16 дней назад

      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 16 дней назад

      I just think index as how many elements to skip

    • @gezenews
      @gezenews 16 дней назад

      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 16 дней назад

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

    • @user-wr2cd1wy3b
      @user-wr2cd1wy3b 13 дней назад +1

      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

  • @Oler-yx7xj
    @Oler-yx7xj 17 дней назад +106

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

    • @kezzyhko
      @kezzyhko 16 дней назад +75

      it went exactly the way zero would expect

    • @SkyyySi
      @SkyyySi 16 дней назад +1

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

    • @Alfred-Neuman
      @Alfred-Neuman 16 дней назад +9

      @@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 16 дней назад +2

      @@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 16 дней назад +10

      @@xybersurfer Way to mix the joke lmao

  • @filipenicoli_
    @filipenicoli_ 16 дней назад +13

    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 16 дней назад +1

      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 16 дней назад +1

      @@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 16 дней назад

      @@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 16 дней назад

      How does one end up working in hardware?

    • @filipenicoli_
      @filipenicoli_ 15 дней назад

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

  • @meowrbius
    @meowrbius 5 дней назад +2

    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.

  • @lifeisfakenews
    @lifeisfakenews 17 дней назад +120

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

    • @jsonkody
      @jsonkody 16 дней назад +11

      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 16 дней назад +17

      @@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 16 дней назад +3

      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 16 дней назад +8

      @@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 16 дней назад +1

      @@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
    @upsidedownChad 17 дней назад +64

    Yooooooooo that Brazilian shirt is fire 🔥🇧🇷

  • @spectrecular9721
    @spectrecular9721 6 дней назад +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.

  • @user-ib3gr9ov5j
    @user-ib3gr9ov5j 16 дней назад +11

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

  • @Oler-yx7xj
    @Oler-yx7xj 17 дней назад +79

    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 16 дней назад +4

      Fortran too!

    • @EngineerErik
      @EngineerErik 16 дней назад +2

      done that in Ada

    • @adissentingopinion848
      @adissentingopinion848 16 дней назад +2

      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 16 дней назад +1

      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__ 16 дней назад

      @@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
    @FlyingOctopus0 16 дней назад +11

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

  • @Exilum
    @Exilum 16 дней назад +19

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

    • @ebmpinyuri
      @ebmpinyuri 16 дней назад +1

      It's actually the best part arguably

    • @Exilum
      @Exilum 16 дней назад

      @@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 16 дней назад

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

  • @daschewie
    @daschewie 16 дней назад +15

    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 16 дней назад +22

      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 16 дней назад

      Also RPG

    • @MartialBoniou
      @MartialBoniou 16 дней назад

      Exactly!

    • @AM-yk5yd
      @AM-yk5yd 16 дней назад +3

      @@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 15 дней назад

      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.

  • @TomMcGuire
    @TomMcGuire 16 дней назад +7

    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.

  • @Becoming-Human
    @Becoming-Human 16 дней назад +13

    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 15 дней назад

      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 11 дней назад +3

      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 2 дня назад +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 18 часов назад +1

      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.

  • @abauchu
    @abauchu 15 дней назад

    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

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

  • @sk-sm9sh
    @sk-sm9sh 16 дней назад +83

    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 16 дней назад +7

      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 16 дней назад +1

      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 16 дней назад +2

      @@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 16 дней назад +3

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

    • @StefanvanAalst
      @StefanvanAalst 16 дней назад

      Nah, pizzas should be delivered to pianos.

  • @AlwaysSunny-qu5zp
    @AlwaysSunny-qu5zp 16 дней назад +31

    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 16 дней назад

      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 16 дней назад +5

      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 16 дней назад +1

      @@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 16 дней назад

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

  • @TheBswan
    @TheBswan 16 дней назад +1

    "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

  • @GoddamnAxl
    @GoddamnAxl 16 дней назад +5

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

  • @Saiphes
    @Saiphes 16 дней назад +62

    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 16 дней назад +13

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

    • @brandongregori995
      @brandongregori995 16 дней назад

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

    • @Thurrak
      @Thurrak 16 дней назад +6

      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 16 дней назад +6

      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 16 дней назад +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

  • @PasiFourmyle
    @PasiFourmyle 16 дней назад +10

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

  • @yeran7017
    @yeran7017 16 дней назад

    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
    @cleptos972 16 дней назад +1

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

  • @robmorgan1214
    @robmorgan1214 16 дней назад +8

    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 15 дней назад +1

      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.

  • @FinalEyes777
    @FinalEyes777 16 дней назад +9

    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.

  • @ryanrobbins3846
    @ryanrobbins3846 16 дней назад

    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.

  • @johnathanrhoades7751
    @johnathanrhoades7751 6 дней назад +1

    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.

  • @pweddy1
    @pweddy1 16 дней назад +16

    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 15 дней назад

      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 14 дней назад

      ​@@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 12 дней назад +1

      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.

  • @mayanksinha6136
    @mayanksinha6136 16 дней назад +66

    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 16 дней назад +2

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

    • @innocentsmith6091
      @innocentsmith6091 16 дней назад +7

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

    • @mayanksinha6136
      @mayanksinha6136 16 дней назад +4

      @@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 16 дней назад +1

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

    • @mayanksinha6136
      @mayanksinha6136 16 дней назад

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

  • @wtfusernamecrap
    @wtfusernamecrap 10 дней назад

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

  • @ytdlgandalf
    @ytdlgandalf 16 дней назад +2

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

  • @Ninakoru
    @Ninakoru 16 дней назад +15

    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 16 дней назад +3

      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 16 дней назад +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 16 дней назад +1

      @@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 16 дней назад

      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 16 дней назад +2

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

  • @dabbopabblo
    @dabbopabblo 16 дней назад +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😂😂☠

  • @Ekitchi0
    @Ekitchi0 14 дней назад +2

    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

  • @christianforler1476
    @christianforler1476 11 часов назад

    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]);
    }

  • @vikiai4241
    @vikiai4241 16 дней назад +24

    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 16 дней назад +3

      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 16 дней назад +1

      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 14 дней назад +1

      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.

  • @asaad1022
    @asaad1022 16 дней назад +7

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

    • @SandraWantsCoke
      @SandraWantsCoke 16 дней назад +2

      I live in a basement

    • @kirkanos771
      @kirkanos771 16 дней назад +3

      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 16 дней назад

      @@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 15 дней назад

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

    • @shaggygoat
      @shaggygoat 15 дней назад +2

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

  • @josefjelinek
    @josefjelinek 16 дней назад +2

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

  • @RogerValor
    @RogerValor 16 дней назад +2

    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

  • @user-nr4ju3qd9o
    @user-nr4ju3qd9o 16 дней назад +8

    live reactions is wicked work

  • @awesomedavid2012
    @awesomedavid2012 16 дней назад +13

    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.

  • @tedlava
    @tedlava 16 дней назад +2

    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 18 часов назад

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

  • @heyrim72
    @heyrim72 15 дней назад +1

    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 2 дня назад

      But nobody actually calls it 0. It's usually E.

  • @RenderingUser
    @RenderingUser 16 дней назад +7

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

    • @jongeduard
      @jongeduard 13 дней назад

      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 10 дней назад

      But you need to know which number to press

    • @jongeduard
      @jongeduard 10 дней назад

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

  • @bjbboy71697
    @bjbboy71697 16 дней назад +2

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

  • @atomicman007
    @atomicman007 16 дней назад +1

    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

  • @simulatrix
    @simulatrix 16 дней назад +26

    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 16 дней назад

      🤯

    • @r6scrubs126
      @r6scrubs126 16 дней назад +8

      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 16 дней назад +1

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

    • @pxolqopt3597
      @pxolqopt3597 16 дней назад +3

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

    • @jackdanielson1997
      @jackdanielson1997 16 дней назад +3

      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

  • @xpusostomos
    @xpusostomos 16 дней назад +6

    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____ 16 дней назад

    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.

  • @orthoplex64
    @orthoplex64 14 дней назад +1

    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.

  • @Misterz3r0
    @Misterz3r0 16 дней назад +3

    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.

  • @skaruts
    @skaruts 16 дней назад +5

    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.

  • @sercan9791
    @sercan9791 16 дней назад

    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.

  • @ssmith99
    @ssmith99 16 дней назад +1

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

  • @IdeaToGame
    @IdeaToGame 16 дней назад +13

    yo Brazil mentioned!!! suddenly caralho

  • @code_combatant
    @code_combatant 16 дней назад +8

    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 16 дней назад +1

      Beacouse C is just assembly with a new mask 🙂

  • @DigitalMetal
    @DigitalMetal 14 дней назад +1

    I think it depends on if you are talking about a position or an amount.
    When you are born, you are 1 yet.
    The day doesn't start at 1 O'clock.
    If I'm standing at a street corner and giving directions I don't count the street I'm at when I say, "Go down one block and turn right"
    You can't count 1 if you don't have 1 yet.
    January is the 1st month, but we don't have a 1 month of the year completed on January first.
    We always start at position 0 and count the amount we have. It has nothing to do with computers, that's just how it works.

  • @ZenoDovahkiin
    @ZenoDovahkiin 10 дней назад +1

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

  • @jsonkody
    @jsonkody 16 дней назад +10

    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 16 дней назад +3

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

    • @isodoubIet
      @isodoubIet 16 дней назад +3

      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 16 дней назад +3

      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 16 дней назад

      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 16 дней назад

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

  • @wojciechbojewski9442
    @wojciechbojewski9442 16 дней назад +5

    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 14 дней назад

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

  • @josegabrielgruber
    @josegabrielgruber 16 дней назад +1

    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

  • @aes0p895
    @aes0p895 12 дней назад +1

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

  • @mduvigneaud
    @mduvigneaud 16 дней назад +8

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

    • @jsonkody
      @jsonkody 16 дней назад

      why?

    • @mduvigneaud
      @mduvigneaud 16 дней назад

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

  • @khhnator
    @khhnator 16 дней назад +3

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

  • @andyc8257
    @andyc8257 8 дней назад

    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]

  • @randyriegel8553
    @randyriegel8553 16 дней назад

    As a developer 0 based indexes are awesome. "foreach" helps with this. I can't remember last time I made an actual Array. Instead of an array in C# I use "List" or "List", "List", etc. And can manipulate them more than array.

  • @hamm8934
    @hamm8934 16 дней назад +5

    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 16 дней назад +2

      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 16 дней назад +1

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

    • @blaisepascal3905
      @blaisepascal3905 10 дней назад

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

  • @softwaretechnologyengineering
    @softwaretechnologyengineering 17 дней назад +4

    No Hood. Unsubscribed.

  • @user-jx7qu9xl2b
    @user-jx7qu9xl2b 16 дней назад +2

    the speech at the end is interesting. love it thanks for the advice.

  • @shanehebert396
    @shanehebert396 14 дней назад

    You will pay with the "- 1" somewhere, no matter which way you go. If you go 1-based, you don't have to put it in for loops (for index = 1 to length) but you will have to include "+ 1" somewhere else... when calculating the "subscript" you need based on data.... subscript = (some calculation to figure out which element of the array you need) + 1. Zero indexing goes back to machine language, even. It's the way processors work. Pascal uses 1-based indexing, too, IIRC.

  • @jsonkody
    @jsonkody 16 дней назад +5

    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 16 дней назад +1

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

  • @user-cx5jj2yv3p
    @user-cx5jj2yv3p 16 дней назад +4

    Gigachad ending

    • @sk-sm9sh
      @sk-sm9sh 16 дней назад +1

      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.

  • @bernardoquina3047
    @bernardoquina3047 16 дней назад

    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.

  • @kc3vv
    @kc3vv 16 дней назад +1

    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.

  • @jsonkody
    @jsonkody 16 дней назад +4

    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 16 дней назад +3

      Now start your Numbers from 0 🙂

    • @isodoubIet
      @isodoubIet 16 дней назад +1

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

    • @volodymyrchelnokov8175
      @volodymyrchelnokov8175 16 дней назад +2

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

    • @kirkanos771
      @kirkanos771 16 дней назад

      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 16 дней назад

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

  • @Dan-codes
    @Dan-codes 17 дней назад +6

    Teej is correct.

  • @chrishamilton1728
    @chrishamilton1728 16 дней назад +1

    0 works better with modulus operator
    int % array.length gives you a valid index for any integer

  • @epiphaeny
    @epiphaeny 16 дней назад +1

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

  • @wtrflsh
    @wtrflsh 10 дней назад

    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.

  • @TawaSkies
    @TawaSkies 16 дней назад

    This is not a language issue. It goes back to physical storage devices, eg like old Reel tapes. We used to put a physical aluminum strip to indicate the start of tape and called, "Start of Tape Index marker", SOT. We could tape drive to go to SOT or index zero to either rewind a tape or get to the SOT at load time. An array is sequel data type modeled on the physical sequel device like a tape.

  • @billybest5276
    @billybest5276 16 дней назад

    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!

  • @aeronwolfe7072
    @aeronwolfe7072 13 дней назад

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

  • @KabukiStarship
    @KabukiStarship 16 дней назад

    I have a situation where this makes perfect sense. With my Scrip2/C++ API I wrote with ASCII Data Types, which are contiguous composed map data types and POD types . For a Dictionary, you use an ASCII List (of type-value tuples) where the the 0 element contains either an ASCII Book (multi-map) or ASCII Table (symbol/hash table). Then element 0 of the Book or Table is an empty string. It works very well.