[swift-evolution] Proposal: Re-instate mandatory self for accessing instance properties and functions

Stephen Celis stephen.celis at gmail.com
Wed Dec 16 06:48:38 CST 2015


> On Dec 15, 2015, at 5:28 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Will I need to qualify associated types with the protocol or type name to refer to them? What about generic type parameters, they're sort of like "instance variables" too.

Hadn’t thought about that. It does seem that requiring “Self.” would be a natural extension of this proposal.

> On Dec 15, 2015, at 5:46 PM, Honza Dvorsky via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I've been following the thread from the beginning and some great arguments have been layed out. As far as I understand, this proposal would lead to fewer correctness bugs (referring to a different variable due to implicit self, has happened to me twice in the last couple of months, was very hard to track down).

It sounds to me that the biggest advantage of requiring self is to avoid the occasional , hard-to-find bug (at the cost of muddying the readability of a lot of code). I’d much rather focus on improving compiler diagnostics and error messaging than limit the expressiveness of the language.

With the current discussion having a lot of voices on both sides, I can’t imagine this proposal passing, especially when a linter could easily enforce such a rule for the audience that prefers it.

Stephen


More information about the swift-evolution mailing list