Separating a Hash type from Object
liorean
liorean at gmail.com
Wed May 23 09:55:40 PDT 2007
On May 5, 2007, at 11:40 PM, Neil Mix wrote:
> > 2) in order to be successful, it needs "good UI" and perhaps weak refs
[- - -]
> > 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?
On 23/05/07, Brendan Eich <brendan at mozilla.org> wrote:
> I do. I think users will gravitate to Object because of the
> initialiser syntax. I may be wrong, but it's definitely a trap that
> JS hackers fall into.
The initialiser syntax is certainly better than having to do many
separate assignments to an object, that's for sure.
On 23/05/07, Brendan Eich <brendan at mozilla.org> wrote:
> So I've been arguing for a week or so, mostly with myself, that we
> have just about enough in the current ES4 proposals to "do almost
> everything", and with a neat syntactic sugar proposal from Lars, I
> think we're done. Here's the scoop:
>
> 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?
Would it be possible to somehow make that into something that works in
expression contexts too, instead of just statement context? Object
initialisers are very handy in expression contexts, and I feel you'd
want this to be usable in the same way too.
Also, you'd want to be able to send a dictionary to some function that
have no idea about the setting up of the dictionary, including the
namespace. I've not read up about the namespace handling, so I don't
know if this is already provided somehow, but I'd like to have a way
to access dictionary keys that is universal.
On 23/05/07, Brad Fults <bfults at gmail.com> wrote:
> Assuming that your proposal is for actual end use of dicts and not
> just implementation details, very simply, that's far more complex
> than:
>
> 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, ...};
Well, the added complexity isn't that very large if you ask me. As
soon as a developer gets used to namespaces, they would understand it
perfectly well. The problem I see with it is that we want to be able
to make functions that can take any dictionary and do some work on it,
without having any special knowledge of which namespace that
particular dictionary uses.
> 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.
If the syntax still allow making specific properties in the literal
belong to another namespace, is it that much different? That is, if it
simply changes the default namespace properties are placed in?
--
David "liorean" Andersson
More information about the Es4-discuss
mailing list