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

else/else if on newline #91

Open
rumkin opened this issue Dec 7, 2016 · 6 comments
Open

else/else if on newline #91

rumkin opened this issue Dec 7, 2016 · 6 comments

Comments

@rumkin
Copy link

rumkin commented Dec 7, 2016

I prefer to move logic constructions in separated lines:

if (a) {
    // ...
}
else if (a != b) {
   // ...
}
else {
    // ...
}

This makes code more git friendly (like trailing commas). And also it makes it simple to comment else if and else sections. Each block is prepended with it's own condition.

@krystianity
Copy link

"} else .." has a more natural feeling to it.

@ivanoff
Copy link

ivanoff commented Jan 25, 2017

to comment else section you has to comment the whole else section, no doubt

@pokatomnik
Copy link

pokatomnik commented Mar 24, 2017

So why u dont prefer this?

if (condition)
{
  logic();
}

You can comment whole code block this way. I think if code consists of lots of lines it looks more complicated.

@rumkin
Copy link
Author

rumkin commented Mar 24, 2017

@pokatomnik Because if could not be presented without {. It would be followed by { anyway.

@michaelmano
Copy link

if (condition) {
 // Trick
} else {
 // Treat
}

@rumkin
Copy link
Author

rumkin commented Sep 12, 2017

If-else condition contains several repeated patterns of: keyword [condition] code_block.

if () {}
else if () {}
else {}

This style contains less parts then monolithic if-else. And as I mentioned before It produce exact diffs when new statement added or removed.

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

No branches or pull requests

5 participants