Separating a Hash type from Object

Andrew Dupont andrew at andrewdupont.net
Sat May 5 23:30:21 PDT 2007


Neil Mix wrote:
> Has this thread dropped again?  That's too bad.  It seems like we keep 
> going in this circle:
>
> 1) we need a base Dictionary class
> 2) in order to be successful, it needs "good UI" and perhaps weak refs
> 3) there's no syntax proposed for this
> 4) it's awfully late for any big changes anyway
> 5) but we need a Dictionary class
>
> I take issue with #2.  It's my impression that the veteran JS 
> developers on this list have all stated a strong desire for key-safe 
> storage, and I believe that they would all agree that a Dictionary 
> without syntactic sugar and weak refs is better than nothing at all.  
> Do any JS hackers here disagree?
No, not at all. To dissect this further: I don't mind having to "opt 
into" key safety by adopting an uglier syntax, but I wouldn't want to 
give up the convenience of an Object when I don't need to be that cautious.

There are ten thousand ways to make key-safe Dictionaries in ES3 -- 
Prototype has tried about half of them -- but the only way we can stick 
a band-aid on this, I think, is to pick *one* UI for dictionaries (as 
simple as feasible, but no simpler) and to make it a built-in. I 
honestly appreciate how seriously this list takes UI/syntax, but as 
critical as key safety is it's still an edge case. If necessary, it can 
be treated like an edge case in the syntax.
> What is the danger in specifying a hobbled Dictionary class for now, 
> with the hope that better syntactical goodness and weak refs can be 
> added in a later version?
I'd call it "conservative" instead of "hobbled," but I agree. If we 
include a very modest Dictionary implementation, then stand back and let 
people hack at it, I think we'll see some conventions emerge for 
smoothing the syntax (using magic getters/setters and such). The best 
idea can be incorporated into ESfour-point-whatever. But we need to 
plant the seed for that to happen.

Cheers,
Andrew



>
> On May 2, 2007, at 3:13 PM, Brendan Eich wrote:
>
>> On May 2, 2007, at 12:56 PM, P T Withington wrote:
>>
>>> Have you considered Hash being a new native type with its own rules
>>> for ToPrimitive, ToString, and ToObject?
>>
>> We have considered a native Dictionary class, as I reported recently.
>> It lacked sugar; it didn't support weak refs. We stepped back and
>> deferred it.
>>
>> Because Dictioinary required users to call has, get and set methods,
>> no changes to avoid bad shadowing of toString and valueOf arose with
>> the proposal.
>>
>> /be
>> _______________________________________________
>> Es4-discuss mailing list
>> Es4-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es4-discuss
>




More information about the Es4-discuss mailing list