by rohshall on 11/10/13, 6:29 AM with 36 comments
by abalone on 11/10/13, 11:02 AM
He is not comparing Scala vs Java. He's comparing Play Framework (async i/o) vs. a Servlet that doesn't use async i/o.
He admits later that he purposefully handicapped the Java version. His reason is, he claims that Java's Promise pattern is so hard to program that "Java developers don't do that." Which.. wow. His evidence: he's written a lot of Java apps and he's personally never used it.
And so he just switches off async i/o for Java.
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 "Java developers don't do" Promise is a huge, unsupported leap.
Also you'd get the impression from his writing that Play Framework is only available for Scala.. but there's a Java API too.
by coolsunglasses on 11/10/13, 9:34 AM
For one thing, a promises based async implementation is not incredibly helpful when you have a strictly one-after-another ordering of data dependencies.
In the interest of comparison, however, I decided to translate the example code to the equivalent synchronous and asynchronous Clojure code.
Things to note:
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.
Deref'ing (@) a promise over and over is totally okay.
Using promises doesn't make the Scala solution meaningfully or usefully asynchronous unless the handler is yielding its thread while blocking on I/O.
by pron on 11/10/13, 11:24 AM
by jondot on 11/10/13, 10:11 AM
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's sad to see that SBT is cryptic and IDEs are slow and misleading.
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.
by js4all on 11/10/13, 9:31 AM
by voidlogic on 11/10/13, 5:25 PM
func stockForProdsTO(uid int, timeout time.Duration) (*Stock, error) {
stockCh := make(chan *Stock, 1)
go func() {
orders := ordersForUser(userById(uid).email)
stockCh <- stockForProds(prodsForOrders(orders))
}()
select {
case result := <-stockCh:
return result, nil
case <-time.After(timeout):
return nil, errors.New("Could not get stock for product before timeout.")
}
}
by willvarfar on 11/10/13, 10:12 AM
by huntc on 11/10/13, 10:31 PM