Book Image

Professional Scala

By : Mads Hartmann, Ruslan Shevchenko
Book Image

Professional Scala

By: Mads Hartmann, Ruslan Shevchenko

Overview of this book

This book teaches you how to build and contribute to Scala programs, recognizing common patterns and techniques used with the language. You’ll learn how to write concise, functional code with Scala. After an introduction to core concepts, syntax, and writing example applications with scalac, you’ll learn about the Scala Collections API and how the language handles type safety via static types out-of-the-box. You’ll then learn about advanced functional programming patterns, and how you can write your own Domain Specific Languages (DSLs). By the end of the book, you’ll be equipped with the skills you need to successfully build smart, efficient applications in Scala that can be compiled to the JVM.
Table of Contents (12 chapters)

DSLs and Types of DSLs

A domain specific language is, as the name suggests, a language that's specialized for a specific domain. Contrast that with a language like Scala, which is a general-purpose language in the sense that it's applicable across a broad range of domains.

By restricting the domain, you'd hope to make a language that's less comprehensive but better suited to solving a specific set of problems within a domain. A well-constructed DSL will make it easy to solve problems within a domain and make it hard for the user to make mistakes. DSLs come in many different shapes and sizes, but you can roughly separate them into two groups: external DSLs and internal DSLs.

External DSLs

External DSLs are written "outside" of the host language (the language that's used to implement the DSL is called the host language). That means you'll have to parse the text, evaluate it, and so on, just as if you were creating a general-purpose programming language. We won't be creating an external...