On 2010-12-21 08:49, Lasse Reichstein wrote: > On Thu, 16 Dec 2010 23:19:12 +0100, Mark S. Miller <[email protected]> wrote: >> On Thu, Dec 16, 2010 at 1:58 PM, Kris Kowal <[email protected]> wrote: >>> On Thu, Dec 16, 2010 at 1:53 PM, David Herman <[email protected]> wrote: >>> > [...] >>> > than >>> > >>> > function Point(x, y) { >>> > var _x = gensym(), _y = gensym(); >>> > this[_x] = x; >>> > this[_y] = y; >>> > } >>> >>> I tend to disagree with most developers, so take it with a grain of >>> salt that I find the latter form, with all the implied abilities, >>> easier to understand. > >> I do too. While terseness clearly contributes to understandability, >> regularity and simplicity do too. When these conflict, we should be very >> careful about sacrificing regularity. > > While I dislike the "private" syntax just as much, it does have the advantage > of being statically detectable as using a private name, both "this.foo" in the > scope of "private foo", and "this[#.foo]".
That's not correct in general, since '#.foo' is first-class. (The specific
case "expr[#.foo]" is more easily optimizable without type inference, but
that's a case in which the #. syntax need not have been used.)
> The "gensym" syntax requires runtime checks to recognize that _x is a
> non-string
> property name.
Any expr[p] lookup needs a check for whether p is a string, when that cannot
be determined by type inference. The check that it is a private name or
soft field when when it is not a string is on the infrequent path, so will
not significantly affect performance.
>> Currently is JS, x['foo'] and x.foo are precisely identical in all contexts.
>> This regularity helps understandability. The terseness difference above is
>> not an adequate reason to sacrifice it.
>
> Agree. I would prefer something like x.#foo to make it obvious that it's not
> the
> same as x.foo (also so you can write both in the same scope), and use
> "var bar = #foo /* or just foo */; x[#bar]" for computed private name lookup.
> I.e. effectively introducing
> ".#", "[#" as alternatives to just "." or "[".
If we're going to add an operator specifically for private lookup, we only
need one, for example:
function Point(x, y) {
var x = SoftField(), y = SoftField();
this.#x = x;
this.#x = y;
}
(i.e. 'MemberExpression .# PrimaryExpression' or alternatively
'MemberExpression [ # Expression ]')
--
David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
signature.asc
Description: OpenPGP digital signature
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

