SlideShare a Scribd company logo
Getting Started with Scala

  Vikas Hazrati - vhazrati@xebia.com

  Meetu Maltiar - mmaltiar@xebia.com

         OSScamp Delhi 2009
Agenda
I. What is FP and OOP?          I. Features
                                    – Quick comparison
                                      with Java
I. Introducing Scala                – Function Values and
                                      Closures
    – Scalable Languages
                                    – Traits
    – Scala is a Scripting
      language                      – Pattern Matching
    – Scala is Java of future   I. End Notes
    – Scala is OO               - Who is using it ?
    – Scala is Interoperable    - Tool support
                                - Learning resources
I. What is FP and OOP?
What is FP
Is a concept where you can pass functions as
  arguments, to store them in variables, and to
  return them from other functions.
What is OOP?
Object Oriented Programming is
 programming which is oriented
 around objects

Takes advantage of Encapsulation,
 Polymorphism, and Inheritance to
 increase code reuse and decrease
 code maintenance.
Scala: FP and OOP language
Scala is a object oriented and functional programming
  language which is completely interoperable with java

FP: Makes it easy to build interesting things from simple parts, using
    – Higher order functions
    – Algebraic types and pattern matching
    – Parametric polymorphism
OOP: Makes it easy to adopt and extend complex systems using
    – Subtyping and inheritance
    – Dynamic configurations
    – Classes as partial abstractions
II. Introducing Scala
Scalable languages

A language is scalable if it is suitable for very small as well as
   very large programs.

A single language for extension scripts and the heavy lifting.

Application-specific needs are handled through libraries and
  embedded DSL's instead of external languages.

Scala shows that this is possible.




                                                                     8
Scala is a scripting language
It has an interactive read-eval-print-loop (REPL).
Types can be inferred.
Boilerplate is scrapped.
scala> var capital = Map("US" → "Washington", "France" → "Paris")
capital: Map[String, String] = Map(US → Washington, France →
Paris)
scala> capital += ("Japan" → "Tokyo")
scala> capital("France")
res7: String = Paris




                                                                    9
Scala is the Java of the future
It has basically everything Java has now.
    (sometimes in different form)
It has closures.
    (proposed for Java 7, but rejected)
It has traits and pattern matching.
    (do not be surprised to see them in Java 8, 9 or 10)
It compiles to .class files, is completely interoperable and runs about as fast as
    Java


          object App {
            def main(args: Array[String]) {
              if (args exists (_.toLowerCase == "-help"))
                printUsage()
              else
                process(args)
            }
          }



                                                                                 10
Scala is object-oriented

Every value is an object
Every operation is a method call
Exceptions to these rules in Java (such as
 primitive types, statics) are eliminated.
    scala> (1).hashCode
    res8: Int = 1
    scala> (1).+(2)
    res10: Int = 3




                                             11
Interoperability

Scala fits seamlessly into a Java environment
Can call Java methods, select Java fields, inherit Java
  classes, implement Java interfaces, etc.
None of this requires glue code or interface descriptions
Java code can also easily call into Scala code
Scala code resembling Java is translated into virtually
  the same bytecodes.
  ⇒ Performance is usually on a par with Java




                                                       12
III. Scala Features




                      13
Scala compared to Java

Scala adds                 Scala removes
+ a pure object system     - static members
+ operator overloading     - primitive types
+ closures                 - break, continue
+ mixin composition with   - special treatment of
traits                     interfaces
+ existential types        - wildcards
+ abstract types           -   raw types
+ pattern matching         -   enums




                                                    14
Scala cheat sheet (1): Definitions

Scala method definitions:     Java method definition:

def fun(x: Int): Int = {         int fun(int x) {
     result                        return result
   }                             }

def fun = result              (no parameterless methods)

Scala variable definitions:   Java variable definitions:

var x: Int = expression          int x = expression
val x: String = expression    final String x = expression




                                                            15
Scala cheat sheet (2): Objects and
             Classes
Scala Class and Object                Java Class with statics

                                        class Sample {
   class Sample(x: Int, val p: Int)
   {                                    private final int x;
      def instMeth(y: Int) = x + y      public final int p;
   }                                    Sample(int x, int p) {
                                             this.x = x;
                                             this.p = p;
   object Sample {
                                        }
     def staticMeth(x: Int, y: Int)        int instMeth(int y) {
   =                                          return x + y;
       x*y                                 }
   }                                       static int staticMeth(int x,
                                        int y) {
                                              return x * y;
                                           }
                                        }




                                                                          16
Scala cheat sheet (3): Traits
Scala Trait                           Java Interface

    trait T {                         interface T {
    def abstractMth(x: String): Int         int abstractMth(String x)
    def concreteMth(x: String) =         }
      x + field
                                      (no concrete methods)
    var field = “!”
                                      (no fields)
}

                                      Java extension + implementation:
Scala mixin composition:
                                         class C extends Super
    class C extends Super with T         implements T




                                                                         17
Scala Compared to Java

 class CreditCard(val number: Int, var creditLimit: Int)


                 javap -private CreditCard

public class CreditCard extends java.lang.Object implements
scala.ScalaObject{
  private int creditLimit;
  private final int number;
  public CreditCard(int, int);
  public void creditLimit_$eq(int);
  public int creditLimit();
  public int number();
  public int $tag()      throws java.rmi.RemoteException;
}
                                                              18
Constructors
class Person(val firstName: String, val lastName: String) {
  private var position: String = _
  println("Creating " + toString())
  def this (firstName: String, lastName: String, positionHeld: String) {
    this (firstName, lastName)
    position = positionHeld
  }
  override def toString() : String = {
    firstName + " " + lastName + " holds " + position + " position "
  }
}




                                                                    19
Statics in Scala




                   20
Higher Order Functions




                         21
Currying & Partial Functions
Currying in Scala transforms a function that takes more than one
parameter into a function that takes multiple parameter lists.




                                                                   22
Closures

You can create code blocks with variables that are not bound.

You will have to bind them before you can invoke the function; however,
they could bind to, or close over, variables outside of their local scope
and parameter list.

That’s why they’re called closures.




                                                                    23
Closures




           24
Traits
They are fundamental unit for code reuse in Scala


A Trait encapsulates method and field definitions, which can be
   reused by mixing them in classes


Unlike class inheritance , in which class must inherit from just one
  superclass, a class may mix in any number of Traits


Unlike Interfaces they can have concrete methods




                                                                       25
Traits
trait Philosophical {
  def philosophize() {
    println("I consume memory, therefore I am!")
 }
}


class Frog extends Philosophical {
override def toString() = "green"
}


val latestFrog = new Frog
println("" + latestFrog)
latestFrog.philosophize()
val phil:Philosophical = latestFrog
phil.philosophize()




                                                   26
Pattern Matching

All that is required is to add a single case
  keyword to each class that is to be pattern
  matchable

Similar to switch expect that Scala compares
  Objects as expressions




                                                27
Pattern Matching
object PatternApplication {
 def main(args : Array[String]) : Unit = {
    println( simplifyTop(UnOperator("-", UnOperator("-", Variable("x")))))
    println( simplifyTop(BinOperator("+", Variable("x"), NumberOperator(0))))
    println( simplifyTop(BinOperator("*", Variable("x"), NumberOperator(1))))
 }


 def simplifyTop(expr: Expression): Expression = expr match {
 case UnOperator("-", UnOperator("-", e)) => e          // Double negation
 case BinOperator("+", e, NumberOperator(0)) => e // Adding zero
 case BinOperator("*", e, NumberOperator(1)) => e // Multiplying by one
 case _ => expr
}
}

                                                                                28
IV. End Notes




                29
Tool support
  – Standalone compiler: scalac
  – Fast background compiler: fsc
  – Interactive interpreter shell and script runner: scala
  – Web framework: lift
  – Testing frameworks:
     Specs, ScalaCheck, ScalaTest, SUnit, …
IDE plugins for:
  – Eclipse (supported by EDF)
  – IntelliJ (supported by JetBrains)
  – Netbeans (supported by Sun)



                                                             30
Who’s using it?
Open source projects:
  lift
  wicket
  NetLogo
  SPDE: Scala branch for Processing
  Isabelle: GUI and code extractor


Companies:
  Twitter: infrastructure
  Sony Pictures: middleware
  Nature.com: infrastructure
  SAP community: ESME company messaging
  Reaktor: many different projects
  Mimesis Republic: multiplayer games
  EDF: trading, …



                                          31
