I love the ternary operator. It’s so terse and clever. It’s been my bread and butter for years. It does things no other operator can do, and on three operands! It’s really a shining example of programming language designer genius.
But lately we’ve been having problems. Things between us just aren’t working out.
I generally catch it sneaking around, hiding complexity in a quick line of seemingly meaningless symbols. I won’t stand for it any longer.
I hardly ever actually type it out, anyway. I always use Resharper to craft it from an existing if statement.
It’s not that I don’t understand the ternary operator. I do. But as it increases the time-to-comprehension while reading and maintaining source code by even one tick, its unholy presence can accumulate an untenable viscosity in my workflow.
Reading code I’ve previously written, I find myself using Resharper to decode those same ternary operators back into if statements.
Source code should be easy to write and easy to read. There are very few contexts in which I’ll tolerate greater terseness over comprehensibility.
Ternary operator, pack your bags. It’s not you it’s me.
4 Responses
Arnis L.
17|Nov|2009 1Works for me fine. Just avoid double/triple ternary operators. Those are pure evil.
Justin Etheredge
17|Nov|2009 2I agree that it can be ugly, but until the if…then block in C# can return a value, there will always be a small number of cases where the ternary operator will be more readable.
Eric Schaefer
18|Nov|2009 3I never liked the ternary operator, but as of lately I am using it sometimes, but with special formatting:
result = isItMondayAgain()
? “Yes, it is!”
: “No, it isn’t!”;
Eric Schaefer
18|Nov|2009 4Well, imagine line 2 and 3 of the code in the previous comment indended…
Leave a reply
Search
Categories
Archives
Links
Recent Posts
Tags