Like many people, I used 4 spaces for years, but 2 spaces has definitely been winning in JS culture. It's been the standard at the last few gigs I've consulted for and is also standard on many OSS projects.
After using it for a while I like it. It's especially nice for nested ternaries:
I fall in the camp that nested ternaries are bad and should be refactored to make more sense to the casual reader so setting breakpoints on indented ternaries will never be in my code.
I find use cases for ternaries exceedingly rare. I only use them in trivial cases, like:
var foo = (useA) ? a : b;
Even then, I'm a lot more likely to do:
var foo = b;
if (use A) {
foo = a;
}
Pretty much only really use them when the case is trivial and there's an aesthetic benefit to keeping the whole assignment on one line (e.g. it's just one in a long list of things being assigned).
38
u/mrkipling Mar 27 '15
Yes - they suggest a tab indent of 2 spaces instead of the obviously-correct value of 4. Hence, mostly reasonable :)