Originally posted by: LeetViet
What is this line of code trying to do:
variable = something ? something->somethingelse() : 0;
Sorry, if I'm being vague. I don't know what the ? and : 0 are for.
Originally posted by: LeetViet
What is this line of code trying to do:
variable = something ? something->somethingelse() : 0;
Sorry, if I'm being vague. I don't know what the ? and : 0 are for.
Originally posted by: dornick
I prefer the tertiary operator. It looks more compact.
Originally posted by: oog
I've always called them ternary operators. And I don't think they make the code less readable. The g++ extension that allows self-assignment takes more getting used to. I wouldn't bother using these since they aren't in the standard:
int a = 5, b=4;
a <?= b; // a is assigned the value of b
Originally posted by: dornick
I prefer the tertiary operator. It looks more compact.
Originally posted by: statik213
Originally posted by: oog
I've always called them ternary operators. And I don't think they make the code less readable. The g++ extension that allows self-assignment takes more getting used to. I wouldn't bother using these since they aren't in the standard:
int a = 5, b=4;
a <?= b; // a is assigned the value of b
what???? how is that different to a = b?
Originally posted by: EagleKeeper
As others stated it is a shorthand notation for a if/then/else statement.
Can make it a pain to read the code and does not make the execution of the code any faster if a decent compiler is used.
Originally posted by: BingBongWongFooey
Originally posted by: EagleKeeper
As others stated it is a shorthand notation for a if/then/else statement.
Can make it a pain to read the code and does not make the execution of the code any faster if a decent compiler is used.
Anything is a pain to read if you're not used to it. There is nothing inherently hard to read about the ternary operator; in fact I value conciseness a lot, and for that reason I like it.
Originally posted by: EagleKeeper
Originally posted by: BingBongWongFooey
Originally posted by: EagleKeeper
As others stated it is a shorthand notation for a if/then/else statement.
Can make it a pain to read the code and does not make the execution of the code any faster if a decent compiler is used.
Anything is a pain to read if you're not used to it. There is nothing inherently hard to read about the ternary operator; in fact I value conciseness a lot, and for that reason I like it.
Maintainence and documenation need to be considered when writing code.
to many people try and keep code as terse as possible and not indicate reason for logic.
These type of statement unless documented can become a both for someone attempting to maintain the code at a later date.
It can create poor habits down the road, even if the code itself is quality.
Same here - I like to write as little code as possible and keep things compact. I hate scrolling through pages and pages of redundant code.I prefer the tertiary operator. It looks more compact.