My preferences in order would be: 1. Split out of Sequence Iterable/ForEachable (whatever the name) and have Set and Dictionary conform to this new protocol instead of Sequence. With further protocols splits made to other 'mixin' protocols to keep the order of iteration undefined.
2. Rename elementsEqual, iterableOrderEqual and change the definitions of all the order dependent methods in the 'collections' hierarchy to explicitly say "based on iteration order" and to explicitly say that "the method iterates over the collection to produce their result and if the collection can only iterate once then subsequent calls will cause a fatal error". There is only one reason that I can see for rejecting my 1st option - it's just too much effort. I don't accept the argument of a breaking change in the true sense of the word breaking because algorithms over Set/Dictionary that rely on order are broken and there explicitly cause a compile time error for these is good. Arguing that it isn't good to deliberately break these algorithms is like saying that if there is a bug in the compiler that accepts faulty code we shouldn't fix it because that will break someones code - no a bug should be flagged. -- Howard. On 17 October 2017 at 10:40, Jonathan Hull via swift-evolution < swift-evolution@swift.org> wrote: > To expand on this, Set([1,2,3,4,5]).hasPrefix([1,2,3]) currently returns > true. But let’s say a year from now, we change Set to return an ordering > based on hash values (which is entirely reasonable). Suddenly the same code > may return true or false. > > No guarantees will be broken by doing that, but the result has still > changed because we are building on top of undefined behavior. Collection > says nothing about the ordering over different builds of a program. > > Thanks, > Jon > > On Oct 16, 2017, at 4:11 PM, Jonathan Hull via swift-evolution < > swift-evolution@swift.org> wrote: > > > On Oct 16, 2017, at 1:05 PM, Xiaodi Wu <xiaodi...@gmail.com> wrote: > > > On Mon, Oct 16, 2017 at 10:49 Jonathan Hull <jh...@gbis.com> wrote: > >> >> On Oct 16, 2017, at 7:20 AM, Xiaodi Wu <xiaodi...@gmail.com> wrote: >> >> To start with, the one you gave as an example at the beginning of this >>> discussion: Two sets with identical elements which have different internal >>> storage and thus give different orderings as sequences. You yourself have >>> argued that the confusion around this is enough of a problem that we need >>> to make a source-breaking change (renaming it) to warn people that the >>> results of the ‘elementsEqual’ algorithm are undefined for sets and >>> dictionaries. >>> >> >> No, I am arguing that the confusion about ‘elementsEqual’ is foremost a >> problem with its name; the result of this operation is not at all undefined >> for two sets but actually clearly defined: it returns true if two sets have >> the same elements in the same iteration order, which is a publicly >> observable behavior of sets (likewise dictionaries). >> >> >> But that iteration order is undefined and could easily change due to >> changes in the private/internal structure of sets/dictionaries. Algorithms >> that rely on that “publicly observable behavior” (i.e. leaking of >> internals) will suddenly break. >> > > And an algorithm in which such “sudden breakage” would occur is…? > > > Here are a few off the top of my head: > > func hasPrefix(Sequence)->Bool > func hasSuffix(Sequence)->Bool > func containsSubsequence(Sequence)->Bool > > What do these methods mean with regards to Set’s “publicly observable > behavior”? > > > You keep claiming that this bug is a feature because it is the current >> behavior… but that is tautological reasoning. >> >> Thanks, >> Jon >> > > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution > > > > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution > >
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution