Separating a Hash type from Object

Brad Fults bfults at
Wed May 23 09:11:11 PDT 2007

On 5/23/07, Brendan Eich <brendan at> wrote:
> 1. Start by satisfying the thirst for object initialiser syntax: let
> dict = {a:1, b:2, ...}.
> 2. To avoid collisions with prototype properties, use a private/
> unique namespace:
>      private namespace u;
>      let dict = {u::a: 1, u::b: 2, ...};
> 3. Since the repeated u:: defeats the purpose of (1), allow a default
> namespace to be specified for all unqualified property names in the
> initialiser:
>      private namespace u;
>      let dict = u::{a:1, b:2, ...};
> 4. Key-safe membership testing: dict.u::[key] or 'use namespace u;
> dict[key]'.
> Comments?

Assuming that your proposal is for actual end use of dicts and not
just implementation details, very simply, that's far more complex

    var d = {a: 1, b: 2};

and therefore won't be used as much and will be abused gratuitously.
In the eyes of the novice (and in JS even the intermediate developer)
your proposal looks something like:

    voodoo voodoo voodoo
    let dict = voodoo{a:1, b:2, ...};

I don't mean to be caustic, I simply mean to represent the novice in a
case that I think should be accessible to all developers
(dicts/hashes). It also has the notable pitfall of applying the
namespace to the entire code block, something that would cause even
more confusion among novice developers.

Would it be at all possible to handle the key safety in the Dictionary
type itself (a bit of magic), leaving us with something like:

    let dict:Dictionary = {a:1, b:2, ...};

This simpler and more intuitive syntax would (I think) be *much* more
likely to be used and not abused by all levels of developers. Though
if this syntax were feasible I'd advocate for naming the type either
Dict or Hash for brevity's sake:

    let myHash:Hash = {a:1, b:2, ...};

So, {a:1} would still represent an Object literal, but when a type
hint of Dict/Hash is used it becomes a Dict/Hash initializer which has
key safety.

Thoughts? Let me know if I'm completely off base.


Brad Fults

More information about the Es4-discuss mailing list