Scala
- Pronunciation
- SKAH-luh
In short
Scala is a statically typed JVM language that combines object-oriented and functional programming and is widely used for data engineering and backend systems.
What is Scala?
Scala is a general-purpose programming language created by Martin Odersky at EPFL in Switzerland and first released in 2004. Its name comes from "scalable language", reflecting the goal of a language that works for small scripts and large systems alike. Scala mainly runs on the Java Virtual Machine and can use any Java library, and it can also compile to JavaScript through Scala.js and to native code through Scala Native. Scala 3, released in 2021, is the current major version.
Scala blends object-oriented and functional programming. Every value is an object, but functions are first-class values, immutable collections are the default, and pattern matching, case classes and traits (reusable bundles of methods that classes can mix in) are core features. Its type system is one of the most advanced among mainstream languages, and strong type inference means most types don't need to be written out.
Scala is used for data engineering, especially with the Apache Spark processing engine, which is itself written in Scala, as well as for backend services, streaming systems and financial software. It works a bit like a toolbox with two trays: you can write familiar class-based code from the top tray or reach for highly functional techniques in the bottom one.
Scala is often compared with Kotlin, since both are modern JVM languages that interoperate with Java. Kotlin aims to be a pragmatic, easy-to-learn improvement on Java with fast compilation and a strong position in Android development, while Scala offers a more powerful type system and deeper functional programming features at the cost of a steeper learning curve and slower builds.
Key takeaways
- Scala runs on the JVM and can use Java libraries directly.
- It combines object-oriented and functional programming in one language.
- Case classes, traits, pattern matching and immutable collections are central features.
- It is widely used for big data processing and backend services.
- Compared with Kotlin, it offers a more powerful type system but a steeper learning curve.
Example
// A case class and pattern matching (Scala 3 syntax)
case class Order(item: String, price: Double)
def describe(order: Order): String = order match
case Order(item, price) if price > 40 => s"$item is a big purchase"
case Order(item, _) => s"$item is a small purchase"
@main def run(): Unit =
val orders = List(Order("lamp", 45.0), Order("pen", 3.0))
orders.map(describe).foreach(println)Readers ask
Is Scala hard to learn?
Scala has a reputation for a steep learning curve because it supports many styles and has an advanced type system. Developers who already know Java or Kotlin can start with familiar object-oriented code and adopt functional features gradually.
What is the difference between Scala 2 and Scala 3?
Scala 3 redesigned parts of the language, adding optional indentation-based syntax, enums, union types and a simpler system for implicit values called givens. Most Scala 2 code can be migrated with modest changes.
Is Scala a functional language?
Scala is a hybrid. It supports pure functional programming with immutable data and higher-order functions, but it also fully supports classes, mutable state and object-oriented design.
See also
- JavaProgramming Languages, p. 15Java is a statically typed, object-oriented programming language that compiles to bytecode for the Java Virtual Machine, so programs run on many platforms.
- KotlinProgramming Languages, p. 18Kotlin is a concise, statically typed language that runs on the JVM, works seamlessly with Java, and is widely used for Android and server-side development.
- Functional ProgrammingProgramming Fundamentals, p. 22Functional programming is a style of building software from pure functions that avoid changing shared data, making code more predictable and easier to test.
- OOPProgramming Fundamentals, p. 40OOP, or object-oriented programming, is a way of structuring code around objects that bundle related data together with the functions that act on that data.
- Type InferenceProgramming Fundamentals, p. 55Type inference is a compiler feature that works out the type of a variable or expression automatically, so you don't have to write every type annotation.
- ClojureProgramming Languages, p. 6Clojure is a modern, dynamic dialect of Lisp that runs on the JVM, emphasizing immutable data, functional programming and interactive, REPL-driven development.
- JVMProgramming Languages, p. 17The JVM runs Java bytecode, so the same compiled program works on any operating system; Kotlin, Scala and Clojure compile to that bytecode too.
Spotted a mistake or something missing on this page?Suggest an edit