Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala, the java of the future(?) [closed]

Tags:

java

scala

People also ask

Is Scala Future blocking?

By default, futures and promises are non-blocking, making use of callbacks instead of typical blocking operations. To simplify the use of callbacks both syntactically and conceptually, Scala provides combinators such as flatMap , foreach , and filter used to compose futures in a non-blocking way.

What is the difference between a Java Future and a Scala Future?

A Java Future works in a synchronous blocking way. It does not work in an asynchronous non-blocking way, whereas a Scala Future works in an asynchronous non-blocking way. If we want an asynchronous non-blocking feature, we should use Java 8's CompletableFuture.

Is Future blocking onComplete?

NOTE: With Future. onComplete() we are no longer blocking for the result from the Future but instead we will receive a callback for either a Success or a Failure.

How does Scala Future work?

Future represents a result of an asynchronous computation that may or may not be available yet. When we create a new Future, Scala spawns a new thread and executes its code. Once the execution is finished, the result of the computation (value or exception) will be assigned to the Future.


I've been using Scala for a year now at work (finance technology) and would not want to move back to Java at all! The things that concerned me most when originally considering the migration were:

  • Tool Support (what are the IDE's like?)
  • Interop with existing Java libraries and build technologies (ant, Spring, internally-written stuff)
  • Talent Pool (where do I find good Scala developers?)
  • Transition-time (how long before I'm writing good Scala?)

I found that IDEA's Scala plugin (for the now free v9 Community Edition) is excellent: not quite as good as Java's tool support but certainly good enough for our needs. It has basic refactoring and debugging and great syntax-highlighting. My experience with Eclipse has been extremely disappointing: I'm led to understand that great improvement is expected for Scala 2.8 but I've seen a recent Eclipse-nightly and it was, frankly, awful.

The interoperability with Java is first-rate - I have had no problems whatsoever and still make heavy use of Spring and our bespoke (ant-based) build-system. The developer-pool is only a consideration for a large company with moderate-to-high staff turnover; it has not been an issue for us so far and interviewees have expressed interest in using Scala anyway.

Perhaps the biggest issue is transition-time. I've found this to be 2 weeks to being able to write anything reasonable, 3 months to start to really "get it" and 6 months-1 year to start taking advantage of the functional and DSL-sides of Scala. So, what are the really big gains for me?

  1. Type inference and co- and contra-variance built in (code is more readable and intuitive - generics just works, unlike Java where it can be extremely painful)
  2. Functional Programming style and closures (code is more readable and quicker to write)
  3. The actors concurrency library (simplifies concurrent programming hugely)

So to conclude:

  • Is Scala any good? Yes - it's fantastic
  • Is it ready for real enterprise use? Yes - there are quite a few compaies using it now, including Twitter, Sony and EDF
  • Are the gains worth the adoption cost? Yes - absolutely

Nobody has a crystal ball, and somebody could come up with something better (or something worse with a powerhouse behind it) anytime.

There's been a lot of articles, podcasts, etc. Here on SO, I suggest you read: https://stackoverflow.com/questions/33744/is-scala-the-next-big-thing

Personally, I think Scala is promising, but may fail to ever attract the crowd. A lot of the production use of Java today revolves around J2EE and I don't see these folks making the transition. For non-Java users, more established languages like Python may provide all the functional features they need even at the cost of not using the JVM.


I've just started working with Scala and I'm starting to see more interest in the financial arena.

I'm now getting more people/colleagues showing interest in this. A number of people have asked me to keep them posted as to my progress. I didn't see the same level of interest in Groovy (or other JVM languages post Java itself).

So it's definitely the Java language de jour, and I think it has more momentum than anything before it in the Java arena. How this carries forward is anyone's guess, however!


I have been programming in Java for many years, and Haskell and OCaml for the last two years. A few months ago I began developing a personal project in Scala, and it's wonderful. A real type system and all the Java supporting libraries.

The ease of mixing Java and Scala means the language definitely has a future. Adoption costs for an existing Java project are very low.


I heard about Scala some months ago, and was pretty excited to see "a better Java than Java" for the JVM. Scala fixes a number of Java's problems with annoying boilerplate code, adds some functional programming and concurrent programming support. It has good (though not perfect) compatibility to Java's libraries, so all that code is instantly available. It's also possible to mix Scala with Java and possibly other JVM languages in the same project.

I tried to learn Lift (the Web framework) and found I wasn't smart enough to handle it. Scala syntax is very terse and cryptic in some places (where Java is wordy) and takes some getting used to. I wrote some small projects and they worked well; but bigger projects were no fun with the half-adequate support of the Eclipse plugins available at the time.

Personally, I gave up on Scala and moved on to Clojure, which offers many of the same advantages and is more (sorry to be subjective here) "fun" to program.


My personal conclusion: Scala has a lot of features crammed into it, which raises the learning curve. It feels like the complexity of C++ with the syntax of Java and the FP constructs of Ruby. I think it will be hard to persuade industry that Scala has significant advantages over Java, enough to justify the costs in re-tooling and re-training.


Not sure if this info helps, but I'm building an online gaming server for a successful and established gaming company, using Scala and Project Darkstar.

Our design is specced to scale to half a million to ten million users (thanks, Amazon EC2!), and Scala gives me extra confidence in my code for five reasons: 1. I catch more things at compile time. 2. It's easy to make much of my game data immutable. 3. Higher level code means that I'm less likely to get a trivial implementation mistake. 4. Shorter, simpler code makes it easier for me to review and find errors. Implicit conversions are a big part of this. 5. The happier I am writing code (and Scala generally makes me happy), the better job I do.

Scala isn't a panacea, and it's got plenty of warts (namely lack of any great tool support) but it's by far the most productive language I could be using for this purpose.

My only complaint is that I wish it could compile down to C or heavily macro'd assembler, as the limitations of the JVM often irk me (type erasure, lack of stack types and by-value object arrays).

I don't think Scala is that popular yet, the 2.8 conversion is woefully behind and has created a rift in the community, and the tool support just isn't there. But if you're a cowboy coder who's not afraid of algebraic type theory and lack of autocomplete, it's hard to go wrong.

If you do decide to use it, do yourself a huge favor and buy Odersky's book. I tried for a while to code in Scala without it, and it was almost impossible to do anything the "scala way" (not that there's consensus on that).