[swift-users] Future(of: self.references)?
Rien
Rien at Balancingrock.nl
Tue May 23 05:17:17 CDT 2017
I will often use this rule: If a scope need to use ‘self’ at least once, then I will always use ‘self’ in that scope.
Otherwise I won’t use ’self’ at all.
There are always exceptions though, first and foremost: if the usage of ‘self’ hinders understandability of the code (interferes with self documentation), then don’t use it.
Also the usage of ‘self’ in a guard statement does not count.
Mostly though I will try and avoid the necessity for using ’self’ at all. It often is an indication that names are not correct or not optimal.
Regards,
Rien
Site: http://balancingrock.nl
Blog: http://swiftrien.blogspot.com
Github: http://github.com/Balancingrock
Project: http://swiftfire.nl - A server for websites build in Swift
> On 23 May 2017, at 11:30, Tino Heth via swift-users <swift-users at swift.org> wrote:
>
> Well, sometimes it might be important that you are dealing with an instance variable, and in other cases, it's just clutter:
> struct Triangle {
> var a: Float
> var b: Float
> var c: Float
>
> var isSquare: Bool {
> return self.a * self.a + self.b * self.b == self.c * self.c
> }
>
> var isStillSquare: Bool {
> return a * a + b * b == c * c
> }
> }
> Imho the second variant is clearly better than the first, and it would be bad to enforce self.
>
> My personal rule of thumb for this is: Use the self prefix for things that should change self, skip it for read-only access — but the exact "rules" are quite arcane, and I think the compiler shouldn't have to deal with complicated rules that still would fail to make everyone happy.
> So, I think the current approach is the best we can do.
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
More information about the swift-users
mailing list