[swift-evolution] [Discussion] Enforcing Calling Super

Jeremy Pereira jeremy.j.pereira at googlemail.com
Thu Feb 25 09:47:05 CST 2016


> On 17 Feb 2016, at 22:26, Kyle Sherman via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Thanks for the replies.
> 
> Kenny: After thinking about it more, discussing with Peter, and looking Haravikk’s comments, I think the best thing would be for this to be a warning as suggested. I respectfully disagree that as a library creator you would not be able to know that a call to super should be required.

I disagree. You can’t possibly know all the use-cases in which your class might be subclassed. 

In particular, it is absurd to enforce having the call to super as the first or last line of the method. That would stop me doing things like this:

    override func viewDidLoad()
    {
        print(“About to run super.viewDidLoad()”)
        super.viewDidLoad()
        print(“Finished super.viewDidLoad()”)
    }

Then there’s the perfectly reasonable case like this:

    override func viewDidLoad()
    {
        functionThatCallsSuperViewDidLoad()
    }

Why shouldn’t I be allowed to do that?

I’m not a fan of "final by default” either because people will leave the virtual (or whatever is called) keyword off through laziness, not because it is definitely impossible to override the method or or subclass the class and make their classes impossible to reuse.

I would, however, accept a warning as long as I can turn it off. I like my tools sharp even though there is a higher risk I might cut myself.

> 
> _______________________________________________
> 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