Closed sebastianwr closed 6 years ago
I believe if (someObject) {} was there on purpose to show something evaluating to YES without checking against not nil
@pietrorea I was thinking that too, but a reader might think the first two "good" examples are supposed to mirror the first two "bad" examples. Not sure if that's what was intended, but for good parallel construction (as an editor might say) I would :+1: the change.
Arguments: If you check for if(!someObject)
and return
or continue
you follow the Golden Path rule. If you check for someObject not being nil
, the if
is a little prettier but the cyclomatic complexity increases if you have more conditions/loops inside. I'm in favor for the Golden Path. ;)
@sebastianwr Thanks for the comments and pull request. The Golden Path is definitely the way to go, however this specific line of code is checking for the existence of an object. You don't necessarily want to leave the method (via Golden Path) if checking for one thing then moving on to other code that needs executed.
If I'm not totally mistaken, the the equivalent short check is
if(!someObject)
when you check forsomeObject == nil