While browsing my code in a weakly-typed language I was seeing that I've trained myself to use identity (===
) where logical. Then I came across a greater (or less) than or equal to (>=
), and it made me wonder... why is there no "greater than or identical to"? I suppose it would be >==
. For example...
5 == 5 // true
5 === 5 // true
5.5 >= 5 // true
5.5 >== 5 // false
6 >= 5 // true
6 >== 5 // true
Basically, I would throw a false if it was of a different type. For example, if I want to check if $x is greater than $y, but I want them both to be integers (or floats, but no mixing), then wouldn't it make sense to have a single call that can do all that, rather than having to check separately to see if they were the same type?
A quick google indicated that this may not exist in any language; why not? Is it just not as useful as I might think it is? :)
>==
is doing two things: testing that the two operands and if they are, compare values of them. That is confusing and I don't like it. Would>==
only be applicable to numeric operands? What if I tried$shoppingcart >== $user_acct_info
? Would that even make sense? I think that$shoppingcart === $user_acct_info
might make sense (I think it would test if the two are of the same type), but>==
? ... I dunno man...===
doing two things, though? It tests that the two operands are identical and, if they are, compares the values.===
does one thing - tests if two things are identical including their types. Your proposed>==
tests if the types are identical and if so compares them. If this is a valid operation, then so is "test if they are the same type and if so, check if one is strictly greater than the other", and how would you notate that?