[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: When is multiple assignment good style?
- From: Sean Conner <sean@...>
- Date: Mon, 13 Mar 2017 04:35:30 -0400
It was thus said that the Great Dirk Laurie once stated:
> Which of the following uses is in your opinion good style?
>
> - 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
> - a,b,c = b,c,a -- permuting values
> - x,t = x+dx, t+dt -- updating related values
> - name,cases,fct = "John", {2,5,6},myfunc -- defining unrelated values
> - local a1,a2,[[...,]]a256 = 1,1,[[...,]1 -- trying to crash the interpreter
I only use multiple assignments in one line for two cases:
permuting values (and then, it's usually only a swap of two values)
when a function returns more than one value
For everything else, I tend to use one variable per line. I tend to like
vertical code layouts (it comes from years of assembly language
programming).
-spc