3 ms·
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 unde
by wmwong 16y ago
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!
- scott_s 16y agoWe 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.