Welcome to Scala Hack Session. What is the best way to start a new language?
- Code immediately following this step-by-step sessions
- Read further materials and resources provided by each sessions
The following hack sessions are available:
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.
What about...
- Start hacking immediately and
- 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.
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).
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:
- First Steps: Expressions, val and var variables, and Scala classes.
- Control Structures: While loops, for expressions, and pattern matching.
- Functions: definition, high-order functions and currying.
- 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.
Here is a list of great Scala materials:
- 12 Free eBooks: eBooks about Scala, Play, Lift, Testing, Cookbooks, etc.
- Scala Tour: an introduction
- Scala Cheatsheet
- Programming in Scala (1st Edition): The latest 2nd Edition can be purchased but the first Edition with about 700 pages provides enough details
- Scala by Example: training materials
- Stack Overflow: Scala topics with lots of code snippets
- Scala School: since Twitter is developed with Scala they created a Scala tutorial
- Scala for the Impatient: a book for Java, C++, and C# developers, first part is free and online
- Online Interpreter: A Scala worksheet in your browser