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

David Bruant bruant.d at gmail.com
Wed Dec 21 04:33:42 PST 2011


Le 21/12/2011 11:25, Andreas Rossberg a écrit :
>> Indeed. What do you think of the different alternative proposals
>> (especially regarding the "ad-hoc complications" you point out)?
> I agree with your analysis that passing the public view of a private
> name to traps is not a true reification. However, I'm not sure I
> prefer the alternative you propose. Putting a random flag on names to
> control the behaviour of a completely different language feature seems
> awkward, and introduces undesirable conceptual coupling.
>
> 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.

Same goes for proper tail calls. Currently no browser implements it
which limitates the ability for some programmers to write JS programs in
a given style. So they change how they write programs. But they
shouldn't have to care (hence the current proposal regarding proper tail
calls).


> 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).
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.

David


More information about the es-discuss mailing list