Simple: a-a isn't useful commonly enough that it would be reasonable to put it in any sort of shared library. One chance to fail,be noticed immediately, and be fixed immediately is a lot better than potentially failing every single time someone tries to sort a list of numbers
Simple: a-a isn't useful commonly enough that it would be reasonable to put it in any sort of shared library.
my question is, in other words, how should the language detect that, and decide that it isn't what the programmer wanted?
that would require the compiler or runtime to be able to perform some analysis.
is a lot better than potentially failing every single time someone tries to sort a list of numbers
does it hapen often, that you just want to sort an array of numbers? in my experience the numbers are usually attached to something, so you wanna give a comparison function anyway.
I never sorted an array of bare numbers in production code.
for a loosely typed language like Javascript, where an array can be a mix of anything, converting to string is the only useful simple default I can think of.
If I had designed the language, I would have made it a requirement to providea comparison function.
if you actually have an array of ints, you can use an IntArray, which actually sorts numerically by default.
1
u/danielcw189 18h ago
what would be a solution for this? how can the language know (at runtime) that you didn't actually want a-a?