Learning Scala
To get started:
First steps in Scala, by Bill Venners
   published in Scalazine at www.artima.com

Scala for Java Refugees by Daniel Spiewack
   (great blog series)

To continue:
Programming in Scala, by Odersky, Spoon,
   Venners, published by Artima,com

Other books are in the pipeline.




                                              32
33
Contact Us
Vikas Hazrati - vhazrati@xebia.com

Meetu Maltiar - mmaltiar@xebia.com




      www.xebiaindia.com
         www.xebia.com
       http://blog.xebia.in
      http://blog.xebia.com


                                     34
References
“Programming in Scala” book by Martin Odersky, Lex Spoon and Bill Venners


Presentation by Martin Odersky at FOSDEM 2009
http://www.slideshare.net/Odersky/fosdem-2009-1013261



Online book on Scala by oreilly
http://programming-scala.labs.oreilly.com/



Magazine for Scala Programming Community
http://www.artima.com/scalazine




                                                                            35

More Related Content

What's hot (16)

Google06
Google06Google06
Google06
Zhiwen Guo
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
Razvan Cojocaru
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
Derek Chen-Becker
 
Scala
ScalaScala
Scala
Zhiwen Guo
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
Martin Odersky
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simple
Martin Odersky
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Brian Hsu
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
3Pillar Global
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Sanjeev_Knoldus
 
Virtual Separation of Concerns
Virtual Separation of ConcernsVirtual Separation of Concerns
Virtual Separation of Concerns
chk49
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
Scala google
Scala google Scala google
Scala google
Navneet Kumar
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
Derek Chen-Becker
 
Scala eXchange opening
Scala eXchange openingScala eXchange opening
Scala eXchange opening
Martin Odersky
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
Jonas Bonér
 
Oscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simpleOscon keynote: Working hard to keep it simple
Oscon keynote: Working hard to keep it simple
Martin Odersky
 
Miles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java DevelopersMiles Sabin Introduction To Scala For Java Developers
Miles Sabin Introduction To Scala For Java Developers
Skills Matter
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Brian Hsu
 
Scala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian DragosScala: Object-Oriented Meets Functional, by Iulian Dragos
Scala: Object-Oriented Meets Functional, by Iulian Dragos
3Pillar Global
 
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Scala traits training by Sanjeev Kumar @Kick Start Scala traits & Play, organ...
Sanjeev_Knoldus
 
Virtual Separation of Concerns
Virtual Separation of ConcernsVirtual Separation of Concerns
Virtual Separation of Concerns
chk49
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
Isaias Barroso
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 

Similar to Getting Started With Scala (20)

Introducing scala
Introducing scalaIntroducing scala
Introducing scala
Meetu Maltiar
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
Knoldus Inc.
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
Mohsen Zainalpour
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
Mohammad Hossein Rimaz
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
Tomasz Wrobel
 
All about scala
All about scalaAll about scala
All about scala
Yardena Meymann
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
league
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
Meetu Maltiar
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
Yardena Meymann
 
2014 holden - databricks umd scala crash course
2014   holden - databricks umd scala crash course2014   holden - databricks umd scala crash course
2014 holden - databricks umd scala crash course
Holden Karau
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Matthew Farwell
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
Alf Kristian Støyle
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
Brian Topping
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
Martin Odersky
 
Scala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud FoundryScala, Play 2.0 & Cloud Foundry
Scala, Play 2.0 & Cloud Foundry
Pray Desai
 
A Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java DevelopersA Brief Introduction to Scala for Java Developers
A Brief Introduction to Scala for Java Developers
Miles Sabin
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java DevelopersBCS SPA 2010 - An Introduction to Scala for Java Developers
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
Tomasz Wrobel
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
league
 
Getting Started With Scala
Getting Started With ScalaGetting Started With Scala
Getting Started With Scala
Meetu Maltiar
 
An Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional ParadigmsAn Introduction to Scala - Blending OO and Functional Paradigms
An Introduction to Scala - Blending OO and Functional Paradigms
Miles Sabin
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
Yardena Meymann
 
2014 holden - databricks umd scala crash course
2014   holden - databricks umd scala crash course2014   holden - databricks umd scala crash course
2014 holden - databricks umd scala crash course
Holden Karau
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Matthew Farwell
 
