TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A first look at records and tuples in JavaScript

28 pointsby flipchartabout 5 years ago

6 comments

combatentropyabout 5 years ago
Is the hash symbol the best? It already is used within classes to mean <i>private</i>. Syntactically for the machine parser, I assume it will work just fine for these other things. But semantically for my human brain, it is mildly incongruous. If for no reason but elegance and developer delight, I ask for a reconsideration of other punctuation.
评论 #23329925 未加载
评论 #23330486 未加载
pull_my_fingerabout 5 years ago
I&#x27;ve always thought it was interesting to see the parallels of PHPs growth and JSs. Both seem to add a lot of popular (at the time) features. Neither can purge old APIs or &quot;break the web&quot;.
评论 #23329252 未加载
amw-zeroabout 5 years ago
This is the number one feature I look for in a language now. It’s hard to describe why value semantics are useful when thinking about a language as it exists today, since the language influences what we think is possible. But having records and tuples like this changes the way you write code.<p>The biggest example is, you don’t have to think in terms of references anymore. Again it’s hard to explain how much were forced to think about references and specific locations that data happens to live at, but that thinking is pervasive in how we write code (if you’re using a language like JS, which most popular languages are like).<p>Value semantics means you can stop thinking about data-as-a-location or data-as-a-reference and finally start thinking about data-as-data. If two records have the same values, they are the same. This means you don’t need to know anything about where data came from, you can construct matching data and say “are these things equal?” And they will be. This inherently reduces coupling and complexity.
olliejabout 5 years ago
So from reading this it sounds like what&#x27;s being asked for essentially syntactic sugar for Object.freeze(), and the function Record(obj) would be doing something along the lines of<p><pre><code> function Record(obj) let result = {}; for (let [key, value] of obj) { switch (typeof value) { case &quot;function&quot;: case &quot;object&quot;: throw ...; } result[key] = obj; } Object.freeze(result); return result; } </code></pre> Or similar.<p>Now obviously have typeof return a new type is exciting, and of questionable value, but having a &quot;only immutable values can be in fields&quot; guarantee could be useful.<p>That said, overloading # is not something I think is great, and the semantics need to be tightened up (fields in prototype chain, etc, what is the prototype of the resulting record&#x2F;tuple object).
评论 #23334393 未加载
ryansobolabout 5 years ago
The Value of Values with Rich Hickey<p><a href="https:&#x2F;&#x2F;youtu.be&#x2F;-6BsiVyC1kM" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;-6BsiVyC1kM</a>
specialistabout 5 years ago
Why do records, tuples need new syntax?
评论 #23329035 未加载