Scala

A Scalable Language

  • A language that grows on you
  • What makes Scala scalable?
  • Why Scala?
  • Scala’s roots
  • Conclusion

First Steps in Scala

  • Learn to use the Scala interpreter
  • Define some variables
  • Define some functions
  • Write some Scala scripts
  • Loop with while; decide with if
  • Iterate with foreach and for

Next Steps in Scala

  • Parameterize arrays with types
  • Use lists
  • Use tuples
  • Use sets and maps
  • Learn to recognize the functional style
  • Read lines from a file
  • Conclusion

Classes and Objects

  • Classes, fields, and methods
  • Semicolon inference
  • Singleton objects
  • A Scala application
  • The Application trait
  • Conclusion

Basic Types and Operations

See Topics ...
  • Some basic types
  • Literals
  • Operators are methods
  • Arithmetic operations
  • Relational and logical operations
  • Bitwise operations
  • Object equality
  • Operator precedence and associativity
  • Rich wrappers
  • Conclusion

Functional Objects

See Topics ...
  • A specification for class Rational
  • Constructing a Rational
  • Reimplementing the toString method
  • Checking preconditions
  • Adding fields
  • Self references
  • Auxiliary constructors
  • Private fields and methods
  • Defining operators
  • Identifiers in Scala
  • Method overloading
  • Implicit conversions
  • A word of caution
  • Conclusion

Built-in Control Structures

See Topics ...
  • If expressions
  • While loops
  • For expressions
  • Exception handling with try expressions
  • Match expressions
  • Living without break and continue
  • Variable scope
  • Refactoring imperative-style code
  • Conclusion

Functions and Closures

See Topics ...
  • Methods
  • Local functions
  • First-class functions
  • Short forms of function literals
  • Placeholder syntax
  • Partially applied functions
  • Closures
  • Repeated parameters
  • Tail recursion
  • Conclusion

Control Abstraction

See Topics ...
  • Reducing code duplication
  • Simplifying client code
  • Currying
  • Writing new control structures
  • By-name parameters
  • Conclusion

Composition and Inheritance

See Topics ...
  • A two-dimensional layout library
  • Abstract classes
  • Defining parameterless methods
  • Extending classes
  • Overriding methods and fields
  • Defining parametric fields
  • Invoking superclass constructors
  • Using override modifiers
  • Polymorphism and dynamic binding
  • Declaring final members
  • Using composition and inheritance
  • Implementing above, beside, and toString
  • Defining a factory object
  • Heighten and widen
  • Putting it all together
  • Conclusion

Scala's Hierarchy

See Topics ...
  • Scala's class hierarchy
  • How primitives are implemented
  • Bottom types
  • Conclusion

Traits

See Topics ...
  • How traits work
  • Thin versus rich interfaces
  • Example: Rectangular objects
  • The Ordered trait
  • Traits as stackable modifications
  • Why not multiple inheritance?
  • To trait, or not to trait?
  • Conclusion

Packages and Imports

> See Topics ...
  • Packages
  • Imports
  • Implicit imports
  • Access modifiers
  • Conclusion

Assertions and Unit Testing

> See Topics ...
  • Assertions
  • Unit testing in Scala
  • Informative failure reports
  • Using JUnit and TestNG
  • Tests as specifications
  • Property-based testing
  • Organizing and running tests
  • Conclusion

Case Classes and Pattern Matching

> See Topics ...
  • A simple example
  • Kinds of patterns
  • Pattern guards
  • Pattern overlaps
  • Sealed classes
  • The Option type
  • Patterns everywhere
  • A larger example
  • Conclusion

Working with Lists

> See Topics ...
  • List literals
  • The List type
  • Constructing lists/li>
  • Basic operations on lists
  • List patterns
  • First-order methods on class List
  • Higher-order methods on class List
  • Methods of the List object
  • Understanding Scala's type inference algorithm
  • Conclusion

Collections

> See Topics ...
  • Overview of the library
  • Sequences
  • Sets and maps
  • Selecting mutable versus immutable collections
  • Initializing collections
  • Tuples
  • Conclusion

Stateful Objects

> See Topics ...
  • What makes an object stateful?
  • Reassignable variables and properties
  • Case study: Discrete event simulation
  • A language for digital circuits
  • The Simulation API
  • Circuit Simulation
  • Conclusion

Type Parameterization

> See Topics ...
  • Functional queues
  • Information hiding
  • Variance annotations
  • Checking variance annotations
  • Lower bounds
  • Contravariance
  • Object private data
  • Upper bounds
  • Conclusion

Abstract Members

> See Topics ...
  • A quick tour of abstract members
  • Type members
  • Abstract vals
  • Abstract vars
  • Initializing abstract vals
  • Abstract types
  • Path-dependent types
  • Enumerations
  • Case study: Currencies
  • Conclusion

Implicit Conversions and Parameters

> See Topics ...
  • Implicit conversions
  • Rules for implicits
  • Implicit conversion to an expected type
  • Converting the receiver
  • Implicit parameters
  • View bounds
  • Debugging implicits
  • Conclusion

Implementing Lists

> See Topics ...
  • The List class in principle
  • The ListBuffer class
  • The List class in practice
  • Functional on the outside
  • Conclusion

For Expressions Revisited

> See Topics ...
  • For expressions
  • The n-queens problem
  • Querying with for expressions
  • Translation of for expressions
  • Going the other way
  • Generalizing for
  • Conclusion

Extractors

> See Topics ...
  • An example: Extracting email addresses
  • Extractors
  • Patterns with zero or one variables
  • Variable argument extractors
  • Extractors and sequence patterns
  • Extractors versus case classes
  • Regular expressions
  • Conclusion

Annotations

> See Topics ...
  • Why have annotations?
  • Syntax of annotations
  • Standard annotations
  • Conclusion

Working with XML

> See Topics ...
  • Semi-structured data
  • XML overview
  • XML literals
  • Serialization
  • Taking XML apart
  • Deserialization
  • Loading and saving
  • Pattern matching on XML
  • Conclusion

Modular Programming Using Objects

> See Topics ...
  • The problem
  • A recipe application
  • Abstraction
  • Splitting modules into traits
  • Runtime linking
  • Tracking module instances
  • Conclusion

Object Equality

> See Topics ...
  • Equality in Scala
  • Writing an equality method
  • Defining equality for parameterized types
  • Recipes for equals and hashCode
  • Conclusion

Combining Scala and Java

> See Topics ...
  • Using Scala from Java
  • Annotations
  • Existential types
  • Conclusion

Actors and Concurrency

> See Topics ...
  • Trouble in paradise
  • Actors and message passing
  • Treating native threads as actors
  • Better performance through thread reuse
  • Good actors style
  • A longer example: Parallel discrete event simulation
  • Conclusion

Combinator Parsing

> See Topics ...
  • Example: Arithmetic expressions
  • Running your parser
  • Basic regular expression parsers
  • Another example: JSON
  • Parser output
  • Implementing combinator parsers
  • String literals and regular expressions
  • Lexing and parsing
  • Error reporting
  • Backtracking versus LL(1)
  • Conclusion

GUI Programming

> See Topics ...
  • A first Swing application
  • Panels and layouts
  • Handling events
  • Example: Celsius/Fahrenheit converter
  • Conclusion

The SCells Spreadsheet

> See Topics ...
  • The visual framework
  • Disconnecting data entry and display
  • Formulas
  • Parsing formulas
  • Evaluation
  • Operation libraries
  • Change propagation
  • Conclusion