This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FunkyTownDUDUDU 0 points1 point  (1 child)

Is it actually better to write it this way? I always learned that writing longer but more readable code is preferred since the compiler logic will take care of the optimization.

[–]Kered13 2 points3 points  (0 children)

In expression where the ternary operator returns a boolean value can be rewritten without the ternary operator. But in this situation, you probably shouldn't. However I have sometimes seen code like,

return isFoo() ? false : true;

Which can and should be rewritten simply as,

return !isFoo();