[ajug-members] Ternary Operator - simplification or complication?

Björn Gustafsson bjorng at gmail.com
Thu Jun 1 16:19:07 EDT 2006


On 6/1/06, Jonathan Komorek <jonathan.komorek at benefitfocus.com> wrote:
>
> I just opened up a can of worms within our development community by stating
> that in certain cases, I find that the Ternary Operator simplifies code.
> I've been given the impression that I'm the last Java developer alive that
> believes the ternary operator should ever be used. I'm interested in hearing
> the opinions of users on this group.
>
> Has the ternary operator helped you? Caused you great grief? Should it even
> be in the language?

Yes, yes, and no.  I guess I'm in the minority here, but I don't think
it should be in Java at all.

I loved the ?: construct in C, and it made sense there. Porting it
into Java was a horrible hack to appease old-timers (like me).  It
should have been left behind with the utterly useless switch/case
implementation and assignments within expressions.

Having said that, I admit that I (rarely) use it in simple return
clauses.  It's too ingrained in my brain to leave behind completely,
as long as the language supports it.  (Though I do like the idea of
making the IDE/compiler/repository deprecate it.)

-- 
Björn Gustafsson




More information about the ajug-members mailing list