SlideShare a Scribd company logo
Polyglot JVM

A Quick Tour of JVM Languages
@ArturoHerrero

http://arturoherrero.com
Working at OSOCO




Small but outstanding software development shop
           Groovy and Grails hackers
               on EC2 cloud nine
              TDD mantra singers
               Quality preachers
Java Platform

    _____________________________________
  /                                     /|
|------------------------------------| |
|         Java Programming Language    | |
|------------------------------------| |
|            Libraries & APIS          | |
|------------------------------------| |
|          Java Virtual Machine        | |
|------------------------------------|/
> 200 languages on JVM
JavaFX           Ceylon      Gosu
         Groovy
                            Clojure
Rhino
                 Java                 Mirah

         Scala              JRuby
Xtend            JPython
                               Fantom
   Oxygene
                   Kotlin
The Da Vinci Machine Project
We are extending the JVM with first-class
architectural support for languages other than
Java, especially dynamic languages. This project
will prototype a number of extensions to the JVM, so
that it can run non-Java languages efficiently, with a
performance level comparable to that of Java itself.
The Da Vinci Machine Project

JSR 223: Scripting for the Java Platform

JSR 292: Supporting Dynamically Typed
         Languages on the Java Platform

New JDK 7 instruction: invokedynamic
Polyglot Programming
Ola Bini Programming Pyramid

                   /
                / 
               / DSL 
              /------
             /             
                 Dynamic
           /          
          /------------
         /                     
                 Stable
        /                
       /------------------
Ola Bini Programming Pyramid

Domain-Specific (DSL, web templating)
 Specific part of the application

Dynamic (Groovy, Clojure)
 Rapid, productive,
 flexible development or funcionality

Stable (Java, Scala)
  Core funcionality, stable,
  well-tested, performance
Civilization advances by extending the
number of important operations which we
can perform without thinking about them.

                   Alfred North Whitehead
New languages

New ways to think about problems
Language Clasification
                functional
                    |
                    |
                    |
                    |
   -----------------+-----------------
static              |              dynamic
                    |
                    |
                    |
              not functional
StackOverflow Questions

|      8,268
|       __
|      | |
|      | |       3,847
|      | |        __       2,762
|      | |       | |        __
|      | |       | |       | |
|      | |       | |       | |
|------+--+------+--+------+--+------
| |
                                     | |
StackOverflow Questions              | |
                                     | |
                             222,722 | |
|      8,268                         | |
|       __                           | |
|      | |                           | |
|      | |       3,847               | |
|      | |        __       2,762     | |
|      | |       | |        __       | |
|      | |       | |       | |       | |
|      | |       | |       | |       | |
|------+--+------+--+------+--+------+--+-
Indeed Job Trends

|      0,06
|       __
|      | |
|      | |       0,03
|      | |        __
|      | |       | |       0,01
|      | |       | |        __
|      | |       | |       | |
|------+--+------+--+------+--+------
| |
                                     | |
Indeed Job Trends                    | |
                                     | |
                                3,40 | |
|      0,06                          | |
|       __                           | |
|      | |                           | |
|      | |       0,03                | |
|      | |        __                 | |
|      | |       | |       0,01      | |
|      | |       | |        __       | |
|      | |       | |       | |       | |
|------+--+------+--+------+--+------+--+-
All of them
●   Everything is an object
●   Operator overloading
●   Native syntax for collection classes
●   Regular expressions as first class citizens
●   Closures
●   Facilities to build DSLs
Groovy
●   Dynamic Language
●   Object-Oriented
●   Designed for the JVM
●   Inspired by Python, Ruby and Smalltalk
●   Good integration with Java
●   2003
Hello Groovy




    println 'Hello World'
Scripting
Typically dynamic languages
  No need to define variable before you use
  them. Many type conversion

Most scripting languages are interpreted
 Perform the script compilation and
 execution within the same process

Fast results for small jobs
  Write application faster
  Execute commands repeatedly
Groovy Beans

class Person {
    String name
    Integer age
}

def person = new Person(name: 'John', age: 30)

def name = person.name
person.age = 35
Static vs. Dynamic

Static typing
 A programming language is said to use static typing
 when type checking is performed during compile time as
 opposed to runtime


Dynamic typing
 A programming language is said to be dynamically typed
 when the majority of its type checking is performed at
 runtime as opposed to at compile time
Optional Typing

    Integer object

    object = 4

    object = 'noun'
    ERROR
    org.codehaus.groovy.runtime.
    typehandling.GroovyCastException
