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

    def compare(a: Int, b: Int): Int

    This one has not only 232 possible results, but an incalculable (232)264 possible implementations. Even if we are generous and only allow the inputs to be 0 or 1, we still have 2128 implementations. If the only meaningful return values are -1, 0 and 1, indicating “less than”, “equal” or “greater than”, then why would we embed them like specks of dust in a big desert of undefined behaviour?
I don't agree with this. This is not a "big desert of undefined behaviour". The behaviour is defined along the entire spectrum of Integer values. "Less than" maps to all values <= -1, "equal" maps to 0, and "greater than" maps to all values >= 1. There's no undefined behaviour here.



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

Search: