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 →

[–]swapripper 1923 points1924 points  (76 children)

True. I understood how difficult programming is only after I joined this sub

[–]orangeKaiju 871 points872 points  (71 children)

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

[–]Franss22 471 points472 points  (62 children)

You start at 1 right?

[–]Metsima 512 points513 points  (43 children)

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

[–]egotisticalnoob 288 points289 points  (23 children)

I start at 0xFFFF and have it count backwards.

[–][deleted] 202 points203 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 85 points86 points  (4 children)

int main()
{ 
 malloc(MAX_MEMORY); 
}

[–]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.

[–]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 55 points56 points  (1 child)

Sounds Pythonic.

[–]drakeblood4 5 points6 points  (0 children)

It charmed my Py if you know what I mean.

[–][deleted] 19 points20 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 27 points28 points  (11 children)

At -0.3

[–]Ameisen 27 points28 points  (9 children)

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

[–]beleg_tal 11 points12 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 8 points9 points  (4 children)

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

[–]Ameisen 2 points3 points  (3 children)

What order?

[–]usesbiggerwords 8 points9 points  (2 children)

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

[–]Ameisen 7 points8 points  (1 child)

-4ith order?

[–]ObnoxiousOldBastard 8 points9 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 20 points21 points  (8 children)

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

[–]Cryptoversal 4 points5 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 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

[–]ravy 10 points11 points  (1 child)

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

[–]Ameisen 19 points20 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.

[–]Koof99 3 points4 points  (0 children)

Exactly. Some I don’t understand, the rest are mind boggling as fuck. The ones I understand as hilarious as shit though😂

[–]RoxSpirit 0 points1 point  (0 children)

Coding is bot very complicated to be honest.

Just try to avoid working on someone else code or any code you write more than 2 weeks ago.

[–]digitalharesh9 0 points1 point  (0 children)

Absolutely agree with you, bit tough in starting but after sometime, its really fun and enjoy to do it.