r/programminghumor • • 14d ago

Lua

Post image
3.1k Upvotes

168 comments sorted by

View all comments

Show parent comment

3

u/MrHellYe 13d ago

Are you a programmer or did this subreddit get randomly recommended to you?

Anyway, an array is a list of elements in a sequence, usually represented by brackets, so:

[10, 5, 7, 2, 1] is an array with 5 integers.

In programming, more often than not, array counting starts at 0, so the 0th number here would 10, 1st would be 5, 2nd is 7, etc.

Lua is a programming language that this counting starts at 1 instead of 0, which although is more intuitive for most people, it isn't for experienced programmers

2

u/Toad128128 13d ago

Also note that array sizes are fixed on declarations.

1

u/OgLikeSmash 13d ago • Bravo

Yuck

1

u/AliceCode 12d ago

That's how arrays usually behave. If you want something dynamic, that requires constant reallocation to resize, which isn't always desireable. At a low level, arrays don't even exist. It's just raw memory. And in order for arrays to keep growing, you have to keep moving them to new places in memory that have enough space to hold all of the elements. Normally, the array grows by a factor of 2 upon resizing so that the next resize is further away each time.

0

u/[deleted] 13d ago

[deleted] — view deleted comment

1

u/MrHellYe 13d ago

The guy said below that he's not joking, he legitimely does not know what an array is

1

u/Informal_954 8d ago

Because it isn't the 0th number to a programmer, it is the number with offset 0, then the number with offset 1, etc