Absolutely love it for it's simplicity and how widely it's been implemented in almost every programming language.
But I absolutely cannot stand it when someone does something like this:
returnexpressionThatReturnsBoolean()?true:false;
or this:
return!expressionThatReturnsBoolean()?true:false;
or any variation of taking an expression that returns a boolean and immediately transforming that boolean with a ternary operator to return a boolean.
I've had many people tell me that this improves the "readability" of the statement, but I strongly disagree. I think all it does is add redundancy to the code and add more complexity with little benefit.
Readability is subjective, but I would say that when your code reads: if true return true, if false return false... I mean you might as well be writing:
Readability is also contextual. I might do similar things in two different ways depending on how readable it would be over there. Doing it your way might be my preference, but sometimes I'll find myself using a ternary for the same.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Absolutely love it for it's simplicity and how widely it's been implemented in almost every programming language.
But I absolutely cannot stand it when someone does something like this:
or this:
or any variation of taking an expression that returns a boolean and immediately transforming that boolean with a ternary operator to return a boolean.
I've had many people tell me that this improves the "readability" of the statement, but I strongly disagree. I think all it does is add redundancy to the code and add more complexity with little benefit.
I agree with you on
return expressionThatReturnsBoolean() ? true : false;
. Readability can be subjective though ¯\(ツ)/¯.Readability is subjective, but I would say that when your code reads: if true return true, if false return false... I mean you might as well be writing:
Perhaps.
Readability is also contextual. I might do similar things in two different ways depending on how readable it would be over there. Doing it your way might be my preference, but sometimes I'll find myself using a ternary for the same.