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

Kevin Ballard kevin at sb.org
Fri Dec 4 17:37:50 CST 2015

Do you use Xcode to edit Swift? Xcode gives a color to
properties/methods and doesn't color local variables/arguments. Is that
not sufficient to distinguish this? In my experience the color is
actually better than seeing the explicit `self.` because the color can
be recognized faster than reading a word, and is visible in a high-level
"squint" view of the function.

If you're using another editor, well, my best suggestion there is to
look into what it would take to integrate SourceKit functionality into
that editor for more intelligent coloring :)


On Fri, Dec 4, 2015, at 03:29 PM, Colin Cornaby wrote:
> +1
> I've had a lot of weird things happen that I've traced to mistakes in
> properties having the same name as function arguments. I've hardly
> ever had this issue in modern Obj-C.
> I'm a little more ok with functions not needing self as it's less
> likely for those to shadow something like an argument, but I guess the
> consistency would be nice too.
> On Dec 04, 2015, at 01:20 PM, David Hart <david at hartbit.com> wrote:
>> I don't understand the reasoning behind removing the need to access
>> instance properties and functions using self. Swift has always seemed
>> to prefer readability to brevity and the feature makes the
>> distinction between local and instance variables/functions crystal
>> clear. Any good reason I shouldn't go on with the proposition?
>> Just as example, my proposition makes the following piece of code
>> illegal:
>> ``` struct FooBar { var foo: String = "foobar"
>>  func bar() { print(foo) // compiler error print(self.foo) //
>>  compiler happy }
>>  func bar2() { bar() // compiler error self.bar() // compiler happy
>>  } } ```
>> _______________________________________________
>> swift-evolution mailing list swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _________________________________________________
> swift-evolution mailing list swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151204/8dfd0be3/attachment.html>

More information about the swift-evolution mailing list