Software Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with ScalaSoftware Engineering Thailand: Programming with Scala
Software Engineering Thailand: Programming with Scala
Brian Topping
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
Hiroshi Ono
 
Ad

More from Xebia IT Architects (20)

Using Graph Databases For Insights Into Connected Data.
Using Graph Databases For Insights Into Connected Data.Using Graph Databases For Insights Into Connected Data.
Using Graph Databases For Insights Into Connected Data.
Xebia IT Architects
 
Use Cases of #Grails in #WebApplications
Use Cases of #Grails in #WebApplicationsUse Cases of #Grails in #WebApplications
Use Cases of #Grails in #WebApplications
Xebia IT Architects
 
When elephants dance , enterprise goes mobile !
When elephants dance , enterprise goes mobile !When elephants dance , enterprise goes mobile !
When elephants dance , enterprise goes mobile !
Xebia IT Architects
 
DevOps demystified
DevOps demystifiedDevOps demystified
DevOps demystified
Xebia IT Architects
 
Exploiting vulnerabilities in location based commerce
Exploiting vulnerabilities in location based commerceExploiting vulnerabilities in location based commerce
Exploiting vulnerabilities in location based commerce
Xebia IT Architects
 
Modelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST urlModelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST url
Xebia IT Architects
 
Scrumban - benefits of both the worlds
Scrumban - benefits of both the worldsScrumban - benefits of both the worlds
Scrumban - benefits of both the worlds
Xebia IT Architects
 
#Continuous delivery with #Deployit
#Continuous delivery with #Deployit#Continuous delivery with #Deployit
#Continuous delivery with #Deployit
Xebia IT Architects
 
Continuous integration using thucydides(bdd) with selenium
Continuous integration using thucydides(bdd) with seleniumContinuous integration using thucydides(bdd) with selenium
Continuous integration using thucydides(bdd) with selenium
Xebia IT Architects
 
Battlefield agility
Battlefield agilityBattlefield agility
Battlefield agility
Xebia IT Architects
 
Fish!ing for agile teams
Fish!ing for agile teamsFish!ing for agile teams
Fish!ing for agile teams
Xebia IT Architects
 
Xebia-Agile consulting and training offerings
Xebia-Agile consulting and training offeringsXebia-Agile consulting and training offerings
Xebia-Agile consulting and training offerings
Xebia IT Architects
 
Xebia e-Commerce / mCommerce Solutions
Xebia e-Commerce / mCommerce SolutionsXebia e-Commerce / mCommerce Solutions
Xebia e-Commerce / mCommerce Solutions
Xebia IT Architects
 
Growth at Xebia
Growth at XebiaGrowth at Xebia
Growth at Xebia
Xebia IT Architects
 
A warm and prosperous Happy Diwali to all our clients
A warm and prosperous Happy Diwali to all our clientsA warm and prosperous Happy Diwali to all our clients
A warm and prosperous Happy Diwali to all our clients
Xebia IT Architects
 
"We Plan to double our headcount" - MD, Xebia India
"We Plan to double our headcount" - MD, Xebia India"We Plan to double our headcount" - MD, Xebia India
"We Plan to double our headcount" - MD, Xebia India
Xebia IT Architects
 
Agile 2.0 - Our Road to Mastery
Agile 2.0 - Our Road to MasteryAgile 2.0 - Our Road to Mastery
Agile 2.0 - Our Road to Mastery
Xebia IT Architects
 
Agile FAQs by Shrikant Vashishtha
Agile FAQs by Shrikant VashishthaAgile FAQs by Shrikant Vashishtha
Agile FAQs by Shrikant Vashishtha
Xebia IT Architects
 
Agile Team Dynamics by Bhavin Chandulal Javia
Agile Team Dynamics by Bhavin Chandulal JaviaAgile Team Dynamics by Bhavin Chandulal Javia
Agile Team Dynamics by Bhavin Chandulal Javia
Xebia IT Architects
 
Practicing Agile in Offshore Environment by Himanshu Seth & Imran Mir
Practicing Agile in Offshore Environment by Himanshu Seth & Imran MirPracticing Agile in Offshore Environment by Himanshu Seth & Imran Mir
Practicing Agile in Offshore Environment by Himanshu Seth & Imran Mir
Xebia IT Architects
 
