The ternary operator.
I'm helping a new co-worker, fresh out of college, become familiar with our products. For one of the tasks he's been assigned, I was showing him how I would go about it, and part of my sample code used the ternary (conditional) operator — the b ? e1 : e2 notation. As it turns out, he had never encountered that notation before, and I had to explain it to him. I'm wondering — is that normal? He's a smart guy, and he had no problem understanding the notation once I explained it, but I was surprised that he wasn't already familiar with it.
I know that the ternary operator is sometimes considered bad style, but this case really seemed to be crying out for it — two versions of a large SQL statement, with only one small difference in the middle. This seemed the clearest and most readable way to code it. But if I can't expect people to be familiar with that operator, then I can't expect that code to be clear to them!
What do y'all think? Would you expect the typical Java programmer to be familiar and comfortable with it?
(With normal simple cases, I mean, like (b ? "string_literal_1" : "string_literal_2") and whatnot. Obviously I wouldn't expect people to be comfortable with crazy edge cases, like when autoboxing or implicit widening conversions are involved.)
I know that the ternary operator is sometimes considered bad style, but this case really seemed to be crying out for it — two versions of a large SQL statement, with only one small difference in the middle. This seemed the clearest and most readable way to code it. But if I can't expect people to be familiar with that operator, then I can't expect that code to be clear to them!
What do y'all think? Would you expect the typical Java programmer to be familiar and comfortable with it?
(With normal simple cases, I mean, like (b ? "string_literal_1" : "string_literal_2") and whatnot. Obviously I wouldn't expect people to be comfortable with crazy edge cases, like when autoboxing or implicit widening conversions are involved.)
