[11] Unlike Java, Scala has many features of functional programming languages (like Scheme, Standard ML, and Haskell), including currying, immutability, lazy evaluation, and pattern matching.
[12] The name Scala is a portmanteau of scalable and language, signifying that it is designed to grow with the demands of its users.
[17] On 12 May 2011, Odersky and collaborators launched Typesafe Inc. (later renamed Lightbend Inc.), a company to provide commercial support, training, and services for Scala.
[22] The reference Scala software distribution, including compiler and libraries, is released under the Apache license.
[26][27] A reference Scala compiler targeting the .NET Framework and its Common Language Runtime was released in June 2004,[14] but was officially dropped in 2012.
[29] Saved in a file named HelloWorld2.scala, this can be run as a script using the command: Commands can also be entered directly into the Scala interpreter, using the option -e: Expressions can be entered interactively in the REPL: The following example shows the differences between Java and Scala syntax.
The following are some examples: By themselves, these may seem like questionable choices, but collectively they serve the purpose of allowing domain-specific languages to be defined in Scala without needing to extend the compiler.
While supporting all of the object-oriented features available in Java (and in fact, augmenting them in various ways), Scala also provides a large number of capabilities that are normally found only in functional programming languages.
Examples are: Unlike C or Java, but similar to languages such as Lisp, Scala makes no distinction between statements and expressions.
Type inference in Scala is essentially local, in contrast to the more global Hindley-Milner algorithm used in Haskell, ML and other more purely functional languages.
Those variables will be available even after the enclosing function returns, and unlike in the case of Java's anonymous inner classes do not need to be declared as final.
Non-strict collections provide a good semantic fit to things like server-produced data, where the evaluation of the code to generate later elements of a list (that in turn triggers a request to a server, possibly located somewhere else on the web) only happens when the elements are actually needed.
Functional programming languages commonly provide tail call optimization to allow for extensive use of recursion without stack overflow problems.
For instance, the recursive version of the factorial: Could be optimized to the tail recursive version like this: However, this could compromise composability with other functions because of the new argument on its definition, so it is common to use closures to preserve its original signature: This ensures tail call optimization and thus prevents a stack overflow error.
Scala has built-in support for pattern matching, which can be thought of as a more sophisticated, extensible version of a switch statement, where arbitrary data types can be matched (rather than just simple types like integers, Booleans and strings), including arbitrary nesting.
As specified above, any string of symbols can serve as function name, and a method applied to an object can be written "infix"-style without the period or parentheses.
However, we can still call this variable exactly as if it were a normal function: Scala is a pure object-oriented language in the sense that every value is an object.
Class abstractions are extended by subclassing and by a flexible mixin-based composition mechanism to avoid the problems of multiple inheritance.
Interfaces in Java versions under 8 are highly restricted, able only to contain abstract function declarations.
This is similar to the decorator pattern, but is more concise and less error-prone, as it doesn't require explicitly encapsulating the parent window, explicitly forwarding functions whose implementation isn't changed, or relying on run-time initialization of entity relationships.
Scala is equipped with an expressive static type system that mostly enforces the safe and coherent use of abstractions.
A common technique in Scala, known as "enrich my library"[39] (originally termed "pimp my library" by Martin Odersky in 2006;[32] concerns were raised about this phrasing due to its negative connotations[40] and immaturity[41]), allows new methods to be used as if they were added to existing types.
The following example shows the enrichment of type Int with methods isEven and isOdd: Importing the members of MyExtensions brings the implicit conversion to extension class IntPredicates into scope.
Scala also comes with built-in support for data-parallel programming in the form of Parallel Collections[46] integrated into its Standard Library since version 2.9.0.
Additionally, Apache Kafka, the publish–subscribe message queue popular with Spark and other stream processing technologies, is written in Scala.
[141] In the 2018 edition of the State of Java survey,[142] which collected data from 5160 developers on various Java-related topics, Scala places third in terms of use of alternative languages on the JVM.
Relative to the prior year's edition of the survey, Scala's use among alternative JVM languages fell from 28.4% to 21.5%, overtaken by Kotlin, which rose from 11.4% in 2017 to 28.8% in 2018.
[144] Here, Scala was placed inside a second-tier group of languages–ahead of Go, PowerShell, and Haskell, and behind Swift, Objective-C, Typescript, and R. The TIOBE index[145] of programming language popularity employs internet search engine rankings and similar publication counting to determine language popularity.
[175] In March 2015, former VP of the Platform Engineering group at Twitter Raffi Krikorian, stated that he would not have chosen Scala in 2011 due to its learning curve.
[176] The same month, LinkedIn SVP Kevin Scott stated their decision to "minimize [their] dependence on Scala".