Using Graph Databases For Insights Into Connected Data.
Using Graph Databases For Insights Into Connected Data.Using Graph Databases For Insights Into Connected Data.
Using Graph Databases For Insights Into Connected Data.
Xebia IT Architects
 
Use Cases of #Grails in #WebApplications
Use Cases of #Grails in #WebApplicationsUse Cases of #Grails in #WebApplications
Use Cases of #Grails in #WebApplications
Xebia IT Architects
 
When elephants dance , enterprise goes mobile !
When elephants dance , enterprise goes mobile !When elephants dance , enterprise goes mobile !
When elephants dance , enterprise goes mobile !
Xebia IT Architects
 
Exploiting vulnerabilities in location based commerce
Exploiting vulnerabilities in location based commerceExploiting vulnerabilities in location based commerce
Exploiting vulnerabilities in location based commerce
Xebia IT Architects
 
Modelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST urlModelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST url
Xebia IT Architects
 
Scrumban - benefits of both the worlds
Scrumban - benefits of both the worldsScrumban - benefits of both the worlds
Scrumban - benefits of both the worlds
Xebia IT Architects
 
#Continuous delivery with #Deployit
#Continuous delivery with #Deployit#Continuous delivery with #Deployit
#Continuous delivery with #Deployit
Xebia IT Architects
 
Continuous integration using thucydides(bdd) with selenium
Continuous integration using thucydides(bdd) with seleniumContinuous integration using thucydides(bdd) with selenium
Continuous integration using thucydides(bdd) with selenium
Xebia IT Architects
 
Xebia-Agile consulting and training offerings
Xebia-Agile consulting and training offeringsXebia-Agile consulting and training offerings
Xebia-Agile consulting and training offerings
Xebia IT Architects
 
Xebia e-Commerce / mCommerce Solutions
Xebia e-Commerce / mCommerce SolutionsXebia e-Commerce / mCommerce Solutions
Xebia e-Commerce / mCommerce Solutions
Xebia IT Architects
 
A warm and prosperous Happy Diwali to all our clients
A warm and prosperous Happy Diwali to all our clientsA warm and prosperous Happy Diwali to all our clients
A warm and prosperous Happy Diwali to all our clients
Xebia IT Architects
 
"We Plan to double our headcount" - MD, Xebia India
"We Plan to double our headcount" - MD, Xebia India"We Plan to double our headcount" - MD, Xebia India
"We Plan to double our headcount" - MD, Xebia India
Xebia IT Architects
 
Agile FAQs by Shrikant Vashishtha
Agile FAQs by Shrikant VashishthaAgile FAQs by Shrikant Vashishtha
Agile FAQs by Shrikant Vashishtha
Xebia IT Architects
 
Agile Team Dynamics by Bhavin Chandulal Javia
Agile Team Dynamics by Bhavin Chandulal JaviaAgile Team Dynamics by Bhavin Chandulal Javia
Agile Team Dynamics by Bhavin Chandulal Javia
Xebia IT Architects
 
Practicing Agile in Offshore Environment by Himanshu Seth & Imran Mir
Practicing Agile in Offshore Environment by Himanshu Seth & Imran MirPracticing Agile in Offshore Environment by Himanshu Seth & Imran Mir
Practicing Agile in Offshore Environment by Himanshu Seth & Imran Mir
Xebia IT Architects
 
Ad

Recently uploaded (20)

TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Soulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate reviewSoulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate review
Soulmaite
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
DevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical PodcastDevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical Podcast
Chris Wahl
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | BluebashMCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
MCP vs A2A vs ACP: Choosing the Right Protocol | Bluebash
Bluebash
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Soulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate reviewSoulmaite review - Find Real AI soulmate review
Soulmaite review - Find Real AI soulmate review
Soulmaite
 
Oracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI ProfessionalOracle Cloud Infrastructure Generative AI Professional
Oracle Cloud Infrastructure Generative AI Professional
VICTOR MAESTRE RAMIREZ
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Domino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use CasesDomino IQ – What to Expect, First Steps and Use Cases
Domino IQ – What to Expect, First Steps and Use Cases
panagenda
 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
 
DevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical PodcastDevOps in the Modern Era - Thoughtfully Critical Podcast
DevOps in the Modern Era - Thoughtfully Critical Podcast
Chris Wahl
 
FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0FCF- Getting Started in Cybersecurity 3.0
FCF- Getting Started in Cybersecurity 3.0
RodrigoMori7
 

Getting Started With Scala

  • 1. Getting Started with Scala Vikas Hazrati - [email protected] Meetu Maltiar - [email protected] OSScamp Delhi 2009
  • 2. Agenda I. What is FP and OOP? I. Features – Quick comparison with Java I. Introducing Scala – Function Values and Closures – Scalable Languages – Traits – Scala is a Scripting language – Pattern Matching – Scala is Java of future I. End Notes – Scala is OO - Who is using it ? – Scala is Interoperable - Tool support - Learning resources
  • 3. I. What is FP and OOP?
  • 4. What is FP Is a concept where you can pass functions as arguments, to store them in variables, and to return them from other functions.
  • 5. What is OOP? Object Oriented Programming is programming which is oriented around objects Takes advantage of Encapsulation, Polymorphism, and Inheritance to increase code reuse and decrease code maintenance.
  • 6. Scala: FP and OOP language Scala is a object oriented and functional programming language which is completely interoperable with java FP: Makes it easy to build interesting things from simple parts, using – Higher order functions – Algebraic types and pattern matching – Parametric polymorphism OOP: Makes it easy to adopt and extend complex systems using – Subtyping and inheritance – Dynamic configurations – Classes as partial abstractions
  • 8. Scalable languages A language is scalable if it is suitable for very small as well as very large programs. A single language for extension scripts and the heavy lifting. Application-specific needs are handled through libraries and embedded DSL's instead of external languages. Scala shows that this is possible. 8
  • 9. Scala is a scripting language It has an interactive read-eval-print-loop (REPL). Types can be inferred. Boilerplate is scrapped. scala> var capital = Map("US" → "Washington", "France" → "Paris") capital: Map[String, String] = Map(US → Washington, France → Paris) scala> capital += ("Japan" → "Tokyo") scala> capital("France") res7: String = Paris 9
  • 10. Scala is the Java of the future It has basically everything Java has now. (sometimes in different form) It has closures. (proposed for Java 7, but rejected) It has traits and pattern matching. (do not be surprised to see them in Java 8, 9 or 10) It compiles to .class files, is completely interoperable and runs about as fast as Java object App { def main(args: Array[String]) { if (args exists (_.toLowerCase == "-help")) printUsage() else process(args) } } 10
  • 11. Scala is object-oriented Every value is an object Every operation is a method call Exceptions to these rules in Java (such as primitive types, statics) are eliminated. scala> (1).hashCode res8: Int = 1 scala> (1).+(2) res10: Int = 3 11
  • 12. Interoperability Scala fits seamlessly into a Java environment Can call Java methods, select Java fields, inherit Java classes, implement Java interfaces, etc. None of this requires glue code or interface descriptions Java code can also easily call into Scala code Scala code resembling Java is translated into virtually the same bytecodes. ⇒ Performance is usually on a par with Java 12
  • 14. Scala compared to Java Scala adds Scala removes + a pure object system - static members + operator overloading - primitive types + closures - break, continue + mixin composition with - special treatment of traits interfaces + existential types - wildcards + abstract types - raw types + pattern matching - enums 14
  • 15. Scala cheat sheet (1): Definitions Scala method definitions: Java method definition: def fun(x: Int): Int = { int fun(int x) { result return result } } def fun = result (no parameterless methods) Scala variable definitions: Java variable definitions: var x: Int = expression int x = expression val x: String = expression final String x = expression 15
  • 16. Scala cheat sheet (2): Objects and Classes Scala Class and Object Java Class with statics class Sample { class Sample(x: Int, val p: Int) { private final int x; def instMeth(y: Int) = x + y public final int p; } Sample(int x, int p) { this.x = x; this.p = p; object Sample { } def staticMeth(x: Int, y: Int) int instMeth(int y) { = return x + y; x*y } } static int staticMeth(int x, int y) { return x * y; } } 16
  • 17. Scala cheat sheet (3): Traits Scala Trait Java Interface trait T { interface T { def abstractMth(x: String): Int int abstractMth(String x) def concreteMth(x: String) = } x + field (no concrete methods) var field = “!” (no fields) } Java extension + implementation: Scala mixin composition: class C extends Super class C extends Super with T implements T 17
  • 18. Scala Compared to Java class CreditCard(val number: Int, var creditLimit: Int) javap -private CreditCard public class CreditCard extends java.lang.Object implements scala.ScalaObject{ private int creditLimit; private final int number; public CreditCard(int, int); public void creditLimit_$eq(int); public int creditLimit(); public int number(); public int $tag() throws java.rmi.RemoteException; } 18
  • 19. Constructors class Person(val firstName: String, val lastName: String) { private var position: String = _ println("Creating " + toString()) def this (firstName: String, lastName: String, positionHeld: String) { this (firstName, lastName) position = positionHeld } override def toString() : String = { firstName + " " + lastName + " holds " + position + " position " } } 19
  • 22. Currying & Partial Functions Currying in Scala transforms a function that takes more than one parameter into a function that takes multiple parameter lists. 22
  • 23. Closures You can create code blocks with variables that are not bound. You will have to bind them before you can invoke the function; however, they could bind to, or close over, variables outside of their local scope and parameter list. That’s why they’re called closures. 23
  • 24. Closures 24
  • 25. Traits They are fundamental unit for code reuse in Scala A Trait encapsulates method and field definitions, which can be reused by mixing them in classes Unlike class inheritance , in which class must inherit from just one superclass, a class may mix in any number of Traits Unlike Interfaces they can have concrete methods 25
  • 26. Traits trait Philosophical { def philosophize() { println("I consume memory, therefore I am!") } } class Frog extends Philosophical { override def toString() = "green" } val latestFrog = new Frog println("" + latestFrog) latestFrog.philosophize() val phil:Philosophical = latestFrog phil.philosophize() 26
  • 27. Pattern Matching All that is required is to add a single case keyword to each class that is to be pattern matchable Similar to switch expect that Scala compares Objects as expressions 27
  • 28. Pattern Matching object PatternApplication { def main(args : Array[String]) : Unit = { println( simplifyTop(UnOperator("-", UnOperator("-", Variable("x"))))) println( simplifyTop(BinOperator("+", Variable("x"), NumberOperator(0)))) println( simplifyTop(BinOperator("*", Variable("x"), NumberOperator(1)))) } def simplifyTop(expr: Expression): Expression = expr match { case UnOperator("-", UnOperator("-", e)) => e // Double negation case BinOperator("+", e, NumberOperator(0)) => e // Adding zero case BinOperator("*", e, NumberOperator(1)) => e // Multiplying by one case _ => expr } } 28
  • 30. Tool support – Standalone compiler: scalac – Fast background compiler: fsc – Interactive interpreter shell and script runner: scala – Web framework: lift – Testing frameworks: Specs, ScalaCheck, ScalaTest, SUnit, … IDE plugins for: – Eclipse (supported by EDF) – IntelliJ (supported by JetBrains) – Netbeans (supported by Sun) 30
  • 31. Who’s using it? Open source projects: lift wicket NetLogo SPDE: Scala branch for Processing Isabelle: GUI and code extractor Companies: Twitter: infrastructure Sony Pictures: middleware Nature.com: infrastructure SAP community: ESME company messaging Reaktor: many different projects Mimesis Republic: multiplayer games EDF: trading, … 31
  • 32. Learning Scala To get started: First steps in Scala, by Bill Venners published in Scalazine at www.artima.com Scala for Java Refugees by Daniel Spiewack (great blog series) To continue: Programming in Scala, by Odersky, Spoon, Venners, published by Artima,com Other books are in the pipeline. 32
  • 33. 33
  • 34. Contact Us Vikas Hazrati - [email protected] Meetu Maltiar - [email protected] www.xebiaindia.com www.xebia.com http://blog.xebia.in http://blog.xebia.com 34
  • 35. References “Programming in Scala” book by Martin Odersky, Lex Spoon and Bill Venners Presentation by Martin Odersky at FOSDEM 2009 http://www.slideshare.net/Odersky/fosdem-2009-1013261 Online book on Scala by oreilly http://programming-scala.labs.oreilly.com/ Magazine for Scala Programming Community http://www.artima.com/scalazine 35