[swift-evolution] Marking sort and sorted with rethrows

Tim Vermeulen tvermeulen at me.com
Wed Jun 8 12:32:12 CDT 2016


Of course, on performance of the normal case should never be compromised. So if making two overloads is the only way to ensure that, then that’s what it takes. But will the performance of the normal case really suffer if we only require a sorting algorithm to restore the array to an arbitrary permutation of the original array, in case of an error?

If the consensus is that the original order of the array should be restored, then the normal case would obviously suffer from it. But I think just making sure no elements are lost is way more important than ensuring that the order is preserved. After all, changing the order is what a sorting algorithm does, so the original order is probably not crucial. But if the elements might be lost, people might be encouraged to make a back-up of the array before sorting it, in case an error is thrown.

> > On Jun 8, 2016, at 7:52 AM, Brent Royal-Gordon<brent at architechies.com>wrote:
> > 
> > > Is there a widely used comparison function that throws?
> > 
> > Any comparison function that examines external data related to the instance:
> > 
> > * Sorting filenames by the data in the corresponding files
> > * Instances backed by a database where actually loading the data could fail
> > * Etc.
> Ok, instead of using rethrows, would it be a better overall design be to define two overloads, one that takes a throwing closure and one that doesn’t? This allows the throw-supporting implementation to be slower without punishing the normal case..
> 
> -Chris
> 
> 
> 


More information about the swift-evolution mailing list