Optional Typing


      def object

      object   =   4
      object   =   'noun'
      object   =   true
      object   =   [1, 'noun', true]
      object   =   [1: 'noun']
Java → Groovy
import java.util.List;
import java.util.ArrayList;

public class Filter {
    public static void main(String[] args) {
        List names = new ArrayList();
        names.add("Ted"); names.add("Fred");
        names.add("Jed"); names.add("Ned");
        System.out.println(names);

          Filter filter = new Filter();
          List shortNames = filter.filterLongerThan(names, 3);
          System.out.println(shortNames.size());
          for (String item : shortNames) {
              System.out.println(item);
          }
      }
...
Java → Groovy

...

      private List filterLongerThan(List strings, int length) {
          List result = new ArrayList();
          for (String item : strings) {
              if (item.length() <= length) {
                  result.add(item);
              }
          }
          return result;
      }
}
Java → Groovy

def names = ["Ted", "Fred"] << "Jed" << "Ned"
println names

def shortNames = names.findAll { it.size() <= 3 }
println shortNames.size()
shortNames.each { name -> println name }
Static language
      interface Animal {
          def quack()
      }

      class Duck implements Animal {
          def quack() {
              println "I am a Duck"
          }
      }

      class Frog implements Animal {
          def quack() {
              println "I am a Frog"
          }
      }
Polymorphism

      Animal animal

      animal = new Duck()
      animal.quack()
      ===> I am a Duck

      animal = new Frog()
      animal.quack()
      ===> I am a Frog
Dynamic language

     class Duck {
         def quack() {
             println "I am a Duck"
         }
     }

     class Frog {
         def quack() {
             println "I am a Frog"
         }
     }
Duck typing

       def animal

       animal = new Duck()
       animal.quack()
       ===> I am a Duck

       animal = new Frog()
       animal.quack()
       ===> I am a Frog
Dynamic Method Call

   class Dog {
       def bark() { println "woof!" }
       def jump() { println "boing!" }
   }


   def doAction(animal, action) {
       animal."$action"()
   }
Dynamic Method Call

     someObject."$methodName"()

     def rex = new Dog()

     doAction(rex, "bark")
     ===> woof!

     doAction(rex, "jump")
     ===> boing!
Metaprogramming
Programs that write or manipulate
other programs

Compile time
  ● Groovy AST




Runtime
  ● Hook into method dispaching

  ● Dynamically create methods/properties

  ● Dynamic execution of expressions
AST Transformations
    @Singleton
    class Singleton {}

    @EqualsAndHashCode
    class Person {
        String name, lastName
    }

    @Immutable
    class Coordinates {
        Double latitude, longitude
    }
Method Missing


   class Dog {
       def bark() { println "woof!" }
       def jump() { println "boing!" }
   }

   def rex = new Dog()
   rex.sit()
   ERROR
   groovy.lang.MissingMethodException
Method Missing

 class Dog {
     def bark() { println "woof!" }
     def jump() { println "boing!" }

     def methodMissing(String name, args) {
         println "sit!"
     }
 }

 rex.sit()
 ===> sit!
Adding methods to a
class at runtime


   4.toRoman()

   ERROR
   groovy.lang.MissingMethodException
Adding methods to a
class at runtime
   SomeObject.metaClass.newMethod = { ->
     // do something
   }

   Integer.metaClass.toRoman = { ->
       println 'IV'
   }

   4.toRoman()
   ===> IV
Scala
●   Object-Oriented and Functional Language
●   Stronger type system
●   Designed for the JVM
●   Concurrency: Actors
●   Many advanced language features
●   As fast as Java
●   2003
Hello Scala


  object HelloWorld {
      def main(args: Array[String]) {
          println("Hello World")
      }
  }
Scala Types

     scala> 1 + 1
     res1: Int = 2

     scala> (1).+(1)
     res2: Int = 2

     scala> "a" + "b"
     res3: java.lang.String = ab

     scala> "abc".size
     res4: Int = 3
Classes



  class Person(name: String, age: Int)

  val person = new Person("John", 30)
Objects


   object Singleton {
       def start = println("Start")
   }

   scala> Singleton.start
   Start
Anatomy of a Function


  def max (x: Int, y: Int): Int = {
      if (x > y)
          x
      else
          y
  }
Type Inference

 // Java
 Map<String, List<Integer>> map =
     new HashMap<String, List<Integer>>()

 // Java 7
 Map<String, List<Integer>> map =
     new HashMap<>()

 // Scala
 val map = new HashMap[String, List[Int]]
