Add guideline: avoid multiple assignments per line - #109
Conversation
jferris
commented
Jul 22, 2013
- Reading requires scanning back and forth across the line
- Adding more assignments causes modifications instead of additions
- Hides complexity
- Easy to miss when scanning a method
* Reading requires scanning back and forth across the line * Adding more assignments causes modifications instead of additions * Hides complexity * Easy to miss when scanning a method
|
hey @jferris, does this covers the following? breakfast, lunch = :bacon, :hamburger |
|
+1 |
|
@sikachu yes, that's exactly what I'd like to avoid. |
|
+1 |
|
This could apply to JavaScript, too. Move it to the general "Formatting" section? |
|
I don't feel strongly about this in JavaScript, because the ordering is still sane. Ruby keeps the variables and values far away from each other: first, second = 123, 234JavaScript keeps them together: var first = 123, second = 234;Anybody else have thoughts on this? |
|
It seems that you used the javascript example in your actual change. Personally, I don't like it happening in either language but if your problem is with this version: first, second = 123, 234then that should probably be the example you use. |
|
@drapergeek yeah, good catch - I pushed a fixed example. I find that pretty confusing. |
|
Agreed, I'm still a +1 on this. |
|
re: JavaScript, for what it's worth: Our guides say use CoffeeScript and the typical way you would do multiple assignment is not supported there. That is, you cannot do |
|
This is still fine, though, right? |
|
Thanks for all the feedback. I fixed the typo that @gylaz pointed out, squashed, and merged as 754875a. @mike-burns I'm not sure I've ever seen somebody do exactly that, but I think that would be a separate guideline. Can you link an example of when you'd do assignment from an Array? |
|
Sure can't. Don't think I've done this in years. |