3 ms·
Comments, and, one would hope, some tests showing how the obscure edge case interacts with everything else.
by davidw 14y ago
Comments, and, one would hope, some tests showing how the obscure edge case interacts with everything else.
- tedunangst 14y agoSometimes you don't know what the edge cases are because you don't know what the everything else is. If you return something sorted, somebody will write a consumer that depends on the sorting. If you change backends and return things in a different order, you've broken their code. Sure, their code was broken from the start, but it used to work, now it doesn't, and you're the guy who changed something. The only way to prevent this, randomly sorting every unsorted collection you export, isn't feasible to reliably maintain.
- eru 14y ago> The only way to prevent this, randomly sorting every unsorted collection you export, isn't feasible to reliably maintain. It's feasible to maintain. But people might rely on it, too. As a random example (and easily avoidable example), quicksort works with random input, but 'breaks' for pre-sorted input.
- dpark 14y agoThat depends on the pivot chosen. If your quicksort implementation actually hits n^2 behavior with sorted input, it's probably not the best implementation. Any implementation can hit n^2 with random input. It's just highly unlikely.
- eru 14y agoYes, I know. That's what the "easily avoidable" was for. I couldn't think of a better example in a few minutes, but if something can go wrong, I am sure it will eventually go wrong.