Variable Declaration


  var mutable = "I am mutable"
  mutable = "Touch me, change me..."


  val immutable = "I am not mutable"
  immutable = "Can't touch this"
  error: reassignment to val
Immutability
Simple
  Immutable objects can only be in exactly
  one state, the state in which it was created

Always consistent
  Less prone to errors and more secure

Immutable objects can be shared freely
  Freedom to cache

Inherently thread-safe
Imperative vs. Declarative

Imperative: how to achieve our goal
 Take the next customer from a list.
 If the customer lives in Spain, show their details.
 If there are more customers in the list, go to the beginning



Declarative: what we want to achieve
 Show customer details of every customer living in Spain
Mutability

   val listOneToTen: List[Int] = {
       var list: List[Int] = List()
       var i: Int = 1
       while (i <= 10) {
           list :+= i
           i += 1
       }
       list
   }
Immutability

 def listToTen(i: Int): List[Int] = {
     if (i <= 10)
         i :: listToTen(i + 1)
     else
         Nil
 }

 val listOneToTen = listToTen(1)
Range


  scala> println(listOneToTen)
  List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)



          (1 to 10) toList
Mixin Traits
 class Person(val name: String)

 trait Power {
     def fly() = println("Fly")
 }

 class SuperHero(override val name:String)
       extends Person(name) with Power

 val superMan = new SuperHero("SuperMan")
 scala> superMan.fly
 Fly
Pattern Matching

def determineType(x:Any) = x match {
    case s: String => println("String")
    case l: List[_] => println("List")
    case l: Map[_,_] => println("Map")
    case _ => println("Unhandled type!")
}

def factorial(n: Int): Int = n match {
    case 0 => 1
    case x if x > 0 => factorial(n - 1) * n
}
Clojure
●   Clojure is LISP
●   Dynamic language
●   Designed for the JVM
●   Code is data
●   Powerful macros
●   Good interoperability with Java
●   Clojure is fast
●   Concurrency. Shared Transactional Memory
●   2007
Why Functional Programming?
    Referential transparency
λ




    Unit testing
λ




    Debbuging
λ




    Parallelization
λ




    Modularity and composition
λ




    Increases the quality of code
λ




    Abstractions
λ
Hello Clojure




    (println "Hello World")
Prefix notation

        (+ 1 2)
        => 3

        (+ 1 2 3 4 5)
        => 15

        (< 1 2 3 4 5)
        => true
Anatomy of a Function



(defn biggest
  "Find the maximum of two numbers"
  [x y]
  (if (> x y) x y))
Anatomy of a Function



(def biggest
  "Find the maximum of two numbers"
  (fn [x y]
    (if (> x y) x y)))
Function Composition


    (defn square [x] (* x x))

    (square 21)
    => 441
    (square (+ 2 5))
    => 49
Function Composition


  (defn sum-of-squares [x y]
      (+ (square x) (square y)))

  (sum-of-squares 3 4)
  => 25
