kodecocodes / objective-c-style-guide

A style guide that outlines the coding conventions for Kodeco
http://www.raywenderlich.com/62570/objective-c-style-guide
3.1k stars 628 forks source link

Fixed logical error in section Booleans #52

Closed sebastianwr closed 5 years ago

sebastianwr commented 10 years ago

If I'm not totally mistaken, the the equivalent short check is if(!someObject) when you check for someObject == nil

pietrorea commented 10 years ago

I believe if (someObject) {} was there on purpose to show something evaluating to YES without checking against not nil

gregheo commented 10 years ago

@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.

sebastianwr commented 10 years ago

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. ;)

ndubbs commented 9 years ago

@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.