[swift-evolution] Static Dispatch Pitfalls

L. Mihalkovic laurent.mihalkovic at gmail.com
Sun May 22 12:36:07 CDT 2016


> On May 22, 2016, at 5:31 PM, Matthew Johnson <matthew at anandabits.com> wrote:
> 
> 
> 
> Sent from my iPad
> 
>> On May 22, 2016, at 8:39 AM, L. Mihalkovic <laurent.mihalkovic at gmail.com> wrote:
>> 
>> 
>>> On May 22, 2016, at 3:15 PM, Matthew Johnson <matthew at anandabits.com> wrote:
>>> 
>>> 
>>> 
>>> Sent from my iPad
>>> 
>>>>> On May 22, 2016, at 1:49 AM, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
>>>>> 
>>>>> On 22.05.2016 3:01, L. Mihalkovic via swift-evolution wrote:
>>>>> Read the proposal... I have an aversion to-go coffee cups that remind
>>>>> people that hot coffee may burn them, and when my daughter was 4 we
>>>>> explained to her why knives were to be handled with care, rather than
>>>>> remove them all from her sight. IMHO the proposal evoques mandating
>>>>> training wheels rather than letting people learn naturally from their
>>>>> errors.
>>>> 
>>>> I can partially support this opinion. But we have a situation with protocol extension methods and static dispatches in which we need Swift's help on compilation stage. IMO Using your words, right now we just got knife in our hands *without* any explanation. Then we hurt ourselves, and *then* we know that such methods will be dispatched statically(and the rule of dispatch is quite non-obvious). This is another extreme like "remove all knives". We need some golden middle. Personally I believe the solution is in compiler warning and in some method to 'fix' this warning.
>>> 
>>> Why not just make it an error and require an annotation on the extension methods?
>> 
>> See   https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160516/018560.html
>> And   https://github.com/lmihalkovic/swift-lang/tree/master/Dispatching.playground
> 
> That doesn't answer my question.  I don't like any of the suggestions you posted.  I think we should just leave the behavior as is (at least for now) and just require annotations on non-default methods in protocol extensions (making it an error to declare a non-default method without the annotation).
> 

Considering how things work fine the way they are today once THEIR logic is understood (the only problem today seems to be one of expectations mismatch, not that something is broken or illogic), it would IMHO be a waste of energy to revisit only to end up with a system that would only support a single model. It something is done, it might as well be to add freedom.

So if you make it optional to have an attribute (I seem to recall chris explicitely saying that annotations were not the idiomatic swift way to convey these types of behavirial adjustments) on non required extension methods, then what you describe is basically one of the proposals I listed.. for a simple reason mind you... what I listed is what I saw people debate. A few options were left out as being too complex to summarize, or not ringing true to what exists today and what has been explained about protocols with great clarity by Dave on stage at WWDC. Interestingly enough, the idea of default methods on the protocol itself (which I like in java8) was already listed by him and at least someone else in the compiler team.

Coming from working in asm, c, c++, perl, tcl, vb, java, c#, js, objc, scala, typescript and go in that order, I can get used to anything as long as its logic seems reasonable and adequately explained.  After reading so many emails I thought I might not be the only one craving a simple one page summary of what had been said so far.


> 
>> 
>> 
>>>> 
>>>> 
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 


More information about the swift-evolution mailing list