Immutability
 (def my-list '(1 2 3))

 +---+      +---+      +---+
 | 1 | ---> | 2 | ---> | 3 |
 +---+      +---+      +---+


 (def new-list (conj my-list 0))

           +-----------------------------+
 +---+     | +---+      +---+      +---+ |
 | 0 | --->| | 1 | ---> | 2 | ---> | 3 | |
 +---+     | +---+      +---+      +---+ |
           +-----------------------------+
Lazy Evaluation
Only does as much work as necessary
 Delays the evaluation of the expression
 until it's needed

CPU efficient
  The value is not calculated or assigned
  until the value is requested

Manage potentially infinite data structures
 Only a manageable subset of the data
 will actually be used
Infinite Sequences

  (take 3 (repeat "Hello"))
  => ("Hello" "Hello" "Hello")

  (take 5 (cycle [1 2 3]))
  => (1 2 3 1 2)

  (take 5 (drop 2 (cycle [1 2 3])))
  (->> [1 2 3] (cycle) (drop 2) (take 5))
  (1 2 3 1 2 3 1 2 3 …
  => (3 1 2 3 1)
Clojure STM

 (def my-account (ref 1000.))
 (def other-account (ref 5000.))

 (defn transfer
     [from to amount]
     (dosync
         (alter from - amount)
         (alter to + amount)))

 (transfer other-account my-account 1000.)
Thank you!
@ArturoHerrero

More Related Content

What's hot

Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
Skills Matter
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovymanishkp84
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
Bartosz Kosarzycki
 
Scala for Java programmers
Scala for Java programmersScala for Java programmers
Scala for Java programmers
輝 子安
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin PresentationAndrzej Sitek
 
Clean code
Clean codeClean code
Clean code
Arturo Herrero
 
groovy transforms
groovy transformsgroovy transforms
groovy transforms
Paul King
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
José Paumard
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
BTI360
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
Nick Plante
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
Stephen Chin
 
Clean code
Clean codeClean code
Clean code
ifnu bima
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
Bartosz Kosarzycki
 
Discovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic GroovyDiscovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic Groovy
Naresha K
 
AST Transformations
AST TransformationsAST Transformations
AST TransformationsHamletDRC
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
Siddhi
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)
Gautam Rege
 

What's hot (20)

Clojure And Swing
Clojure And SwingClojure And Swing
Clojure And Swing
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
Introduction To Groovy
Introduction To GroovyIntroduction To Groovy
Introduction To Groovy
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Scala for Java programmers
Scala for Java programmersScala for Java programmers
Scala for Java programmers
 
Swift and Kotlin Presentation
Swift and Kotlin PresentationSwift and Kotlin Presentation
Swift and Kotlin Presentation
 
Clean code
Clean codeClean code
Clean code
 
groovy transforms
groovy transformsgroovy transforms
groovy transforms
 
Java Full Throttle
Java Full ThrottleJava Full Throttle
Java Full Throttle
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
Building native Android applications with Mirah and Pindah
Building native Android applications with Mirah and PindahBuilding native Android applications with Mirah and Pindah
Building native Android applications with Mirah and Pindah
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
 
Clean code
Clean codeClean code
Clean code
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Discovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic GroovyDiscovering functional treasure in idiomatic Groovy
Discovering functional treasure in idiomatic Groovy
 
AST Transformations
AST TransformationsAST Transformations
AST Transformations
 
Creating Domain Specific Languages in Python
Creating Domain Specific Languages in PythonCreating Domain Specific Languages in Python
Creating Domain Specific Languages in Python
 
Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)Ruby and rails - Advanced Training (Cybage)
Ruby and rails - Advanced Training (Cybage)
 

Viewers also liked

Spring Annotations: Proxy
Spring Annotations: ProxySpring Annotations: Proxy
Spring Annotations: Proxy
OSOCO
 
Proactive monitoring with Monit
Proactive monitoring with MonitProactive monitoring with Monit
Proactive monitoring with Monit
OSOCO
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic Proxies
OSOCO
 
AWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 MinutosAWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 Minutos
OSOCO
 
SSH Tunneling Recipes
SSH Tunneling RecipesSSH Tunneling Recipes
SSH Tunneling RecipesOSOCO
 
Polyglot how i learn languages
Polyglot  how i learn languagesPolyglot  how i learn languages
Polyglot how i learn languagesPaulo Deghi Deghi
 
Polyglot engineering
Polyglot engineeringPolyglot engineering
Polyglot engineering
Klaus Salchner
 
Polyglot Programming in the JVM - Øredev
Polyglot Programming in the JVM - ØredevPolyglot Programming in the JVM - Øredev
Polyglot Programming in the JVM - Øredev
Andres Almiray
 
Polyglot Programming in the JVM - 33rd Degree
Polyglot Programming in the JVM - 33rd DegreePolyglot Programming in the JVM - 33rd Degree
Polyglot Programming in the JVM - 33rd Degree
Andres Almiray
 
How to Setup Continuous Integration With Git, Jenkins, and Force.com
How to Setup Continuous Integration With Git, Jenkins, and Force.comHow to Setup Continuous Integration With Git, Jenkins, and Force.com
How to Setup Continuous Integration With Git, Jenkins, and Force.com
Salesforce Developers
 
Polyglot
PolyglotPolyglot
Polyglot
Rory Preddy
 
Force.com Canvas - a Quick Introduction
Force.com Canvas - a Quick IntroductionForce.com Canvas - a Quick Introduction
Force.com Canvas - a Quick Introduction
Steven Herod
 
Automating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationAutomating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous Integration
Sebastian Wagner
 
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for DeploymentSalesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Developers
 
MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)
MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)
MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)
Alex Rupérez
 
NSCoder Keynote - Multipeer Connectivity Framework
NSCoder Keynote - Multipeer Connectivity FrameworkNSCoder Keynote - Multipeer Connectivity Framework
NSCoder Keynote - Multipeer Connectivity Framework
Alex Rupérez
 
Gigigo Keynote - Geofences & iBeacons
Gigigo Keynote - Geofences & iBeaconsGigigo Keynote - Geofences & iBeacons
Gigigo Keynote - Geofences & iBeacons
Alex Rupérez
 
Gigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die tryingGigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die trying
Alex Rupérez
 

Viewers also liked (20)

Spring Annotations: Proxy
Spring Annotations: ProxySpring Annotations: Proxy
Spring Annotations: Proxy
 
Proactive monitoring with Monit
Proactive monitoring with MonitProactive monitoring with Monit
Proactive monitoring with Monit
 
Understanding Java Dynamic Proxies
Understanding Java Dynamic ProxiesUnderstanding Java Dynamic Proxies
Understanding Java Dynamic Proxies
 
AWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 MinutosAWS CloudFormation en 5 Minutos
AWS CloudFormation en 5 Minutos
 
SSH Tunneling Recipes
SSH Tunneling RecipesSSH Tunneling Recipes
SSH Tunneling Recipes
 
Polyglot how i learn languages
Polyglot  how i learn languagesPolyglot  how i learn languages
Polyglot how i learn languages
 
Polyglot engineering
Polyglot engineeringPolyglot engineering
Polyglot engineering
 
Polyglot
Polyglot Polyglot
Polyglot
 
Polyglot Programming in the JVM - Øredev
Polyglot Programming in the JVM - ØredevPolyglot Programming in the JVM - Øredev
Polyglot Programming in the JVM - Øredev
 
Polyglot Programming in the JVM - 33rd Degree
Polyglot Programming in the JVM - 33rd DegreePolyglot Programming in the JVM - 33rd Degree
Polyglot Programming in the JVM - 33rd Degree
 
How to Setup Continuous Integration With Git, Jenkins, and Force.com
How to Setup Continuous Integration With Git, Jenkins, and Force.comHow to Setup Continuous Integration With Git, Jenkins, and Force.com
How to Setup Continuous Integration With Git, Jenkins, and Force.com
 
Polyglot
PolyglotPolyglot
Polyglot
 
Force.com Canvas - a Quick Introduction
Force.com Canvas - a Quick IntroductionForce.com Canvas - a Quick Introduction
Force.com Canvas - a Quick Introduction
 
Automating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous IntegrationAutomating Deployment Between Orgs Using Git & Continuous Integration
Automating Deployment Between Orgs Using Git & Continuous Integration
 
Salesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for DeploymentSalesforce Release Management - Best Practices and Tools for Deployment
Salesforce Release Management - Best Practices and Tools for Deployment
 
MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)
MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)
MADBike – Destapando la seguridad de BiciMAD (T3chFest 2017)
 
Governor limits
Governor limitsGovernor limits
Governor limits
 
NSCoder Keynote - Multipeer Connectivity Framework
NSCoder Keynote - Multipeer Connectivity FrameworkNSCoder Keynote - Multipeer Connectivity Framework
NSCoder Keynote - Multipeer Connectivity Framework
 
Gigigo Keynote - Geofences & iBeacons
Gigigo Keynote - Geofences & iBeaconsGigigo Keynote - Geofences & iBeacons
Gigigo Keynote - Geofences & iBeacons
 
Gigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die tryingGigigo Workshop - Create an iOS Framework, document it and not die trying
Gigigo Workshop - Create an iOS Framework, document it and not die trying
 

Similar to Polyglot JVM

Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applications
IndicThreads
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
loffenauer
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
Eric Pederson
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
pmanvi
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
Andres Almiray
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
Sunghyouk Bae
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
rohitnayak
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
Marcus Lagergren
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
Michelangelo van Dam
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-final
Marcus Lagergren
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
Ramnivas Laddad
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with ClojureDmitry Buzdin
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
Guillaume Laforge
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
Doris Chen
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
jbandi
 
Remixing Confluence With Speakeasy
Remixing Confluence With SpeakeasyRemixing Confluence With Speakeasy
Remixing Confluence With Speakeasynabeelahali
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
Peter Maas
 

Similar to Polyglot JVM (20)

Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Groovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applicationsGroovy - Grails as a modern scripting language for Web applications
Groovy - Grails as a modern scripting language for Web applications
 
2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws2007 09 10 Fzi Training Groovy Grails V Ws
2007 09 10 Fzi Training Groovy Grails V Ws
 
