[swift-evolution] Add code to super methods.
Mustafa Sabur
mustafa.sabur at icloud.com
Wed Nov 16 16:55:25 CST 2016
Mustafa Sabur
Yes I was talking about the override(before/after) like Sean. I don’t think it would make sense to actually extend some method, since the caller might not know that it happend.
I can see some problems now and im going to try to find the old discussions. Thank you.
Mustafa Sabur
> On 16 Nov 2016, at 23:42, Adrian Zubarev <adrian.zubarev at devandartist.com> wrote:
>
> At first glance I though about this:
>
>
> // Module A
> open class X {
>
> open func b() {}
> }
>
> // Module B
>
> class Y : X {
> addinto func b() {
> explodeExploit()
> }
> }
>
> class Z : X {}
>
> Z().b() // does this also call my `explodeExploit` :D ?
> Are you speaking of code injection of a sugar like syntax like override(before/after) like Sean suggested?
>
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> Am 16. November 2016 um 23:30:35, Mustafa Sabur via swift-evolution (swift-evolution at swift.org <mailto:swift-evolution at swift.org>) schrieb:
>
>> Hallo,
>>
>> I have a very simple suggestion. And I’m not very sure then it haven’t been discussed already, so I’m sorry if that is the case.
>> I would like to see the ability to just add code to base methods instead of overriding it and calling supers method. So basically an extension for methods.
>>
>> Example:
>>
>> Now:
>> override func viewDidLoad() {
>> super.viewDidLoad()
>> // Your code
>> }
>>
>> Suggestion:
>> addinto func viewDidLoad() {
>> // Your code
>> }
>>
>> My reasons:
>> 1. Its very verbose about your intentions, which fits into Swift style. The thing you actually want is not overriding but appending.
>> 2. You cannot make the mistake of forgetting to call the supers method.
>> 3. It open ways to introducing ‘semi-final’ methods, which cannot be override but you still can append to it.
>> This to make sure your API implementation will always be executed . I’m thinking about a keyword like extendable to specify that you can only add to it.
>> 4. Less code.
>>
>> I can’t think of any cons... Thought I can imagine that the benefits are quite small and maybe not worth the effort.
>> I would like to read some thoughts about this. Thank you!
>>
>> Kind regards,
>> Mustafa Sabur
>>
>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161116/1639e2e8/attachment.html>
More information about the swift-evolution
mailing list