I index at -1


...so, the end of the iterable? #python




You're a fucking monster.


Chad move.


My man


0 indexing is superior


That is the only answer. Whoever says 1-idx, is a sad Stats major learning R


Does R 1 index? Now I’m going to have to blacklist our one developer who keeps saying we need to do more projects in R.


Yup! Had to learn it for a data science / analytics class I took back in college. Was a weird change, but I think it's cause R is focused on non-hardcore programmer types so it makes more sense from their perspective


It makes more sense for any human. Zero means empty. If you have one apple it isn't your zero'eth apple. Everyone here pretending zero indexing makes sense for humans is just Stockholm syndroming. We only do it because the computorr works that way and it stuck in a legacy way.


You are confusing two different ideas. Indices are labels, addresses, "things" that need to be unique in order to *refer* to the actual data. Therefore, it makes no sense to skip the first of the possible labels that one can create with n-bits. So what you call "index zero" is actually "index 00000000" (for an indexable space of 8 bits) Indeed, nobody says that "an array of size 0 has one element". Don't confuse the size with the indice.


Julia also indexes from 1. MATLAB as well.


I would honestly use Julia if not for this. It seems like a great language otherwise.




Unpopular opinion that I hold with almost religious firmness: 0 indexing isn’t just better for programming; it is the correct way to label things in real life. The word “first” should correspond to the number 0, not the number 1. 1-indexed systems like dates just lead to contrived complexity because they are trying to impose a false first number. If you are halfway through page 9 of a book, how many pages have you completed? The logical answer is 9.5, which is correct if the pages are 0-indexed. When was your first birthday? The day you were born, of course! Why does PM roll over to AM at midnight, but the numbers roll over an hour later? They roll over at the same time if you use 0-indexed military time! Why don’t musical intervals add in a natural way? If they were zero-indexed, they would! If a system consistently produces simpler and less counterintuitive results, it is my belief that said system is reflecting a fundamental truth about reality.


I don't understand why you're bringing birthdays into this. Aren't they already zero indexed? The day you were born was your zeroth birthday. Your first birthday is then the completion of your first year


“Zeroth” isn’t really a word that’s used in everyday language. “First” doesn’t mean “corresponding to 1”, but rather “the element that precedes every other element”. In this sense, your first birthday (the first birthday you have) is the day you are born. And, the natural cardinal to identify with the ordinal “first” is 0. Edit: to clarify, like you say, birthdays are already zero-indexed. I brought them up since they expose the fact that our language for ordinals should also be zero-indexed.


I disagree about the book. "Halfway through page 9" is using subtractive language, it means you finished page 8 and half of the next page, i.e. you've read 8.5 pages. The page number already correctly reflects your "position" at the END of the page, which I find more useful and intuitive.


Ya this guys half way to terryology with this math


Why is using subtractive language more intuitive? By the time you’ve finished 9 pages you’re already on page 10. I would posit that you only find it more intuitive because it’s what you’re used to.


>Why is using subtractive language more intuitive? I didn't say that. I said the language you are using is subtractive. If I'm halfway through page 9, I haven't finished page 9 yet. That's what the sentence means. My progress, expressed in additive language, is page 8 and half. The two sentences are equivalent, logically must be equivalent, no matter where we start counting. >By the time you’ve finished 9 pages you’re already on page 10. Not necessarily. What if there is no page 10? What if there is, but I ignore it, and just close the book after reaching the bottom of page 9?


The language I’m using is purely additive. If you’re on page 9 of a zero indexed book and have completed half a page, you have read 9.5 pages. If you’re on page 9 of a one-indexed book and have completed have a page, you have read 8.5 pages. Subtractive. > What if there is no page 10? What if there is, but I ignore it, and just close the book after reaching the bottom of page 9? Then you have read 9+1 = 10 pages, since you read a full page since starting one 9.


The language in the sentence "I'm halfway through page 9" is objectively subtractive, how can you not see it even with he other sentence to compare and contrast? Again, I'm talking about the language of the sentence, and it's universal no matter how we number the pages. If I'm halfway through X, I haven't reached X yet, it's a future goal. My current station is (X-1) + 0.5. It's not logical at all to represent "halfway through X" as X + 0.5. If I'm halfway through my second beer, I've drank 1.5. If I'm halfway home (let's represent it as vector and assume I'm setting off from (0,0)), I'm at 0.5home.