Scala for Java Programmers
Scala for Java ProgrammersScala for Java Programmers
Scala for Java Programmers
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
 
[Start] Scala
[Start] Scala[Start] Scala
[Start] Scala
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Oscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast LaneOscon Java Testing on the Fast Lane
Oscon Java Testing on the Fast Lane
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
Groovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web ApplicationsGroovy & Grails: Scripting for Modern Web Applications
Groovy & Grails: Scripting for Modern Web Applications
 
A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9A new execution model for Nashorn in Java 9
A new execution model for Nashorn in Java 9
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 
Lagergren jvmls-2013-final
Lagergren jvmls-2013-finalLagergren jvmls-2013-final
Lagergren jvmls-2013-final
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Refactoring to Macros with Clojure
Refactoring to Macros with ClojureRefactoring to Macros with Clojure
Refactoring to Macros with Clojure
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015The curious Life of JavaScript - Talk at SI-SE 2015
The curious Life of JavaScript - Talk at SI-SE 2015
 
Remixing Confluence With Speakeasy
Remixing Confluence With SpeakeasyRemixing Confluence With Speakeasy
Remixing Confluence With Speakeasy
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 

Recently uploaded

SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
Alex Pruden
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 

Recently uploaded (20)

SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex ProofszkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
zkStudyClub - Reef: Fast Succinct Non-Interactive Zero-Knowledge Regex Proofs
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 

