SlideShare una empresa de Scribd logo
1 de 38
Descargar para leer sin conexión
Polyglot and Functional Programming
on the Java Virtual Machine
Mohan Kumar Muddana
InfoStretch Pvt. Ltd.
Some of the languages on JVM




                               2
Why so many languages on JVM

• JVM has grown over the years and has become a
  mature platform.

• Very wide industry adoption.

• Availability of large developer community.

• Plethora of Tools and Technologies
                                                  3
Polyglot Programming on the JVM
• Different languages bring in different features.

• Wider choice of availability.

• Better programming features.

• Imperative and Functional

• Interoperability between the languages.
                                                     4
JVM – The Polyglot Platform
JVM was initially built for (Java) Classes.

How does it handles so different kind of language
 constructs.

the Da Vinci Machine Project
  (http://openjdk.java.net/projects/mlvm/)




                                                    5
How JVM incorporates and consumes

Java 6 : - JSR 223: Scripting for the Java Platform
   (Groovy, Jython, JRuby)




Java 7 :- JSR 292: Supporting Dynamically Typed Languages on
  the JavaTM Platform

    MLVM – Multi Language Virtual Machine.


                                                               6
History of Functional Programming



              Alonzo Church
         Creator of λ-Calculus – 1940



 λ-Calculus is the basis of all functional programming languages




                                                                   7
History of Functional Programming

• What does it fundamentally say-
   A function is an action that is applied to one thing (the argument) to
  obtain another thing (the value).

• Two Fundamental functions in λ-Calculus
  (I, the identity function). I is defined as follows: (Ix) is x, whatever
  x may be.

  (H). H is defined as the function that always returns the identity
  function. That is, (Hx) is I for whatever x may be.

                                                                             8
Functional Programming
• Derives from mathematics, Lambda Calculus

• Built on the basis of functions

• Immutability and Concurrency

• Data Structures with strong filtering

• Lesser code with fewer language constructs.
                                                9
Functional Programming Languages
• Lisp –   One of t he oldest programming language
 (Lisp is functional language)


• Haskel – Pure functional language

• Erlang -  Massively scalable soft real-time systems with
  requirements on high availability and fault tolerant systems.


• Scheme, ML, OCAML etc.

• And many others                                                 10
Scala Language aka Scalable
Why Scala
Ordersky says:
 "We wanted to make Java more expressive, so people
  could be more productive" and write at a higher level
  of abstraction with fewer lines of code, Odersky says.

How it is scalable

Getting Started

                                                           11
Scala – Object World

• Scala is Pure Object Oriented Language

• Traits

• Case Classes and Pattern Matching

• Type safety and Type Erasure


                                           12
Scala – Classes and Objects
Everything is objects.
Store objects into a variables.

   class HelloWorld() {
     val welcome: String = “Hello World ”
      def msg(name: String) = println(welcome + name)
   }

   val h = new HelloWorld()
   h.msg(“Your Name”)


                                                        13
Scala – Traits
It is an kind of an Interface with fields and concrete methods.
Unlike Class inheritance, a class can mix (Mixins) in any number
    of traits.


 trait PolyglotProgrammer {
     def polyProg() {
            println("Polyglot Programmer")
     }
  }
 class Person extends PolyglotProgrammer with
 PolyglotSpeaker {}
 val person = new Person
 println(person.polyProg)
 println(person.polySpeaker)                                       14
Scala – Case Classes and Pattern Match

• Case classes provides pattern matching on objects
  without large amount of boilerplate code.

• Case classes are normal classes with a case modifier as
  prefix.

  case Class Rectangle(length: Int, breadth: Int)




                                                            15
Scala – Case Classes and Pattern Match
Case Classes comes with additional conventions

  - The compiler adds a factory method with the name
    of the class, so no need to create an instance with
    new operator.

  - All arguments in the parameter list gets implicit val
       prefix, so they are maintained as fields.

  - Compiler adds natural implementations of toString,
    hashCode and equals.
                                                            16
Groovy
Groovy is the closest to Java language.

Supports both static and dynamic type binding.

Powerful XML processing constructs.

Very good support for regular expressions



                                                 17
Groovy – XML Processing
 def writer = new StringWriter();
 def xml = new groovy.xml.MarkupBuilder(writer);
 xml.person(id:2) {
     name 'Gweneth‘ age 1
 }
 println writer.toString();


 <person id='2'>
 <name>Gweneth</name>
 <age>1</age>
 </person>
                                                   18
Groovy Beans - Conciseness

 class Person {
    private String name
     private int age
  }

 def p = new Person(name: “Ramu”, age: 15)
 (No syntactic ceremony)

 @Immutable annotation to make it immutable

                                              19
Groovy – Elvis Operator ?:
 In Java if/else construct would look like this
   String tradeStatus = "Active";
   String status = tradeStatus != null ? tradeStatus :
       “Inactive";

 In Groovy
    String tradeStatus = "Active"
    String status = tradeStatus ?: "Inactive“

 Groovy coerces the String into a boolean; assuming the
 String was null, it will convert to the Boolean value of
 false. No ceremonial Null Pointer check                    20
Groovy – DSL
DSL with the help of identity: The Context Method

     Trade trade = new Trade()
     trade.identity {
          setOrderId(1)
          setOrderStatus(false)
          setEquityName("Fictious Inc")
          setQuantity(100)
          setPrice(17.25)
      }


                                                    21
Clojure a Lisp dialect on JVM
Why Clojure
  – Predominately functional language
  – Stateless
  – Homoiconicity
  – (Un)digestive Syntax – Which you might fall in love
    later
  – Persistent data structures
  – STM
  – Atom and Agents


                                                          22
Clojure – Functional
  Predominately Functional language

  (defn name doc-string? attr-map? [params*] body)
  (defn helloworld [username] “returns a String hello message”
    (str “Hello,” username))


  Dynamic Language
  Resolves types at runtime




                                                                 23
Clojure – Homoiconicity
 Representation of its own data structures and atomic
 values or more casually code-as-data and data-as-code

 (defn average [numbers]
   (/ (apply + numbers) (count numbers)))
                            Stateless
 This definition is a list of data structure containing symbols,
 values, vectors and another list consists of function body

 (+ 7 3) on REPL yields
 => (+ 7 3)
 10                                                                24
Clojure – Homoiconicity
Data as Code – Consider map
 (def names {"Rich" "Hickey" "Martin" "Odersky"})


 Now use names as function
 (names “Rich”) will result in Hickey
 else more verbose get
 (get names “Rich” “None”)


 Any Clojure data structure can be a key in a map
  (def names {:Lisp “Rich” :Scala “Martin”})
                                                    25
Clojure – Parenthesis and Prefix Notation
  A method in general of most of the languages
   methodName(arg1, arg2, arg3);


  A clojure function has prefix notation
   (function-name arg1 arg2 arg3)


  Imagine if you want to operate on a large list of values
   sum (60+80+90+120)


  Whereas in Lisp or Clojure syntax
   (apply + [60 80 90 120])
                                                             26
Clojure – Functional
First Class Functions
  Functions that always return the same result when passed the
  same arguments
  Functions exist as data (function value).



Higher Order Functions
  Take other functions as arguments or return a function as a
  result.




                                                                 27
Clojure – Collections
All of them are immutable, heterogeneous and persistent.

  Heterogeneous means that they can hold any kind of
  object.

  Being persistent means that old versions of them are
  preserved when new versions are created.

  Very rich data structures as well functions to operate on.


                                                           28
Clojure – Sequences
• In Clojure, all these data structures can be accessed
  through a single abstraction: the sequence (seq)

• Every aggregate data structure in Clojure can be viewed
  as a sequence

• (first {"Rich" "Hickey" "Martin" "Odersky"})
• (rest {"Rich" "Hickey" "Martin" "Odersky"})
• (cons [“James" “Gosling“] {"Rich" "Hickey" "Martin"
  "Odersky"})

                                                            29
Clojure – STM
 Software Transactional Manager is the way to handle
   concurrency of mutable data in Clojure.
   STM is very optimistic.

 Alternative to lock based synchronization.
   Mutual Exclusion

 Every read and write that it is performing is in a log.

 Onus is on reader which will commit to the shared memory in
  case no modifications are done during the time, else would
  re-execute the transaction.

                                                               30
Clojure – STM
 Mutable References
   ref, deref or @ , ref-set, dosync

 Need to be explicit when mutable data is required.
   (def value (ref 100))
 ref wraps and protects access to its internal state.

 Even to read, it needs to deref
   (deref value) or @value

 As the value is in STM

                                                        31
Clojure – STM
 STM provides similar transaction properties of a Database
 But STM handles in memory, so can’t guarantee durability.

 • Updates are atomic. If you update more than one ref in a
   transaction, the cumulative effect of all the updates will
   appear as a single instantaneous event to anyone not inside
   your transaction.
                             Stateless

 • Updates are consistent. Refs can specify validation functions.
   If any of these functions fail, the entire transaction will fail.

 • Updates are isolated. Running transactions cannot see
   partially completed results from other transactions.

                                                                       32
Clojure – STM
 Agents

   Agents provide independent, asynchronous change of individual
   locations.

   Agents are bound to a single storage location for their
   lifetime, and only allow mutation of that location (to a new
   state) to occur as a result of an action.




                                                                  33
Interop – Clojure to Java
  Clojure is complied and generates Bytecode
  Clojure embraces Java and its libraries. Idiomatic
  Clojure code can call Java libraries directly

  Creating Java instances and accessing its methods.
  In REPL:
                               Stateless
  (def cal (java.util.Calendar/getInstance)
  (. cal getTime)

  Code:
  (import [java.util.Calendar])
  (defn cal (.getInstance java.util.Calendar))
                                                       34
Interop – Java to Clojure
  Clojure is implemented as Java class library.
  Embed Clojure using load code and call functions

  import clojure.lang.RT;
  import clojure.lang.Var;
  public class Foo {
     public static void main(String[] args) throws Exception {
                                Stateless

     RT.loadResourceScript("foo.clj"); Var foo = RT.var("user", "foo");
     Object result = foo.invoke("Hi", "there");
     System.out.println(result);
     }
   }
  (“user” being the namespace and “foo” being the function from Clj)
                                                                          35
Polylingualism
 Sapir-Whorf Hypothesis

 According to the first, linguistic determinism,
 our thinking is determined by language.

 According to the second, linguistic relativity,
 people who speak different languages
 perceive and think about the world quite
 differently.
                                                   36
References

 Programming in Scala (Martin Odersky, Lex Spoon, Bill Venners)
 Clojure Programming (Chas Emerick, Brian Carper, Christophe
   Grand)
 Programming Clojure (Stuart Halloway)
 Well Gounded Java Developer (Benjamin Evans, Martin Verburg)
 Programming in Groovy (Venkat Subramaniam)
 Wikipedia.org




                                                                  37
Thank you !

gmail mohanjune@gmail.com
twitter @mohanjune Stateless




                               38

Más contenido relacionado

La actualidad más candente

Better DSL Support for Groovy-Eclipse
Better DSL Support for Groovy-EclipseBetter DSL Support for Groovy-Eclipse
Better DSL Support for Groovy-EclipseAndrew Eisenberg
 
Clojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVMClojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVMMatthias Nüßler
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than everKai Koenig
 
Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)RichardWarburton
 
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
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampKai Koenig
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdfHiroshi Ono
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)lennartkats
 
