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

Dan Loewenherz dan at lionheartsw.com
Mon Dec 14 14:15:31 CST 2015

Jumping in here as a newbie to the list. :)

On Mon, Dec 14, 2015 at 1:32 PM, Marc Knaup via swift-evolution
<swift-evolution at swift.org> wrote:
> Having so many symbols like @ all over the place kept me from learning and using Ruby and Perl. It just felt wrong and artificial.
> A language quickly becomes more difficult to learn, use and understand when much of the code consists of symbols.
> I love Swift for having such a simple & clear structure and syntax in most cases. Adding symbols for every instance access on self (which is a very common case) would oppose these benefits and make its learning curve steeper.

I agree wholeheartedly. Adding additional symbols to the language will
likely confuse newcomers and will inevitably lead to bike-shedding
(“@“ versus “self”).

Moreover, as much of my daily work is in Python (in addition to Obj-C
and increasingly more Swift!), I have a very strong affinity for
explicit over implicit. The optional “self” struck me from day 1 of my
learnings of Swift as a nice feature for convenience’s sake, but also
a bit risky in that ambiguous scoping issues could be a problem.

> On Mon, Dec 14, 2015 at 8:17 PM, Andrey Tarantsov via swift-evolution <swift-evolution at swift.org> wrote:
>> obj1.prop1 = X
>> obj1.prop2 = Y
>> ...
>> obj1.prop10 = Z
>> superview1.addSubview(obj1)
>> Adding “self.” everywhere adds a significant amount of visual noise; I've tried _property and self.property access styles in Objective-C, and find the former one to be noticeably more readable.

Python enforces the usage of “self” for all instance variables and
methods, and—perhaps I’m biased—but I have never felt that it was
visual noise. On the contrary, it’s presence generally made code
_less_ noisy and easier to read.

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.

>From “Draft proposal: Implicit self in Python 3.0”,

For any who are curious to read through the whole thread (there are
good arguments for and against in there):

[Python-Dev] Draft proposal: Implicit self in Python 3.0,


More information about the swift-evolution mailing list