GithubHelp home page GithubHelp logo

edwardt / seductionsofscalatutorial Goto Github PK

View Code? Open in Web Editor NEW

This project forked from deanwampler/seductionsofscalatutorial

0.0 3.0 0.0 20.29 MB

An introduction to Scala and what makes it seductive. See also my SeductionsOfScala talk in my Presentations repo.

License: Apache License 2.0

seductionsofscalatutorial's Introduction

The Seductions of Scala Tutorial

Dean Wampler, Concurrent Thought
[email protected]
@deanwampler
Hire Me!

Copyright (c) 2009-2013, Dean Wampler under the Apache License; see the attached LICENSE file.

Introduction

This hands-on tutorial introduces you to the Scala programming language, a modern JVM language that provides a more concise syntax than Java, addresses some of the limitations of the Java object model, and adds full support for Functional Programming.

Setup

PDFs of the tutorial slides and all the exercise source code will be provided in class. You should also clone this GitHub repo in advance.

Either way, you'll need to setup the following tools in advance.

Please do the following installation steps before the tutorial!

Git

You'll need git if you want to clone the tutorial repository. See Getting Started Installing Git for details.

This Tutorial

Once git is installed, clone this tutorial from GitHub. Use your favorite Git GUI or the command line. Using bash:

cd $HOME/fun
git clone git://github.com/deanwampler/SeductionsOfScalaTutorial.git

On Windows:

cd C:\fun
git clone git://github.com/deanwampler/SeductionsOfScalaTutorial.git

Scala 2.10

At the time of this writing, version 2.10 is the latest available version of Scala. Even if you have 2.9.X, we'll discuss some features new to 2.10, so I recommend installing it. I'll indicate what features are new. However, most of the material works for 2.9.X.

Go to to the Scala download page and download the 2.10 installer for your platform. Also, download the API archive that appears in the same list of download links.

NOTE
Be sure to grab the installer for version 2.10 of Scala. However, most of the tutorial will apply to the current production release, 2.9.X.

Install Scala somewhere convenient. We'll use $SCALA_HOME to refer to this location. Be sure to add $SCALA_HOME/bin to your PATH.

SBT

We will use the de-facto build tool for Scala, sbt, for some exercises and examples. See the sbt website for installation instructions. Actually, what you install is a driver Java programm. The actual version of sbt used will be bootstrapped for the project...

A Programmer's Editor or IDE

You can use any editor you want, preferably one that supports Scala syntax highlighting. Most do these days, but you may need to install a Scala plugin for your favorite editor.

If you like using Eclipse, consider installing the Scala IDE. Be careful to pick to the version of the IDE for your version of Scala (e.g., 2.10) and the version of Eclipse you have (e.g., Indigo). IntelliJ IDEA also has good support for Scala. However, we won't need IDE features for the tutorial exercises.

Sanity Check

Once Scala is installed, try running the REPL (Read, Eval, Print, Loop) to make sure everything is working. The commands you type outside the REPL (e.g., at the bash shell for Linux and Mac OS X) are shown with the $ prompt. The scala prompt is scala>. Everything else is output. Your version details my differ slightly.

$ scala
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'.          **
** scala.tools.nsc._ has been imported      **
** global._, definitions._ also imported    **
** Try  :help, :vals, power.<tab>           **

scala> :help
All commands can be abbreviated, e.g. :he instead of :help.
Those marked with a * have more detailed help, e.g. :help imports.

:cp <path>                 add a jar or directory to the classpath
:help [command]            print this summary or command-specific help
:history [num]             show the history (optional num is commands to show)
:h? <string>               search the history
:imports [name name ...]   show import history, identifying sources of names
:implicits [-v]            show the implicits in scope
:javap <path|class>        disassemble a file or class name
:load <path>               load and interpret a Scala file
:paste                     enter paste mode: all input up to ctrl-D compiled together
:power                     enable power user mode
:quit                      exit the interpreter
:replay                    reset execution and replay all previous commands
:reset                     reset the repl to its initial state, forgetting all session entries
:sh <command line>         run a shell command (result is implicitly => List[String])
:silent                    disable/enable automatic printing of results
:type [-v] <expr>          display the type of an expression without evaluating it
:warnings                  show the suppressed warnings from the most recent line which had any
:phase <phase>             set the implicit phase for power commands

scala> ^D

I used control-d (^D) to exit. It's an old terminal control, similar to ^C, that means "end of input". It's more "polite" than ^C...

The REPL commands that begin with a colon (:) are used for non-code directives, like turning on the useful "power" mode, viewing help, loading source files, etc.

Open the API in your browser.

It's convenient to open the API documentation you downloaded in a browser. The Scaladocs are analogous to Javadocs. See also the [References][References] below.

That's It!

You're ready to go.

I welcome feedback on the tutorial. See my contact information at the beginning of this file.

References [References]

General Scala Resources

scala-lang.org : The main website for Scala.

Typesafe : The official developer of Scala and other components that are part of the Typesafe stack.

docs.scala-lang.org : Lots of documentation for Scala, including the Scaladocs tutorials, the Scala Improvement Process (SIP) proposals (for new features), etc.

akka.io : The website for the Akka distributed computing library that's part of the Typesafe stack.

Play Framework : One of many web frameworks for Scala, this one is an official part of the Typesafe stack.

Programming Scala : The book I co-wrote with Alex Payne. It's a bit dated, to be honest, but we have plans to update it soon. Links for other books can be found at scala-lang.org.

What's New in Scala Version 2.10?

Here are two nice lists of the new features with links to more details:

Specifically on Macros

Macros provide a hygienic macro facility, somewhat like Lisp and not like C or C++. It's one of the most significant new features that promises to revolutionalize API and DSL development. It's an evolving feature. The principle documentation is available here:

The following projects are using Macros. The first three are referenced on this scalamacros.org "getting started" page:

Slick

Slick is a type-safe, data-access API inspired by .NET's LINQ.

Working Through the Tutorial

The slides are too long ;) So, we'll skip through them, allowing us to spend most of our time on the actual exercises. The following sections list the slides we'll actually look at in class. You might look at the skipped slides later for more background information.

SeductionsOfScala.pdf

Note that the solutions for the exercises are in the tutorial-exercises/solutions folder. Also, we do the first few together as a class, then you'll work on your own.

Slides Description Exercise
Slides 14-26 Succinct code 1
Slides 27-34 Case classes 2
Slides 35-61 Objects as functions, implicits, etc. 3*
Slides 78-86, 91 Recursion 4, 5 (on slide 107) for extra credit
Slides 109-117 Option type -
Slides 121-122, 127-131 For comprehensions 6
Slides 135-142 Traits ("mixins") -
Slides 184-214 Companion object, pattern matching 8 (optional)
  • We'll discuss the solution to Exercise 3, but not work through it (for time's sake).

That is, we'll cover about half the slides ;)

SeductionsOfScala-Applications.pdf

This section discusses two important applications of Scala.

  1. The Akka Actor model for concurrency.
  2. Scalding, a DSL for Hadoop.

We'll just discuss Akka today.

Slides Description Exercise
Slides 4-22 Akka and an example drawing-actors

The drawing-actors exercise is in its own directory. See tutorial-exercises/drawing-actors/README.html for details. It also demonstrates the use of sbt, the de-facto build tool for Scala and one of several test frameworks, ScalaTest.

seductionsofscalatutorial's People

Contributors

chicagoscala avatar

Watchers

edwardt avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.