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

Kenny Leung kenny_leung at pobox.com
Tue Dec 15 22:10:47 CST 2015


This is the full text of what Chris said in regard to “Proposal: Add Flags to Disable [Optional] Conversions"

> I don’t like the idea of having different incompatible dialects, and behavior changing modes.  That said, I’m personally not opposed to providing functionality that would enable people to use a reduced subsets of the language, and have the compiler enforce it.  For example, I don’t have a problem with someone saying they never want to use the x!, as!, try! family and have the compiler tell them if they do.
> 
> To relate this to your question, I’d be fine with functionality that causes the compiler to produce an error when code requires an implicit conversion, but I wouldn’t want them to be just “disabled”, because I think this could change the interpretation of valid swift code (in admittedly weird cases).
> 
> In terms of how to express this, I’m not in love with modal compiler flags :-).  I’d much rather this sort of requirement be specified as a pragma-like construct that applies to an arbitrary scope (e.g. class or function body) or a whole file.  This keeps the code self describing.

I think the mandatory self problem is analogous to never wanting to use x!, as! or try!. If you restrict yourself to always using self.whatever, it is not unusual to someone else, and if they leave off the compiler flag or pragma that enforces this, the code will still compile.

-Kenny


> On Dec 14, 2015, at 8:12 PM, Dennis Lysenko <dennis.s.lysenko at gmail.com> wrote:
> 
> Looks like the conversation is going in circles a bit. I believe Chris Lattner said he was opposed to any compiler flags that would lead to different dialects of Swift, and it's a valid concern, so I'm not sure how feasible an optional compiler flag would be.
> 
> 
> On Mon, Dec 14, 2015, 8:48 PM Kenny Leung via swift-evolution <swift-evolution at swift.org> wrote:
> This sounds like a candidate for a compiler option to add a warning (or error) if you leave out self. It adds no overhead to the language, but if you like it, you can enforce it.
> 
> -Kenny
> 
> _______________________________________________
> 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