Andres	  Almiray	        @aalmiray	  Polyglot Programming      in the JVM
ABOUT THE SPEAKERJava developer since the beginningTrue believer in Open SourceGroovy committer since 2007Project lead of ...
SOME FACTS ABOUTJAVAPrevious name was Oak. Bonus points for knowing its realname before thatMade its public appearance in ...
HOWEVER...It‘s already in its teensIt has not seen a groundbreaking feature upgrade since JDK5was released back in 2004 ->...
MORE SO...It is rather verbose when compared to how other languagesdo the same taskIts threading features are no longer en...
TRUTH OR MYTH?Is Java oftenly referred as overengineered?Can you build a Java based web application (for argumentssake a b...
The JVM is a greatplace to work howeverJava makes it painfulsometimes...
What can we do about it?!
DISCLAIMER(THIS IS NOT A BASH-THE-OTHER-LANGUAGES TALK)
REDUCEDVERBOSITY
STANDARD BEANSpublic class Bean {    private String name;    public String getName() {        return name;    }    public ...
STANDARD BEANSpublic class Bean {    private String name;    public String getName() {        return name;    }    public ...
STANDARD BEANSclass Bean {    String name}
STANDARD BEANSclass Bean(var name:String)class Bean {  @scala.reflect.BeanProperty  var name: String}
STANDARD BEANS(defstruct Bean :name)
CLOSURES (OR FUNCTIONS)public interfaceAdder {    int add(int a, int b);}public class  MyAdder implements Adder {    publi...
CLOSURES (OR FUNCTIONS)// JDK7^H8 Closures proposal(int a, int b)(a + b)#(int a, int b) { return a + b; }(int a, int b) ->...
CLOSURES (OR FUNCTIONS)def adder = { a , b -> a + b }
CLOSURES (OR FUNCTIONS)val adder = (a:Int, b:Int) => a + b
CLOSURES (OR FUNCTIONS)(defn adder [a b] (+ a b))
ENHANCED SWITCHchar letterGrade(int grade) {    if(grade >= 0 && grade <= 60) return ‘F‘;    if(grade > 60 && grade <= 70)...
ENHANCED SWITCHdef letterGrade(grade) {  switch(grade) {     case 90..100: return ‘A‘     case 80..<90: return ‘B‘     cas...
ENHANCED SWITCHval VALID_GRADES = Set("A", "B", "C", "D", "F")def letterGrade(value: Any):String = value match {  case x:I...
ENHANCED SWITCH(defn letter-grade [grade]  (cond   (in grade 90 100) "A"   (in grade 80 90) "B"   (in grade 70 80) "C"   (...
JAVAINTEROPERABILITY
ALL OF THESE ARETRUEJava can call Groovy, Scala and Clojure classes as if theywere Java classesGroovy, Scala and Clojure c...
OK, SO...WHAT ELSECAN THESELANGUAGESDO?
ALL OF THEMNative syntax for collection classesEverything is an objectClosures!Regular expressions as first class citizen
GROOVYMetaprogramming (HOT!) both at buildtime and runtimeBuildersOperator overloadingHealthy ecosystem: Grails, Griffon, ...
SCALARicher type systemFunctional meets Object OrientedType inferencePattern matching (+ case classes)Actor modelCreate yo...
CLOJUREData as code and viceversaImmutable structuresSTMNot an exhaustive list of features!
DEMO
OTHER PLACESWHERE YOU‘LLFINDPOLYGLOTPROGRAMMING
WEB APPDEVELOPMENTXMLSQLJavaScriptJSONCSSFlash/Flex/ActionScript
NEXT-GENDATASTORES (NOSQL)FleetDB -> ClojureFlockDB -> ScalaCouchDB, Riak -> ErlangBy the way, watch out for Polyglot Pers...
BUILD SYSTEMSGradle, Gant -> GroovyRake -> Ruby/JRubyMaven3 -> XML, Groovy, RubySBT -> ScalaLeiningen -> Clojure
PARTING THOUGHTSJava (the language) may have reached its maturity featurewiseOther JVM languages have evolved fasterPolygl...
RESOURCES
RESOURCES
RESOURCES
Q&A
Thank You!                @aalmirayandres.almiray@canoo.com
Polyglot Programming in the JVM - 33rd Degree
Polyglot Programming in the JVM - 33rd Degree
Polyglot Programming in the JVM - 33rd Degree
Polyglot Programming in the JVM - 33rd Degree
Upcoming SlideShare
Loading in...5
×

Polyglot Programming in the JVM - 33rd Degree

764

Published on

Polyglot Programming in the JVM - 33rd Degree

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
764
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Polyglot Programming in the JVM - 33rd Degree

  1. 1. Andres  Almiray   @aalmiray  Polyglot Programming in the JVM
  2. 2. ABOUT THE SPEAKERJava developer since the beginningTrue believer in Open SourceGroovy committer since 2007Project lead of the Griffon frameworkCurrently working for
  3. 3. SOME FACTS ABOUTJAVAPrevious name was Oak. Bonus points for knowing its realname before thatMade its public appearance in 1995C/C++ were king at the timeNetworking, multithreading were baked right into thelanguageDevelopers came for the applets and stayed for thecomponents (JEE and all that jazz)
  4. 4. HOWEVER...It‘s already in its teensIt has not seen a groundbreaking feature upgrade since JDK5was released back in 2004 -> generics (and we do know howthat turned out to be, don’t we?)JDK7 was delayed again (late 2010, actual 2011). Somefeatures did not make the cut (lambdas)JDK8, late 2013?
  5. 5. MORE SO...It is rather verbose when compared to how other languagesdo the same taskIts threading features are no longer enough. Concurrentprograms desperately cry for immutability these days
  6. 6. TRUTH OR MYTH?Is Java oftenly referred as overengineered?Can you build a Java based web application (for argumentssake a basic Twitter clone) in less than a day‘s workWITHOUT an IDE?Did James Gosling ever say he was threatened with bodilyharm should operator overloading find its way into Java?
  7. 7. The JVM is a greatplace to work howeverJava makes it painfulsometimes...
  8. 8. What can we do about it?!
  9. 9. DISCLAIMER(THIS IS NOT A BASH-THE-OTHER-LANGUAGES TALK)
  10. 10. REDUCEDVERBOSITY
  11. 11. STANDARD BEANSpublic class Bean { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }}
  12. 12. STANDARD BEANSpublic class Bean { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; }}
  13. 13. STANDARD BEANSclass Bean { String name}
  14. 14. STANDARD BEANSclass Bean(var name:String)class Bean { @scala.reflect.BeanProperty var name: String}
  15. 15. STANDARD BEANS(defstruct Bean :name)
  16. 16. CLOSURES (OR FUNCTIONS)public interfaceAdder { int add(int a, int b);}public class MyAdder implements Adder { public int add(int a, int b) { return a + b; }}
  17. 17. CLOSURES (OR FUNCTIONS)// JDK7^H8 Closures proposal(int a, int b)(a + b)#(int a, int b) { return a + b; }(int a, int b) -> a + b
  18. 18. CLOSURES (OR FUNCTIONS)def adder = { a , b -> a + b }
  19. 19. CLOSURES (OR FUNCTIONS)val adder = (a:Int, b:Int) => a + b
  20. 20. CLOSURES (OR FUNCTIONS)(defn adder [a b] (+ a b))
  21. 21. ENHANCED SWITCHchar letterGrade(int grade) { if(grade >= 0 && grade <= 60) return ‘F‘; if(grade > 60 && grade <= 70) return ‘D‘; if(grade > 70 && grade <= 80) return ‘C‘; if(grade > 80 && grade <= 90) return ‘B‘; if(grade > 90 && grade <= 100) return ‘A‘; throw new IllegalArgumentException(“invalidgrade “+grade);}
  22. 22. ENHANCED SWITCHdef letterGrade(grade) { switch(grade) { case 90..100: return ‘A‘ case 80..<90: return ‘B‘ case 70..<80: return ‘C‘ case 60..<70: return ‘D‘ case 0..<60: return ‘F‘ case ~"[ABCDFabcdf]": return grade.toUpperCase() } throw new IllegalArgumentException(‘invalidgrade ‘+grade)}
  23. 23. ENHANCED SWITCHval VALID_GRADES = Set("A", "B", "C", "D", "F")def letterGrade(value: Any):String = value match { case x:Int if (90 to 100).contains(x) => "A" case x:Int if (80 to 90).contains(x) => "B" case x:Int if (70 to 80).contains(x) => "C" case x:Int if (60 to 70).contains(x) => "D" case x:Int if (0 to 60).contains(x) => "F" case x:String if VALID_GRADES(x.toUpperCase) =>x.toUpperCase()}
  24. 24. ENHANCED SWITCH(defn letter-grade [grade] (cond (in grade 90 100) "A" (in grade 80 90) "B" (in grade 70 80) "C" (in grade 60 70) "D" (in grade 0 60) "F" (re-find #"[ABCDFabcdf]" grade) (.toUpperCasegrade)))
  25. 25. JAVAINTEROPERABILITY
  26. 26. ALL OF THESE ARETRUEJava can call Groovy, Scala and Clojure classes as if theywere Java classesGroovy, Scala and Clojure can call Java code withoutbreaking a sweatIn other words, interoperability with Java is a given. No needfor complicated bridges between languages (i.e. JSR 223)
  27. 27. OK, SO...WHAT ELSECAN THESELANGUAGESDO?
  28. 28. ALL OF THEMNative syntax for collection classesEverything is an objectClosures!Regular expressions as first class citizen
  29. 29. GROOVYMetaprogramming (HOT!) both at buildtime and runtimeBuildersOperator overloadingHealthy ecosystem: Grails, Griffon, Gant, Gradle, Spock,Gaelyk, Gpars, CodeNarc, etc...Not an exhaustive list of features!
  30. 30. SCALARicher type systemFunctional meets Object OrientedType inferencePattern matching (+ case classes)Actor modelCreate your own operatorTraitsNot an exhaustive list of features!
  31. 31. CLOJUREData as code and viceversaImmutable structuresSTMNot an exhaustive list of features!
  32. 32. DEMO
  33. 33. OTHER PLACESWHERE YOU‘LLFINDPOLYGLOTPROGRAMMING
  34. 34. WEB APPDEVELOPMENTXMLSQLJavaScriptJSONCSSFlash/Flex/ActionScript
  35. 35. NEXT-GENDATASTORES (NOSQL)FleetDB -> ClojureFlockDB -> ScalaCouchDB, Riak -> ErlangBy the way, watch out for Polyglot Persistence ;-)
  36. 36. BUILD SYSTEMSGradle, Gant -> GroovyRake -> Ruby/JRubyMaven3 -> XML, Groovy, RubySBT -> ScalaLeiningen -> Clojure
  37. 37. PARTING THOUGHTSJava (the language) may have reached its maturity featurewiseOther JVM languages have evolved fasterPolyglot Programming is not a new conceptDownload and play with each of the demoed languages,maybe one of them strikes your fancy
  38. 38. RESOURCES
  39. 39. RESOURCES
  40. 40. RESOURCES
  41. 41. Q&A
  42. 42. Thank You! @aalmirayandres.almiray@canoo.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×