Polyglot Grails
Me• @mgryszko• @osoco• Groovy/Grails (sometimes Java) hacker• test addicted and clean code lover
Osoco• Small but outstanding • Quality preachers software development shop • TDD mantra s...
Osoco• Small but outstanding • Quality preachers software development shop • TDD mantra s...
Polyglot
Polyglot programming• term coined 2006 by Neil Ford• general + special-purpose languages• http://memeagora.blogspot....
http://www.flickr.com/photos/pinelife/269961241/
Maybe you didn’t know... http://www.flickr.com/photos/pinelife/269961241/
Maybe you didn’t know...But you are already polyglot programmer! http://www.flickr.com/photos/pin...
From relational algebra to JVM• relational algebra, rise of RDBMS -> SQL• world-wide-web -> JavaScript, HTML (?)• mu...
> 200 languages on JVM
> 200 languages on JVM
> 200 languages on JVM
Why polyglot?• General purpose languages evolve too slowly• Specific-languages solve specific problems (DSLs included)• Ne...
Do we have to speakGroovy with Grails?
Do we have to speak Groovy with Grails?• Yes...• Groovy and Grails are inseparable
Do we have to speak Groovy with Grails?• Yes...• Groovy and Grails are inseparable• But...• Non-Groovy code can be execute...
Grails is alreadypolyglot, can we push it further?
Grails plugins • Clojure • Scala • JRuby
Grails plugins • Clojure • Scala • JRuby
Clojure• Functional language• Lisp reloaded• Built-in support for concurrency• Java interoperability
Clojure• Functional language• Lisp reloaded• Built-in support for concurrency• Java interoperability
Functional language• Not pure functional• Explicit state management• Immutable, lazy and infinite data structures• Higher-o...
Functional language• Not pure functional• Explicit state management• Immutable, lazy and infinite data structures• Higher-o...
Lisp reloaded• Everything is sequence (extended Lisp list)• Extended data structures - maps, sets• Less parentheses, comma...
Lisp reloaded• Everything is sequence (extended Lisp list)• Extended data structures - maps, sets• Less parentheses, comma...
Concurrency• Managed references (refs, agents, atoms, vars)• Software Transactional Memory• Actors• Atoms (~ java.util.c...
Concurrency• Managed references (refs, agents, atoms, vars)• Software Transactional Memory• Actors• Atoms (~ java.util.c...
Java interoperability• Import Java classes• Direct access to class/instance fields and methods• Syntactic sugar• Implement...
Java interoperability• Import Java classes• Direct access to class/instance fields and methods• Syntactic sugar• Implement...
Why Clojure & Grails?• Concurrency• Laziness• Rich collection library • Relational algebra
Why Clojure & Grails?• Concurrency• Laziness• Rich collection library • Relational algebra
Clojure and Grails• Install Clojure plugin http://grails.org/plugin/clojure grails install-plugin clojure• Put your sour...
Clojure and Grails• Install Clojure plugin http://grails.org/plugin/clojure grails install-plugin clojure• Put your sour...
Demo - bootstrap• Clojure code can access Grails objects• Sample note added during bootstrap
Demo - bootstrap• Clojure code can access Grails objects• Sample note added during bootstrap
Demo - tag counter• Note taking application• Notes can be tagged• Calculate most popular tags
Demo - tag counter• Note taking application• Notes can be tagged• Calculate most popular tags
Plugin gotchas• Uses Clojure 1.2• No access to Groovy-augmented methods e.g. String.reverse()
Plugin gotchas• Uses Clojure 1.2• No access to Groovy-augmented methods e.g. String.reverse()
Scala• Object-functional• Statically typed but with type inference• Concurrency through actors• Almost as fast as Java
Scala• Object-functional• Statically typed but with type inference• Concurrency through actors• Almost as fast as Java
Functional language• Immutability• Higher-order functions• Pattern matching + case classes• Lazy evaluation• Monads• Parse...
Functional language• Immutability• Higher-order functions• Pattern matching + case classes• Lazy evaluation• Monads• Parse...
Why Scala in Grails?• High performance without Java• Functional features• DSLs
Why Scala in Grails?• High performance without Java• Functional features• DSLs
Scala and Grails• Install Scala plugin http://www.grails.org/plugin/scala grails install-plugin scala• Put your source u...
Scala and Grails• Install Scala plugin http://www.grails.org/plugin/scala grails install-plugin scala• Put your source u...
Demo shortest path• Calculate shortest path between two cities• Use Scala4Graph library
Demo shortest path• Calculate shortest path between two cities• Use Scala4Graph library
Plugin gotchas• No access to Groovy/Grails classes• Execute Grails with --verbose option for Scala compiler error• No IDE...
Plugin gotchas• No access to Groovy/Grails classes• Execute Grails with --verbose option for Scala compiler error• No IDE...
Plugin gotchas• DSL objects must be 100% Scala• Boilerplate code for accessing Scala results scalaList.foreach( [apply...
Plugin gotchas• DSL objects must be 100% Scala• Boilerplate code for accessing Scala results scalaList.foreach( [apply...
Ruby• JRuby - Ruby 1.8.7 & 1.9.2 compatible• Object-oriented, dynamic• Some functional features• Tones of gems
Ruby• JRuby - Ruby 1.8.7 & 1.9.2 compatible• Object-oriented, dynamic• Some functional features• Tones of gems
Why Ruby in Grails?• Hard to find a valid reason...• Rails app migration to Grails?• Particular gem?
Why Ruby in Grails?• Hard to find a valid reason...• Rails app migration to Grails?• Particular gem?
Ruby and Grails• Install Ruby plugin http://www.grails.org/plugin/ruby grails install-plugin ruby• Put your sources unde...
Ruby and Grails• Install Ruby plugin http://www.grails.org/plugin/ruby grails install-plugin ruby• Put your sources unde...
Demo - BOFH server• http://en.wikipedia.org/wiki/ Bastard_Operator_From_Hell• bofh-excuse gem
Demo - BOFH server• http://en.wikipedia.org/wiki/ Bastard_Operator_From_Hell• bofh-excuse gem
Plugin gotchas• No gem installation• No access to Grails classes
Plugin gotchas• No gem installation• No access to Grails classes
Speak your mother tongue• plug in your compiler on compileStart event (Scala plugin)• use JSR223 javax.script.Scr...
My ranking for
My ranking for
My ranking for
My ranking for
Thank you! ¡Gracias! Danke! Dziękuję!
Source code• http://github.com/mgryszko/grails-polyglot-demo
of 71

Polyglot Grails

Talk from the Spring IO 2012 conference.
Published on: Mar 4, 2016
Published in: Technology      
Source: www.slideshare.net


Transcripts - Polyglot Grails

  • 1. Polyglot Grails
  • 2. Me• @mgryszko• @osoco• Groovy/Grails (sometimes Java) hacker• test addicted and clean code lover
  • 3. Osoco• Small but outstanding • Quality preachers software development shop • TDD mantra singers• Groovy and Grails • On EC2 cloud nine hackers
  • 4. Osoco• Small but outstanding • Quality preachers software development shop • TDD mantra singers• Groovy and Grails • On EC2 cloud nine hackers Julián David
  • 5. Polyglot
  • 6. Polyglot programming• term coined 2006 by Neil Ford• general + special-purpose languages• http://memeagora.blogspot.com/2006/12/polyglot- programming.html
  • 7. http://www.flickr.com/photos/pinelife/269961241/
  • 8. Maybe you didn’t know... http://www.flickr.com/photos/pinelife/269961241/
  • 9. Maybe you didn’t know...But you are already polyglot programmer! http://www.flickr.com/photos/pinelife/269961241/
  • 10. From relational algebra to JVM• relational algebra, rise of RDBMS -> SQL• world-wide-web -> JavaScript, HTML (?)• multilanguage platforms - .NET, JVM
  • 11. > 200 languages on JVM
  • 12. > 200 languages on JVM
  • 13. > 200 languages on JVM
  • 14. Why polyglot?• General purpose languages evolve too slowly• Specific-languages solve specific problems (DSLs included)• New challenges• Old habits die hard
  • 15. Do we have to speakGroovy with Grails?
  • 16. Do we have to speak Groovy with Grails?• Yes...• Groovy and Grails are inseparable
  • 17. Do we have to speak Groovy with Grails?• Yes...• Groovy and Grails are inseparable• But...• Non-Groovy code can be executed from Grails components
  • 18. Grails is alreadypolyglot, can we push it further?
  • 19. Grails plugins • Clojure • Scala • JRuby
  • 20. Grails plugins • Clojure • Scala • JRuby
  • 21. Clojure• Functional language• Lisp reloaded• Built-in support for concurrency• Java interoperability
  • 22. Clojure• Functional language• Lisp reloaded• Built-in support for concurrency• Java interoperability
  • 23. Functional language• Not pure functional• Explicit state management• Immutable, lazy and infinite data structures• Higher-order functions• Dynamically typed*
  • 24. Functional language• Not pure functional• Explicit state management• Immutable, lazy and infinite data structures• Higher-order functions• Dynamically typed*
  • 25. Lisp reloaded• Everything is sequence (extended Lisp list)• Extended data structures - maps, sets• Less parentheses, commas = whitespaces• Multimethods dispatch on anything• Metadata• Tail call optimization on JVM
  • 26. Lisp reloaded• Everything is sequence (extended Lisp list)• Extended data structures - maps, sets• Less parentheses, commas = whitespaces• Multimethods dispatch on anything• Metadata• Tail call optimization on JVM
  • 27. Concurrency• Managed references (refs, agents, atoms, vars)• Software Transactional Memory• Actors• Atoms (~ java.util.concurrent.atomic.Atomic* )• Vars (~ ) java.lang.ThreadLocal
  • 28. Concurrency• Managed references (refs, agents, atoms, vars)• Software Transactional Memory• Actors• Atoms (~ java.util.concurrent.atomic.Atomic* )• Vars (~ ) java.lang.ThreadLocal
  • 29. Java interoperability• Import Java classes• Direct access to class/instance fields and methods• Syntactic sugar• Implement Java interfaces and classes on the fly• Create Java classes
  • 30. Java interoperability• Import Java classes• Direct access to class/instance fields and methods• Syntactic sugar• Implement Java interfaces and classes on the fly• Create Java classes
  • 31. Why Clojure & Grails?• Concurrency• Laziness• Rich collection library • Relational algebra
  • 32. Why Clojure & Grails?• Concurrency• Laziness• Rich collection library • Relational algebra
  • 33. Clojure and Grails• Install Clojure plugin http://grails.org/plugin/clojure grails install-plugin clojure• Put your sources under src/clj• Use grails namespace (ns grails)• Access Clojure code through clj property
  • 34. Clojure and Grails• Install Clojure plugin http://grails.org/plugin/clojure grails install-plugin clojure• Put your sources under src/clj• Use grails namespace (ns grails)• Access Clojure code through clj property
  • 35. Demo - bootstrap• Clojure code can access Grails objects• Sample note added during bootstrap
  • 36. Demo - bootstrap• Clojure code can access Grails objects• Sample note added during bootstrap
  • 37. Demo - tag counter• Note taking application• Notes can be tagged• Calculate most popular tags
  • 38. Demo - tag counter• Note taking application• Notes can be tagged• Calculate most popular tags
  • 39. Plugin gotchas• Uses Clojure 1.2• No access to Groovy-augmented methods e.g. String.reverse()
  • 40. Plugin gotchas• Uses Clojure 1.2• No access to Groovy-augmented methods e.g. String.reverse()
  • 41. Scala• Object-functional• Statically typed but with type inference• Concurrency through actors• Almost as fast as Java
  • 42. Scala• Object-functional• Statically typed but with type inference• Concurrency through actors• Almost as fast as Java
  • 43. Functional language• Immutability• Higher-order functions• Pattern matching + case classes• Lazy evaluation• Monads• Parser combinators
  • 44. Functional language• Immutability• Higher-order functions• Pattern matching + case classes• Lazy evaluation• Monads• Parser combinators
  • 45. Why Scala in Grails?• High performance without Java• Functional features• DSLs
  • 46. Why Scala in Grails?• High performance without Java• Functional features• DSLs
  • 47. Scala and Grails• Install Scala plugin http://www.grails.org/plugin/scala grails install-plugin scala• Put your source under src/scala• Add explicit Scala dependencies compile "org.scala-lang:scala-compiler:2.9.1", "org.scala-lang:scala-library:2.9.1"
  • 48. Scala and Grails• Install Scala plugin http://www.grails.org/plugin/scala grails install-plugin scala• Put your source under src/scala• Add explicit Scala dependencies compile "org.scala-lang:scala-compiler:2.9.1", "org.scala-lang:scala-library:2.9.1"
  • 49. Demo shortest path• Calculate shortest path between two cities• Use Scala4Graph library
  • 50. Demo shortest path• Calculate shortest path between two cities• Use Scala4Graph library
  • 51. Plugin gotchas• No access to Groovy/Grails classes• Execute Grails with --verbose option for Scala compiler error• No IDE support for executing Scala code tests
  • 52. Plugin gotchas• No access to Groovy/Grails classes• Execute Grails with --verbose option for Scala compiler error• No IDE support for executing Scala code tests
  • 53. Plugin gotchas• DSL objects must be 100% Scala• Boilerplate code for accessing Scala results scalaList.foreach( [apply: {groovyList << it}] as Function1 )• Scala components can be Spring beans
  • 54. Plugin gotchas• DSL objects must be 100% Scala• Boilerplate code for accessing Scala results scalaList.foreach( [apply: {groovyList << it}] as Function1 )• Scala components can be Spring beans
  • 55. Ruby• JRuby - Ruby 1.8.7 & 1.9.2 compatible• Object-oriented, dynamic• Some functional features• Tones of gems
  • 56. Ruby• JRuby - Ruby 1.8.7 & 1.9.2 compatible• Object-oriented, dynamic• Some functional features• Tones of gems
  • 57. Why Ruby in Grails?• Hard to find a valid reason...• Rails app migration to Grails?• Particular gem?
  • 58. Why Ruby in Grails?• Hard to find a valid reason...• Rails app migration to Grails?• Particular gem?
  • 59. Ruby and Grails• Install Ruby plugin http://www.grails.org/plugin/ruby grails install-plugin ruby• Put your sources under src/ruby• Access Ruby code through ruby property
  • 60. Ruby and Grails• Install Ruby plugin http://www.grails.org/plugin/ruby grails install-plugin ruby• Put your sources under src/ruby• Access Ruby code through ruby property
  • 61. Demo - BOFH server• http://en.wikipedia.org/wiki/ Bastard_Operator_From_Hell• bofh-excuse gem
  • 62. Demo - BOFH server• http://en.wikipedia.org/wiki/ Bastard_Operator_From_Hell• bofh-excuse gem
  • 63. Plugin gotchas• No gem installation• No access to Grails classes
  • 64. Plugin gotchas• No gem installation• No access to Grails classes
  • 65. Speak your mother tongue• plug in your compiler on compileStart event (Scala plugin)• use JSR223 javax.script.ScriptEngine (Ruby plugin)• use custom interpreter (Clojure plugin, clojure.lang.Compiler)• trigger code reloading when changed
  • 66. My ranking for
  • 67. My ranking for
  • 68. My ranking for
  • 69. My ranking for
  • 70. Thank you! ¡Gracias! Danke! Dziękuję!
  • 71. Source code• http://github.com/mgryszko/grails-polyglot-demo

Related Documents