5 ms·
I'm part of a team who moved from Java to Scala recently (C# is a nicer language than Java these days). Apart from me, nobody else had real-world Scala experien
by karterk 13y ago
I'm part of a team who moved from Java to Scala recently (C# is a nicer language than Java these days). Apart from me, nobody else had real-world Scala experience but were generally good programmers and were able to pick up the functional aspects of Scala fairly quickly. The move was a big success, and a frequent comment I hear is "I can't imagine moving back to Java".
One of the reasons why the migration worked for us was that one can (with a bit of discipline) get into idiomatic Scala slowly. You can definitely start off writing Java-ish Scala and still gain a lot from the decreased verbosity and nicer APIs. You can safely stay away from over-using implicits, functional programming etc. till you get a good grasp of the language. With excellent Java interoperability, you don't have to convert your entire stack to Scala overnight, but slowly replace old code with Scala.
With respect to performance, if you insist on writing idiomatic Scala, there is definitely a performance overhead, because the JVM is not suited for large amounts of small allocations, as is often the case with an immutable style of programming. However, we run a pretty large scale data crunching system, and depending on what your code does, CPU bound performance hit pales in comparison to the network and I/O waits, so for us, it was not a big deal. When we absolutely needed to optimize a tight loop or something, we wrote C-like Scala, using while loops and mutable data structures.
Addendum: The greatest win for us was the readability of the code base. Scala allows you to largely keep your data structures immutable, so it's much easier to reason about. With parallel collections, Actors and Futures, concurrency support is excellent as well. You definitely need to pick up a few new concepts, but the time is well spent as once you get a hang of those things, your productivity will be 10x - you don't have to wrangle with primitive concurrency constructs.
- flipchart 13y agoWhy is it so hard to keep your data structures immutable in C# or Java? C# (my primary language) has parallel collections as of .Net 4.0 and with .Net 4.5 you have the async keyword support on top of the TPL. Could you elaborate on the differences between Scala and C# which make Sala more preferable for you? I'm not trying to start a war on C# vs Scala, I'm genuinely interested in the differences (I enjoy learning new languages, but for the right reasons)
- karterk 13y agoI can't talk too much about C#, but in Java there is no first class support for `map`, 'filter`, `reduce` etc. (with Google's Guava, you can imitate these things, but not so elegantly). So transforming a data structure involves a for-loop and lots of mutable operations. Iterating and transforming a collection in a functional style is much nicer.
- flipchart 13y agoI agree with you on the functional style. C#'s LINQ solves this problem quite well, although they named them differently (map -> select, filter -> where, reduce -> Aggregate). I've seen a number of people laud C# for being functional-ish because of such features.
- seglo 13y agoLINQ is a fantastic DSL akin to Scala's collection types. Odersky gives C# the nod as one of the few other traditionally imperative languages to have such a rich way of transforming data in his Functional Programming with Scala coursera course. I do prefer Scala's collection types and for comprehensions over LINQ though. I find them much easier to read and more powerful.
- _random_ 13y agoYou are explaining it a bit wrong. C# provides delegates (Action, Func etc.), lambda expressions, expression trees, anonymous functions, anonymous types, extensions methods. Those features make it a functional language and make succinct monads possible. LINQ happens to be one of those monads, but you can implement yours (e.g. rename Select to map etc.).
- flipchart 13y agoYes I agree with you. I'm not as well versed in monads and the technicalities around them as I would like to be, so thank you for pointing that out!
- 13y ago
- trailfox 13y agoOur team's experience was extremely similar. I almost did a quick check to see if any of my co-workers was on HN and had your username. Uncanny.
- seglo 13y agoJava to Scala is definitely an easier and more natural transition to make. I agree 100% with your sentiments.