Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
S ECTION 1.4 ยท Scala's roots useful documentation is what readers of a program cannot easily derive by themselves. In a method definition like: def f(x: String) = ... it's useful to know that f 's argument should be a String . On the other hand, at least one of the two annotations in the following example is annoying: val x: HashMap[Int, String] = new HashMap[Int, String]() Clearly, it should be enough to say just once that x is a HashMap with Int s as keys and String s as values; there's no need to repeat the same phrase twice. Scala has a very sophisticated type inference system that lets you omit almost all type information that's usually considered annoying. In the previ- ous example, the following two less annoying alternatives would work just as well: val x = new HashMap[Int, String]() val x: Map[Int, String] = new HashMap() Type inference in Scala can go quite far. In fact, it's not uncommon for user code to have no explicit types at all. Therefore, Scala programs often look a bit like programs written in a dynamically typed scripting language. This holds particularly for client application code, which glues together pre- written library components. It's less true for the library components them- selves, because these often employ fairly sophisticated types to allow flexible usage patterns. This is only natural. After all, the type signatures of the mem- bers that make up the interface of a reusable component should be explicitly given, because they constitute an essential part of the contract between the component and its clients. 1.4 Scala's roots Scala's design has been influenced by many programming languages and ideas in programming language research. In fact, only a few features of Scala are genuinely new; most have been already applied in some form in other languages. Scala's innovations come primarily from how its constructs are put together. In this section, we list the main influences on Scala's design. The list cannot be exhaustive--there are simply too many smart ideas around in programming language design to enumerate them all here. 19