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.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution