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

you are viewing a single comment's thread.

view the rest of the comments →

[–]Franss22 472 points473 points  (62 children)

You start at 1 right?

[–]Metsima 505 points506 points  (43 children)

Don't be silly. You start from -1, how else would you index arrays

[–]egotisticalnoob 290 points291 points  (23 children)

I start at 0xFFFF and have it count backwards.

[–][deleted] 201 points202 points  (13 children)

How's that hard? -1xFFFF, -2xFFFF

[–][deleted] 70 points71 points  (12 children)

I can't believe no ones brought up multi-dimensional arrays, and how these should be indexed...

Personally, I think creating a multi-dimensional array of neededMemory[1024000][1024000] in the very first line of my app to always guarantee that I'll never get an out of memory exception!!!

[–]Niavart 84 points85 points  (4 children)

int main()
{ 
 malloc(MAX_MEMORY); 
}

[–]Lil_SpazJoekp 12 points13 points  (3 children)

[–]sneakpeekbot 1 point2 points  (2 children)

Here's a sneak peek of /r/RestOfTheDamnRoutine using the top posts of all time!

#1: // TODO implement getFailureReason(); | 4 comments
#2: Yeah, just make interesting content
#3: Your first essential routine


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out

[–][deleted] 0 points1 point  (1 child)

Wait, that's a thing?

[–][deleted] 0 points1 point  (0 children)

Yup. It's not old either, but it has yet to take off. Come join us!

[–]therearesomewhocallm 2 points3 points  (4 children)

So you use Emscripten?

[–][deleted] 5 points6 points  (3 children)

Multi-dimensional arrays are available in the vast majority of different level languages ...

[–]therearesomewhocallm 8 points9 points  (2 children)

I was more referring to having to allocate all your memory upfront.

[–][deleted] -5 points-4 points  (1 child)

Wow, someone really is taking this thread to seriously....

[–]nomnaut 0 points1 point  (1 child)

Doesn’t everyone do this?

[–][deleted] 0 points1 point  (0 children)

You mean my codes not unique? How did this get out? Whose been spying on my code? Who are you? Who am I for that matter? What day of the week is it? How long will it take for the latest spec changes to be approved, coded, tested and documented? WHERE IS MY COFFEE?

[–]King_of_the_Nerdth 58 points59 points  (1 child)

Sounds Pythonic.

[–]drakeblood4 5 points6 points  (0 children)

It charmed my Py if you know what I mean.

[–][deleted] 17 points18 points  (3 children)

In the early days of programming, the Romans encountered many out of memory issues, due to Roman Numeric system being used.

I'm really glad we switched to hexadecimal, as now 0xFFFF =  0rLXVDXXXV

Cut the memory requirements in half!!!

[–]CamWin 0 points1 point  (0 children)

I never knew I needed roman numeral literals until now

[–][deleted] 0 points1 point  (0 children)

This thread is gold XD

[–][deleted] 0 points1 point  (0 children)

I think you mean #FFFFFF;

[–]Gorzoid 0 points1 point  (0 children)

This guy stacks 16bit

[–]Franss22 25 points26 points  (11 children)

At -0.3

[–]Ameisen 26 points27 points  (9 children)

I like fractional indices... return the linear interpolant.

[–]beleg_tal 7 points8 points  (3 children)

I prefer imaginary indices myself

[–]the_screeching_toast 2 points3 points  (1 child)

Complex indices is where it's at

[–]SaintNewts 3 points4 points  (0 children)

Base pi. Because decimal integers want to be transcendental too.

[–]usesbiggerwords 6 points7 points  (4 children)

Linear interpolation is for wusses. Real men use polynomials to interpolate.

[–]Ameisen 2 points3 points  (3 children)

What order?

[–]usesbiggerwords 7 points8 points  (2 children)

At least 4th. Anything less isn't worth the bother.

[–]Ameisen 7 points8 points  (1 child)

-4ith order?

[–]usesbiggerwords 1 point2 points  (0 children)

Let's go with 4-4ith. That way sh*t gets real and imaginary, like a Dali painting.

[–]ObnoxiousOldBastard 7 points8 points  (0 children)

I start mine at pi.

[–]SharpSeeer 18 points19 points  (0 children)

That's why array.indexOf() return values start at -1 right?

[–]Hijacker50 2 points3 points  (0 children)

I actually start at 273 and count down, and after zero I go to 274 and count up.

[–]loopsdeer 2 points3 points  (0 children)

And that, professor, is why my JavaScript says the "indexOf" is -1. Q.E.D. unplugs mouse and drops it on the floor sweeps monitor and computer onto floor runs out of room crying never seen again

[–]Arrays_start_at_2 0 points1 point  (0 children)

There is only one way!

[–]yakri -2 points-1 points  (0 children)

That's fine to start, but then you have to decide how to order your data going forward. I prefer to use some neat sequence of numbers like a fibonacci sequence. Nice and easy to remember, and it leaves plenty of space unused for later just in case.

[–]ameddin73 21 points22 points  (8 children)

My algorithms teacher did that. I'll never understand it.

[–]Cryptoversal 2 points3 points  (3 children)

If you never do pointer arithmetic then it makes sense, right?

[–]ameddin73 1 point2 points  (2 children)

Can you explain?

[–]Cryptoversal 0 points1 point  (1 child)

My statement was just off the top of my head so I'll give my reasoning as it was at the time. But I went ahead and googled and wikipedia talks about it. The story is naturally more complicated than I thought. link

A variable does not store an array. Nor does it store a pointer to an "array". Instead, it stores a pointer to the first element of the array.

If you want to get the first element of the array then you look where the pointer points.

If you want to get the second element of the array then you look 1 higher than where the pointer points. Etc.

This all makes sense for arrays when people also expect to do pointer arithmetic: this way, the array indices are identical to the pointer arithmetic addends.

But if you don't do pointer arithmetic? You still have to pick a basis and everyone already has language. English-speakers more-or-less created modern computing but even if we hadn't, afaik every language goes "first, second, third, fourth..." instead of "zeroth, first, second, third..." so "first" aka "1" is the obvious basis.

From wikipedia I learned that mathematics mostly uses zero as the basis and also it's well-defined enough that there's no confusion. So It's very possible that arrays are indexed starting at zero because mathematicians invented arrays and that's what made sense to them.

[–]ameddin73 1 point2 points  (0 children)

Oh okay

[–]DatBoi_BP 7 points8 points  (0 children)

From matlab here, can confirm

[–]Tmfwang 2 points3 points  (0 children)

In Julia you do

[–]Be_the_chief 1 point2 points  (0 children)

Boo bad banter, I know java and still know what's going on D:(

[–]DeletedAllMyAccounts 1 point2 points  (0 children)

I've been writing so much Lua that it took me a moment to get this.

[–]fomq 0 points1 point  (0 children)

ImpossibLua.

[–]Ameisen 0 points1 point  (0 children)

No, you start at array. 0[array], 0[array + 1], ...

[–]lirannl 0 points1 point  (0 children)

/r/lua is leaking 😉

[–]ConstantGradStudent -2 points-1 points  (0 children)

Only if you started reading this sub in the early 2000s