class sugar: static inheritance
brendan at mozilla.com
Wed Jun 8 08:27:02 PDT 2011
On Jun 8, 2011, at 8:14 AM, Mark S. Miller wrote:
> The "private record" especially views as an "object" is a kind of placeholder too. It doesn't help to think of it as a record. It probably does not help to think of it as an object, either, especially if you cannot get at it via anything like the still-straw private(this) or private(other) syntax.
> On another topic, it does seem like "protected" is inevitable, doesn't it?
> Actually, it isn't another topic. It's why Kam's GilaMonster cannot see Monster's "health".
My topic changed from "private record/object", 'sall ;-).
> "private" means "private to the class", not "private to the class and subclasses". "protected" would mean the second, and no, I don't think it's inevitable.
It's not, we can choose to hold the line -- question below, though.
> E and Caja have been doing very well with "private", "public", and inheritance, and I've only ever been frustrated by the lack of "protected" once in a blue moon. And it was always easy to work around its absence. Given ES-next's private names and weak maps, it becomes even easier to work around the absence of "protected".
You can make all kinds of friend relations with lexical scope and weak maps, it's true. But these can have the same cost problem that led to the private instance variable goal:
* An efficient implementation. The private state should be allocated with the instance as part of a single allocation, and with no undue burden on the garbage collector.
Private name objects can be shared via lexical scope and used more efficiently to address a property on a base class from both base and subclass, where the property storage is conceptually packed, and implementations can do their best, as with any ad-hoc property added non-declaratively. But such properties will not be part of the declarative class instance state.
Having declarative syntax in the constructor body for public and private variables serves several goals, not just efficiency. Also, private name objects must be accessed using  not dot.
We can say "for protected, use these patterns". But patterns are not always the best solution. As Peter Norvig said they often show bugs in one's programming language.
> Btw, in both C++ and Java, the semantics of "protected" is a mess, in different ways.
Sure. Let's not make those mistakes. Non-fixable in your view?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss