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

[coffee] assignment to conditionals #2

Open
davidpfahler opened this issue Nov 11, 2013 · 5 comments
Open

[coffee] assignment to conditionals #2

davidpfahler opened this issue Nov 11, 2013 · 5 comments

Comments

@davidpfahler
Copy link
Member

I open this for discussion. Should it be:

result = 
  if _.isObject wrappedData
    {}
  else if _.isArray wrappedData
    []

or

result = if _.isObject wrappedData
  {}
else if _.isArray wrappedData
  []

Both produce the same output.

@boennemann
Copy link
Contributor

What's your preference here?

I'd prefer the latter, unless L1 > 79 chars.

@davidpfahler
Copy link
Member Author

I prefer former because a) it's simpler (no "unless L1 > 79 chars" condition to keep in mind) and b) it makes if more obvious for my brain to recognize what's going on: i.e. The primary function of what is happening here is an assignment which is conditional. The assignment has its own hierarchy above the conditionals.

@boennemann
Copy link
Contributor

imho

result = 

is an entire line w/o meaning and therefore to be avoided. If we have to break lines for > 79chars we'd probably do it elsewhere anyways

result = if someFunctionThatHasALongNameAnd(takes
  a
  lot
  "of"
  args
)
  wat
else
  wot

needless to say this code is super ugly anyways

@boennemann
Copy link
Contributor

but still prettier than

result = 
  if someFunctionThatHasALongNameAnd(takes
    a
    lot
    "of"
    args
  )
    wat
  else
    wot

where we have to indent one level further

@davidpfahler
Copy link
Member Author

Ha, this is clearly a subjective perception difference. I'd absolutely prefer your second example. Make it much easier for me to grasp what is happening. Reason probably is that I don't read line-by-line but I observe blocks. I agree that the line itself

result =

doesn't mean anything, but it is not without context. In context, it makes more sense for me.

But then again, it really doesn't make that much of a difference and you can argue that the other variant is better for you, so it probably doesn't matter.

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

No branches or pull requests

2 participants