Scala
Upcoming SlideShare
Loading in...5
×
 

Scala

on

  • 1,101 views

Scala presentation at Sourcesense company meeting held in Amsterdam in October/2009

Scala presentation at Sourcesense company meeting held in Amsterdam in October/2009

Statistics

Views

Total Views
1,101
Views on SlideShare
1,094
Embed Views
7

Actions

Likes
1
Downloads
23
Comments
0

2 Embeds 7

http://www.slideshare.net 4
http://www.linkedin.com 3

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Scala Scala Presentation Transcript

  • Scala Supersonic Tour Gustavo Fernandes
  • What is Scala? • A JVM programming language • Open Source (BSD-like license) • Functional + OO multiparadigm • Created by Martin Odersky at University of Lausanne in 2003
  • Why care? • Run on JVM • Statically typed • Concise and powerfull • Seamless integration/drop in replacement for Java • Grow with you
  • Features – Native XML • Declaring var axml = <root><child1>value</child1></root> • Reading var childValue = axml  "child1".text • Reading from file var desc = scala.xml.XML.loadFile("web.xml")  "description" text • Producing var currentMillis = <now>{System.currentTimeMillis}</now>
  • Features – Conciseness public class Beer { public String name; public int price; public Beer(String name, int price) { this.name = name; this.price = price; } @Override public String toString() { return "Beer(" + name + "," + price + ")"; } @Override JAVA public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Beer other = (Beer) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } }
  • Features – Conciseness (Cont.) SCALA case class Beer(name: String, price: Int)
  • Features – Actors • Powerfull abstration for Multithreading programming • No synchronization blocks and complex libraries • Simple to use • Implements Erlang actor model
  • Features – Actors (cont.) Declaring class BusyActor extends  Actor {     def  doSomeLengthyCalculation() = print("Look ma! No syncronization!")      def act() {         react {             case _ => doSomeLengthyCalculation()         }     } } Using val actor = new BusyActor() actor.start actor !? "A message"           // Send a synchronous message actor !? (300, "My message")   // Send a synchronous message with timeout  actor ! “A message”            // Asynchronous
  • Features – Collections • Rich collection library • Immutable by default • High performance and concise
  • Features – Collections (Cont.) Creating val map = Map("key1"­>”value1”, "key2"­>”value2”) val seq = 1 to 10 val list = List(1,2,3,4)
  • Features – Collections (Cont.) Filtering val pairs = list.filter(x => x%2==0)   val pairs = list.filter(_%2==0)
  • Features – Collections (Cont.) Looping var list = List(1,2,3,4,5) list.foreach( x => print(x+" ") ) 12345
  • Features – Collections (Cont.) Reducing val sum = list.foldLeft(0) ( (x:Int,y:Int) => x+y ) val sum = list.foldLeft(0) (_+_) Creating, Filtering and Reducing val res = (0/:(1 to 10).filter(_%2==0))(_+_)
  • Features - Traits • Interfaces with fields and methods implementation • Add behaviour to a class without messing with the hierarchy • Can be applied in runtime
  • Features – Traits (Cont.) trait ReflectionStats { def getNumberOfMethods() = this.getClass.getMethods.length } val myList = new java.util.ArrayList with ReflectionStats print( myList.getNumberOfMethods() )
  • There's more... • Easy to create Domain Specific Languages (DSL) • Pattern matching • Annotations • Generics
  • Tooling • Eclipse Plugin • Netbeans Plugin (Better)
  • Tooling - Maven Project Archetype mvn archetype:create -DarchetypeGroupId=org.scala-tools.archetypes -DarchetypeArtifactId=scala-archetype-simple -DarchetypeVersion=1.2 -DremoteRepositories=http://scala-tools.org/repo-releases -DgroupId=com.mycompany.scala -DartifactId=scalaTest <plugin> <groupId>org.scala-tools</groupId> <artifactId>maven-scala-plugin</artifactId> <executions> <execution> <id>compile</id> <goals> <goal>compile</goal> </goals> <phase>compile</phase> </execution </executions> </plugin>
  • Thank you Gustavo Fernandes g.fernandes@sourcesense.com