This is the course I give to my students. Most of them are at the end of their studies and during the next year, they are going to enter the job market. In this course, for me, it is important for the students to confront the daily life of professional developers in industry, as closed as possible, considering their current understanding of such environment (limited to some internships).
Lectures
I first start with 4h of lectures. Here are the main slides:
1 - Discovering Scala: 01 - Scala - Discovering Scala - Google Präsentationen
2 - Functional programming: 02 - Scala - Functional Programming - Google Präsentationen
The first thing I do is a demo, in which I show how to setup IntelliJ IDEA and how to create a new Scala project. Then, I first introduce Scala and its main features and specificities (OOP in Scala, pattern matching, call-by-name parameters…). I do this mostly through live coding.
For FP (functional programming) part, I start with a short presentation of the history of FP and why it is widely adopted in a way or another by industry and the main programming languages nowadays. Then, I focus on some FP principles: function-as-value, immutability (vs side-effects), referential transparency, and all the other principles that brings to functional purity. After that, I present some universal types (List, Option, Either, Future…) and universal operations (map, flatMap, fols, filter…) of FP. I end up with presentation of ADT, parameterised ADT, and GADT.
Labs
The labs are simply based on this Github project below, in which the students have to run the Scala files one by one. Here I use Scala 3. Some macros make it possible to divide the files into sections and exercises, in which they must pass tests (different markups are provided for the students to give their answers). Of course, there is a phase where students have to clone the project from Github and open it with an IDE (I use IntelliJ IDEA). The comments in the files are here to introduce the exercises or to give recommendations.
Here is an example of use of those macros:
import io.univalence.education.internal.exercise_tools.*
/**
* A box is just a generic container for exactly one value.
*
* @param value
* the value inside the box.
* @tparam A
* the type of the value.
*/
case class Box[+A](value: A)
section("Living in a box") {
exercise("map a box") {
/**
* With the extension syntax, we add the `map` function to the Box
* type. This addition is only effective in the current exercise.
* It is not available outside.
*
* The `map` operation aims to modify the value inside the box.
*/
extension [A](box: Box[A]) def map[B](f: A => B): Box[B] = |>?
check(Box(42).map(_ * 2) == Box(84))
check(Box("42").map(_.toInt) == Box(42))
}
}
It displays this output:
07-generic_types.scala:126 - Living in a box
07-generic_types.scala:126 - Living in a box > map a box
>>> TODO missing implementation detected while calling Box(42).map(_ * 2) == Box(84) (/Users/fsarradin/src/training/education-scala/src/main/scala/io/univalence/education/07-generic_types.scala:58)
>>> TODO missing implementation detected while calling Box("42").map(_.toInt) == Box(42) (/Users/fsarradin/src/training/education-scala/src/main/scala/io/univalence/education/07-generic_types.scala:59)
Notice that lines starting with >>>
, ends with a location in the source code. IntelliJ IDEA automatically converts this into a hyperlink. Once clicked, IntelliJ directly opens an editor focused on this line.
Once the exercise is solved, the output is then:
07-generic_types.scala:126 - Living in a box
07-generic_types.scala:126 - Living in a box > map a box
>>> Box(42).map(_ * 2) == Box(84) OK (line:58)
>>> Box("42").map(_.toInt) == Box(42) OK (line:59)
Validation
The course validation is done through project, that students has to work on in teams. Each team has to work on different projects. The project topics looks like:
- Building a library for serialization in a custom binary format and RPC
- Building a library of parser combinators
- Developing an spreadsheet application
- Developing simple Web framework
- Building a simple library to solve some constraint satisfaction problems
I let some hours during labs, so teams can move forward on their project, and ask me any questions.