Polyglot JVM

  • 1. Polyglot JVM A Quick Tour of JVM Languages
  • 3. Working at OSOCO Small but outstanding software development shop Groovy and Grails hackers on EC2 cloud nine TDD mantra singers Quality preachers
  • 4.
  • 5. Java Platform _____________________________________ / /| |------------------------------------| | | Java Programming Language | | |------------------------------------| | | Libraries & APIS | | |------------------------------------| | | Java Virtual Machine | | |------------------------------------|/
  • 6. > 200 languages on JVM JavaFX Ceylon Gosu Groovy Clojure Rhino Java Mirah Scala JRuby Xtend JPython Fantom Oxygene Kotlin
  • 7. The Da Vinci Machine Project We are extending the JVM with first-class architectural support for languages other than Java, especially dynamic languages. This project will prototype a number of extensions to the JVM, so that it can run non-Java languages efficiently, with a performance level comparable to that of Java itself.
  • 8. The Da Vinci Machine Project JSR 223: Scripting for the Java Platform JSR 292: Supporting Dynamically Typed Languages on the Java Platform New JDK 7 instruction: invokedynamic
  • 10. Ola Bini Programming Pyramid / / / DSL /------ / Dynamic / /------------ / Stable / /------------------
  • 11. Ola Bini Programming Pyramid Domain-Specific (DSL, web templating) Specific part of the application Dynamic (Groovy, Clojure) Rapid, productive, flexible development or funcionality Stable (Java, Scala) Core funcionality, stable, well-tested, performance
  • 12. Civilization advances by extending the number of important operations which we can perform without thinking about them. Alfred North Whitehead
  • 13. New languages New ways to think about problems
  • 14. Language Clasification functional | | | | -----------------+----------------- static | dynamic | | | not functional
  • 15. StackOverflow Questions | 8,268 | __ | | | | | | 3,847 | | | __ 2,762 | | | | | __ | | | | | | | | | | | | | | |------+--+------+--+------+--+------
  • 16. | | | | StackOverflow Questions | | | | 222,722 | | | 8,268 | | | __ | | | | | | | | | | 3,847 | | | | | __ 2,762 | | | | | | | __ | | | | | | | | | | | | | | | | | | | | |------+--+------+--+------+--+------+--+-
  • 17. Indeed Job Trends | 0,06 | __ | | | | | | 0,03 | | | __ | | | | | 0,01 | | | | | __ | | | | | | | |------+--+------+--+------+--+------
  • 18. | | | | Indeed Job Trends | | | | 3,40 | | | 0,06 | | | __ | | | | | | | | | | 0,03 | | | | | __ | | | | | | | 0,01 | | | | | | | __ | | | | | | | | | | | |------+--+------+--+------+--+------+--+-
  • 19. All of them ● Everything is an object ● Operator overloading ● Native syntax for collection classes ● Regular expressions as first class citizens ● Closures ● Facilities to build DSLs
  • 20. Groovy ● Dynamic Language ● Object-Oriented ● Designed for the JVM ● Inspired by Python, Ruby and Smalltalk ● Good integration with Java ● 2003
  • 21. Hello Groovy println 'Hello World'
  • 22. Scripting Typically dynamic languages No need to define variable before you use them. Many type conversion Most scripting languages are interpreted Perform the script compilation and execution within the same process Fast results for small jobs Write application faster Execute commands repeatedly
  • 23. Groovy Beans class Person { String name Integer age } def person = new Person(name: 'John', age: 30) def name = person.name person.age = 35
  • 24. Static vs. Dynamic Static typing A programming language is said to use static typing when type checking is performed during compile time as opposed to runtime Dynamic typing A programming language is said to be dynamically typed when the majority of its type checking is performed at runtime as opposed to at compile time
  • 25. Optional Typing Integer object object = 4 object = 'noun' ERROR org.codehaus.groovy.runtime. typehandling.GroovyCastException
  • 26. Optional Typing def object object = 4 object = 'noun' object = true object = [1, 'noun', true] object = [1: 'noun']
  • 27. Java → Groovy import java.util.List; import java.util.ArrayList; public class Filter { public static void main(String[] args) { List names = new ArrayList(); names.add("Ted"); names.add("Fred"); names.add("Jed"); names.add("Ned"); System.out.println(names); Filter filter = new Filter(); List shortNames = filter.filterLongerThan(names, 3); System.out.println(shortNames.size()); for (String item : shortNames) { System.out.println(item); } } ...
  • 28. Java → Groovy ... private List filterLongerThan(List strings, int length) { List result = new ArrayList(); for (String item : strings) { if (item.length() <= length) { result.add(item); } } return result; } }
  • 29. Java → Groovy def names = ["Ted", "Fred"] << "Jed" << "Ned" println names def shortNames = names.findAll { it.size() <= 3 } println shortNames.size() shortNames.each { name -> println name }
  • 30. Static language interface Animal { def quack() } class Duck implements Animal { def quack() { println "I am a Duck" } } class Frog implements Animal { def quack() { println "I am a Frog" } }
  • 31. Polymorphism Animal animal animal = new Duck() animal.quack() ===> I am a Duck animal = new Frog() animal.quack() ===> I am a Frog
  • 32. Dynamic language class Duck { def quack() { println "I am a Duck" } } class Frog { def quack() { println "I am a Frog" } }
  • 33. Duck typing def animal animal = new Duck() animal.quack() ===> I am a Duck animal = new Frog() animal.quack() ===> I am a Frog
  • 34. Dynamic Method Call class Dog { def bark() { println "woof!" } def jump() { println "boing!" } } def doAction(animal, action) { animal."$action"() }
  • 35. Dynamic Method Call someObject."$methodName"() def rex = new Dog() doAction(rex, "bark") ===> woof! doAction(rex, "jump") ===> boing!
  • 36. Metaprogramming Programs that write or manipulate other programs Compile time ● Groovy AST Runtime ● Hook into method dispaching ● Dynamically create methods/properties ● Dynamic execution of expressions
  • 37. AST Transformations @Singleton class Singleton {} @EqualsAndHashCode class Person { String name, lastName } @Immutable class Coordinates { Double latitude, longitude }
  • 38. Method Missing class Dog { def bark() { println "woof!" } def jump() { println "boing!" } } def rex = new Dog() rex.sit() ERROR groovy.lang.MissingMethodException
  • 39. Method Missing class Dog { def bark() { println "woof!" } def jump() { println "boing!" } def methodMissing(String name, args) { println "sit!" } } rex.sit() ===> sit!
  • 40. Adding methods to a class at runtime 4.toRoman() ERROR groovy.lang.MissingMethodException
  • 41. Adding methods to a class at runtime SomeObject.metaClass.newMethod = { -> // do something } Integer.metaClass.toRoman = { -> println 'IV' } 4.toRoman() ===> IV
  • 42. Scala ● Object-Oriented and Functional Language ● Stronger type system ● Designed for the JVM ● Concurrency: Actors ● Many advanced language features ● As fast as Java ● 2003
  • 43. Hello Scala object HelloWorld { def main(args: Array[String]) { println("Hello World") } }
  • 44. Scala Types scala> 1 + 1 res1: Int = 2 scala> (1).+(1) res2: Int = 2 scala> "a" + "b" res3: java.lang.String = ab scala> "abc".size res4: Int = 3
  • 45. Classes class Person(name: String, age: Int) val person = new Person("John", 30)
  • 46. Objects object Singleton { def start = println("Start") } scala> Singleton.start Start
  • 47. Anatomy of a Function def max (x: Int, y: Int): Int = { if (x > y) x else y }
  • 48. Type Inference // Java Map<String, List<Integer>> map = new HashMap<String, List<Integer>>() // Java 7 Map<String, List<Integer>> map = new HashMap<>() // Scala val map = new HashMap[String, List[Int]]
  • 49. Variable Declaration var mutable = "I am mutable" mutable = "Touch me, change me..." val immutable = "I am not mutable" immutable = "Can't touch this" error: reassignment to val
  • 50. Immutability Simple Immutable objects can only be in exactly one state, the state in which it was created Always consistent Less prone to errors and more secure Immutable objects can be shared freely Freedom to cache Inherently thread-safe
  • 51. Imperative vs. Declarative Imperative: how to achieve our goal Take the next customer from a list. If the customer lives in Spain, show their details. If there are more customers in the list, go to the beginning Declarative: what we want to achieve Show customer details of every customer living in Spain
  • 52. Mutability val listOneToTen: List[Int] = { var list: List[Int] = List() var i: Int = 1 while (i <= 10) { list :+= i i += 1 } list }
  • 53. Immutability def listToTen(i: Int): List[Int] = { if (i <= 10) i :: listToTen(i + 1) else Nil } val listOneToTen = listToTen(1)
  • 54. Range scala> println(listOneToTen) List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10) (1 to 10) toList
  • 55. Mixin Traits class Person(val name: String) trait Power { def fly() = println("Fly") } class SuperHero(override val name:String) extends Person(name) with Power val superMan = new SuperHero("SuperMan") scala> superMan.fly Fly
  • 56. Pattern Matching def determineType(x:Any) = x match { case s: String => println("String") case l: List[_] => println("List") case l: Map[_,_] => println("Map") case _ => println("Unhandled type!") } def factorial(n: Int): Int = n match { case 0 => 1 case x if x > 0 => factorial(n - 1) * n }
  • 57. Clojure ● Clojure is LISP ● Dynamic language ● Designed for the JVM ● Code is data ● Powerful macros ● Good interoperability with Java ● Clojure is fast ● Concurrency. Shared Transactional Memory ● 2007
  • 58. Why Functional Programming? Referential transparency λ Unit testing λ Debbuging λ Parallelization λ Modularity and composition λ Increases the quality of code λ Abstractions λ
  • 59. Hello Clojure (println "Hello World")
  • 60. Prefix notation (+ 1 2) => 3 (+ 1 2 3 4 5) => 15 (< 1 2 3 4 5) => true
  • 61. Anatomy of a Function (defn biggest "Find the maximum of two numbers" [x y] (if (> x y) x y))
  • 62. Anatomy of a Function (def biggest "Find the maximum of two numbers" (fn [x y] (if (> x y) x y)))
  • 63. Function Composition (defn square [x] (* x x)) (square 21) => 441 (square (+ 2 5)) => 49
  • 64. Function Composition (defn sum-of-squares [x y] (+ (square x) (square y))) (sum-of-squares 3 4) => 25
  • 65. Immutability (def my-list '(1 2 3)) +---+ +---+ +---+ | 1 | ---> | 2 | ---> | 3 | +---+ +---+ +---+ (def new-list (conj my-list 0)) +-----------------------------+ +---+ | +---+ +---+ +---+ | | 0 | --->| | 1 | ---> | 2 | ---> | 3 | | +---+ | +---+ +---+ +---+ | +-----------------------------+
  • 66. Lazy Evaluation Only does as much work as necessary Delays the evaluation of the expression until it's needed CPU efficient The value is not calculated or assigned until the value is requested Manage potentially infinite data structures Only a manageable subset of the data will actually be used
  • 67. Infinite Sequences (take 3 (repeat "Hello")) => ("Hello" "Hello" "Hello") (take 5 (cycle [1 2 3])) => (1 2 3 1 2) (take 5 (drop 2 (cycle [1 2 3]))) (->> [1 2 3] (cycle) (drop 2) (take 5)) (1 2 3 1 2 3 1 2 3 … => (3 1 2 3 1)
  • 68. Clojure STM (def my-account (ref 1000.)) (def other-account (ref 5000.)) (defn transfer [from to amount] (dosync (alter from - amount) (alter to + amount))) (transfer other-account my-account 1000.)
  • 69.