Comment by int_19h

1 year ago

There was a time when this approach was common for dynamic languages in general. PHP and, to some extent, JS also come to mind.

I think it's clear in retrospect that it makes more sense to keep lists and maps separate even in a high-level dynamic language that doesn't care much about perf, and any purported gains in simplicity from having a single data structure are illusory because of footguns. But perhaps it wasn't so clear before we had enough experience with this kind of design.

Then again, Python had a clean separation between lists and dicts from the get go, and it predates Lua as well as PHP and JS...

> even in a high-level dynamic language that doesn't care much about perf

Lua is mostly used inside games, and the JIT compilers for it are said to be pretty good. (I haven't tried this yet, but will have to soon.)

  • These days, yes, but this particular design point predates both LuaJIT and Lua popularity as a gaming scripting language specifically. I remember first seeing it sometime circa 2002 - I believe that was Lua 4.0? - and I was stricken by how much it reminded me of PHP and JS in this regard.

    But yeah, my point is that one of the most common arguments against using associative arrays as the data structure is that perf overhead is unacceptably high if you use it as a list, but we've learned how to implement it in a way that can adapt to this use case at runtime just fine a loooong time ago. But regardless of perf, it just makes more sense to keep sequences and maps separate, not because of any specific technical reason, but because it's easier for humans to reason about things and model them that way.