[Insight-developers] The Evil Ternary operator.

Luis Ibanez luis.ibanez at kitware.com
Sat Aug 28 16:27:08 EDT 2010


>
>
> As for the style of a trinary operator vs seven lines of code, I just found
> seven to be too many.
>
> ---------

Well,
they are three lines of code and four brackets.      :-)

The real difference comes when you run this in a debugger,
and when a new reader of the code has to come and figure
out what the code is doing.

Human readers will mentally translate that ternary operator
into an "if", and it will simply increase the cost of maintenance
of the code (most of the time of debugging code is spent
reading code, trying to figure out what it was supposed to do).


It is a lot better to have three lines of code and four brackets
than having a single line of code with a ternary operator that
is not easily debuggable nor maintainable.


At the end,
the code is intended for human readers.


    Luis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100828/d7995890/attachment.htm>


More information about the Insight-developers mailing list