[swift-users] Future(of: self.references)?

Tino Heth 2th at gmx.de
Tue May 23 04:30:18 CDT 2017


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170523/1f8dd651/attachment.html>


More information about the swift-users mailing list