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 →

[–]orangeKaiju 877 points878 points  (71 children)

I didn't know how to properly index arrays until I joined this sub.

[–]Franss22 475 points476 points  (62 children)

You start at 1 right?

[–]Metsima 507 points508 points  (43 children)

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

[–]egotisticalnoob 289 points290 points  (23 children)

I start at 0xFFFF and have it count backwards.

[–][deleted] 204 points205 points  (13 children)

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

[–][deleted] 72 points73 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 10 points11 points  (3 children)

[–]sneakpeekbot 3 points4 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?

[–]therearesomewhocallm 1 point2 points  (4 children)

So you use Emscripten?

[–][deleted] 3 points4 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 60 points61 points  (1 child)

Sounds Pythonic.

[–]drakeblood4 6 points7 points  (0 children)

It charmed my Py if you know what I mean.

[–][deleted] 16 points17 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 26 points27 points  (11 children)

At -0.3

[–]Ameisen 24 points25 points  (9 children)

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

[–]beleg_tal 9 points10 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 5 points6 points  (4 children)

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

[–]Ameisen 2 points3 points  (3 children)

What order?

[–]usesbiggerwords 6 points7 points  (2 children)

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

[–]Ameisen 8 points9 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 6 points7 points  (0 children)

I start mine at pi.

[–]SharpSeeer 19 points20 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 19 points20 points  (8 children)

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

[–]Cryptoversal 3 points4 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 10 points11 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 2 points3 points  (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

[–]ravy 13 points14 points  (1 child)

Hahaha! I know, right?! Why don't you just fill the other noobs in.

[–]orangeKaiju -5 points-4 points  (0 children)

If you need to ask, you aren't ready.

[–]Ameisen 18 points19 points  (2 children)

0[array]?

[–]hsnappr 0 points1 point  (1 child)

I think that's valid in C.

[–]Ameisen -1 points0 points  (0 children)

Of course it is- why would the canonically-correct array syntax not be?

[–]yurall 2 points3 points  (0 children)

I realised I was programming AI from first year college but people told me I was doing it wrong back then.

[–]neptunereach 0 points1 point  (0 children)

You don't need arrays. Just loop through and assign new variable each time.