lua-users home
lua-l archive

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


On 13 March 2017 at 18:20, Dirk Laurie <dirk.laurie@gmail.com> wrote:
> Which of the following uses is in your opinion good style?
>
> - local a,r,k,n = 10000.0, 5.2, 12, 5   -- initializing locals

Only if they are related constants (e.g. constants from a known
formula if you're implementing an algorithm described in a paper)

> - local a,r,k,n = 10000,0                    -- initializing only some

Rarely

> - local sort, open, min = table.sort, io.open, math.min  -- caching
> library functions

I used to do this, but not any more.

> - a,b,c = b,c,a                             -- permuting values

Yes.

> - x,t = x+dx, t+dt                        -- updating related values

Usually only for *very* related values (e.g. x,y for a point)

> - name,cases,fct = "John", {2,5,6},myfunc   -- defining unrelated values

No.

> - local a1,a2,[[...,]]a256 = 1,1,[[...,]1  -- trying to crash the interpreter

This style can be useful for larger vectors.