[swift-evolution] [Discussion] Enforcing Calling Super

Haravikk swift-evolution at haravikk.me
Thu Feb 18 12:09:40 CST 2016

> On 17 Feb 2016, at 23:56, Dennis Weissmann <dennis at dennisweissmann.me> wrote:
> Note: I’ve changed the syntax to # because I think this is compiler-magic and as Chris mentioned the following in the property behavior thread:

Is it compiler magic though? To me compiler magic is something that the compiler does to change your code, for example testing for OS version lets you add code specific to that OS. This wouldn’t actually change anything, it’s really just a directive in how the method should be implemented, personally that puts it closer to attributes such as @warn_unused_result IMO. You cite the case of the property behaviours proposal, however that is a proposal that introduces custom code that the compiler would connect to your properties for you, so it’s undoubtedly compiler magic of a sort.

If we do go for the hash prefix though, I don’t think that we need #requireSuperStart etc., just a general #requireSuper would do with optional brackets to add more specific requirements as has been proposed with attributes and keywords. That said, I think #requireSuper may be the wrong term, unless your intention was to also have #optionalSuper and #warnSuper? Personally I think it’d be easier to just to #super(required, before, warn) or whatever, same as we’ve been discussing for attributes and keywords, as it groups everything into the one command; there should be no reason we can’t just use super for the naming either since it’s unambiguous (and actually it’s relevant).

> The compiler would inject (invisible to the dev) the super() call at the very beginning. The same is true for #requireSuperEnd.
> I don’t think we need a #requireSuper because it means we don’t care when it’s called so the compiler can decide where to put it.

Like others have said I think we should shy away from the compiler adding this for us, as it may introduce debugging issues if someone didn’t notice the requirements and the compiler just went and fulfilled them automatically. By encouraging/forcing the developer to actually add the call then the implementation is at least complete and self-contained in its own right. I suppose maybe this is why you favoured the hash prefix as it definitely would be compiler magic for these cases, but I think without auto-insertion it isn’t really compiler magic, certainly no more than visibility keywords are.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160218/5b41a89c/attachment.html>

More information about the swift-evolution mailing list