[swift-evolution] Proposal: Re-instate mandatory self for accessing instance properties and functions

Andrey Tarantsov andrey at tarantsov.com
Mon Dec 14 15:54:56 CST 2015


> We are fortunate because the Python mailing list debated this exact
> issue in 2006 (albeit, in the reverse direction). I’ll quote from
> https://www.python.org/dev/peps/pep-3099/ (“Things that will Not
> Change in Python 3000”):
> 
>> Having self be explicit is a good thing . It makes the code clear by removing ambiguity about how a variable resolves. It also makes the difference between functions and methods small.

Theoretically, if we were debating this on principle, I would agree with explicit self references.

However, I talk from experience using the relevant Apple frameworks writing dozens of apps. The UI code, which is more than a half of a typical app's code, consists of lines upon lines of simple object setup and manipulation, where (1) it is absolutely clear which names are properties and which are variables; (2) in many cases, it doesn't matter anyway (like maybe that tableView is an argument and not your property, but still the same object); (3) the code is fairly verbose as it is, and adding any extra syntactic elements obscures its intention.

And, perhaps more importantly, Xcode uses a different color to highlight property names. There's no need for further textual differentiation there.

A.



More information about the swift-evolution mailing list