Skip to content
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

Closed
wants to merge 3 commits into from

Conversation

jferris
Copy link
Contributor

@jferris 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
@sikachu
Copy link
Contributor

sikachu commented Jul 22, 2013

hey @jferris, does this covers the following?

breakfast, lunch = :bacon, :hamburger

@gylaz
Copy link
Contributor

gylaz commented Jul 22, 2013

+1

@jferris
Copy link
Contributor Author

jferris commented Jul 22, 2013

@sikachu yes, that's exactly what I'd like to avoid.

@drapergeek
Copy link
Contributor

+1

@croaky
Copy link
Contributor

croaky commented Jul 22, 2013

This could apply to JavaScript, too. Move it to the general "Formatting" section?

@jferris
Copy link
Contributor Author

jferris commented Jul 22, 2013

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?

@drapergeek
Copy link
Contributor

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.

@jferris
Copy link
Contributor Author

jferris commented Jul 22, 2013

@drapergeek yeah, good catch - I pushed a fixed example.

> one, two = 1, 2
=> [1, 2]
> one
=> 1
> two
=> 2

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`).
Copy link
Contributor

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.

@drapergeek
Copy link
Contributor

Agreed, I'm still a +1 on this.

@derekprior
Copy link
Contributor

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 x = 1, y =2. You can do the JavaScript 1.7 style "destructuring assignment" though. [a,b] = [1,2]. I don't really think it warrants mentioning.

@mike-burns
Copy link
Contributor

This is still fine, though, right?

> a = [1,2]
> one, two = a
> one
 => 1 
> two
 => 2 

@jferris jferris closed this Aug 9, 2013
@jferris
Copy link
Contributor Author

jferris commented Aug 9, 2013

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?

@mike-burns
Copy link
Contributor

Sure can't. Don't think I've done this in years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants