This is a short introduction to the Scala programming language and its ecosystem, giving some background about how the language came to be and a quick taste of what it looks like. It also shortly introduces a few tools and technologies related to it
had shown me the Programming Scala book by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I’d probably have never created Groovy. James Strachan Creator of Groovy http://macstrac.blogspot.co.at/2009/04/scala-as-long-term-replacement-for.html Dienstag, 03. Dezember 13
User.findOneByName("bob") // returns Some[User] maybeUser == None // false maybeUser.foreach { user => println(user.fullName) // prints "Bob Marley" if there is a user! } val name = maybeUser.map(_.name).getOrElse("Unknown user") Dienstag, 03. Dezember 13
var email: String) val bob = new User("Bob", "Marley", "[email protected]") // bob: User = User@5c3f1224 bob.name // res0: String = Bob bob.name = "Bobby" // bob.name: String = Bobby Dienstag, 03. Dezember 13
String) val bob = ImmutableUser("Bob", "Marley", "[email protected]") // hashcode and equals for free! val namedBob = ImmutableUser(name = "Bob", surname = "Marley", email = "email") val bobby = bob.copy(name = "Bobby") // returns a User with name Bobby bob.toString // res0: String = ImmutableUser(Bob,Marley,email) Dienstag, 03. Dezember 13
extends FlatSpec with Matchers { "A Stack" should "pop values in last-in-first-out order" in { val stack = new Stack[Int] stack.push(1) stack.push(2) stack.pop() should be (2) stack.pop() should be (1) } it should "throw NoSuchElementException if an empty stack is popped" in { val emptyStack = new Stack[Int] a [NoSuchElementException] should be thrownBy { emptyStack.pop() } } } Dienstag, 03. Dezember 13
extends FlatSpec with Matchers { "A Stack" should "pop values in last-in-first-out order" in { val stack = new Stack[Int] stack.push(1) stack.push(2) stack.pop() should be (2) stack.pop() should be (1) } it should "throw NoSuchElementException if an empty stack is popped" in { val emptyStack = new Stack[Int] a [NoSuchElementException] should be thrownBy { emptyStack.pop() } } } Dienstag, 03. Dezember 13
• “Human” design: actors talk to eachother and form hierarchies • Much, much, much simpler to work and reason with than threads Dienstag, 03. Dezember 13