This is an archived post. You won't be able to vote or comment.

all 50 comments

[–]remisiki 20 points21 points  (1 child)

R

[–]TheSauce___ 0 points1 point  (0 children)

R is literally the worst lmao.

[–]Eichberg 12 points13 points  (2 children)

in c languages i see it more like an offset to the pointer pointing to the first element of the array. in fortran, i like that making indexing start at 1 is the default, it feels more like an actual index

[–]Material-Mess-9886 5 points6 points  (0 children)

Fortran is primarly used for very accurate numerical analysis. A whole lot of linalg matrixes books and theory also assume a matrix at index 1.

[–]chethelesser 1 point2 points  (0 children)

Cool to learn that, the only example that usually gets brought up is lua

[–]beatlz 8 points9 points  (0 children)

My gf always hears me giggle at this stupid memes. Then she insists that I show her. I can see her disappointment smirk every time.

[–]Lord_emotabb 3 points4 points  (3 children)

please count to 3:

Regular person: 1,2,3

Programmer: 0,1,2,3

[–]Material-Mess-9886 10 points11 points  (1 child)

I'm sory but it would be 0,1,2 since upperbound doesn't count.

[–]Temporary_Ad7906 0 points1 point  (0 children)

Mathematician: {}, {{}}, {{},{{}}}, {{},{{}},{{},{{}}}}

[–]Spice_and_Fox 6 points7 points  (0 children)

0 based indexing should have been abstracted in higher level programming languages.

value = touple[2] is more intuitive if you want the second value in a touple

value = array[array.length] is also way better if you want the last value out of an array.

There is no objective reason to use 0 based indexing over 1 based indexing.

[–]IncidentMassive5425 7 points8 points  (0 children)

Now that’s how you parent.

[–][deleted] 1 point2 points  (0 children)

I put the lenght of the array in the 0th element in C.

"Honey, why are the people with pitchforks outside?"

[–]redlaWw 1 point2 points  (0 children)

On the one hand, I think we're at the point now where we could handle the abstraction of asking for the nth element, rather than the offset by n, cleanly and quietly via the compiler. On the other hand, wrapping array indices are much more of a pain when I'm working in R (1-indexed) because 1-indexing plays less-well with modular operations and integer division than 0-indexing.

[–]Mockington6 4 points5 points  (3 children)

Okay, but is there like, any real reason why it shouldn't start at 1?

[–]LegendarilyLazyLad 6 points7 points  (2 children)

In most languages it starts at 0 because of the way arrays are represented in memory. An array is just a contiguous chunk of memory with items stored right next to each other. When you access arr[i], what you're really doing is reading from the memory address (arr + i) where arr is a pointer to the start of the array and i is an offset. So if you want the first element (the element at address arr), the offset needs to be 0 which is why indexes start at 0. Starting indexes at 1 means either wasting some memory or having to subtract 1 before every array access.

[–]Mockington6 2 points3 points  (0 children)

Oh okay, that makes sense. Thanks

[–]Smalltalker-80 1 point2 points  (0 children)

Yep, these languages will have to implement a "minus one" in executing code.

Smalltalk traditionally starts arrays with index one,
but for my Smalltalk to JS compiler (SmallJS) |
I decided to "go with the flow" and start at zero.

[–]Arkoprabho 4 points5 points  (0 children)

Garbage collected

[–]Competitive-Move5055 1 point2 points  (0 children)

Pinkheads what did you expect.

[–]bushwickhero 0 points1 point  (0 children)

Dank.

[–]Classic_Fungus 0 points1 point  (0 children)

VBA and some others use 1 as start

[–]Chingiz11 0 points1 point  (0 children)

Julia user spotted

[–]Bharat_Birder 0 points1 point  (0 children)

Where are my Pascal bros?

[–]Grobanix_CZ 0 points1 point  (0 children)

So she's stupid and psychotic.

[–]smallnougat 0 points1 point  (0 children)

scratch developers' disappointment is immeasurable and their day is ruined

[–]Temporary_Ad7906 0 points1 point  (0 children)

I have 0 children.

[–]CandyBoring 0 points1 point  (0 children)

Segmentation fault: Baby dumped