Hacker News new | past | comments | ask | show | jobs | submit login

> This is exceedingly interesting to me because you'd expect Compare to cost more than < (it does more stuff), and yet people are somehow baited into writing it.

I would expect it to be the same within a couple nanoseconds, because "more stuff" is an extremely small amount of stuff.

The naive direct implementation of a 3 way compare does the exact same comparisons as a direct implementation of less than, it merely returns more information, which makes it more generally useful.




Yeah. To me, I just think it's weird to ask for two pieces of information and then throw one of them away. Sometimes it's not a performance hit, but I feel like it's one of those things where you should get a feeling "I might be doing this wrong". But if you don't know that < exists (and obviously searched for strings.Less), then you won't get that feeling. That's what I find so fascinating; if other people's feelings are similar to mine, then they simply didn't know that you were allowed to use < here.


I don't see it as two pieces of information. It's returning one idea either way, but the tri-state tells you more than a boolean.


But that is more useful, we should agree, for implementing binary trees or sorting algorithms.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: