View Single Post
  #3   Spotlight this post!  
Unread 03-04-2004, 07:55
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
Re: Do you use ternary operators in your code?

Quote:
Originally Posted by NotQuiteFree
I figure using an if-then statement that says:

if(y > 5)
x = 1;

is easier to read and understand, than:

x = ((y > 5) ? 1 : 0);
Just as a warning, those aren't completely equilivant. For them to be the same, you should do:

Code:
if(y > 5)
    x = 1;
else
    x = 0;
Or:
Code:
x = 0;
if(y > 5)
    x = 1;
Just pointing that out.

Personally, I think that the extra else clause is worth it in terms of readablitiy. When I'm reading other's code, I find it hard to spot terenary operators, as they are on one line and it is only noted by a : and a ?.
__________________