As already noted, some special numbers can be either < or >= , so your reviewer is just right.
Question: what made you want to encode it that way in the first place? Why do you even think that life is so hard for yourself and for others (people who need to maintain your code)? Just the fact that you are smart enough to infer that < and >= should cover all cases does not mean that you need to make the code more complex than necessary. As for physics, for code too: make everything as simple as possible, but not simpler (I believe Einstein said that).
Think about it. What are you trying to achieve? There should be something like this: "Return 0 if the input is less than 1, otherwise return 1." What you did was add intelligence by saying ... oh, but that means I return 1 if t is greater than or equal to 1. This kind of unnecessary "x implies y" requires additional thought work on behalf of the maintainer. If you think this is good, I would advise doing a couple of years of code maintenance on your own.
If this were my review, I would make one more remark. If you use the if statement, you can basically do whatever you want in all branches. But in this case you are not doing anything. All you want to do is return 0 or 1 depending on whether t <1 or not. In such cases, I think the expression ??: is much better and readable than the if . In this way:
return t<1 ? 0 : 1;
I know that the operator ?: prohibited in some companies, and I think this is terrible. ?: Usually better complies with specifications, and it can make the code much easier to read (if used with caution) ...
Bert Bril Sep 29 '17 at 13:45 2017-09-29 13:45
source share