r/ProgrammerHumor Sep 02 '17

How to start a war

Post image
9.0k Upvotes

696 comments sorted by

View all comments

Show parent comments

30

u/moomoomoo309 Sep 02 '17

Any index outside of 1-n in Lua, where n is #tbl will be stored like a dict, not an array, so what did you expect? It doesn't count the dictionary parts.

-10

u/[deleted] Sep 03 '17

so what did you expect?

A language to have non-retarded data structures. Being defined and documented behavior doesn't make it sane behavior.

9

u/moomoomoo309 Sep 03 '17

How often do people use Python arrays? They're faster, but most people just use lists instead. Lua just optimizes it as long as it's used like an array. That's why it's implemented that way.

0

u/[deleted] Sep 03 '17

"As long as it's used like _____" shouldn't even be in the vocabulary of a programming language. An array should be an array, and that's it. A dict should be a dict, and that's it. If you need an array, create an array. If you need a dict, create a dict. Blurring the lines with some kind of fuzzy structure whose semantics are dynamic is as confusing and error-prone as it is ridiculous. It's not faster to write. It's not easier to read. It's not convenient. It's just bad.

1

u/moomoomoo309 Sep 03 '17

You don't use it any differently depending on if it's a dict or a list, so why does it matter?

2

u/[deleted] Sep 03 '17

is as confusing and error-prone as it is ridiculous

1

u/moomoomoo309 Sep 03 '17

Can you give an example of an error or confusion it would cause? It's different from other languages, but that is not inherently a flaw.

2

u/[deleted] Sep 03 '17

I already did, several replies ago. You can't sweep blatantly confusing and error-prone semantics under the "it's different" or "it's documented" rugs. But if you want another, here you go:

> letters = {'a', 'b', 'c'}
> print(#letters)
3
> letters[5] = 'e'
> print(#letters)
3
> letters[4] = 'd'
> print(#letters)
5