Skip to content

point-software-ag/scala-hack-session

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 

Repository files navigation

Scala Hack Session

Welcome to Scala Hack Session. What is the best way to start a new language?

  1. Code immediately following this step-by-step sessions
  2. Read further materials and resources provided by each sessions

ToC - Scala Hack Sessions

The following hack sessions are available:

  1. Scala Principles

Social Coding

Feedback, additional exercises, and alternative solutions from you are appeciated. In case you have alternate solutions you are free to pull a request to my GitHub repository.

Is there a good way to start a new language?

What about...

  1. Start hacking immediately and
  2. Read further materials in the meanwhile?

One advantage of Scala is its interactive interpreter. Like in a worksheet file: you can enter code and get immediate output. This way gets you quickly into Scala. Another goal is to encourage you to dive deeper.

Please walk through this blog to install your Scala IDE and import the hack session project.

Abstract

Under the assumption you have coding skills in another object-oriented language I will cover 4 basic topics in the Scala Hack Session.

First, you start with (readme) simple arithmetic operations, constant/final and assignable variables, and finally how to define Scala classes. You will finish the first session with an exercise (readme) learning about singleton objects and writing a calculator.

Second (readme), you will get familiar with while loops, for expressions, and pattern matching.

Third (readme), we will finally jump into Functions. You start with function definitions, naming conventions and unnamed literals, and why Scala treats functions as first class citizens.

Fourth and finally (readme), you learn to work with the most used collection type: Lists. I recommend you to to get familiar with this in detail. You learn the basisc operations like accessing the head and tail elements. Another common task is using pattern matching on lists. In the second part of the hack session you learn higher-order methods like map allowing you to convert a List of Type A into another List of Type B (by passing another function as an input parameter List.map(f:A => B)) and foreach allowing you to operate on each element (without returning another list).

How are the sessions organized?

Each session covers a topic and contains several exercises. Instructions and further explanations are described in the code as comments in two ways:

In this example of the first session it demonstrates the 'print line' function first, then it encourages you writing in the next line a println for 'Hello, World'. Here, it describes a [syntax] (01-principles/day-01/src/main/scala/day01session01/first_steps/FirstSteps02Variables.sc#L25:L33) where you should replace the '???' with a value for the message variable.

Each session contains further materials I have gathered through my work with Scala. I have summed them up on GitHub. In the future you may find more hack sessions around Scala here.

In the next upcoming parts of this blog series you can read more about these sessions:

  1. First Steps: Expressions, val and var variables, and Scala classes.
  2. Control Structures: While loops, for expressions, and pattern matching.
  3. Functions: definition, high-order functions and currying.
  4. Lists: basic operations, pattern matching on lists, and high-order methods.

Ok, let's get ready. Instead of reading further you can also stop here and start hacking yourself through the sessions. In case you get stuck you can come back, read the wiki for more details, or compare your result with the provided solutions. You can find them in the solution sub packages in every session. Like here.

#Next: First Steps In the first session I will discuss the first worksheet with you. You will learn that arithmetic operations are represented by methods, the usage of semicolons, parenthesis, and braces, about variable scopes, and the difference between a class and case class. In addition you will also learn about implicit conversion - a powerful Scala feature allowing for example to extend existing classes like String or define your own domain specific language DSL or adding other languages into Scala like Basic.

Resources

Here is a list of great Scala materials: