lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2016-08-20 5:34 GMT+02:00 Andrew Starks <andrew@starksfam.org>:
> On Fri, Aug 19, 2016 at 8:02 PM, Ross Berteig <Ross@cheshireeng.com> wrote:
>> On 8/19/2016 10:13 AM, Viacheslav Usov wrote:
[...]
> Lua has tables. It does not have sequences/arrays.
...
> First, in every other computer programming language an array would not
> contain any non-index keys at all. This concept is already unfamiliar
> to them, but we allow it in Lua, because it is too convent not to. So
> array-like tables are already extended beyond most people's
> experience.
...
> The above concession to convenience creates a behavior that silently
> "does what you hope" at the expense of consistently following the
> rules. This is very un-Lua like.

The theorem that the base angles of an isosceles triangle are equal
is known as the "Pons Asinorum" (bridge of asses). Current use of the
term is defined by WordNet as

  pons asinorum
      n 1: a problem that severely tests the ability of an inexperienced person

Translated into geek jargon, "a gotcha that trips up newbies".

I think that understanding tables is the Pons Asinorum of Lua. Andrew gives
a nice explanation of why it is so. Most experienced Lua users have at some
time also had a stab, often several, at explaining it to newbies.

By now, we all realize that if there were a simple way of explaining the
consequences of practically implementing the super-simple abstract
definition of a table, someone would have found it.

My own experience went like this:

1. I had been programming for decades, starting at Fortran, with Python
as the most recent acquisition, when I encountered Lua.
2. Having a table as only structure charmed me: so minimal and so
powerful.
3. I discovered that simple did not mean easy, and it only got worse for
almost a year. With the help of John, I redesigned and rewrote the table
library ...
4. Suddenly tables just clicked into place, and I could no longer understand
why anybody, including me, ever struggled with them.
5. It's still like that, except that once in a blue moon, something crops up
which makes me realize that the topic is never totally free of pitfalls, even
for an experienced user. Like needing Philipp to point out that the fact that
`false` is a valid key, spoils a `repeat`-based traversal of a table by `next`.

So maybe the best answer to a newbie question on our Pons Asinorum
is the one that suits questions like "Mummy, why must I stay out of the
lounge when my sister and her boyfriend ar in there?", namely "Never
mind dear, you will understand why when you grow up."

I hated that answer, but I did understand when I grew up.