Polyglot  Programming  in the JVM Or how I Learned to Stop Worrying and  Love  the JVM Andres Almiray | Canoo Engineering AG
About the speaker <ul><li>Java  developer since the beginning </li></ul><ul><li>True believer in  Open Source </li></ul><u...
Some facts about Java <ul><li>Previous name was Oak.  </li></ul><ul><ul><li>Bonus points for knowing its real name before ...
However... <ul><li>It‘s already in i ts teens </li></ul><ul><li>It has not seen a major feature upgrade since JDK5 was rel...
More so... <ul><li>It  is rather  verbose  when compared to how other languages do the same task </li></ul><ul><li>I ts   ...
Truth or myth? <ul><li>Is Java oftenly referred as  overengineered ? </li></ul>
Truth or myth? <ul><li>Can you build a Java based web application (for argument sake a basic Twitter clone) in less than a...
Truth or myth? <ul><li>Did James Gosling ever say he was  threatened with bodily harm  should operator overloading find i ...
The  JVM  is a  great  place to work however Java makes it  painful  sometimes...
What can we do about it?!
 
Disclaimer (this is not a bash-the-other-languages talk)
Reduced Verbosity
Standard Beans p ublic   class  Bean { private  String name; public  String getName() { return  name; } public   void  set...
Standard Beans p ublic   class  Bean { private  String name; public  String getName() { return  name; } public   void  set...
Standard Beans p ublic   class  Bean { private   String name ; public  String getName() { return  name; } public   void  s...
Standard Beans class  Bean { String name }
Standard Beans class  Bean( var  name:String) class  Bean { @scala.reflect.BeanProperty var  name: String }
Standard Beans ( defstruct  Bean :name)
Closures (or Functions) public   i nterface  Adder { int add(int a, int b); } p ublic   class  MyAdder implements Adder { ...
Closures (or Functions) // JDK7 Lambdas proposal #(int a, int b)( a + b ) #(int a, int b) {  return a + b;  }
Closures (or Functions) d ef  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 switch c har  letterGrade(int grade) { if (grade >= 0 && grade <= 60)  return   ‘F‘; if (grade > 60 && grade <= 7...
Enhanced Switch d ef  letterGrade(grade) { switch (grade) { case  90..100:  return   ‘A‘ case  80..<90:  return   ‘B‘ case...
Enhanced Switch val  VALID_GRADES = Set(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;F&quot;) def  le...
Enhanced Switch ( defn  letter-grade [grade] (cond (in grade 90 100) &quot;A&quot; (in grade 80 90) &quot;B&quot; (in grad...
Java Interoperability
All of these are true <ul><li>Java can call Groovy, Scala and Clojure classes as if they were Java classes </li></ul><ul><...
Ok, so...  What else can these languages do?
All of them  <ul><li>Native syntax for collection classes </li></ul><ul><li>Everything is an object </li></ul><ul><li>Clos...
Groovy <ul><li>Metaprogramming (HOT!) both at buildtime and runtime </li></ul><ul><li>Builders </li></ul><ul><li>Healthy e...
Scala <ul><li>Richer type system </li></ul><ul><li>Type inference </li></ul><ul><li>Pattern matching (case classes) </li><...
Clojure <ul><li>D ata as code and viceversa </li></ul><ul><li>Immutable structures </li></ul><ul><li>STM </li></ul><ul><li...
Demo
Other places where you‘ll find Polyglot Programming
Web app development <ul><li>XML </li></ul><ul><li>SQL </li></ul><ul><li>JavaScript </li></ul><ul><li>JSON </li></ul><ul><l...
Next-Gen datastores (NoSQL) <ul><li>FleetDB -> Clojure </li></ul><ul><li>FlockDB -> Scala </li></ul><ul><li>CouchDB, Riak ...
Build systems <ul><li>Gradle, Gant -> Groovy </li></ul><ul><li>Rake -> Ruby/JRuby </li></ul><ul><li>Maven3 -> XML, Groovy,...
Parting thoughts <ul><li>Java (the language) may have reached its maturity feature wise </li></ul><ul><li>Other JVM langua...
Resources
Q & A
Thank you!
Upcoming SlideShare
Loading in …5
×

Polyglot Programming in the JVM

2,750 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,750
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
27
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Polyglot Programming in the JVM

  1. 1. Polyglot Programming in the JVM Or how I Learned to Stop Worrying and Love the JVM Andres Almiray | Canoo Engineering AG
  2. 2. About the speaker <ul><li>Java developer since the beginning </li></ul><ul><li>True believer in Open Source </li></ul><ul><li>Groovy committer since 2007 </li></ul><ul><li>Project lead of the Griffon framework </li></ul><ul><li>Currently working for </li></ul>
  3. 3. Some facts about Java <ul><li>Previous name was Oak. </li></ul><ul><ul><li>Bonus points for knowing its real name before that </li></ul></ul><ul><li>Made its public appearance in 1995 </li></ul><ul><li>C/C++ were king at the time </li></ul><ul><li>Networking, multithreading were baked right into the language </li></ul><ul><li>Developers came for the applets and stayed for the components </li></ul><ul><ul><li>(JEE and all that jazz) </li></ul></ul>
  4. 4. However... <ul><li>It‘s already in i ts teens </li></ul><ul><li>It has not seen a major feature upgrade since JDK5 was released back in 2004 -> generics </li></ul><ul><ul><li>(and we do know how that turned out to be, don’t we?) </li></ul></ul><ul><li>JDK7 has been delayed again </li></ul><ul><ul><li>Some features might or might not make the cut </li></ul></ul><ul><ul><li>(the closures debacle) </li></ul></ul>late 2010 early 2011?
  5. 5. More so... <ul><li>It is rather verbose when compared to how other languages do the same task </li></ul><ul><li>I ts threading features are no longer enough. </li></ul><ul><ul><li>Concurrent programs desperately cry for immutability these days </li></ul></ul>
  6. 6. Truth or myth? <ul><li>Is Java oftenly referred as overengineered ? </li></ul>
  7. 7. Truth or myth? <ul><li>Can you build a Java based web application (for argument sake a basic Twitter clone) in less than a day‘s work WITHOUT an IDE ? </li></ul>
  8. 8. Truth or myth? <ul><li>Did James Gosling ever say he was threatened with bodily harm should operator overloading find i ts way into Java? </li></ul>
  9. 9. The JVM is a great place to work however Java makes it painful sometimes...
  10. 10. What can we do about it?!
  11. 12. Disclaimer (this is not a bash-the-other-languages talk)
  12. 13. Reduced Verbosity
  13. 14. Standard Beans p ublic class Bean { private String name; public String getName() { return name; } public void setName(String name) { this .name = name; } }
  14. 15. Standard Beans p ublic class Bean { private String name; public String getName() { return name; } public void setName(String name) { this .name = name; } }
  15. 16. Standard Beans p ublic class Bean { private String name ; public String getName() { return name; } public void setName(String name) { this .name = name; } }
  16. 17. Standard Beans class Bean { String name }
  17. 18. Standard Beans class Bean( var name:String) class Bean { @scala.reflect.BeanProperty var name: String }
  18. 19. Standard Beans ( defstruct Bean :name)
  19. 20. Closures (or Functions) public i nterface Adder { int add(int a, int b); } p ublic class MyAdder implements Adder { public int add(int a, int b) { return a + b; } }
  20. 21. Closures (or Functions) // JDK7 Lambdas proposal #(int a, int b)( a + b ) #(int a, int b) { return a + b; }
  21. 22. Closures (or Functions) d ef adder = { a , b -> a + b }
  22. 23. Closures (or Functions) val adder = (a:Int, b:Int) => a + b
  23. 24. Closures (or Functions) ( defn adder [a b] ( + a b ))
  24. 25. Enhanced switch c har 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(“invalid grade “+grade); }
  25. 26. Enhanced Switch d ef 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 ~&quot;[ABCDFabcdf]&quot;: return grade.toUpperCase() } throw new IllegalArgumentException(‘invalid grade ‘+grade) }
  26. 27. Enhanced Switch val VALID_GRADES = Set(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;, &quot;D&quot;, &quot;F&quot;) def letterGrade(value: Any):String = value match { case x:Int if (90 to 100).contains(x) => &quot;A&quot; case x:Int if (80 to 90).contains(x) => &quot;B&quot; case x:Int if (70 to 80).contains(x) => &quot;C&quot; case x:Int if (60 to 70).contains(x) => &quot;D&quot; case x:Int if (0 to 60).contains(x) => &quot;F&quot; case x:String if VALID_GRADES(x.toUpperCase) => x.toUpperCase() }
  27. 28. Enhanced Switch ( defn letter-grade [grade] (cond (in grade 90 100) &quot;A&quot; (in grade 80 90) &quot;B&quot; (in grade 70 80) &quot;C&quot; (in grade 60 70) &quot;D&quot; (in grade 0 60) &quot;F&quot; (re-find #&quot;[ABCDFabcdf]&quot; grade) (.toUpperCase grade)))
  28. 29. Java Interoperability
  29. 30. All of these are true <ul><li>Java can call Groovy, Scala and Clojure classes as if they were Java classes </li></ul><ul><li>Groovy, Scala and Clojure can call Java code without breaking a sweat! </li></ul><ul><li>In other words, interoperability with Java is a given. </li></ul><ul><li> No need for complicated bridges between languages (i.e. JSR 223) </li></ul>
  30. 31. Ok, so... What else can these languages do?
  31. 32. All of them <ul><li>Native syntax for collection classes </li></ul><ul><li>Everything is an object </li></ul><ul><li>Closures! </li></ul><ul><li>Regular expressions as first class citizens </li></ul><ul><li>Operator overloading </li></ul>
  32. 33. Groovy <ul><li>Metaprogramming (HOT!) both at buildtime and runtime </li></ul><ul><li>Builders </li></ul><ul><li>Healthy ecosystem: Grails, Griffon, Gant, Gradle, Spock, Gaelyk, G p ars, CodeNarc, etc... </li></ul><ul><li>N ot an exhaustive list of features! </li></ul>
  33. 34. Scala <ul><li>Richer type system </li></ul><ul><li>Type inference </li></ul><ul><li>Pattern matching (case classes) </li></ul><ul><li>Actor model </li></ul><ul><li>Traits </li></ul><ul><li>N ot an exhaustive list of features! </li></ul>
  34. 35. Clojure <ul><li>D ata as code and viceversa </li></ul><ul><li>Immutable structures </li></ul><ul><li>STM </li></ul><ul><li>N ot an exhaustive list of features! </li></ul>
  35. 36. Demo
  36. 37. Other places where you‘ll find Polyglot Programming
  37. 38. Web app development <ul><li>XML </li></ul><ul><li>SQL </li></ul><ul><li>JavaScript </li></ul><ul><li>JSON </li></ul><ul><li>CSS </li></ul><ul><li>Flash/Flex/ActionScript </li></ul>
  38. 39. Next-Gen datastores (NoSQL) <ul><li>FleetDB -> Clojure </li></ul><ul><li>FlockDB -> Scala </li></ul><ul><li>CouchDB, Riak -> Erlang </li></ul><ul><li>B y the way, watch out for Polyglot Persistence ;-) </li></ul>
  39. 40. Build systems <ul><li>Gradle, Gant -> Groovy </li></ul><ul><li>Rake -> Ruby/JRuby </li></ul><ul><li>Maven3 -> XML, Groovy, Ruby </li></ul>
  40. 41. Parting thoughts <ul><li>Java (the language) may have reached its maturity feature wise </li></ul><ul><li>Other JVM languages have evolved faster </li></ul><ul><li>Polyglot Programming is not a new concept </li></ul><ul><li>Download and play with each of the demoed languages, maybe one of them strikes your fancy </li></ul>
  41. 42. Resources
  42. 43. Q & A
  43. 44. Thank you!

×