It's self again
Nearly two years ago, I wrote a short piece about
self. Since then, a lot has changed: I got fired, found a new job, quit, and found another new job. I'm working from home now as employee of a fully distributed company. To reflect on that, I've started another German-speaking podcast called "Allein zuhaus" (German for "Home Alone"). But basically, only little has changed: I'm still working as an iOS developer, mainly writing Swift-code these days. In the last months I noticed, that my "write always
self"-approach started to crack.
And then, a few days ago, I read about
self in a tweet:
I cannot stand Swift that doesn't use
self.in front of properties, methods, etc.
It's bearable in Xcode (where you have syntax highlighting), but it makes code review on GitHub, Bitbucket, etc, a huge pain (where there is no highlighting): "Where did this come from???" — @kyleve on Twitter
I read this argument before, in the blogpost that inspired me to write the piece nearly two years ago. Suddenly, I realized, that I didn't write
self a lot anymore, only in those occassions, where it was absolutely necessary. Cause, you know, syntax highlighting does the job. But this argument totally made sense to me. When reviewing code in the web browser, there's no syntax highlighting. One could say, that using
self means more independence from tools.
But according to the answers to that tweet, implicit
self still seems to be a highly controversial topic and so, I highly encourage you to read them. It seems to become pretty similar to the vim vs. emacs-fight.=
In July 2018, I wrote:
The aforementioned blogpost argues, that not using
selfhelps you finding memory leaks in closures. I don't think, that this is an issue of having/not having
selfeverywhere in the first place, but more of an issue of paying attention.
Whenever I use a closure, I try to think about cycles — I've started to develop a habit out of this. And sure, sometimes I miss a thing, but but this is basically my way of dealing with it. I see the point, that using
self only in closures — and other places, where the compiler needs it — it makes it easier to find cycles. But this hasn't been an issuet to me. Either I haven't had any problems with cycles ore I just oversaw them. Probably, but hopefully not, the latter.
When I change closure-code in the future, I might add retain-cycles, but this is, when my habit comes into play: "Oh, this is closure-code. I have to be super extra careful now."
I hope, that my future self and other developers will profit from using