-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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, 234 JavaScript 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, 234 then that should probably be the example you use. |
@drapergeek yeah, good catch - I pushed a fixed example.
I find that pretty confusing. |
@@ -88,6 +88,7 @@ Ruby | |||
|
|||
* Avoid conditional modifiers (lines that end with conditionals). | |||
* Avoid organizational comments (`# Validations`). | |||
* Avoid multiple assignments per line (`one two, = 1, 2`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo on the first comma.
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. |