This is in PHP, but it should (I think) apply to any language with a ternary operator.
I have a simple line with a ternary operator assigning a string to a value. The strings ended up being a little too long to put it on one line, though, so the end result looks like this:
$resultingString = ($isValid) ?
"This statement is true."
:
"This statement is false."
;
The code runs perfectly, but it just looks... weird... Is this bad practice? The only alternative I can think of is this:
if ($isValid) {
$resultingString = "This statement is true.";
} else {
$resultingString = "This statement is false.";
}
Which is slightly less DRY.