On the elementsEqual problem, or “[Pitch] Set and Dictionary should not be Sequences”

Here's a recent relevant thread that covers this issue. I still hold the following opinions, expressed in much greater detail in that thread:

  • The fact that you can iterate Set and Dictionary in a fixed order is inherent to these types being useful (see the implementation of the various Set methods, for example), not an accident.
  • The main problem with elementsEqual was the name, but it was decided that the name wouldn't be changed. If the name of this method made it clear that compared in sequence order then it would be somewhat useless for Set but not harmful.
  • Equatable and elementsEqual are entirely unrelated, so nobody should expect that a == b implies a.elementsEqual(b) OR vice versa. e.g. You can reasonably create a collection type with additional properties that should be compared in an Equatable conformance, so even if elementsEqual is true, == may not be.
  • There are many possibly useful methods you can call on a Set or Dictionary because of Collection conformance, and a small number of possibly useless methods.
  • As I said in that other thread, I wouldn't mind collection conformance being moved to a property that provides a Collection conforming view, which is the topic of this thread. But, as @DeFrenZ mentioned above, the opposite decision was made for String, so I would have to understand what is different about this case. I don't understand the reasoning that the situation is different because of the clash between Equatable and elementsEqual, because that clash is inherent as mentioned above (and we failed to make the change to the name required to make the difference clear).

Again, the majority of methods on Set provided by Collection conformance are not demonstrably useless, see the above link. If you shuffle an Array the number of useful Collection methods on that Array is similar to that on Set.

3 Likes