Herman wants to restrict access to private and protected fields to only references to this object, i.e. to prevent access to private/protected fields in other objects of the same class
Herman's rationale is that it would be hard to explain to folks that the new version of ECMAScript will slower for untyped variables that the current version. This would be true he asserts without the above restriction.
The implication of such a rule is that getters and setters to private fields have to be made public, making private data publically visible
Chris observes that making private variables override other references in the local scope is a simple way to evade this penalty
class X { private field y; method m(x) { // any reference to y must be // to the private field y x.y; } }
Most people find this rule to surprising. It would be too hard to sell to users.
Dave offers an alternative whereby the programmer annotates the reference to make the access explicit:
class Foo { private var f; method m (x) { x.Foo::f // refers to local f } }
Another possibility is to use a cast, e.g.
((Foo)x).f
Rok proposes we adopt Herman's suggestion that references to other objects from untyped variables is restricted to publics unless there is an annotation such as one of the above two choices, or you are using a statically typed variable.
The consequence of this is that adding the annotation can change whether you get the private field of some object or the public field of its base class.
class Foo extends Bar { public var f; } class Bar { private var f method m() { Foo y = new Foo(); y.f; // Foo::f y.Bar::f; // Bar::f ((Bar)y).f; // Bar::f } }