[swift-evolution] [Proposal] Instance Operators

Haravikk swift-evolution at haravikk.me
Thu Feb 25 16:12:42 CST 2016


I’m a big +1 for the proposal, I hate managing operators the way they are now. In fact I tend to implement Equatable and Comparable with .equals() and .compareTo() methods in my types so that I only have to call those in the operator implementations (which coincidentally can avoid the problem you mention):

> On 25 Feb 2016, at 20:11, David Waite via swift-evolution <swift-evolution at swift.org> wrote:
> 
> If operators are not effectively final or static, then the semantics change - operators do not perform dynamic dispatch today, same as functions but different from methods.

An important point, but this proposal does suggest keeping the current method as well for the time being, so we can have the instance form use dynamic dispatch like any other method. Personally though I think that making the transition is important as the lack of dynamic dispatch is something that can be confusing and lead to hard to find bugs; in your example the bug is pretty obvious to track down, but in more detailed implementations it may not be obvious that the type of your value is changing the behaviour for operators when it doesn’t for methods.


More information about the swift-evolution mailing list