/scala-training-slides

Contains slides for the Scala training course.

OtherNOASSERTION

Scala training – slides

This github project contains slides used for the Scala training course. The code which goes along with the slides is located at Scala training code.

When doing the training course, we created a VirtualBox image containing all the code and working versions of Java, Maven, Scala, Eclipse and IDEA. We used a trimmed down version of Debian Linux and we distrubuted it through DropBox. If you would like a copy of the image we created, please contact us directly.

Each day of the course is meant to be approximately 4 hours.

Day one

The first day is very controlled. We start off by giving a motivation talk, then go through basic Scala syntax and an intro to tools. After this the participants get a little hands on programming.

The course then proceeds with short intros to topics (15-20 minutes) followed by programming exercises (about 30 minutes). The programming exercises are JUnit tests which give immediate feedback on correctness. It is important the participants are made aware that they may skip exercises if they get stuck, there are plenty of exercises for each topic.

The day ends with a motivational talk on pure functional programming.

Day one is divided into the following slide set/topic:

1.1 – start.odp

This is 10 minute motivational talk for learning Scala. Starts off with a few quotes on Scala from prominent figures in the community, then shows quite a few code examples to show the power of Scala. We do not try to explain how these examples work, just the benefit. However it is a goal of the training class that everyone should be able to understand all the examples shown here at the end of the training course.

1.2 – scala basics.odp

Covers a lot of the basic syntax in Scala compared with Java. We aimed here not to show how similar concepts map between Scala and Java. On purpose we avoided the more advanced constructs and concepts. This is meant as a quick intro to the language syntax, to make the participants feel right at home.

1.3 – tools_and_repl.odp

Short discussion on available tools and IDE support. The first hands on exercise is followed by these slides. The aim of the exercises is to see that everyone has a working development environment. There are also very simple tasks to perform, to make the participants feel a little at ease.

1.1 – 1.3 is meant to be about and hour. We spent about 15 minutes doing the practical part of 1.3, including a short summary.

1.4 – firstclassfunctions.odp

Defines first class functions and closures and how to use them. Also how this differs fundamentally from Java’s iteration approach.

We tried to make it a point about deferred execution, through a constructed example of a Swing action listener. Participants need to understand that even though it looks like first class functions are executed right then and there, they are actually executed later, whenever appropriate. In the Swing action listener example, whenever the button is pressed.

Closures is explained in detail.

The presentation section should be no longer than 15 minutes. 30 minutes are spent on the programming tasks and 5 minutes on summary and questions.

1.5 – PatternMatching.odp

Shows the power of pattern matching. Starts off by showing how matching can be done on existing types. Also shows iteration with lists on pattern matching. We are perfectly aware that the iteration example is not tail recursive, however we tried not to make the concepts too difficult to understand.

We then show how pattern matching can be done on your own types, with case classes. We believe that introducing extractors would be a little too advanced for the first day.

We felt that at this point it would be natural to introduce the Option type.

The presentation section should be no longer than 15 minutes. 30 minutes are spent on the programming tasks and 5 minutes on summary and questions.

1.6 – OO-traits.odp

This part is meant to cover all of the OO stuff which we felt was too advanced for the “basic syntax” sections. It covers quite a few different topics

  • Annotations – supports annotations just as well as Java. Does not use marker interfaces.
  • Object – in stead of statics. A lot more powerful, and can inherit classes/traits, and can be passed around as normal references.
  • Companion object – Special use of object. Can create some really nice syntax around types.
  • Primary constructors – Only one, and every constructor must call it. Class body is primary constructor body.
  • Auxiliary constructors – Easy to define, but must chain up to primary constructor
  • Inheritance – works similar as in Java
  • Traits – Multiple inheritance done right. Can do almost the same as with classes, except has not constructors. Possible to mix in traits on instance creations.
  • Composition vs inheritance – traits makes it easy not to inherit but to ‘mix in’, which is almost always what you want.

The presentation section should be no longer than 20 minutes. 30 minutes are spent on the programming tasks and 5 minutes on summary and questions.

1.7 – functional_programming.odp

This part is meant as a motivational ending of day one. Functional concepts have been introduced, however pure functional programming has not. Try to explain why to strive for functional purity, how Scala helps in this way, and how Scala lets you choose.

This section should not be more than 10 minutes.

Day two

The second day of the training class is meant to bee more free than day one. This means that the participant are more free to explore the language on their own.

It starts of we a quick recap of day one. Following is two advanced topics. With “advanced” we mean concepts the participants have to understand in order to use Scala and Scala libraries, but not necessarily be able to write themselves. At least not every day. We then give an intro to Scala’s XML support followed by the programming task of the day. We set 3 hours for the task. The day ends with information on where to go next, with pointers to some good resources on learning more Scala.

2.1 – recap from day one.odp

This is a really short wrap up of most of the topics of day one. This is meant to get the participants back into the topic matter quickly. This part should not take more than 10 minutes.

2.2 – higherorderfunctions.odp

Defines higher order functions and how they are used. Also discusses ‘call by name’ vs ‘call by value’. We chose to show the ‘using’ example for closing resources, shown by Martin Odersky several times, for instance at Fosdem. This also introduced structural types. We also felt it was important to explain that structural types are not thread safe and use reflection, which may lead to unexpected behavior. However they can be extremely powerful when used appropriately.

This section should not take more than 15 minutes.

2.3 – implicits.odp

Shows how implicit conversions work and how to define them. This is mainly to explain of the “built in” library implicit conversions. In particular all rich types and implicits which are always available through the scala.Predef object.

We also explained all the rules regarding implicit conversions. It is important to understand that there are strict rules regarding the use of them. We also made the point that they should be used with care.

2.4 – XML.odp

A short introduction to the XML support in Scala. This is mainly meant to help along the participant for the programming task of the evening.

2.5 – The quiz game.odp

A short intro to the exercise and demo of what the participant should create. Both shows the console game and the Swing game in action. Show part of the code, for instance the model classes. Also show that the provided Mock quiz which participants may use if they are stuck on XML parsing.

This part should be about 3 hours. When participants start to finish up, it might be an idea to wrap up.

2.6 – summary day 2.odp

Basically tries to point the participants in directions for learning more Scala.

License

The training course is licensed under Creative Commons Attribution 3.0 Unported.

All this means, is that you need to credit Fredrik Vraalsen (fredrik@vraalsen.no) and Alf Kristian Støyle (alf.kristian@gmail.com) of scalaBin for the original work. Apart from that you may do whatever you please with the work.

We hope you find it useful.