[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: When is multiple assignment good style?
- From: Coda Highland <chighland@...>
- Date: Mon, 13 Mar 2017 09:59:20 -0700
On Mon, Mar 13, 2017 at 9:41 AM, Tim Hill <email@example.com> wrote:
>> On Mar 13, 2017, at 1:35 AM, Sean Conner <firstname.lastname@example.org> wrote:
>> 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
> Interesting, because I like multiple assignment to get just the opposite effect (also after many years of assembly coding). Given that the more of my code I can see on the screen at once, the more I like it, I tend to try to use a more horizontal style. However, I try to avoid piling up too many assignments (3-4 max), and only when the RHS expressions are simple.
> Another case is when a few local control variables are being setup for some following block of code. I like that they are grouped together to essentially say “setup state for the following code”.
I think there's a reasonable argument for
local a, b, c, d =
e, f, g, h
This gives you some level of alignment between value and variable that
one-lining it doesn't, while being more compact than a series of