This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
If statements without blocks #97
Comments
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 |
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.
Here - don't do it kids.
The text was updated successfully, but these errors were encountered: