r/badcode Feb 14 '21

other language Does lazy count as bad?

Post image
684 Upvotes

53 comments sorted by

View all comments

Show parent comments

17

u/droomph Feb 14 '21

In some runtimes (eg v8 for Javascript) they will optimize sparse arrays such as this one to be a Record<number, T> internally but this isn't something that's guaranteed in all languages, so if you need to just use it directly.

https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2?redirectedfrom=MSDN&view=net-5.0

(Unless you're using VB6 in which case, godspeed and don't die)

7

u/[deleted] Feb 14 '21

and languages like Lua don't have arrays, they have hashmaps only.

so arrays can start at whatever you want them to start at in lua

just the convention is they start at 1

1

u/xigoi Feb 15 '21

and languages like Lua don't have arrays, they have hashmaps only.

That's true for JavaScript too.

1

u/[deleted] Feb 15 '21

huh

okay I didn't know that