loading...

re: What do you think about the ternary operator? VIEW POST

TOP OF THREAD FULL DISCUSSION
re: 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:

if (expressionThatReturnsBoolean() == true) {
  return true;
}
else {
  return false;
}

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.

Code of Conduct Report abuse