[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Do you also use superfluous table keys?
- From: Daurnimator <quae@...>
- Date: Mon, 20 Feb 2017 19:10:25 +1100
On 20 February 2017 at 19:00, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> Would you occasionally code
>
> tbl = { [1]="abc", [2]="def", k1=nil, k2=nil}
>
> rather than
>
> tbl = {"abc","def"}
>
> deliberately?
>
Yes; this A) is a form of documentation that shows the
expected/allowed/future members of your table; and B) will preallocate
a table that will be sure to fit all the members.
I often do it in my libraries. e.g.
https://github.com/daurnimator/lua-http/blob/6d79d1233077d9be54cf76686783044e1a17e0d1/http/h2_connection.lua#L151