Scala v Java: Which Side Are You On?

In the programming community, the relative merits of Scala and Java have fuelled one of the hottest debates of the past decade.

As in all heavyweight contests, each language attracts its own legions of diehard fans. Java is widely viewed as the undisputed champion of object oriented programming, the original Write Once, Run Anywhere (WORA) language favoured by millions of developers worldwide working on countless different platforms. In the opposite corner, Scala is the fresh faced upstart, more nimble, efficient and agile than its lumbering opponent.

So, which side of the fence do you sit on? Which would you tell a young programmer to focus on? Or, with their shared bytecode and continual cross pollination of influences, are the differences between Scala and Java over played?

To get the debate going, here are some key differences between Scala and Java 8 to chew over:

1.    Scala is more concise

This one is hard for even the most passionate Java advocates to contest. Scala was developed to avoid the need for long strings of getters and setters typical of much Java code. However, there is some argument that the tendency for Java programming to be long winded is a hangover from earlier versions, and that Java 8 is more than capable of supporting concise scripts if users can break old habits.

2.    Functional v Imperative

The main reason Scala is more concise than Java is that it was developed to make full use of mathematical functions, creating transferable rules which can be applied to input-output strings in a wide variety of programming contexts. This is a much more streamlined approach than an imperative language like Java, which requires developers to specify how input X leads to Output Y in every instance.

The current Scala v Java debate has been muddied by the fact that Java 8 has added many elements of functional programming. Fans now contend that Java can now do everything Scala can do, while Scala advocates insist the appearance of functions in Java 8 is merely ‘syntactic sugar’.

3.    Lambda Expressions

A lot of the debate around how functional Java 8 is revolves around its support for lambda expressions. For Scala diehards, the introduction of lambda expressions in Java 8 is just  window dressing because Java does not allow users to modify the expressions themselves. Scala, on the other hand, allows the context of expressions to be changed, giving far greater control over how functions are shaped and deployed.

4.    Scala can be complex

What some Scala users celebrate as its greatest strength is criticised by others for making the language difficult to learn and inaccessible. Using mathematical functions might allow programming to be more concise and efficient, but it is also challenging, especially for people without a mathematical background. The use of symbols in place of method names, and laying out processes according to the syntax of mathematical expressions, can sometimes create strings of code that are very difficult to decipher or which are ambiguous in meaning.

5.    Domain Specific vs General Purpose

Java was developed to be a General Purpose Language (GSL), with a minimum of implementation dependencies and the ability to run in as many different domains as possible. While Scala was intended to largely mimic Java in this respect, it also allows programmers the possibility of altering the language itself, and can therefore be used to create Domain Specific Languages (DSLs).

This is flagged up by Scala supporters as an incredibly powerful feature, offering supreme levels of flexibility in manipulating the grammar or even the compilation of the language to suit specific purposes. However, critics would again point out how complex and challenging this is, supporting arguments that Scala is a niche language for specialists, while Java is  the much more accessible and usable of the pair.

Why not join the debate?

On Thursday 2 March, Fruition IT will be hosting a special live debate on the merits of Scala and Java in Leeds city centre. Java vs Scala: The Odd Couple??!! will feature guest speakers Neil Dunlop, principal consultant at Infinity Works, setting out the case for Java, and Jon Humble, principal engineer at Sky Betting & Gaming, leading the representations for Scala. The event takes place at FutureLabs, 1 Eastgate, Leeds, LS2 7LY, starting at 6pm. To register for tickets, please visit javavscala.eventbrite.co.uk.