PBP: 020 Ternaries

The book talks about how confusing the ternary operator can be and how much of a mess it can make.  I’m almost surprised it doesn’t say, “Don’t use it.”

It suggests columns instead, with the condition, then the positive result.

I really don’t like it.  I find the wide columns hard to read, and want to sit and rewrite the code into something more readable.  This is one of the first things the PBP has suggested that I find utterly unreadable.

Of course, I find chains of ?: unreadable almost how ever you format them.  But columns are not it.

What’s better?  I’m not sure.  I’d want to be intending the succeeding blocks, as they’re really if – else clauses, and that’s how I need to think about them to make sense of them, but nobody does.

In general, I avoid chains of them, and use other structures.  I would never format them this way.  Ugh.

 

Tags:

Leave a Reply