Generics Past, Present and Future
Generics Past, Present and FutureGenerics Past, Present and Future
Generics Past, Present and FutureRichardWarburton
 
Generics past, present and future
Generics  past, present and futureGenerics  past, present and future
Generics past, present and futureRichardWarburton
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Akshay Nagpurkar
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in ScalaPatrick Nicolas
 
Incremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a WebsiteIncremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a WebsiteJames Long
 
2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritancebergel
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakensRichardWarburton
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to ScalaTim Underwood
 
Scala for the doubters
Scala for the doubtersScala for the doubters
Scala for the doubtersMax Klyga
 

La actualidad más candente (18)

Better DSL Support for Groovy-Eclipse
Better DSL Support for Groovy-EclipseBetter DSL Support for Groovy-Eclipse
Better DSL Support for Groovy-Eclipse
 
Clojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVMClojure - A practical LISP for the JVM
Clojure - A practical LISP for the JVM
 
2017: Kotlin - now more than ever
2017: Kotlin - now more than ever2017: Kotlin - now more than ever
2017: Kotlin - now more than ever
 
Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)Generics Past, Present and Future (Latest)
Generics Past, Present and Future (Latest)
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcamp
 
scalaliftoff2009.pdf
scalaliftoff2009.pdfscalaliftoff2009.pdf
scalaliftoff2009.pdf
 
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
Domain-Specific Languages for Composable Editor Plugins (LDTA 2009)
 
Generics Past, Present and Future
Generics Past, Present and FutureGenerics Past, Present and Future
Generics Past, Present and Future
 
Generics past, present and future
Generics  past, present and futureGenerics  past, present and future
Generics past, present and future
 
Ppl for students unit 4 and 5
Ppl for students unit 4 and 5Ppl for students unit 4 and 5
Ppl for students unit 4 and 5
 
Collections forceawakens
Collections forceawakensCollections forceawakens
Collections forceawakens
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
Incremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a WebsiteIncremental Development with Lisp: Building a Game and a Website
Incremental Development with Lisp: Building a Game and a Website
 
2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritance
 
Java collections the force awakens
Java collections  the force awakensJava collections  the force awakens
Java collections the force awakens
 
A Brief Intro to Scala
A Brief Intro to ScalaA Brief Intro to Scala
A Brief Intro to Scala
 
Scala for the doubters
Scala for the doubtersScala for the doubters
Scala for the doubters
 

Destacado

MedicinMan September 2012
MedicinMan  September 2012MedicinMan  September 2012
MedicinMan September 2012Anup Soans
 
Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'
Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'
Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'JISC RSC Eastern
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudIndicThreads
 
Lets SAASify that Desktop Application
Lets SAASify that Desktop ApplicationLets SAASify that Desktop Application
Lets SAASify that Desktop ApplicationIndicThreads
 
E learning forum oct 2013 - Introduction & News Update
E learning forum oct 2013 - Introduction & News UpdateE learning forum oct 2013 - Introduction & News Update
E learning forum oct 2013 - Introduction & News UpdateJISC RSC Eastern
 
Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...
Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...
Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...JISC RSC Eastern
 
STM in Haskell
STM in HaskellSTM in Haskell
STM in Haskellbegriffs
 
Transactional Memory for Smalltalk
Transactional Memory for SmalltalkTransactional Memory for Smalltalk
Transactional Memory for SmalltalkLukas Renggli
 
jvm/java - towards lock-free concurrency
jvm/java - towards lock-free concurrencyjvm/java - towards lock-free concurrency
jvm/java - towards lock-free concurrencyArvind Kalyan
 
