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.

ClojureScript performance revisited

26 pointsby greenonionover 9 years ago

3 comments

khgvljhkbover 9 years ago
The difference (like the author states) is that JS &amp; family has mutable data by default, while Clojurescript defaults to immutable such. You have to specify that you want your vectors and maps etc to be transient (fancy pants word for mutable).<p>You want immutability - think about it: how large % of your bugs are due to more than one procedure changing the value of one variable, and state getting out of sync?<p>For me in my JS day job, it is definitely a majority of the bugs we create. We also code very defensively to protect us against this.<p>In CLJS on the other hand, you&#x27;d have immutable data, and in tight loops where allocating objects would be expensive, you make your data transient, and then mutate it as much as you wish.<p>Living your life with immutable values is a serious improvement. Not only to code, but honestly quality of life.<p>Edit: Clojure doesn&#x27;t return whole new data structures under the hood, but you never notice that. Here is a great explanation, prepare for (= (mind article) :blown) =&gt; <a href="http:&#x2F;&#x2F;hypirion.com&#x2F;musings&#x2F;understanding-persistent-vector-pt-1" rel="nofollow">http:&#x2F;&#x2F;hypirion.com&#x2F;musings&#x2F;understanding-persistent-vector-...</a>
评论 #10738751 未加载
dkerstenover 9 years ago
<p><pre><code> (map (defn f [c] {:overlap-amount (circle-overlap-distance circle c) :mid-point (mid-point circle c)}) circle-list) </code></pre> Is there a reason this uses <i>defn</i> instead of <i>fn</i>? This is the first time I&#x27;ve seen defn used like this.<p>Since this expands to something like <i>(def f (fn [c] ...</i> and <i>f</i> is never used anywhere, I&#x27;d change it to fn. If f <i>is</i> used, I&#x27;d consider <i>letfn</i> instead.<p>The revised code replaces it with #(...) which is shorthand for (fn [...] ...), but am curious if there was a reason for using defn or if it was just an oversight.
评论 #10738292 未加载
atratusover 9 years ago
kind of misleading when it&#x27;s throttled the whole time isn&#x27;t it?
评论 #10737415 未加载