Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use `return x == 5 ? true : false;`? [closed]

Tags:

I can not see the advantage of this coding practice. The project I'm working with now is full of these statements so it is not a single mistake.

Another example:

return getNumberOfBooks() > 5 ? true : false; 

And another:

return isRed() ? true : false; 
like image 329
Christian Nilsson Avatar asked Jun 08 '12 18:06

Christian Nilsson


1 Answers

There is absolutely no reason to do this.

It is redundant and makes the code harder to read.

The following are far easier to read:

return ( getNumberOfBooks() > 5 );  return isRed(); 
like image 180
jahroy Avatar answered Oct 01 '22 01:10

jahroy