Extensible destructuring proposal
Andreas Rossberg
rossberg at google.com
Tue Aug 4 12:26:45 UTC 2015
On 31 July 2015 at 20:09, Samuel Hapák <samuel.hapak at vacuumapps.com> wrote:
> So, do you still have objections against this proposal? Could we summarize
> them?
>
> @Andreas, do you still think that there is category error involved?
>
If you want to overload existing object pattern syntax, then yes,
definitely. I strongly disagree with that. It breaks regularity and
substitutability (you cannot pass a map to where a generic object is
expected).
As for a more Scala-like variant with distinguished syntax, I'm fine with
that semantically. But I still don't buy the specific motivation with maps.
Can you give a practical example where you'd want to create a map
(immutable or not) for something that is just a record of statically known
shape? And explain _why_ you need to do that? Surely it can't be
immutability, since objects can be frozen, too.
To be clear, I wouldn't reject such a feature outright. In fact, in a
language with abstract data types, "views", as they are sometimes called in
literature, can be valuable. But they are also notorious for a high
complexity cost vs minor convenience they typically provide. In particular,
it is no longer to write
let {a: x, b: y} = unMap(map)
as you can today, then it would be to move the transformation to the
pattern:
let Map({a: x, b: y}) = map
So I encourage you to come up with more convincing examples in the
JavaScript context. Short of that, I'd argue that the complexity is not
justified, at least for the time being.
/Andreas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150804/3bb5fa10/attachment.html>
More information about the es-discuss
mailing list