
A quick run-through of the reasons why people are so excited about Scala
Let's plunge in! Setting up Scala is surprisingly simple. You do need Java though.
Immutable variables are a big part of Scala - understand why.
Scala aims to achieve the best of both worlds: rapid prototyping like Python, type safety like Java, C++ and other statically typed languages.
Scala has 3 types that unify the type system: Any (literally anything!), AnyRef (supertype to all reference types) and AnyVal (supertype to all value types)
Nil, null, Null, Nothing, Unit..Scala has many ways to skin a non-existent cat!
This is an important semantic difference - statements don't return a value, while expressions do. Scala converts many familiar constructs into expressions - which allows them to be composed.
Expression blocks are prototypical "r-values", i.e. they sit on the right of assignment statements.
Scala has if-else expressions (not if-else statements). This is a fine point, and an important one.
Pattern matching is very easy in Scala - this is a more popular language construct than if/else expressions
Explore match expressions in Scala, including pattern guards and or-ed expressions, to extend conditions with boolean expressions and value bindings.
Scala has a way to convert for loop statements into for loop expressions - using 'yield'
Explore two for loop styles in Scala: value binding over a list and numeric ranges using until or to; and learn how foreach, map, and flatMap offer alternatives.
While loops are pure statements, and are rather clunky. See why they are not the most popular construct in town.
Functions are 'first class citizens' in Scala - this actually has a technical term!
Discover how Scala treats functions as objects and entities, defined with the value keyword and stored in val or var, while methods use def and stay tied to a class.
Learn that functions are named, reusable expression blocks with parameters and return values, behaving like first-class functions and enabling closures across scope in Scala.
Scala allows parameters to be specified out of order - using their names
Yet another mechanism to encourage code re-use
Scala loves using formidable terms for everyday concepts:-) Think generics in Java.
Learn how procedures are named, reusable statements in Scala that are functions without a return value, must produce a side effect to change state, and use def with Unit.
Explore Scala methods with and without parentheses, where parentheses denote function-like behavior and methods without parentheses look like properties, and learn how the compiler enforces their invocation.
Functions that take in other functions as parameters, or return function objects, are called Higher Order Functions
Partially Applied Functions are a really cool code re-use trick: fix some (but not all) parameters of a function and you have a new function!
Explore by-name parameters in Scala, showing how the first evaluation is lazy and every subsequent reference triggers ego evaluation for both functions and methods.
Explore closures in Scala, where nested functions capture their referencing environment and outlive their outer scope. Learn how higher-order functions return language-specific greetings.
Discover how Scala supports collections with higher-order functions, where container classes provide methods that apply function objects to their elements in powerful ways.
Learn Scala tuples as ordered, immutable containers of heterogeneous values. Create with parentheses, access with _1, _2, or deconstruct into variables; they are not true collections, making iteration awkward.
Explore creating and manipulating lists in Scala, including immutable lists, Nil, the cons operator ::, the apply method, and concatenation with ::: and ++, plus zip and flatten.
Explore fold, foldLeft, foldRight and scan, scanLeft, scanRight in Scala. Understand how they relate and that they operate from right to left, with results shaped by leftmost and rightmost elements.
Explore reduce, reduceLeft, and reduceRight in Scala, focusing on initial values and left versus right associative behavior, and compare them with scan.
Explore error handling in Scala using Try, comparing success and failure patterns with option collections to gracefully manage exceptions and specify a plan B.
Explore anonymous classes in Scala to quickly instantiate abstract classes by redefining methods in braces and using new, with shape and sheep examples returning the value 100 for get area.
Learn how singleton objects in Scala, defined with the object keyword, provide static-like behavior via companion objects, explain why Scala omits static, and define the entry point.
Explore companion objects in Scala, where a singleton object and a class share a name in the same file to access private data and implement a factory pattern via apply.
These 65 examples will make this cool-new-kid-on-the-block your steady, reliable friend
Let's parse that.
What's Included: