TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

ClojureScript performance revisited

26 点作者 greenonion超过 9 年前

3 条评论

khgvljhkb超过 9 年前
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 未加载
dkersten超过 9 年前
<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 未加载
atratus超过 9 年前
kind of misleading when it&#x27;s throttled the whole time isn&#x27;t it?
评论 #10737415 未加载