(boolean_expression) ? statement;

C

Chris Dollin

Vladimir said:
Tastes differ. I find the above quite unreadable (both variants).

How strange. For me it's utterly transparent (with the second being
the better): pick a (function) value and call it.
I'm not saying `?:` has no uses whatsoever, though.

I assume not.
 
V

Vladimir Oka

Chris said:
How strange. For me it's utterly transparent (with the second being
the better): pick a (function) value and call it.

It could be my Pascal upbringing. I don't mind (I actually prefer)
wordiness. I tend to use `?:` for calculations.

It could also be down to those few years I was banned from using it at
work (coding standard at the time, I think I mentioned it).

I wouldn't criticise anyone using it, I just often won't use it myself.
 
D

Duncan Muirhead

It could be my Pascal upbringing. I don't mind (I actually prefer)
wordiness. I tend to use `?:` for calculations.

It could also be down to those few years I was banned from using it at
work (coding standard at the time, I think I mentioned it).

I wouldn't criticise anyone using it, I just often won't use it myself.

I've used this in the case that the functions have many and/or complicated
arguments. In this case I feel its easier to be sure that the arguments
are the same in
(x == 42 ? f : g)( /* complicated argument list */);
then in
if ( x == 42)
{ f( /* complicate argument list */);
}
else
{ g( /* complicated argment list */);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top