When discussing ternaries, we also have to discuss readability. While short and concise, they’re in some ways too compact. But don’t worry, Mark‘s co-worker has a wonderful simplification to ternaries. This representative line is a pattern used throughout the codebase.
pnlErrorMessage.Visible = !string.IsNullOrEmpty(errorMsg) ? true : false;
This is genius, as the ternary becomes documentation for a boolean expression, telling us when we’re setting things to true or false without having to think about what the expression we’re evaluating means. If there is an error message, we set the error message UI element’s visibility to true. Explicit, verbose, and readable.
What we’re really looking at here is the ol’:
if (expression)
return true;
else
return false;
pattern, compressed into a single ternary. Annoying, useless, and a hint that our developer doesn’t understand booleans.
Continuously monitor your servers for configuration changes, and report when there’s configuration drift. Get started with Otter today!
Source: Read MoreÂ