Hacker News new | ask | show | jobs
by tel 5703 days ago
As long as we're enforcing ordering on casually unordered sets, when not define it as length of the string? Now 'aa' is certainly greater than 'z'.
1 comments

There's a pretty good case for making the comparison closer to alphabetical ordering. 'apple' before 'pear' even though 'apple' is the longer string.

'z' before 'zz' also follows alphabetical ordering.

Note that there is no such thing as "the alphabetical ordering". Different languages define different collations, and some even multiple ones (e.g., German collation vs German phone book collation, or the various collation systems for Chinese characters). I'm pretty sure PHP's comparison operator will define non-ASCII characters as being outside of the alphabet, and probably just fail on multi-byte strings (UTF-8).

So if you are doing comparisons on strings, you probably either have an i18n bug or a really, really specific use case.

That's what I was thinking, and in this case 'zz' would be > 'a'. I'd say that's a reasonable choice.