News for hackers. Stuff that matters.
Re:No ifs...alternatives to statement branching in JavaScript by wmwong on Friday August 06, 2010 @09:54PM (#1582890)
I agree that in some cases, guards, defaults and ternaries flow more naturally. However, I feel that there's a contradiction. You say that it is easier to understand but have learned to write them in plain old "if" first because it's better. It's easier to get it wrong if you write it shorthand. If it's better to start writing them in "if", doesn't that mean it's easier to understand? If it is easier to use guards, defaults, and ternaries, you shouldn't have to resort to plain "if" to get the logic right. And I agree, DOCUMENT!
Re:No ifs...alternatives to statement branching in JavaScript by scott_s on Friday August 06, 2010 @10:59PM (#1582977)
We sometimes use if-else statements to write out some straight-up logic because we don't understand it at first. So we build it from the ground up. If, after writing it all out with primitives, we realize "Oh, it's just this anded with this and ored with that" then we actually understand the problem.

Put another way: if you write a boolean expression as a sequence of statements, my assumption is you don't really understand what you're doing.