Topics

Featured in Development

As part of our core values of sharing knowledge, the InfoQ editors were keen to capture and share our book and article recommendations for 2018, so that others can benefit from this too. In this second part we are sharing the final batch of recommendations

Featured in Architecture & Design

Tanya Reilly discusses her research into how the fire code evolved in New York and draws on some of the parallels she sees in software. Along the way, she discusses what it means to be an SRE, what effective aspects of the role might look like, and her opinions on what we as an industry should be doing to prevent disasters.

Featured in Culture & Methods

Mik Kersten has published a book, Project to Product, in which he describes a framework for delivering products in the age of software. Drawing on research and experience with many organisations across a wide range of industries, he presents the Flow Framework™ as a way for organisations to adapt their product delivery to the speed of the market.

Featured in DevOps

The fact that machine learning development focuses on hyperparameter tuning and data pipelines does not mean that we need to reinvent the wheel or look for a completely new way. According to Thiago de Faria, DevOps lays a strong foundation: culture change to support experimentation, continuous evaluation, sharing, abstraction layers, observability, and working in products and services.

Choose your language

Why Scala?

Before answering the question of "Why Scala?", we first need to answer the question "what is Scala?" From the Scala website, the following overview can be found:

Scala is a modern multi-paradigm programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates features of object-oriented and functional languages.

Scala is object-oriented: Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Class abstractions are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.

Scala is functional: Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala's case classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.

Scala is statically typed: Scala is equipped with an expressive type system that enforces statically that abstractions are used in a safe and coherent manner.

Scala is extensible: The design of Scala acknowledges the fact that in practice, the development of domain-specific applications often requires domain-specific language extensions. Scala provides a unique combination of language mechanisms that make it easy to smoothly add new language constructs in form of libraries:

A joint use of both features facilitates the definition of new statements without extending the syntax and without using macro-like meta-programming facilities.

Scala interoperates with Java and .NET: Scala is designed to interoperate well with popular programming environments like the Java 2 Runtime Environment (JRE) and the .NET Framework (CLR). In particular, the interaction with mainstream object-oriented languages like Java and C# is as smooth as possible. Scala has the same compilation model (separate compilation, dynamic class loading) like Java and C# and allows access to thousands of high-quality libraries.

For some developers, these incentives will be enough to lure you away from Java into the Scala world. But for others, they provide no additional benifits for the day-to-day programming that is currently being performed in Java.

So, once again, "why Scala?"

In a post titled "Scala: The best of both Ruby and Java", Ian describes that it might not be a choice between Java and Scala, but instead the choice to use a combination of Java and Scala as an alternative to other language choices such as Ruby:

Many programmers love Ruby, they just can’t get enough of it. Its probably one of the most aggressively evangelized languages since Java first came on the scene. They generally cite features that include a flexible and extensible syntax, closures, and how concise and expressive the code can be.

For example, you can create a Map (Ruby calls them “hashes”, even though a hashtable is only one way a map can be implemented) with a simple syntax like:

You will notice that it looks very similar to the equivalent code in Ruby, but there are some important differences. In particular, just like Java, the Scala compiler knows that numberMap uses Strings as keys, and Integers as values. Unlike Java, you didn’t have to tell it this, it just figured it out for itself! This is called “type inference”.

This means that if I try adding a new key-value pair to numberMap, but using an Integer for the key, and a String for the value, Scala will complain as soon as you try to compile it (or your IDE will warn you immediately). With Ruby, it is only likely to cause a problem when you run your software and try to retrieve this key and value from the Map and get an Integer and a String, rather than the String and the Integer that you were expecting.

It is hard to overemphasize what a timesaver compile-time type checking can be, it eliminates a whole class of bugs that would otherwise occur at runtime, and Scala brings you the benefits of this, without the verbosity.

To further show the reduction of code in a less trival example, Ted Neward explores the differences between a class developed in Java, C#, Visual Basic, Ruby and Scala in his blog posting Scala pt 2: Brevity.

Continuing on, Ian notes that:

Scala also has a bunch of other nice Ruby features, which Java lacks, including closures, and a very malleable syntax that makes it well suited for “domain specific languages”. It has all of these features, and combines them with the benefits of static typing.

This opinion is shared by David MacIver in the blog posting No, seriously, why Scala? where he points to object orientated programming, module orientated programming, static typing, functional programming, and implicits as features that he likes in the language. He does add that

Scala's far from perfect. It has some syntactic weirdnesses, a few issues carried over from Java, a moderately buggy compiler and a host of little features and edge cases that are really hard to keep in your head. However, I find that these issues don't actually do more than annoy you from time to time. The core language is powerful and very useful for just sitting down and writing good code in.

Providing a balance outlook, David follows up with the blog post Why not Scala where he expands upon some of the edge cases. Summing up, David had the following comment:

All in all, I find these add up to just a bunch of annoyances. It's still my preferred language for the JVM, but depending on how you wait your priorities they might be more significant for you.

Showing that Scala as a language is maturing, the book Programming in Scala will soon be available. For those that cannot wait, there is a pre-print version available as PDF from the Artima web site.

To make your own decision, and to learn more about Scala check out their website.

Community comments

.Net

Your message is awaiting moderation. Thank you for participating in the discussion.

Not so many info about .Net support and all blog posts for Java, hence I think it would be nice to mention Boo - a language for .Net with similar objectives and functionality (but Python-inspired syntax).

Re: .Net

Your message is awaiting moderation. Thank you for participating in the discussion.

Boo++

I love the simple syntax but Boo still has the 'trendy' language features like closures and AST macros. Languages that use lots of symbols (like Perl & Ruby) are difficult to read unless you know what all those symbols mean.