Java vs Scala – Is Scala a Better Choice Than Java?

cjavascala

We will be starting a new project which will involve training all the .net developers in Java (frameworks/ECO system etc). We have a lot of code written in C# and it seems that all of this will be wasted as we have to re-write it all in Java. The problem I see is that the first year or so (probably 2 years) we will have nothing to deliver as we will spend most of the time reproducing what we had before but now in Java.

Since our team is distributed in different offices around the world and we have a large number of java developers (20 to 30) and 10 developers using .net, we want to get all the developers using the same language/platform so we can start to reuse components/modules. So I can understand managements point of view.

Yesterday I came across Scala and was wondering if it would be better to use this with the current product (which is written in C#) and then at least we will have a working product in a year. Also in a year we have modules that can be used in the Java world whilst we migrate other parts of the product.

Would Scala be a better choice than Java considering what we are trying to achieve?

Best Answer

Some points to consider:

  • Scala is a great language - but it is worth noting that is it also quite a challenging language to learn and use correctly. Not just my opinion - even experienced Scala experts say so. Depending on the level of skills in your team, it is probably best suited as a tool for your most experienced / expert developers
  • Java and C# are pretty similar in many ways - it won't take long for developers trained in one to move across (the syntax is similar, it's mostly just a case of learning the quirks of each and getting an understanding of the different libraries, which often have similar functionality but are packaged differently and/or have different names). I've personally switched from Java to C# and back to Java again without any difficulty.
  • It's also worth noting that all the JVM languages (Java and Scala, but also JRuby and Clojure etc.) are very compatible - they share the same fundamental JVM platform and can share code / libraries very easily.

Given all this, you might want to hedge your bets and go for a mixed Java/Scala strategy - i.e. migrate to the JVM platform, and focus initially on Java, but keep open the option to use Scala when your developers are comfortable and/or it fits the problem at hand.

From a management perspective this has lots of advantages:

  • You can still share all the libraries so your investments will be safe
  • Your less experienced devs will be able to transfer C# -> Java pretty quicky
  • Your more experienced devs can take full advantage of the advanced features in Scala
  • All the tools are are compatible / can be shared (build systems, IDEs, deployment tools etc.)
  • You get free access to the very broad open source ecosystem of libraries on the JVM (alongside cross-platform portability, this is arguably the best reason to be on the JVM platform)
  • Your developers get to use the language that makes them most productive given their skills / the task at hand (Java in some cases, Scala in others, maybe other languages like Clojure in the future)

The downside is that you still have two primary languages to support. But you probably actually have many more than just two already (shell scripts? domain-specific XML formats? config files? rules engines? HTML? Javascript?) so you could argue that it isn't actually that much of a big deal.