Scala
Core Concepts & Features
-
Immutable
-
Functions as 1. class citizens
- Object Oriented & Functional
- Concurrent by Design
- Less Boilerplate Code
- JVM Language
Start Small
Scala vs. Java
Syntax Comparison
Variables
Java - mutable by default
Scala -
Immutable by default
String foo = "foo";
final String foo = "foo";
val foo = "foo"
var foo = "foo"
Functions
Java
public String foo() {
return "foo";
}
Scala - less is more (readable)
def foo(): String = {
"foo"
}
def foo(): String = "foo"
def foo() = "foo"
def foo = "foo"
Classes
Java
public class Foo {
private final String bar;
public Foo() {
this("empty");
}
public Foo(String bar) {
this.bar = bar;
}
public String getBar() {
return bar;
}
}
Scala - less is more (readable)
class Foo(bar: String = "empty")
Traits vs. Interfaces
Java (7)
interface Foo {
public void bar();
}
Scala
trait Foo {
def bar()
}
object vs static
Java - static keyword
class Foo() {
public String static bar() {
return "bar";
}
}
Scala - object keyword
object Foo {
def bar() = "bar"
}
SBT
- Maven für Scala
- Interaktiv
- Jeder startet als Hater
build.sbt
name := "tdd-katas"
version := "1.0-SNAPSHOT"
scalaVersion := "2.10.4"
global Plugins
~/.sbt/0.13/plugins/plugins.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.2.0")
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
~/.sbt/0.13/global.sbt
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
resolvers += "IA Nexus" at "http://buildsystem-ana.rz1.intelliad.com:8081/nexus/content/groups/public/"
Links & Readmes
K a t a
String Calculator
Scala
By Nepomuk Seiler
Scala
- 1,361