“Halfway through x” does not mean (x-1 + 0.5), it just means x/2. If I am halfway through a marathon, I have run half a marathon. If I am halfway through my 1nd beer, I have drunk one beer and am halfway through another. If I am halfway through page 9, I have read 9 pages and am halfway through the current page.


I can see both sides. For their side you'll start on page 0 and then it's easy to see how far you are, as if you've read half the page you've read 0 full pages and 1 half page. For page 9 you've then read 9 full pages and however much of a fraction of the current page. It's a bit like a clock like that (at least in 24h); how many full hours have passed, and how far to the next full hour are we along? But then again the book case probably seems strange because we're used to the first page being numbered 1. And in general it works fine.


>When was your first birthday? The definition of birthday and day of birth are not the same. In most cultures (that I'm aware of) "birthday" is the anniversary of your day of birth, not the actual day you were born


That seems like a rather artificial definition, doesn’t it? Basically “every day you’re alive on the same month and day as your birth counts as a birthday, except the first one”. Human culture is full of strange 1-based conventions. All of them, in my opinion, are contrived and wrong.


Your birth actually declares a variable called "age" and initializes it to 0.


That's really bad practice. You should never have a variable to keep "age" for more than a very temporary storage; you should rather calculate the age from "DOB" field and current date and time.


>That seems like a rather artificial definition, doesn’t it? Sounds like how natural languages in general are


Agreed, natural languages are a product of a bygone era and we should all use conlangs or more accurately just one conlang, having multiple introduces problems with translation for different audiences .


Yeah, we all have been counting from zero our whole lives. When you count on your fingers you make a fist first, zero (except you, you know who you are). Then you start putting fingers out (fuck zodiac signs, which finger do you start counting with pointer, thumb,...) 0, 1, 2... You likely don't think "zero" in your head because it is so natural and obvious that you are indexing from zero, you don't have to.


Can you explain what you mean about musical intervals? A 0-2-4 chord doesn't seem to make more sense to me than a 1-3-5


Two thirds (minor and major, technically) make a fifth. 3+3 = 5? An interval is supposed to measure the distance between two notes in a scale. But why is the distance between a note and itself regarded to be 1, and not 0? The distance between a point and itself should always be 0. (This is fixed by making the word “first” correspond to the number 0, but with current definitions it is quite nonsensical) Why is a 1-3-5 chord more natural to you? 0-2-4 is part of an ideal. 1-3-5 is part of a nasty coset.


Don't forget they even missed also out the year zero, causing a discontinuity from 1BC to 1AD. This fear of zero is long standing and has caused all manner of inconsistencies.


If you counted birthdays by the day you were born they would be 1-indexes


How so? Day you’re born = first = 0 1 year later = second = 1 2 years later = twixt = 2 (my linguistic proposal to fix the ordinals after “second” sounding like the wrong cardinals — since they aren’t used nearly as often as “first” or “second” I don’t think it would be so hard to adopt) 3 years later = third = 3 etc


That is how it works already. It seemed like you were proposing a different system, where the day of your birth was your first birthday, not your zeroeth birthday


Yes, birthdays are already zero indexed. I was using them as an example to demonstrate that our current language for ordinals isn’t really compatible with zero indexing. “First” doesn’t mean “1”, it means “before everything else”. So, your first birthday is literally the day you are born. But this is incompatible with the common interpretation of “first” as corresponding to the cardinal 1. Hence, I propose a modified system of ordinals: - First <-> 0 - Second <-> 1 - Twixt <-> 2 - Third <-> 3 - Fourth <-> 4 - … - Nineteenth <-> 19 - Twentieth <-> 20 - Twenty-second <-> 21 - Twenty-twixt <-> 22 - etc


Gotcha. I reread your comment and you were actually pretty clear about that. I just was being dense.


It's the only one that works with real memory addresses unless you're trying to waste one slot like Satan....


Alphabetical indexing


You just want to watch the world burn, don't you?


reply[a] = "yes"


`a` not even `'a'`?


Yes, to use this far superior notation just run this first; import string for index, letter in enumerate(string.ascii_letters): exec(f"{letter}={index}")


Ahhhhh! That's so awful, the only thing I can think of that could make this worse would be to implicitly do `from string import *` and just enumerate over `ascii_letters`.


Don't use `exec`. Use this instead: import string globals().update({a: i for i, a in enumerate(string.ascii_letters)})


Beautiful! The world of alphabetical indexing has become even more graceful.


``` globals().update({a: i for i, a in enumerate(__import__("string").ascii_letters)}) ``` There, condensed it into a neat one-liner


Now make the values random numbers so it's even worse to use


Global variables everywhere. ```python a='a' b='b' l='I' I='|' ```


\#define a 0


a = 'a'


reply[String.fromCharCode(97)] = "yes"


No. He just likes to use fancy words for 0-indexed team. Or perhaps 97-indexed team.


8, 5, 4, 9, 1, 7, 6, 3, 2, 0 is the way to go


I see what you did there and I like it


Now do it based on the current system locale.




Peak programming is when your offset looks like you're screaming


and when you use dereferencing


arraa arraa oni chan ?


So.. a hashtable?


Not even, in c/c++, all characters get converted to their ascii value, so, array[‘A’] is perfectly legal, and it refers to the 65th index


Oh God, this again. Which collation are we using? Unicode letters get funky.


I don't know what you're talking about and I'd like to keep it that way


This is the time[1] I’ve seen this meme


Means you like 1-indexing


Or it's their 2nd time seeing it


How about Excel. It's 2 based indexing.


Can we meet in the middle at 0.5


With Fortran, you can.


In some computer vision and computer graphics contexts 0.5 is the middle of the pixel, not an integer value.


Huh. I haven't worked with vision or graphics so that interesting to hear. It makes sense though, since aren't pixels usually modeled in a 3+ dimensional space even though your display is a matrix? Fortran isn't that smart. It literally lets you use a float ("real" as it calls them) as a loop control variable.


This seems even worse


for item in items


``` i = Index() for item in items: # Whatever code... i = i.nextItem() ```


1 makes index math more annoying. You could say having to subtract 1 from length to get the last index is annoying, but you do that a whole lot less than index generally.


If I want to repeat all indices from 0-9 based on the increasing value of I, you can use which works great for 0 based indexes. Because 0 is a valid number, I don't see why we'd use anything else.


Subtracting one can be easily solved by using ranges. So range(0,10) will iterate over 10 elements (0..=9).


Python has `-1` to index to the last element


If your language uses 1, use 1, if it uses 0, use 0


That is deep


I'm surprised anyone is advocating for 1-indexing. I'm more of an engineer than a programmer so it makes sense for me (I can't imagine a 3D vector having indices of 0,1,2 lol) and also I do virtually all of my programming in matlab. Are there working programmers who \*don't\* dislike 1-indexing, or prefer it? (Genuine question)


it’s me, hi. Why can I positively reference an array from 0:(length-1) but negatively reference -1:-length. Make it symmetrical >:( but also a stats programmer so, team R all the way home


Solution: introduce -0 (we already have the floating point representation for it!)


>it’s me, hi. "I'm the problem, it's me" ;P


I learnt R first, Python second and the 0 indexing still confuses me.


That 0 is there because in C `arr[i]` was short for `*(arr+i)`, and yes, you can do `i[arr]` in C.


Engineer? This sub is for programmers


My PhD was accomplished nearly entirely by programming in Fortran. I don't post, I'm just here for the memes and to learn something now and then


the sidelines watching the red attack blue, left attack right, conservative attack liberal, rural attack urban. anything to keep them distracted from me while I'm the only one actually stealing their cookies


Tough one. I'm definitely used to 0 indexing but starting at 1 is something I could work.


I'm used to having to add 1 to each indexed item to make it more visible on the UI for the user...


If I ever make a UI, I’m going to leave it zero indexed. Users must be indoctrinated.


So many people are gonna be so confused... And so many of us nerds are gonna find it funny....


So would you instantiate integers at 1 too? Fucking monster


I think he means starting at 1:00.


The proper meme format would be to use a Winnie-the-Pooh wearing a suit on the left and a Winnie-the-Pooh looking disfigured on the right


I'm just following all of the Blood vs Crips memes, also different people have different opinions


Yes, some prefer indexing from 0 and some have wrong opinions


The correct side: 0 based


I mean, it's there for historical reasons. Arrays in C are pointers in disguise, and `arr[i]` is just `*(arr+i)`. So you can index out of bounds into junk memory 🤓.


Lua vs every. other. language. to. exist (except maybe fortran or cobol but please correct me if i’m wrong


*Prolog existing with both `nth0` and `nth1`*


Julia starts at 1 by default, but you can change it.


R also starts at 1


If all your arrays are implemented as dictionaries, indexing never fails.


Clearly this sub has never read Numerical Recipes in C, which advocates both.


Let's take this further. First we had exponentiation with integers. Then with reals, then with complex numbers and matrices. So I won't be happy until we have array indices using complex numbers.


I index at 65,535 and decrement with each proceeding position.


What happens when you reach -1?


This post is here only so we know who the 'Index 1' people are. You will all be shot when gpt takes over.


0 indexing and fuck matlab for making me use 1


my wife was trying to get a puzzle in the latest harry potter game, and when i told her>! the numbering starts at zero she said "who in the hell would start numbering at zero?!". Your husband...as a career. !< made this a spoiler in case anyone doesn't want a puzzle spoiled.




1 indexing is more intuitive imo


Why is it that the year 1901 is in the 20th Century, the year 1900 is the 19th Century, and yet 1900 and 1901 are part of the same decade yet different centuries?


Only to people who don't index at 0


Because you dont know how memory works? The 0th index is the beginning of the array, `array[i]` is equal to `*(array + i)`


look. 0 indexing a historic relic of C, because originally in C (technically still true), arrays and pointers were indistinguishable. In fact array indexing in C is literally syntactic sugar for pointer plus index. That is why in C, x[1] and 1[x] give you the same answer. In C array indexing turns into *(x + i). So if you want the first "element" the offset is zero. If you are rationally designing a new language, arrays should start at 1 by default.


Except if your language also has pointers and pointer arithmetic. Then you should keep 0 to make containers and pointer arrays consistent.


Modern languages can get a long fine without pointer arithmetic. You can use bounded arrays or vectors just fine without needing to do pointer arithmetic.


Both, both is good


I'd like to make a language in which all containers are based on maps with no guaranteed iteration order.


Circular arrays


Whelp… it’s going to be really awkward when working with binaries and masks and suddenly you’re missing the index equivalent to 00000000 lol.


95% of the time I don't need either because I use a for-each style construction because being fast to code and less error prone means there is rarely any downside to doing so. Of the remaining 5% of the time, 95% of *that,* I am looking at the first or second member of an array and I am so used to 0-based indexing that I would automatically go to element \[0\] or \[1\]. In these cases, 1-based would confuse me. Of the remaining 5% of those 5%, I am debugging a large array with someone else and have to verbally call out the 9th, or 69th, etc. member of the array, and when numbers get that large it's hard to be sure if you're talking about element \[9\] or \[8\] in the debugger, so in that particular case, being 0-based is annoying.


I just map over lists. I do not need to care about indices.


0-indexing simply because that’s how all the languages I’ve used are setup. It’s the norm.


a friend of mine had to learn R, so i helped them (they didn’t have any programming background) and as i found out R has 1-indexing i asked if it really had to be R. it really had to be R );


It makes sense for R to start at 1 because it is a software for data analysis. You want the first datapoint, just use [1]. It makes sense naturally and you don't have to think much about it. If you work with iterative algorithms and need a starting point (iteration 0), 0 indexing is more practical. Just my 2 cents...


I side with "0-Indexing" because it is really an offset value to be added to the memory location of the start of the array of data objects. The "indexing" is just abstraction to make programming easier for people who don't want to put the effort to write code in assembly or machine code. We are not the same.


Floating point indexing.


what's the actual reason for index at 0, im used to it but is there an actual reason with early computers or just convention?


It’s because of C. In C, arrays are literally pointers in disguise, as another user puts it, and any array access translate to *(array+i), or in plain English, for those who don’t use C, Get the value at memory location array + index


Basically, it's adding to the memory address to find an element. Memory address for item = memory address of array + index. Index being zero will return the start of the array, that's why


On top of memory addressing like other comments have mentioned, in hardware you often want to use as few bits as possible to represent as much information as possible since wires take up a lot of space and power and more bits means more wires. So in hardware, not using 0 means you are just giving up an index you could be using for something, so indexing in hardware typically starts at 0.


Because 1 is annoying most of the time


would it be so annoying if it was standard though?


Probably not, but there was definitely reason for that decision, and people don’t like change unless you can make a very good argument to do so.


Probably. There are some things you have to look out for when using 0-based indexing, but to me it seems that any other has more annoying things to look out for. Where you start your index really just defines which problems you can have.


1 indexing. It's not like languages can't just subtract one to access the right item in memory, now that almost no newer languages make much use of pointer arithmetic, and I think it's just more intuitive that way


1 index is the worst. 0 index or bust.


The standard of the programming language, I'm currently using, so 0-indexing because all 1-indexing languages are bullshit


Bullshit until you get paid to use it; then it's the best language ever.


I'd do a lot of bullshit if I get paid for it


I'd require a lot to have a career using matlab.


Indexing at 1, offsets at 0. If you know, you know.


But now the traditional indexing is at 0 becaus C stupidly merged the terms index and offset. In fact you could do things like `0[arr]`, which desugars to `*arr`.


I'm old enough to have never been taught anything but 0-indexing...


1 indexing would make coding easier sometimes. But man I am already so used to 0 indexed stuff that I would rather it not change.


I start all my arrays at 3. /s There's a difference between an index (starts at 1) and an offset (starts at 0). C just happens to conflate the two. So the real answer is "whatever's idiomatic in the language you're currently using."


I worked in industrial automation for four years. On some controllers there you can freely choose the indexes you want. From [-11 to +4] or [„D“ to „Z“] … You cant imagine how much that triggers me


0 but I ain't no blood


1 indexing for sure. It just makes more sense. However, I just read some people don't like to do math with 1 indexing, but I am okay with it, as in my entire time studying Maths (I'm in 12th grade), we've never used 0 indexing, so 1 indexing makes more sense.


All math is 0-indexed. What do you think the number 1 is? It's 0 + 1. Counting things start at 0; you have none of the thing/things. We just usually don't think about the 0 because it's not something we're consciously aware of.


Indexing at 0 is just natural for computers. I think it originated with the C language, in which a zero index is simply the pointer with zero offset. Indexing at 1 is an ancient mathematical tradition. Array indices always started at 1, and because of this, the earliest numerical algorithms also used 1 as the first array index, and indeed, Fortran uses 1-indexing for arrays. So which side are you on? The modern side, or old-fashioned side?


There is a specific place in hell for people who prefere 1-based indexing


i looked at the 1 in horror as i was learning lua


0 indexing > 1 indexing


0 is a positive integer, so yeah, the only right answer.


Wtf is 1 indexing and why is it a thing


Da fuck! I don't care about your language, I can deal with your OS, I can even forgive you for not using emacs... but this... this is bs! Whoever is blue team must be banned from this sub.


Logically one makes sense, until you know it stands for offset. So for me I always think of it as zero.


0, always


who the hell is doing 1 indexing i need to stay away from them


theres really people for 1 indexing???


This doesn’t need to be done before. If you say 1 index you should be castrated so that in the next generation we don’t need to have this discussion


All 1-indexing is, is 0-indexing plus one to make it easier to understand for the peasants 🤷


I feel like there can only be one answer to this. The index is an offset from the memory address of the first element. location of element = \[first address\] + \[index \* sizeof(an element)\] How can it ever be anything other than zero-based?


Or, index can be defined as 'element number in array'. Doesn't have to be defined as offset to pointer.


yea... 1 indexing gang is pretty much empty


How does this have upvotes? It’s not humorous


This was done before


The psychiatric hospital called, they want their recently escaped patient back. The patient was last reported masquerading as a software engineer.


Oh VB6. If you declared an array with a length of 1 it would give you a 1 indexed array. Len would also return 1. However there was a 0 index accessible.


I like emoji indexing


VB used both


0 indexing by default with a built in option to 1 index if needed.


-1 indexing


2 base indexing because starting with 0 is stupid but I love off by 1 errors.


0, but I like Pascal's idea of starting arrays wherever you want to.


Emoji indexing


Better red than dead.


Wrong. Both are wrong. Fortran allows you to decide this for yourself. Fortran also uses to let you have real numbers for loop variables, and increment by real numbers. Like GOD intended. Who is REAL by the way, unless declare integer.


With Pascal, the array starts wherever you want.


Depends on the language I am using I suppose.


Index with non-scalars `myCar = carsArray[{make: “toyota”, model: “corolla”}]`


I want one of the middle elements to be zero and the +1 and -1 to each side


Just use iterator


I don’t fucking care. Everyone make up your mind so I can just remember one or the other. Fuck being different (in this instance).


My bro Pascal laughs at your inferiority


0 in the repo 1 end user facing


Both are fine.




Out of the two 0-indexing, but personally I dont index. I use pointers and 'address' the matter directly... im sorry 😔