Skip to content
This repository has been archived by the owner on Feb 23, 2021. It is now read-only.

If statements without blocks #97

Open
Jwhiles opened this issue May 11, 2017 · 2 comments
Open

If statements without blocks #97

Jwhiles opened this issue May 11, 2017 · 2 comments

Comments

@Jwhiles
Copy link

Jwhiles commented May 11, 2017

Here - don't do it kids.

@oliverjam
Copy link
Owner

Is this a personal preference thing or is there a reason for it? It's come up a few times on the course as it seems quite common to write

if (thing) return a;
return b;

instead of

if (thing) {
  return a;
} else {
  return b;
}

We've never managed to figure out if there's a reason to do the latter, since the former is cleaner/less code

@Jwhiles
Copy link
Author

Jwhiles commented May 12, 2017

It's not particularly dangerous, but there are ways you can break that line if you insert semicolons in the wrong place.

Having multi line if statements block scoped, and single line if statements without blocks makes it slightly harder to glance at the code and understand what's happening.

Finally, I can't see any benefit to omitting the braces. You are saving 1 or 2 keypresses and nothing else.

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

No branches or pull requests

2 participants