-
Notifications
You must be signed in to change notification settings - Fork 1.3k
What about the conditional to check if an integer is higher than 0? #23
Comments
I use the former |
Speaking of clarity "former" and "latter" are the parts-of-speech equivalents of ternary operators. ;) |
I think if (text.length) {
[array addObject:text];
} is the more common style on the team. Anyone have a problem if we write this one in? Edit: Edited code example |
I think - length is a method, so unless I misunderstood the dot-syntax rules, should be: If ([text length] > 0) { I prefer the > 0 formulation because its more clear you're testing an integer value, and not a nil check. On Aug 4, 2013, at 11:55 AM, Matthew Bischoff notifications@github.com wrote:
|
You're right. Updated my post to make it a method, but I'm still proposing no |
I disagree about it not being a nil check. It also will return 0 if text is nil, so it's an easy way to check both the existence of text and make sure its contents aren't empty. -Samuel E. Giddins On Aug 4, 2013, at 12:02 PM, Matthew Bischoff notifications@github.com wrote: You're right. Updated my post to make it a method, but I'm still proposing no > 0. — |
if ([text length]) {
[thing doSomething];
} is perfectly valid code, and will excecute |
I’d recommend closing this issue. |
Would you use:
if(text.length){
// do something
}
or
if(text.length>0){
// do something
}
?
The text was updated successfully, but these errors were encountered: