Re:Lua: Good, Bad, and Ugly Parts (2012)
by aeternum on Monday December 27, 2021 @03:14AM
(#29700533)
Since this is a Lua thread, your reference list should probably start at 1 rather than 0
[ Parent
| on HN ]
It is about embedding how easy it is to embed lua, so you should be able to use the host conventions
Re:Lua: Good, Bad, and Ugly Parts (2012)
by anothernewdude on Monday December 27, 2021 @04:39AM
(#29700996)
Oh wow, that does make the non-standard array references rather catastrophic.
you wrap the host across the embedding boundary so that the host and lua can either use their own convention or have access to a special object that explicitely and clearly exposes the other convention.
In general using array indexes as foreign keys should always be considered carefully.
And if all you will be doing is iterating then the starting index doesn't really matter (unless you copy paste loop logic, which is a problem in itself)
Errata: you wrap the host across -> you wrap the array across
Re:Lua: Good, Bad, and Ugly Parts (2012)
by BulgarianIdiot on Monday December 27, 2021 @09:34AM
(#29702763)
Because of this I always thought lists should be iterable/traversable, but have no direct (numeric) index to their items.
Re:Lua: Good, Bad, and Ugly Parts (2012)
by stirfish on Monday December 27, 2021 @10:22AM
(#29703171)
Like a stream?
Re:Lua: Good, Bad, and Ugly Parts (2012)
by BulgarianIdiot on Monday December 27, 2021 @12:07PM
(#29704268)
Yes, like a stream, or an iterator. Where you fetch also a reverse iterator if you wish, filter by some predicate etc. A lot of overlap with both relational algebra/sql and with functional programming filter/map/reduce, I guess. Indexes seem convenient, but they're a hack in most cases.
Consider what happens when you sort your array, or delete or insert an item in the middle, or start. Now all your indexes have changed.
React had this issue, and this is why they had to add stable "key" to collections so that when you mutate a sequence of <li/> items for example, it doesn't get confused which is which.