Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

notjustjay

macrumors 603
Sep 19, 2003
6,056
167
Canada, eh?
The other issue with a ternary operator is with future code modification. In the example we've used:

return foo? x : y;

This is reasonable, if slightly confusing (I have to stop and think... x is the true case, y is the false case). I might prefer the if/else construct for readability purposes alone, but it would be more likely that I would use the if/else in case I ever need to add code -- perhaps later that simple statement has to become more complex:

if (foo)
{
log("Foo is true: manipulate x and y accordingly");
y+=x/2;
return x++;
}
else ...

Then I'm converting it from the ternary operator anyway, so may as well write it this way in the first place.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.