Research Review Slides
Research Review SlidesResearch Review Slides
Research Review Slideskarsithe
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMVaclav Pech
 
Sql Server 2014 In Memory
Sql Server 2014 In MemorySql Server 2014 In Memory
Sql Server 2014 In MemoryRavi Okade
 
ClojureではじめるSTM入門
ClojureではじめるSTM入門ClojureではじめるSTM入門
ClojureではじめるSTM入門sohta
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threadsmperham
 
Implementing STM in Java
Implementing STM in JavaImplementing STM in Java
Implementing STM in JavaMisha Kozik
 
Transactional Memory
Transactional MemoryTransactional Memory
Transactional MemoryYuuki Takano
 
Applications of Hierarchical Temporal Memory (HTM)
Applications of Hierarchical Temporal Memory (HTM)Applications of Hierarchical Temporal Memory (HTM)
Applications of Hierarchical Temporal Memory (HTM)Numenta
 

Destacado (20)

MedicinMan September 2012
MedicinMan  September 2012MedicinMan  September 2012
MedicinMan September 2012
 
Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'
Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'
Jisc RSC Eastern Technical Managers forum June 2013 'BYOD Tech Managers forum'
 
Rsc eastern 2010
Rsc eastern 2010Rsc eastern 2010
Rsc eastern 2010
 
Running your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the CloudRunning your Java EE 6 applications in the Cloud
Running your Java EE 6 applications in the Cloud
 
Lets SAASify that Desktop Application
Lets SAASify that Desktop ApplicationLets SAASify that Desktop Application
Lets SAASify that Desktop Application
 
E learning forum oct 2013 - Introduction & News Update
E learning forum oct 2013 - Introduction & News UpdateE learning forum oct 2013 - Introduction & News Update
E learning forum oct 2013 - Introduction & News Update
 
Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...
Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...
Jisc RSC Eastern Learning Resources Managers forum 14/03/14 - Mobile users an...
 
STM in Haskell
STM in HaskellSTM in Haskell
STM in Haskell
 
Transactional Memory for Smalltalk
Transactional Memory for SmalltalkTransactional Memory for Smalltalk
Transactional Memory for Smalltalk
 
jvm/java - towards lock-free concurrency
jvm/java - towards lock-free concurrencyjvm/java - towards lock-free concurrency
jvm/java - towards lock-free concurrency
 
Research Review Slides
Research Review SlidesResearch Review Slides
Research Review Slides
 
Core Java Part-1
Core Java Part-1Core Java Part-1
Core Java Part-1
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Sql Server 2014 In Memory
Sql Server 2014 In MemorySql Server 2014 In Memory
Sql Server 2014 In Memory
 
ClojureではじめるSTM入門
ClojureではじめるSTM入門ClojureではじめるSTM入門
ClojureではじめるSTM入門
 
Actors and Threads
Actors and ThreadsActors and Threads
Actors and Threads
 
Implementing STM in Java
Implementing STM in JavaImplementing STM in Java
Implementing STM in Java
 
Transactional Memory
Transactional MemoryTransactional Memory
Transactional Memory
 
Applications of Hierarchical Temporal Memory (HTM)
Applications of Hierarchical Temporal Memory (HTM)Applications of Hierarchical Temporal Memory (HTM)
Applications of Hierarchical Temporal Memory (HTM)
 
HTM Theory
HTM TheoryHTM Theory
HTM Theory
 

Similar a JVM Polyglot and Functional Programming

Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypseelliando dias
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistpmanvi
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Mark Menard
 
Scala overview
Scala overviewScala overview
Scala overviewSteve Min
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationMartin Odersky
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John StevensonJAX London
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMarakana Inc.
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overviewstasimus
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaDmitry Buzdin
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?sbjug
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with ClojureJohn Stevenson
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaScala Italy
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to ClojureRenzo Borgatti
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論scalaconfjp
 
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 DevelopersMiles Sabin
 
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 DevelopersSkills Matter
 

Similar a JVM Polyglot and Functional Programming (20)

Clojure and The Robot Apocalypse
Clojure and The Robot ApocalypseClojure and The Robot Apocalypse
Clojure and The Robot Apocalypse
 
Scala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on Heroku
 
Scala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologistScala and jvm_languages_praveen_technologist
Scala and jvm_languages_praveen_technologist
 
Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1Ruby on Rails Training - Module 1
Ruby on Rails Training - Module 1
 
Scala overview
Scala overviewScala overview
Scala overview
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Clojure made-simple - John Stevenson
Clojure made-simple - John StevensonClojure made-simple - John Stevenson
Clojure made-simple - John Stevenson
 
Martin Odersky: What's next for Scala
Martin Odersky: What's next for ScalaMartin Odersky: What's next for Scala
Martin Odersky: What's next for Scala
 
Seeking Clojure
Seeking ClojureSeeking Clojure
Seeking Clojure
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in Scala
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?I know Java, why should I consider Clojure?
I know Java, why should I consider Clojure?
 
Getting started with Clojure
Getting started with ClojureGetting started with Clojure
Getting started with Clojure
 
