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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Scaling Scala vs Java

49 点作者 rohshall超过 11 年前

8 条评论

abalone超过 11 年前
This comparison is extremely flawed.<p>He is not comparing Scala vs Java. He&#x27;s comparing Play Framework (async i&#x2F;o) vs. a Servlet that doesn&#x27;t use async i&#x2F;o.<p>He admits later that he purposefully handicapped the Java version. His reason is, he claims that Java&#x27;s Promise pattern is <i>so hard to program</i> that &quot;Java developers don&#x27;t do that.&quot; Which.. wow. His evidence: he&#x27;s written a lot of Java apps and <i>he&#x27;s</i> personally never used it.<p>And so he just switches off async i&#x2F;o for Java.<p>We all know Java has more boilerplate. The Promise pattern is 2 lines of boilerplate code per call, much like an event handler. To go from that to claiming &quot;Java developers don&#x27;t do&quot; Promise is a huge, unsupported leap.<p>Also you&#x27;d get the impression from his writing that Play Framework is only available for Scala.. but there&#x27;s a Java API too.
评论 #6706269 未加载
评论 #6706421 未加载
评论 #6706129 未加载
coolsunglasses超过 11 年前
This blog post is not great. It&#x27;s also not about scaling at all.<p>For one thing, a promises based async implementation is not incredibly helpful when you have a strictly one-after-another ordering of data dependencies.<p>In the interest of comparison, however, I decided to translate the example code to the equivalent synchronous and asynchronous Clojure code.<p><a href="https://www.refheap.com/20640" rel="nofollow">https:&#x2F;&#x2F;www.refheap.com&#x2F;20640</a><p>Things to note:<p>Instead of being forced to use a compiler-assisted construct, promises on Clojure get dereferenced. Dereferencing is the same operation used to get the value of agents, atoms, and refs as well.<p>Deref&#x27;ing (@) a promise over and over is totally okay.<p>Using promises doesn&#x27;t make the Scala solution meaningfully or usefully asynchronous unless the handler is yielding its thread while blocking on I&#x2F;O.
评论 #6705986 未加载
评论 #6706408 未加载
pron超过 11 年前
Well, it&#x27;s a good thing we&#x27;ve got Java lightweight threads[1]. They let you write synchronous, blocking, simple code, which it transforms to asynchronous calls. It gives you this &quot;Scala scalability&quot; to Java (or any JVM language) without wrapping your head around functional constructs. Scalaists can think of it as an async macro that works for all JVM languages, and can span a whole call-stack rather than just a single expression.<p>[1]: <a href="https://github.com/puniverse/quasar" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;puniverse&#x2F;quasar</a>
评论 #6707052 未加载
jondot超过 11 年前
Every now and then comes such an article and nudges me towards Scala again. It can really be an elegant and succinct language that can be all-encompassing.<p>But although I have a production running Scala project, I cringe every time I have to work with Scala just because of the tooling. It&#x27;s sad to see that SBT is cryptic and IDEs are slow and misleading.<p>When I work on the JVM I prefer Clojure. I think lein makes an exemplary development, build, and dependency management tool. I wish Scala had that.
评论 #6706028 未加载
评论 #6706138 未加载
评论 #6706306 未加载
js4all超过 11 年前
The title is a bit misleading. The blog post is about async calls in Java vs Scala using promises. Good read though.
voidlogic超过 11 年前
I dislike how the Java Promises and the Scala code unnecessarily hide the reality of the computation from the developer, take a Go version as counterpoint:<p><pre><code> func stockForProdsTO(uid int, timeout time.Duration) (*Stock, error) { stockCh := make(chan *Stock, 1) go func() { orders := ordersForUser(userById(uid).email) stockCh &lt;- stockForProds(prodsForOrders(orders)) }() select { case result := &lt;-stockCh: return result, nil case &lt;-time.After(timeout): return nil, errors.New(&quot;Could not get stock for product before timeout.&quot;) } }</code></pre>
willvarfar超过 11 年前
I&#x27;m a bit surprised because all my big Java servers have used Netty and are fully asynchronous. I didn&#x27;t realise there&#x27;s any big load of synchronous Java servers out there.
评论 #6706389 未加载
huntc超过 11 年前
In fairness to James, I think the comparison he&#x27;s making is in regard to the idiosyncrasies of developers, and that Java developers tend more often than not to use synchronous blocking calls. It is entirely possible to perform async IO in Java of course, but James&#x27;s point is that being async is a more natural state when using Scala.