User talk:DarthKitty/Lua style guide

Parallel assignment
The problem with parallel assignment is that you have to mentally find the correct name-value pairs, which makes it more time-consuming to read than separate assignment.

++      |                                |       |    ++      |       |    |                    |      |       |    |     +---+      |      |       |    |     |       |      |      | local one, two, three = 'foo', 'bar', 'baz'

Even if every value is the same, other devs won't automatically know that; they'll either match pairs like I described above, or compare the values to determine if they're equal. Either way involves parsing.

++                                       |        |                               ++        |                               |        |        | local text1, text2, text3 = 'equal', 'equal', 'equal'

In fact, the only cases where parallel assignment does NOT create more work are...

When all values are
Parallel assignment is okay here because there are no values to match or compare.


 * -|Parallel=


 * -|Separate=

When all values are returned from a single function
Parallel assignment is okay here because the alternative is ridiculous.


 * -|Parallel=


 * -|Separate=

When swapping variables
Parallel assignment is okay here because the alternative is confusing and requires an extra variable.


 * -|Parallel=


 * -|Separate=

Conclusion
I'm explaining all of this because [ Dessamator's recent edit] made me wonder if the corresponding section of the style guide is clear enough. Suggestions are welcome!

DarthKitty (talk) 18:25, July 21, 2015 (UTC)