lua-users home
lua-l archive

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


On Mon, Mar 13, 2017 at 8:20 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:

> - local a,r,k,n = 10000.0, 5.2, 12, 5   -- initializing locals
> - local a,r,k,n = 10000,0                    -- initializing only some
> - local sort, open, min = table.sort, io.open, math.min  -- caching library functions

The above reminds of an email I sent to my colleagues a couple of weeks ago, which said:

local a, b, c, d, e, f, g, h, I, j = k, l, m, n, o, o, q, r, s

One will have to count variables above to figure out what is assigned to what. It is not immediately obvious that the list on the right is shorter than the left-hand list.

(end)

Your first example, with four variables, is already problematic in the sense that while it can be dealt with comfortably, I still have to pause for a brief moment and think along these lines: "5.2, being the second from the left corresponds to r, the second from the left". This flashes through my brain very quickly and so it is almost effortless, but still it means this is less comfortable than the third example, which does not require that sort of reasoning, where I can just see what is assigned to what. So I would say more than three values should be avoided.

That also applies to these:

> - a,b,c = b,c,a                             -- permuting values
> - x,t = x+dx, t+dt                        -- updating related values

where, while the multi-assignment style is clearly beneficial for clarity, one ought to stay within reason (which you did).

The rest of your examples is nonsensical either in style or in function.

Cheers,
V.