

Ask HN: Scala vs. Java in real world - pedrorijo91

I like Scala. And I&#x27;m used to programming in Java.<p>Scala presents itself as THE programming language for concurrency and scalability, but I&#x27;ve heard of many cases where Scala was not sufficiently  efficient in really big and complex applications and when changed from Scala to Java they achieved a much better performance. Something about Java libraries&#x2F;frameworks being much more tuned...<p>Does someone has real world experience that can confirm&#x2F;deny this?
======
kasey_junk
I have used Scala in extremely performance sensitive environments. There are
places where you have to move down the "elegance scale" but you don't have to
abandon Scala entirely.

In general, performance is not the reason I would choose Java over Scala.

~~~
pedrorijo91
But is the bytecode generated by Java more efficient than the one generated by
Scala (in comparable situations ofc) ?

And which reasons would make you choose Java over Scala?

~~~
kasey_junk
I'm not comfortable answering that generally. That said, bytecode generation
was never the major issue, though I did find some cases where seemingly
identical implementations would be faster/slower in one compiler or the other.

Much more troubling:

\- Some Scala idioms are just not as performant as the naive java
implementations. Function passing can create lots of objects for instance.

\- Some of Scala's "magic" features that allow for terse-ness can behind the
scenes cause performance issues, that you might not expect without a clear
understanding of what is going on. Implicit conversions for instance can also
create tons of garbage.

\- The Scala collections library, while improving some, has lots of
performance gotchas. Collections that don't match modern hardware or implicit
conversions that de-optimize operations can happen pretty easily.

Personally, I would choose Java over Scala if any of the following were true:

\- You were going to have many different versions of your software in the
wild.

\- You had a constrained release cycle.

\- You intended for artifacts to exist for long periods without change.

\- You had specific backwards compatibility requirements.

\- You had a large team.

\- You had a team of highly varying skill sets.

That is to say, I'd only pick Scala if I were working on a project where I
controlled the life cycle of the product, releases were common, backwards
compatibility was not an issue, and my team was small, cohesive and
experienced.

If those things weren't true, I might not pick Java, but I certainly wouldn't
pick Scala.

------
thorin
Maintainability of code and number of available skilled developers would seem
like a reason for not choosing Scala. A small team of highly skilled and
motivated developers on a new project would seem like a good reason. Note I've
done Java dev but only have a bit of Scala knowledge.

