[swift-evolution] [Draft] Rename Sequence.elementsEqual

Thorsten Seitz tseitz42 at icloud.com
Wed Oct 18 17:38:07 CDT 2017


> Am 18.10.2017 um 22:31 schrieb Adam Kemp <adam_kemp at apple.com>:
> 
> 
>> On Oct 18, 2017, at 1:20 PM, David Sweeris <davesweeris at mac.com <mailto:davesweeris at mac.com>> wrote:
>> 
>> How many bugs have been caused by floating point types violating the programmer's mental model of how numbers work? To me, their both in the same category... both involve specific types that claim to adhere to a certain behavior, and both don't in sometimes subtle ways.
> 
> I think we have plenty of evidence that misunderstandings about floating point lead to bugs. For example: https://www.theinquirer.net/inquirer/news/1047844/floating-point-bugs-explode <https://www.theinquirer.net/inquirer/news/1047844/floating-point-bugs-explode>
> 
> It took me about 30 seconds to find a clear example for floating point, and we all know there are many many more.
> 
> Can anyone find even a single example of this function leading to a shipping bug in the real world?

Well, it took me not much longer to find a clear example of a bug in a suggested usage of `elementsEqual` on Stackoverflow:

"And, finally, if the two arrays of permissions are actually sets of permissions then you can use
return Set(tokenPermissions).elementsEqual(Set(permissions))
"
(https://stackoverflow.com/questions/33354709/swift-compare-set)


Clearly the example will given random results depending on the order of `tokenPermissions` and `permissions` which is obviously *not* what the author had in mind.

Now this is not production code (hopefully) but it demonstrates the problem.

How will I know if the code behind a generic function taking a Sequence as argument will internally use `elementsEqual` so that I cannot use a Set as argument? 

-Thorsten

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171019/b58c43d1/attachment.html>


More information about the swift-evolution mailing list