[swift-evolution] [Review] SE-0068: Expanding Swift Self to class members and value types
Vladimir.S
svabox at gmail.com
Thu Apr 21 01:56:24 CDT 2016
I almost totally support this proposal.
The only thing is worrying me in confusion between the currently defined
type(where method is declared) and dynamic type of class at runtime.
Plus, note that we have currently "self" as *type* object inside
class/static methods.
I.e. let's we have such code :
--------------------
class A {
class func classX() { print("in classX : class A") }
class func classY() { self.classX() } // Self.classX() is proposed. if
we'll have A.classX() here - we'll have another behavior
func y() { self.dynamicType.classY() } // Self.classY() is proposed
}
class B: A {
override class func classX() { print("in classX : class B") }
}
var a = A()
var b = B()
a.y() >> in classX : class A
b.y() >> in classX : class B
--------------------
Currently, in classY() "self.classX()" is also confusing. "self" is not "A"
here, but "dynamicType". So it is ok to have "Self.classX()" at this place.
(the same (probably less) level of confusion i.e. "is Self is A or
dynamicType")
But in y() the "self.dynamicType" is much more explicit and clear than
"Self". Yes, if we'll know that Swift *is* dynamicType - we'll use it
correctly, I believe. And if I have to choose : to implement this proposal
or leave "dynamicType" and "self" in static/class methods - I choose to
have proposed "Self" in Swift 3.0.
Probably, it will be better to name this "Self" in some other way..
Don't have good variants.. like "DynamicSelf" ?
And, I believe we need some kind of "Self" to address currently defined
class like in this case(I support, we should be able to just copy-paste the
func from protocol to our class definition, typing the name of our class in
implementation is making our codebase more fragile if class is renamed ):
protocol AProtocol {
func assignFrom(a: Self) // now. confusing if this is Self =
"dynamicType" ?
// func assignFrom(a: ThisType) // suggested
}
class A : AProtocol {
var x = 10
func assignFrom(a: A) { // now . no that "Self" is placeholder for "A"
// func assignFrom(a: ThisType) { // suggested
self.x = a.x
}
}
Probably #ThisType, as this is compilator's business to replace this with
actually defined class name. Or #Type.. Or even #Self. This can be discussed.
Opinions?
Btw, can't understand how self and Self could be confused - in Swift it is
so natural to have the instance name as just lowercased name of class :
let page = Page(withTitle: "Page Title")
so, we have self, the instance of some type, and the type of that instance
is Self.
On 20.04.2016 20:16, Chris Lattner via swift-evolution wrote:
> Hello Swift community,
>
> The review of "SE-0068: Expanding Swift Self to class members and value
> types" begins now and runs through April 25. The proposal is available here:
>
> https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md
>
> Reviews are an important part of the Swift evolution process. All reviews
> should be sent to the swift-evolution mailing list at
>
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> or, if you would like to keep your feedback private, directly to the review
> manager.
>
> What goes into a review?
>
> The goal of the review process is to improve the proposal under review
> through constructive criticism and, eventually, determine the direction of
> Swift. When writing your review, here are some questions you might want to
> answer in your review:
>
> * What is your evaluation of the proposal?
> * Is the problem being addressed significant enough to warrant a change to
> Swift?
> * Does this proposal fit well with the feel and direction of Swift?
> * If you have you used other languages or libraries with a similar feature,
> how do you feel that this proposal compares to those?
> * How much effort did you put into your review? A glance, a quick reading,
> or an in-depth study?
>
> More information about the Swift evolution process is available at
>
> https://github.com/apple/swift-evolution/blob/master/process.md
>
> Thank you,
>
> -Chris Lattner
> Review Manager
>
>
>
>
> _______________________________________________
> 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