[swift-evolution] Proposal SE-0009 Reconsideration

Paul Ossenbruggen possen at gmail.com
Thu May 26 14:26:49 CDT 2016


Since this keeps coming up, it seems that something would be good here. Perhaps this has been explored before but why can’t we just use dot without the word “self", to indicate self? 

class DotIsSelf
{
    func p() -> String {
        return "self p"
    }
    
    func g() {
        print(.p()) 	// print “self p"
	print(p)	// error undefined
        let p = "local p"
        print(p) 	// print “local p"
        print(.p())	// print “self p”
    }
    
    class func k() -> String
    {
        return "self k"
    }
    
    class func j() {
        print(.k()) 	// print “self k"
	print(k)	// error undefined
        let k = "local k” 
        print(k) 	// print “local k"
        print(.k()) 	// print “self k"
    }
}

Self could still be used but “self.” or “.” would be required to access self. 

Rationale:
• since self is referenced quite often in classes it should be very short and easy to type
• less cluttered than self being everywhere but not ambiguous. whether you mean the local variable or the instance.
* Already very similar notation for enums where you leave off the entity name when it can be implied.
• Does not interfere, that I could see, with other uses of dot. (I am sure I will be corrected if wrong, but putting it out there because I want to know why :-) 
• Feels quite intuitive and easy to understand. 
* Make Swift safer because it eliminates potential ambiguity as has been pointed out many times.
• Other characters would be less natural than dot. 
• In the IDE, hitting dot would immediately bring up self items as choices.




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160526/22d12568/attachment.html>


More information about the swift-evolution mailing list