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.

Structs and ImmutableStructs

26 pointsby nwjsmithalmost 11 years ago

2 comments

phungealmost 11 years ago
I only read as far as &quot;rentAmount.dollars = 600; &#x2F;&#x2F; =&gt; 600&quot; before I got all ragey. Why would someone think that read-only attributes that silently ignore assignments are a good idea?<p>This is a criticism in JS, not in the article. But IMHO most modern dynamically-typed languages err <i>way</i> to far on the side of permitting (or ignoring) operations which should raise exceptions. &quot;3&quot; + 4 should be an error, not &quot;34&quot; (JavaScript) or 7 (Perl). ({}).foo should be an error, not undefined. etc. etc.<p>It has nothing to do with dynamic typing -- IMHO languages like Scheme and Python got things right in having a object &amp; type models which have a small, well-defined set of operations with few rough edges. But somewhere along the way, &quot;do what I mean&quot; AKA &quot;do the thing that I almost never need but may blow up in corner cases&quot; became accepted as a good idea. And IMHO it&#x27;s not.<p>EDIT: if anyone is interested in ideas around immutability, read up on functional programming -- specifically read Structure and Interpretation of Computer Programming, and play around with Scheme. It&#x27;ll make you a better programmer regardless of language. Some of the basic ideas from the functional programming community definitely need to be preserved and disseminated.
评论 #7912598 未加载
评论 #7913137 未加载
ape4almost 11 years ago
One way to make an immutable constant:<p><pre><code> function rentAmountDollars() { return 600; }</code></pre>
评论 #7912818 未加载
评论 #7912859 未加载