Martin Odersky - Evolution of Scala
Martin Odersky - Evolution of ScalaMartin Odersky - Evolution of Scala
Martin Odersky - Evolution of Scala
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論The Evolution of Scala / Scala進化論
The Evolution of Scala / Scala進化論
 
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 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
 

Más de IndicThreads

Http2 is here! And why the web needs it
Http2 is here! And why the web needs itHttp2 is here! And why the web needs it
Http2 is here! And why the web needs itIndicThreads
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive ApplicationsUnderstanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive ApplicationsIndicThreads
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang wayGo Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang wayIndicThreads
 
Building Resilient Microservices
Building Resilient Microservices Building Resilient Microservices
Building Resilient Microservices IndicThreads
 
App using golang indicthreads
App using golang  indicthreadsApp using golang  indicthreads
App using golang indicthreadsIndicThreads
 
Building on quicksand microservices indicthreads
Building on quicksand microservices  indicthreadsBuilding on quicksand microservices  indicthreads
Building on quicksand microservices indicthreadsIndicThreads
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingIndicThreads
 
Iot secure connected devices indicthreads
Iot secure connected devices indicthreadsIot secure connected devices indicthreads
Iot secure connected devices indicthreadsIndicThreads
 
Real world IoT for enterprises
Real world IoT for enterprisesReal world IoT for enterprises
Real world IoT for enterprisesIndicThreads
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIndicThreads
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present FutureIndicThreads
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams IndicThreads
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fameBuilding & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fameIndicThreads
 
Internet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads ConferenceInternet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads ConferenceIndicThreads
 
Cars and Computers: Building a Java Carputer
 Cars and Computers: Building a Java Carputer Cars and Computers: Building a Java Carputer
Cars and Computers: Building a Java CarputerIndicThreads
 
Scrap Your MapReduce - Apache Spark
 Scrap Your MapReduce - Apache Spark Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache SparkIndicThreads
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & DockerIndicThreads
 
Speed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedbackSpeed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedbackIndicThreads
 
Unraveling OpenStack Clouds
 Unraveling OpenStack Clouds Unraveling OpenStack Clouds
Unraveling OpenStack CloudsIndicThreads
 
Digital Transformation of the Enterprise. What IT leaders need to know!
Digital Transformation of the Enterprise. What IT  leaders need to know!Digital Transformation of the Enterprise. What IT  leaders need to know!
Digital Transformation of the Enterprise. What IT leaders need to know!IndicThreads
 

Más de IndicThreads (20)

Http2 is here! And why the web needs it
Http2 is here! And why the web needs itHttp2 is here! And why the web needs it
Http2 is here! And why the web needs it
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive ApplicationsUnderstanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang wayGo Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang way
 
Building Resilient Microservices
Building Resilient Microservices Building Resilient Microservices
Building Resilient Microservices
 
App using golang indicthreads
App using golang  indicthreadsApp using golang  indicthreads
App using golang indicthreads
 
Building on quicksand microservices indicthreads
Building on quicksand microservices  indicthreadsBuilding on quicksand microservices  indicthreads
Building on quicksand microservices indicthreads
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
 
Iot secure connected devices indicthreads
Iot secure connected devices indicthreadsIot secure connected devices indicthreads
Iot secure connected devices indicthreads
 
Real world IoT for enterprises
Real world IoT for enterprisesReal world IoT for enterprises
Real world IoT for enterprises
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreads
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fameBuilding & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fame
 
Internet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads ConferenceInternet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads Conference
 
Cars and Computers: Building a Java Carputer
 Cars and Computers: Building a Java Carputer Cars and Computers: Building a Java Carputer
Cars and Computers: Building a Java Carputer
 
Scrap Your MapReduce - Apache Spark
 Scrap Your MapReduce - Apache Spark Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache Spark
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 
Speed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedbackSpeed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedback
 
Unraveling OpenStack Clouds
 Unraveling OpenStack Clouds Unraveling OpenStack Clouds
Unraveling OpenStack Clouds
 
Digital Transformation of the Enterprise. What IT leaders need to know!
Digital Transformation of the Enterprise. What IT  leaders need to know!Digital Transformation of the Enterprise. What IT  leaders need to know!
Digital Transformation of the Enterprise. What IT leaders need to know!
 

JVM Polyglot and Functional Programming

  • 1. Polyglot and Functional Programming on the Java Virtual Machine Mohan Kumar Muddana InfoStretch Pvt. Ltd.
  • 2. Some of the languages on JVM 2
  • 3. Why so many languages on JVM • JVM has grown over the years and has become a mature platform. • Very wide industry adoption. • Availability of large developer community. • Plethora of Tools and Technologies 3
  • 4. Polyglot Programming on the JVM • Different languages bring in different features. • Wider choice of availability. • Better programming features. • Imperative and Functional • Interoperability between the languages. 4
  • 5. JVM – The Polyglot Platform JVM was initially built for (Java) Classes. How does it handles so different kind of language constructs. the Da Vinci Machine Project (http://openjdk.java.net/projects/mlvm/) 5
  • 6. How JVM incorporates and consumes Java 6 : - JSR 223: Scripting for the Java Platform (Groovy, Jython, JRuby) Java 7 :- JSR 292: Supporting Dynamically Typed Languages on the JavaTM Platform MLVM – Multi Language Virtual Machine. 6
  • 7. History of Functional Programming Alonzo Church Creator of λ-Calculus – 1940 λ-Calculus is the basis of all functional programming languages 7
  • 8. History of Functional Programming • What does it fundamentally say- A function is an action that is applied to one thing (the argument) to obtain another thing (the value). • Two Fundamental functions in λ-Calculus (I, the identity function). I is defined as follows: (Ix) is x, whatever x may be. (H). H is defined as the function that always returns the identity function. That is, (Hx) is I for whatever x may be. 8
  • 9. Functional Programming • Derives from mathematics, Lambda Calculus • Built on the basis of functions • Immutability and Concurrency • Data Structures with strong filtering • Lesser code with fewer language constructs. 9
  • 10. Functional Programming Languages • Lisp – One of t he oldest programming language (Lisp is functional language) • Haskel – Pure functional language • Erlang - Massively scalable soft real-time systems with requirements on high availability and fault tolerant systems. • Scheme, ML, OCAML etc. • And many others 10
  • 11. Scala Language aka Scalable Why Scala Ordersky says: "We wanted to make Java more expressive, so people could be more productive" and write at a higher level of abstraction with fewer lines of code, Odersky says. How it is scalable Getting Started 11
  • 12. Scala – Object World • Scala is Pure Object Oriented Language • Traits • Case Classes and Pattern Matching • Type safety and Type Erasure 12
  • 13. Scala – Classes and Objects Everything is objects. Store objects into a variables. class HelloWorld() { val welcome: String = “Hello World ” def msg(name: String) = println(welcome + name) } val h = new HelloWorld() h.msg(“Your Name”) 13
  • 14. Scala – Traits It is an kind of an Interface with fields and concrete methods. Unlike Class inheritance, a class can mix (Mixins) in any number of traits. trait PolyglotProgrammer { def polyProg() { println("Polyglot Programmer") } } class Person extends PolyglotProgrammer with PolyglotSpeaker {} val person = new Person println(person.polyProg) println(person.polySpeaker) 14
  • 15. Scala – Case Classes and Pattern Match • Case classes provides pattern matching on objects without large amount of boilerplate code. • Case classes are normal classes with a case modifier as prefix. case Class Rectangle(length: Int, breadth: Int) 15
  • 16. Scala – Case Classes and Pattern Match Case Classes comes with additional conventions - The compiler adds a factory method with the name of the class, so no need to create an instance with new operator. - All arguments in the parameter list gets implicit val prefix, so they are maintained as fields. - Compiler adds natural implementations of toString, hashCode and equals. 16
  • 17. Groovy Groovy is the closest to Java language. Supports both static and dynamic type binding. Powerful XML processing constructs. Very good support for regular expressions 17
  • 18. Groovy – XML Processing def writer = new StringWriter(); def xml = new groovy.xml.MarkupBuilder(writer); xml.person(id:2) { name 'Gweneth‘ age 1 } println writer.toString(); <person id='2'> <name>Gweneth</name> <age>1</age> </person> 18
  • 19. Groovy Beans - Conciseness class Person { private String name private int age } def p = new Person(name: “Ramu”, age: 15) (No syntactic ceremony) @Immutable annotation to make it immutable 19
  • 20. Groovy – Elvis Operator ?: In Java if/else construct would look like this String tradeStatus = "Active"; String status = tradeStatus != null ? tradeStatus : “Inactive"; In Groovy String tradeStatus = "Active" String status = tradeStatus ?: "Inactive“ Groovy coerces the String into a boolean; assuming the String was null, it will convert to the Boolean value of false. No ceremonial Null Pointer check 20
  • 21. Groovy – DSL DSL with the help of identity: The Context Method Trade trade = new Trade() trade.identity { setOrderId(1) setOrderStatus(false) setEquityName("Fictious Inc") setQuantity(100) setPrice(17.25) } 21
  • 22. Clojure a Lisp dialect on JVM Why Clojure – Predominately functional language – Stateless – Homoiconicity – (Un)digestive Syntax – Which you might fall in love later – Persistent data structures – STM – Atom and Agents 22
  • 23. Clojure – Functional Predominately Functional language (defn name doc-string? attr-map? [params*] body) (defn helloworld [username] “returns a String hello message” (str “Hello,” username)) Dynamic Language Resolves types at runtime 23
  • 24. Clojure – Homoiconicity Representation of its own data structures and atomic values or more casually code-as-data and data-as-code (defn average [numbers] (/ (apply + numbers) (count numbers))) Stateless This definition is a list of data structure containing symbols, values, vectors and another list consists of function body (+ 7 3) on REPL yields => (+ 7 3) 10 24
  • 25. Clojure – Homoiconicity Data as Code – Consider map (def names {"Rich" "Hickey" "Martin" "Odersky"}) Now use names as function (names “Rich”) will result in Hickey else more verbose get (get names “Rich” “None”) Any Clojure data structure can be a key in a map (def names {:Lisp “Rich” :Scala “Martin”}) 25
  • 26. Clojure – Parenthesis and Prefix Notation A method in general of most of the languages methodName(arg1, arg2, arg3); A clojure function has prefix notation (function-name arg1 arg2 arg3) Imagine if you want to operate on a large list of values sum (60+80+90+120) Whereas in Lisp or Clojure syntax (apply + [60 80 90 120]) 26
  • 27. Clojure – Functional First Class Functions Functions that always return the same result when passed the same arguments Functions exist as data (function value). Higher Order Functions Take other functions as arguments or return a function as a result. 27
  • 28. Clojure – Collections All of them are immutable, heterogeneous and persistent. Heterogeneous means that they can hold any kind of object. Being persistent means that old versions of them are preserved when new versions are created. Very rich data structures as well functions to operate on. 28
  • 29. Clojure – Sequences • In Clojure, all these data structures can be accessed through a single abstraction: the sequence (seq) • Every aggregate data structure in Clojure can be viewed as a sequence • (first {"Rich" "Hickey" "Martin" "Odersky"}) • (rest {"Rich" "Hickey" "Martin" "Odersky"}) • (cons [“James" “Gosling“] {"Rich" "Hickey" "Martin" "Odersky"}) 29
  • 30. Clojure – STM Software Transactional Manager is the way to handle concurrency of mutable data in Clojure. STM is very optimistic. Alternative to lock based synchronization. Mutual Exclusion Every read and write that it is performing is in a log. Onus is on reader which will commit to the shared memory in case no modifications are done during the time, else would re-execute the transaction. 30
  • 31. Clojure – STM Mutable References ref, deref or @ , ref-set, dosync Need to be explicit when mutable data is required. (def value (ref 100)) ref wraps and protects access to its internal state. Even to read, it needs to deref (deref value) or @value As the value is in STM 31
  • 32. Clojure – STM STM provides similar transaction properties of a Database But STM handles in memory, so can’t guarantee durability. • Updates are atomic. If you update more than one ref in a transaction, the cumulative effect of all the updates will appear as a single instantaneous event to anyone not inside your transaction. Stateless • Updates are consistent. Refs can specify validation functions. If any of these functions fail, the entire transaction will fail. • Updates are isolated. Running transactions cannot see partially completed results from other transactions. 32
  • 33. Clojure – STM Agents Agents provide independent, asynchronous change of individual locations. Agents are bound to a single storage location for their lifetime, and only allow mutation of that location (to a new state) to occur as a result of an action. 33
  • 34. Interop – Clojure to Java Clojure is complied and generates Bytecode Clojure embraces Java and its libraries. Idiomatic Clojure code can call Java libraries directly Creating Java instances and accessing its methods. In REPL: Stateless (def cal (java.util.Calendar/getInstance) (. cal getTime) Code: (import [java.util.Calendar]) (defn cal (.getInstance java.util.Calendar)) 34
  • 35. Interop – Java to Clojure Clojure is implemented as Java class library. Embed Clojure using load code and call functions import clojure.lang.RT; import clojure.lang.Var; public class Foo { public static void main(String[] args) throws Exception { Stateless RT.loadResourceScript("foo.clj"); Var foo = RT.var("user", "foo"); Object result = foo.invoke("Hi", "there"); System.out.println(result); } } (“user” being the namespace and “foo” being the function from Clj) 35
  • 36. Polylingualism Sapir-Whorf Hypothesis According to the first, linguistic determinism, our thinking is determined by language. According to the second, linguistic relativity, people who speak different languages perceive and think about the world quite differently. 36
  • 37. References Programming in Scala (Martin Odersky, Lex Spoon, Bill Venners) Clojure Programming (Chas Emerick, Brian Carper, Christophe Grand) Programming Clojure (Stuart Halloway) Well Gounded Java Developer (Benjamin Evans, Martin Verburg) Programming in Groovy (Venkat Subramaniam) Wikipedia.org 37
  • 38. Thank you ! gmail mohanjune@gmail.com twitter @mohanjune Stateless 38

Notas del editor

  1. Imperative, Interpreted, Java Scripting, Dynamic, Language ports, Functional languages. P - built for the electronic arts and visual design GOSU – General Purpose Fantom – General Purpose
  2. Language experts target JVM because of all of the above reasons. You might think since JVM is built for Objects how it handles Functions (Focus on invokedynamic)
  3. Till now being a Java Developer we have several tools and frameworks to choose from. Now we have wider choice with languages itself. Disadvantage- More choice means confusion. A person who has got a flavor of functional language can pick the other one with some ease.
  4. JVM as such doesn’t know anything about Java Language, only a particular format of .class file. The new languages which are targeted makes sure the bytcode generated is as close as Java objects. These languages also have their runtime( supporting libraries) supporting JVM. Some are static type and some are dynamic languages.
  5. Any language with functionality that can be expressed in terms of valid class file can be hosted by the Virtual Machine. Similar revolution is happening around in the Microsoft world and with CLR (Common Language Runtime) and DLR (Dynamic Language Runtime). If anyone has any little affinity with .Net this would be interesting. Around 55 languages are listed in the Wikipedia which run on CLR. And in fact .Net has opened its doors much earlier than the JVM.
  6. Lambda calculus is much older than modern day digital computers. A function is a rule of correspondence by which when anything is given (as argument) another thing (the value of the function for that argument) may be obtained.
  7. Lambda calculus is much older than modern day digital computers. A function is a rule of correspondence by which when anything is given (as argument) another thing (the value of the function for that argument) may be obtained.
  8. Major paradigm shift from OOPs to Functional Initially difficult to grasp. Functional programming is the way to go. One cant ignore it. Being a Java developer it is going to knock at your door with Lambda expressions with the release of Java 8.
  9. These languages have their own runtime.
  10. There are older Functional languages like Lisp, Haskel, Erlang Scala is both OO and Functional. It’s a nice blend between the two. Martin wanted to take the niceties of both the worlds (Imperative and Functional) Scala has very little language constructs. What you feel like built in methods or constructs are not part of the core language but provided by Scala library. you can design and implement abstractions in Scala that address radically new application domains, yet still feel like native language support.
  11. Arguments for Pure Object Oriented Language
  12. No primitives wandering around your objects. Java like classes definitions.
  13. Traits: How does it help Unlike Abstract classes in Java where you can’t extend more than one abstract class, neither you can have implement several Interfaces implementations. Moving the different features to different Traits makes lot of sense. Several classes may want to have different common traits.
  14. toString, hashCode and equals will print, hash, and compare a whole tree consisting of the class and (recursively) all its arguments. Case pattern is also applicable to Constants, Sequence, Tuple etc. Almost solves Visitor pattern easily without any if and else. To avoid a MatchError exception add a default case which does nothing.
  15. toString, hashCode and equals will print, hash, and compare a whole tree consisting of the class and (recursively) all its arguments. Case pattern is also applicable to Constants, Sequence, Tuple etc. Almost solves Visitor pattern easily without any if and else. To avoid a MatchError exception add a default case which does nothing.
  16. Performance of Groovy has been questioned it is mostly scripting. With the invodedynamic coming with java7 would considerably increase its speed.
  17. Performance of Groovy has been questioned it is mostly scripting. With the invodedynamic coming with java7 would considerably increase its speed.
  18. Performance of Groovy has been questioned it is mostly scripting. With the invodedynamic coming with java7 would considerably increase its speed.
  19. So, what is so special about it. Groovy can shorten this because it coerces types to boolean values as needed, such as in conditional checks like if statements. In the preceding code snippet, Groovy coerces the String into a boolean; assuming the String was null, it will convert to the Boolean value of false, so you can omit the null check. You can then write the previous snippet as follows:
  20. Performance of Groovy has been questioned it is mostly scripting. With the invodedynamic coming with java7 would considerably increase its speed.
  21. Duck typing is aided by habitually not testing for the type of arguments in method and function bodies, relying on documentation, clear code and testing to ensure correct use.
  22. Most languages parse the textual code into abstract syntax tree (AST). Clojure programs are written using data structures that represent that AST directly. This becomes basis for macros, meta programming features. Though Clojure code is in text format, those texts are in fact Clojure data structures.
  23. (inventors :Clojure) ) &quot;Hickey&quot; (:Clojure inventors) ) &quot;Hickey&quot; Report
  24. If a large set of variables need to be applied the same operation, the repetition of the operator is avoided. Clojure gives a function ‘let’ to store independent
  25. [ Clojure does this in a very efficient manner where new versions share memory with old versions .]
  26. A thread completes modifications to shared memory without regard for what other threads might be doing, recording every read and write that it is performing in a log. it is placed on the reader, who after completing an entire transaction verifies that other threads have not concurrently made changes to memory that it accessed in the past. This final operation, in which the changes of a transaction are validated and, if validation is successful, made permanent, is called a commit . A transaction may also abort at any time, causing all of its prior changes to be rolled back or undone. If a transaction cannot be committed due to conflicting changes, it is typically aborted and re-executed from the beginning until it succeeds.
  27. Databases provide the additional guarantee that updates are durable . Because Clojure’s transactions are in-memory transactions, Clojure does not guarantee that updates are durable. If you want a durable transaction in Clojure, you should use a databases
  28. Databases provide the additional guarantee that updates are durable . Because Clojure’s transactions are in-memory transactions, Clojure does not guarantee that updates are durable. If you want a durable transaction in Clojure, you should use a databases
  29. Databases provide the additional guarantee that updates are durable . Because Clojure’s transactions are in-memory transactions, Clojure does not guarantee that updates are durable. If you want a durable transaction in Clojure, you should use a databases
  30. Load the Clojure script -- as a side effect this initializes the runtime. Get a reference to the foo function. Call it!