Scala Fundamentals Training Course

Training » All Courses » Scala » Scala Fundamentals

Course Summary

The Scala Language Fundamentals course serves as an introduction to the Scala language, with particular attention to its novel approach combining the object-oriented and functional programming paradigms. Students with a background in imperative, object-oriented programming will learn to incorporate patterns from functional programming into their design repertoires.

[top] Duration

2 days.

[top] Objectives

On completion of this course, students will have written a simple application using idiomatic, functional-style Scala. The application will demonstrate how the use of first-class functions and pattern matching, along with a powerful expressive type system can result in very easily understandable and maintainable code. Students will be able to:

  • Explain what Scala is and how it compares to both its object-oriented and functional language predecessors
  • Exploit the compositional nature of functions and expressions to avoid the pitfalls associated with Java-style imperative code
  • Navigate and utilize Scala's rich standard library
  • Write highly composable, modular code using a pure functional style
  • Use sbt to manage the build lifecycle and dependencies

[top] Audience

The Scala Language Fundamentals course is geared primarily toward developers with some Java experience, who are interested in becoming more effective or leading more effective teams by adopting the next generation of JVM-platform languages. Prior experience with Java is not strictly required, but will be helpful to understand some examples where the two languages, and the patterns and frameworks used most commonly in each, are compared.

The course is also appropriate for developers with experience in other object-oriented languages who are interested in understanding the principles of functional programming, applicable to many other languages gaining momentum in the industry including Clojure and Haskell.

[top] Prerequisites

Students enrolled in the Fundamentals of Scala course should have some prior software development experience, preferably in Java. The course assumes some familiarity with:

  • IDEs such as Eclipse or IntelliJ IDEA
  • Build tools such as Make, Ant or Maven
  • Basic procedural language constructs (e.g. for-loops) and object-oriented programming concepts (e.g. inheritance, polymorphism)

[top] Instructors

Photo
Dan Rosen believes in beautiful code. Beautiful code is understandable and maintainable, it is self-documenting and self-testing, it is robust and scalable, it can be composed and reused. Beautiful code doesn't come around every day, and even the most elegant code can still have its warts, but when you see beautiful code, you know it.

For twelve years, Dan has been doing his best to write and help others write some damn fine code. Dan is author of Marakana's Scala Fundamentals course, the latest addition the the Marakana course catalog. Before joining Marakana, he worked as a Developer Advocate at Atlassian, teaching developers how to write plugins for Atlassian's collaboration and development tools. Prior to Atlassian, Dan worked in both engineering and sales for Coverity, helping developers maintain code quality using Coverity's sophisticated static and dynamic analysis tools.

Between Coverity, Atlassian and Marakana, his tutorials have covered C/C++ best practices, Java web development (including Maven, Spring, OSGi, Guava, and RESTful web services using Jersey and Jackson), front-end development using jQuery, and functional programming with Scala.

Dan's latest hobby is lurking on StackOverflow as user "mergeconflict," waiting for tricky Haskell and Scala language questions to jump on. More about Dan Rosen...

[top] Outline

About Scala

  • Scala's pedigree: Java, Haskell, Pizza, GJ
  • Who uses Scala? Debunking the Functional Programming "ivory tower" myth

Basic Mechanics

  • sbt: "Simple Build Tool" and the Scala REPL
  • The "Scala IDE" plugin for Eclipse
  • Scala API docs

Data and Control Flow

  • Syntax introduction: declaring classes, primary constructors and class members (val and lazy val, var, def)
  • By-value and by-name parameters
  • Scala's unified type hierarchy
    • Any / AnyVal / AnyRef, Unit, Null, Nothing
  • Local type inference
  • Pattern matching and control-flow expressions
    • match/case
    • if/else
    • for/yield
  • Syntactic sugar: omitting dots and parentheses

Object-Oriented Programming

  • Encapsulation
    • Classes, objects and companions
    • Case classes and case objects
    • apply and unapply
  • Inheritance and Polymorphism
    • The "Uniform Access Principle"
    • The override keyword
    • Fine-grained access modifiers
    • Traits, mix-in inheritance and linearization

Introduction to Generics

  • Parametric polymorphism: generic classes and generic methods
  • Generic type bounds: when inheritance and generics collide
  • A quick peek at variance annotations

Functional Programming

  • Functions are objects
    • def foo(a: A): B is a function A => B or a Function1[-A, +B]
    • Functions can be bound to variables and passed as parameters to other functions
  • Standard functional collection methods: filter, map, fold...
  • Anonymous functions (lambdas, closures)
  • Syntactic sugar: the mysterious _
  • Currying and partial application: the "loan" pattern

Real-World Scala

  • Error handling
    • try/catch/finally (with pattern matching)
    • Turning exceptions into Option and Either
  • Common mistakes
    • Pattern matching pitfalls: variable patterns vs. stable identifier patterns
    • Underscores gone awry: block expressions and function literals