4 ms·
That's another great way to reduce nesting--factor it out into smaller more-focused functions. I came up with an intentionally contrived example to specificall
by ericflo 15y ago
That's another great way to reduce nesting--factor it out into smaller more-focused functions. I came up with an intentionally contrived example to specifically induce nesting, but you're right that's a better way to write it.
- vog 15y agoNote that the "or" operator has some important downsides. For reducing bugs, using a COALESCE-like operator is IMHO more feasible. (see also: http://news.ycombinator.com/item?id=3415522 http://news.ycombinator.com/item?id=3415522)
- masklinn 15y agoConsidering the semantics of the method (getting a user object or identifier), I don't think that's an issue. And a falsy OR also allows for using good (and falsy) null objects instead of nulls in object-oriented languages, an ability which would be lost (and lead to more reliance on NULLs, a behavior which should not be promoted) through a stricter selective operator. The inability to trivially use null objects in conditionals is, in fact, one of the things I dislike in Ruby (where only `false` and `nil` are falsy).
- yxhuvud 15y agoCan you exemplify that inability? What is it you can't trivially do?