[swift-evolution] Add code to super methods.

Jeremy Pereira jeremy.j.pereira at googlemail.com
Tue Nov 29 11:33:03 CST 2016


> On 29 Nov 2016, at 16:55, Aron Lindberg via swift-evolution <swift-evolution at swift.org> wrote:
> 
> While I agree with most of your points Dave, I think forgetting to call super is very much a (hard to debug) real world problem today.

I don’t. I’ve done it a few times but I don’t remember ever having a hard time debugging it.


> Especially new developers seems unsure or likely to forget to call super when it is required.
> 
> I think my point is this; When you subclass code you have not written yourself you have no idea if the class you are subclassing is "poorly designed" and you should call super somewhere in your documentation. You can make assumptions, read the documentation or use trial and error, but there is no way to be certain unless the documentation is specific about it.

There’s a fine line between being a safe language and being as nannying language and I think proposals about “must call super” and “must not call super” overstep the line - that’s just my opinion, of course.

> 
> I went over the documentation for UIViewController. Is contains:
> - 11 functions that specify that your subclass must call super during the implementation.
> - 2 functions where the documentation specifies the default implementation is empty.
> - 2 functions where you must not call super.
> - 8 functions where you properly want to call super.
> - 23 functions where I think there is no need to call super.

Well that selection should tell us that whether you warn/error for not calling super or warn/error for calling super the decision is going to be the wrong one in some cases.

Also, the two functions where you must not call super are really two functions that you must override. After all, if the subclass fails to override the functions its implementation is going to call super by default, thus breaking the rule.




More information about the swift-evolution mailing list