Skip to content

Add guideline: avoid multiple assignments per line - #109

Closed
jferris wants to merge 3 commits into
masterfrom
jf-multi-assignments
Closed

Add guideline: avoid multiple assignments per line#109
jferris wants to merge 3 commits into
masterfrom
jf-multi-assignments

Conversation

@jferris

@jferris jferris commented Jul 22, 2013

Copy link
Copy Markdown
Contributor
  • 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

sikachu commented Jul 22, 2013

Copy link
Copy Markdown
Contributor

hey @jferris, does this covers the following?

breakfast, lunch = :bacon, :hamburger

@gylaz

gylaz commented Jul 22, 2013

Copy link
Copy Markdown
Contributor

+1

@jferris

jferris commented Jul 22, 2013

Copy link
Copy Markdown
Contributor Author

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

@drapergeek

Copy link
Copy Markdown
Contributor

+1

@croaky

croaky commented Jul 22, 2013

Copy link
Copy Markdown
Contributor

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

@jferris

jferris commented Jul 22, 2013

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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

jferris commented Jul 22, 2013

Copy link
Copy Markdown
Contributor Author

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

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

I find that pretty confusing.

Comment thread style/README.md Outdated

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@derekprior

Copy link
Copy Markdown
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
Copy Markdown
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

jferris commented Aug 9, 2013

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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