-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmp: Add constants LessThan, GreaterThan, EqualTo #61593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
my preference would be |
I agree with @jimmyfrasche: the proposed names are verbose. I'm not even sure they're necessary, although they're certainly clear. But then giving small integers big names for common uses like seeking and comparison was not the tradition I grew up in; maybe things have moved on. I would prefer LT, EQ, etc. but then that's Fortran, so who am I to say? |
I think if it’s short it should be |
I prefer what @carlmjohnson proposed. More effort to type, but unambiguous and thus easier to read. |
These names would steer developers away from the most elegant way to use cmp.Compare and related functions. In addition to LT, GT, and EQ, what about defining LE and GE? You can't. The reason you can't is that these functions are intended to be used with actual operators in a comparison with zero. That is, the idiom is that if you are trying to find out We could add the named constants, and then if We could of course define LT, GT, and EQ for use in comparison implementations, but then they become an attractive nuisance, something that is possibly okay for defining compare functions but definitely inappropriate when using them. Perhaps the expected usage should be made clearer in the documentation of these functions. I don't believe the constants are a net win. |
You could write GTE as switch cmp.Compare(a.Foo, b.Foo) {
case cmp.GT, cmp.Eq: But I take the point. |
Along the lines of
io.SeekStart
, add constants to cmp to make the magic numbers more readable:The text was updated successfully, but these errors were encountered: