Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scala

 Scala

Scripps Networks Techtoberfest

Avatar for christinejones

christinejones

October 11, 2012
Tweet

More Decks by christinejones

Other Decks in Technology

Transcript

  1. History of Scala  Created by Martin Odersky  Intended

    to blend Functional and Object- Oriented paradigms  Influenced by Haskell and ML  Current Version: 2.9.1 (released August 2011)  http://www.scala-lang.org/
  2. Why should we care about Scala?  JVM Language 

    Also runs on Android smartphones  Shorter code  Scalability  Integration with XML  Growing use  Twitter, FourSquare, LinkedIn  http://www.scala-lang.org/node/1658 for more examples
  3. How is Scala Different from Java? • Mixins & traits

    • Operator overloading • Tuples • First-class functions & closures
  4. Code Java: class Person { private String firstName; private String

    lastName; private int age; public Person(String firstName, String lastName, int age) { this.firstName = firstName; this.lastName = lastName; this.age = age; } } Scala: class Person(var firstName: String, var lastName: String, var age: Int) • Source: http://blog.objectmentor.com/articles/2008/08/03/the-seductions-of-scala-part-i
  5. Mixins & Traits  Mixin – class that provides functionality

    to be inherited/reused  Traits can be used to create a mixin class  Similar to interfaces  Interfaces only specify what must be supported, NOT the implementation
  6. Trait trait Similarity { def isSimilar(x: Any): Boolean def isNotSimilar(x:

    Any): Boolean = !isSimilar(x) } Mixin class Point(xc: Int, yc: Int) extends Similarity { var x: Int = xc var y: Int = yc def isSimilar(obj: Any) = obj.isInstanceOf[Point] && obj.asInstanceOf[Point].x == x } object TraitsTest extends Application { val p1 = new Point(2, 3) val p2 = new Point(2, 4) val p3 = new Point(3, 3) println(p1.isNotSimilar(p2)) println(p1.isNotSimilar(p3)) println(p1.isNotSimilar(2)) }
  7. Closures  First implemented in Scheme in 1975  Function

    + referencing environment for non-local variables  Supported in Scala, but not Java  Similar to anonymous inner classes
  8. Lift Framework • High-performance, scalable • Open Source web application

    framework • Similar to Ruby on Rails • FourSquare moved to Scala/Lift in 2009 • http://liftweb.net
  9. Resources  http://www.ibm.com/developerworks/views/java/libraryview.jsp?search_by=scala +neward  http://www.ibm.com/developerworks/library/x-scalaxml/  http://www.geekontheloose.com/wp- content/uploads/2010/02/Scala_Cheatsheet.pdf 

    http://www.codecommit.com/blog/scala/working-with-scalas-xml-support  http://blog.objectmentor.com/articles/2008/08/14/the-seductions-of-scala-part- iii-concurrent-programming