Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

They're identical to dictionaries/hash tables in pretty much any language, unless I'm missing something. Besides C, every language I've worked in comes with one of these things built-in. It's surprising to me that so many people consider this noteworthy today. Would someone please enlighten me as to why it is?


Because `.foo` means `[‘foo’]` and because you can easily make sequences out of them (if you write `{ ... i1 = v1, v2, ... }` then `v2` automatically gets the “next” natural number as a key) the ergonomics make them usable as structures and arrays easily. Also the ‘:foo()` syntax binds the LHS of the operator as the first parameter for a method call, and metamethods allow you to easily implement inheritance / dispatch / etc.

It’s more about ergonomics than availability.


Not a full equivalence, but this[0] gets you x.foo, x.bar ergonomics as opposed to x['foo'] etc.

[0] https://docs.python.org/3/library/types.html#types.SimpleNam...


> `.foo` means `['foo']`

Ruby does the same, except that it's `[:'foo']` because Ruby has two string types because fuck you.


>Besides C, every language I've worked in comes with one of these things built-in.

JavaScript? When talking about a language most refer to as "JavaScript-like", it's definitely a noteworthy feature. Otherwise, you're right, it's pretty much expected to be available. Although, I'd say beginner developers might forget about it since the typical use case has string or number keys.


In both languages objects double as arrays, although they do this slightly differently. But the differences are mostly superficial.


PHP also does that, yet doesn't use its arrays for metaprogramming & object orientation (using a separate object system instead).


> Would someone please enlighten me as to why it is?

Both Lua and Javascript attach protocols to their hashmaps which most languages attach to other bits (classes, typeclasses, traits, …) — even if those other bits are underlaid by hashmaps at the end of the day.

They're more like general-purpose objects which can act as hashmaps (badly in the case of javascript).


one can "overload" operations on table instances, most importantly, accessors by forwarding them to another table, which is somewhat similar to prototype-based inheritance


I don't think it's just similar, I think it actually is prototypical.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: