Created
September 18, 2012 15:10
-
-
Save chrisjpowers/3743662 to your computer and use it in GitHub Desktop.
JavaScript Syntax Question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Do you prefer... | |
if (a) { | |
doA(); | |
} else if (b) { | |
doB(); | |
} else { | |
doC(); | |
} | |
// or... | |
if (a) { | |
doA(); | |
} | |
else if (b) { | |
doB(); | |
} | |
else { | |
doC(); | |
} | |
// Similarly, this... | |
try { | |
doSomething(); | |
} catch (e) { | |
console.log(e); | |
} | |
// or... | |
try { | |
doSomething(); | |
} | |
catch (e) { | |
console.log(e); | |
} |
the fist captures the idea of a logical block better, which, I think, is more valuable than any potential lost clarity by condensing it. (also, as mentioned, saves screen real estate)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've got to say that I prefer the less condensed syntax; How much code I can fit on my screen is not a metric I particularly care about, but how quickly I can parse code very much so is something I care about. Placing the conditionals immediately after the braces can lead to some extremely samey line lengths and that is one of the fastest ways to get me to miss something at a glance.