Are Private name and Weak Map the same feature? and the Assoc API

Andreas Rossberg rossberg at google.com
Wed Dec 21 04:59:31 PST 2011


On 21 December 2011 13:33, David Bruant <bruant.d at gmail.com> wrote:
> Le 21/12/2011 11:25, Andreas Rossberg a écrit :
>> In essence, you are introducing two separate types of private names,
>> but the distinction only is observable in situations that the
>> implementer should not need to think about in the first place.
> I don't know to what extent this is a receivable arguments. There are
> other instances of "the implementer should not need to think about in
> the first place" (I assume you meant "JavaScript programmer"). For
> instance, WeakMaps and Maps.
> As a programmer, I want an object -> value map. Why am I given 2
> almost-similar features to do this? Because it's an undecidable problem
> to know whether or not the program is going to iterate over the keys, so
> 2 features are created. One without key enumeration and one with
> enumeration.

I don't think these examples are comparable. In any case, every
programming language, except the bare lambda calculus, has semantic
redundancy. In JavaScript today, why are there functions with multiple
arguments? You could as well pass an object. (And in fact, some
languages work along these lines.)

There are pragmatic reasons for introducing redundancy. And the
properties of weak maps vs private names are sufficiently different
beyond a superficial abstract level to warrant the redundancy.

>> What would be the guideline for picking the right one?
>> When would I ever want to pick the weaker variant?
> You would pick the weaker variant whenever you would share a
> public->private name map under the current proposal (which is when you
> want a proxy to have access to the private name).

OK, that's what I'd refer to as the "stronger" variant :) (in the
sense of being somewhat safer wrt privacy). So when would you pick the
other?

> I really see this like WeakMaps and Maps. What would be the guideline
> for picking the right one? Understand the differences, understand the
> problem you want to solve and your choice is made.

Well, I'd argue that those guidelines are pretty well established
regarding weak maps.

/Andreas


More information about the es-discuss mailing list