Dynamic Languages on the JVM


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Dynamic Languages on the JVM

  1. 1. Dynamic Languages on the JVM Groovy, Grails, JRuby, and JRuby on Rails Matt Stine Memphis/Mid-South JUG October 18, 2007
  2. 2. Dynamic Languages <ul><li>&quot;Dynamic programming language is a term used broadly in computer science to describe a class of high level programming languages that execute at runtime many common behaviors that other languages might perform during compilation, if at all. These behaviors could include extension of the program, by adding new code, or by extending objects and definitions, or by modifying the type system, all during program execution. These behaviors can be emulated in nearly any language of sufficient complexity, but dynamic languages provide direct tools to make use of them.&quot; - Wikipedia </li></ul>
  3. 3. Examples of Dynamic Languages: <ul><li>Ruby </li></ul><ul><ul><li>Created by Yukihiro “matz” Matsumoto </li></ul></ul><ul><ul><li>First released in 1995 </li></ul></ul><ul><ul><li>Currently at version 1.8.6 </li></ul></ul><ul><ul><li>http://www. ruby-lang .org </li></ul></ul><ul><li>Groovy </li></ul><ul><ul><li>Project founded by James Strachan and Bob McWhirter in 2003 </li></ul></ul><ul><ul><li>Became JSR-241 in 2004 </li></ul></ul><ul><ul><li>Currently at version 1.1-RC-1 </li></ul></ul><ul><ul><li>http://groovy. codehaus .org </li></ul></ul>
  4. 4. DL Quick Feature Tour <ul><li>Absolutely everything is an object – no primitives! </li></ul><ul><ul><ul><li>7.class => java.lang.Integer </li></ul></ul></ul><ul><li>Lots of syntactical sugar for lists, maps, ranges, regular expressions, etc. </li></ul><ul><ul><ul><li>def numbers = [1,2,3] // a list </li></ul></ul></ul><ul><ul><ul><li>def ages = 18..65 // a range </li></ul></ul></ul><ul><ul><ul><li>def currencies = [USD: “US Dollar”, GBP: “Pounds”, EUR: “Euros”] </li></ul></ul></ul><ul><li>Dynamic typing </li></ul><ul><li>Blocks / Closures </li></ul><ul><ul><ul><li>3.times {println it} </li></ul></ul></ul><ul><li>Metaprogramming </li></ul><ul><ul><ul><li>Dynamically generate classes </li></ul></ul></ul><ul><ul><ul><li>Modify existing classes </li></ul></ul></ul><ul><ul><ul><li>Special dispatching to pretend things exist </li></ul></ul></ul>
  5. 5. Metaprogramming (Groovy)
  6. 6. DL for the Web <ul><li>Ruby = Ruby on Rails </li></ul><ul><ul><li>Full-stack MVC web development framework </li></ul></ul><ul><ul><li>Open Source (MIT) </li></ul></ul><ul><ul><li>First released in 2004 by David Heinemeier Hansson </li></ul></ul><ul><ul><li>Currently at version 1.2.4 (2.0 coming soon!!!) </li></ul></ul><ul><ul><li>Ruby and Rails books are outselling Perl books </li></ul></ul><ul><ul><li>http: //rubyonrails .org </li></ul></ul>
  7. 7. DL for the Web <ul><li>Groovy = Grails (formerly “Groovy on Rails”) </li></ul><ul><ul><li>Model View Controller (MVC) action-based web framework </li></ul></ul><ul><ul><li>Open Source (Apache 2.0) </li></ul></ul><ul><ul><li>First released in early 2006 by Graeme Rocher, Guillaume LaForge, and Steven Devijver </li></ul></ul><ul><ul><li>Currently at version 0.6 (1.0 coming soon!!!) </li></ul></ul><ul><ul><li>Now backed by a company, G2one, formed by authors (October 2007). </li></ul></ul><ul><ul><li>http://grails.org </li></ul></ul>
  8. 8. DL Web Framework Similarities <ul><li>Convention over configuration </li></ul><ul><ul><li>Why punish the common cases? </li></ul></ul><ul><ul><li>Encourages standard practices </li></ul></ul><ul><ul><li>Everything simpler and smaller </li></ul></ul><ul><li>Don’t Repeat Yourself (DRY) </li></ul><ul><ul><li>Frameworks written around minimizing repetition </li></ul></ul><ul><ul><li>Repetitive code harmful to adaptability </li></ul></ul>
  9. 9. DL Web Framework Similarities <ul><li>Agile development environment </li></ul><ul><ul><li>No recompile, deploy, restart cycles </li></ul></ul><ul><ul><li>Simple tools to generate code quickly </li></ul></ul><ul><ul><li>Testing built into the frameworks </li></ul></ul><ul><li>Full Stack </li></ul><ul><ul><li>All technologies necessary to build persistence, service, and web layers fully integrated. </li></ul></ul>
  10. 10. What does all of this have to do with Java?!?!?! Both of these languages are FIRST CLASS CITIZENS on the Java Virtual Machine!
  11. 11. JRuby <ul><li>Started in 2002 </li></ul><ul><li>Java platform implementation of Ruby language </li></ul><ul><li>Open source, many active contributors, including full-time Sun employees </li></ul><ul><li>Currently at version 1.0.1 </li></ul><ul><li>Fully compatible with Ruby 1.8.5 (including Rails!) </li></ul><ul><li>http: //jruby . codehaus .org </li></ul>
  12. 12. JRuby <ul><li>Integrates with Java technology </li></ul><ul><ul><li>Call to Ruby from Java technology via JSR 223, BSF, Spring </li></ul></ul><ul><ul><li>Use Java class files from Ruby (e.g. Script Java) </li></ul></ul><ul><li>Growing set of external projects based on JRuby </li></ul><ul><ul><li>JRuby-extras (GoldSpike, ActiveRecord-JDBC, Mongrel-JRuby, Mongrel-JCluster, …) </li></ul></ul>
  13. 13. Why JRuby? <ul><li>JRuby over Ruby </li></ul><ul><ul><li>Strong likelihood it will be faster soon </li></ul></ul><ul><ul><li>Better scalability with native threading </li></ul></ul><ul><ul><li>Native Unicode support </li></ul></ul><ul><ul><li>Compilation </li></ul></ul><ul><ul><li>Integration with Java libraries </li></ul></ul><ul><ul><li>Easier path to getting Ruby in the enterprise </li></ul></ul>
  14. 14. Why JRuby? <ul><li>JRuby over Java technology </li></ul><ul><ul><li>Language features </li></ul></ul><ul><ul><ul><li>Blocks, modules, metaprogramming, dynamic-typing </li></ul></ul></ul><ul><ul><li>Ruby applications/libraries </li></ul></ul><ul><ul><ul><li>Rails, Rspec, Rake, Raven, other R’s </li></ul></ul></ul>
  15. 15. Why JRuby on Rails? <ul><li>“ Less Rails code that Java application configuration.” </li></ul><ul><li>Growing excited community of developers </li></ul><ul><li>Makes small apps trivial to create </li></ul><ul><li>Deployment to Java application servers </li></ul><ul><li>Java technology production environments are pervasive </li></ul><ul><ul><li>Easier to switch framework vs. whole architecture </li></ul></ul><ul><ul><li>Lower barrier to entry </li></ul></ul><ul><li>Broader, more scalable database support </li></ul><ul><li>Integration w/ Java technology libs, legacy services </li></ul>
  16. 16. JRuby on Rails: Java EE Platform <ul><li>Pool database connections </li></ul><ul><li>Access any JNDI resource </li></ul><ul><li>Access any Java EE platform TLA: </li></ul><ul><ul><li>Java Persistence API (JPA) </li></ul></ul><ul><ul><li>Java Management Extensions (JMX) </li></ul></ul><ul><ul><li>Enterprise JavaBeans ™ (EJB ™ ) </li></ul></ul><ul><ul><li>Java Message Service (JMS) API </li></ul></ul><ul><ul><li>SOAP/WSDL/SOA </li></ul></ul>
  17. 17. JRuby on Rails: Deployment <ul><li>Use goldspike plugin to build WAR file </li></ul><ul><li>Deploy to any Java EE App Server </li></ul>
  18. 18. DEMO <ul><li>JUG Meeting App </li></ul><ul><ul><li>Create Meetings </li></ul></ul><ul><ul><li>Create Attendees </li></ul></ul><ul><ul><li>Associate Attendees w/ Meetings </li></ul></ul><ul><ul><li>Conduct Prize Drawings </li></ul></ul>
  19. 19. Groovy <ul><li>Written specifically for the JVM (JSR-241) </li></ul><ul><li>Generates bytecode for the JVM and supports both static and dynamic typing </li></ul><ul><li>A runtime and library (GDK) extension to Java </li></ul><ul><li>Expressive Java-like syntax </li></ul><ul><li>Same object model as Java (a Groovy object is a Java object!) </li></ul>
  20. 20. Groovy <ul><li>Same mechanisms for: </li></ul><ul><ul><li>Class extension and interface implementation </li></ul></ul><ul><ul><li>Method overloading </li></ul></ul><ul><ul><li>JavaBean ™ creation (with a twist!) </li></ul></ul><ul><li>But brings the dynamic features of Ruby, Python, and Smalltalk to a Java friendly environment </li></ul>
  21. 21. <ul><li>Based on solid foundations </li></ul><ul><ul><li>Groovy </li></ul></ul><ul><ul><li>Spring and Spring MVC </li></ul></ul><ul><ul><li>Hibernate </li></ul></ul><ul><ul><li>Quartz </li></ul></ul><ul><ul><li>Sitemesh </li></ul></ul><ul><ul><li>Embedded Jetty and HSQLDB </li></ul></ul><ul><li>And, of course, Java ™ technology </li></ul>Grails
  22. 22. Why Groovy/Grails? <ul><li>Simplicity and flexibility </li></ul><ul><ul><li>All the power of the underlying frameworks is available to you, but you don’t have to use it! </li></ul></ul><ul><li>Mindshare integration </li></ul><ul><ul><li>Developers have no need to abandon their existing Java knowledge </li></ul></ul><ul><li>API integration </li></ul><ul><ul><li>Groovy/Grails provides elegant extensions to existing good APIs (GORM). </li></ul></ul>
  23. 23. Why Groovy/Grails? <ul><li>Blended Development Approach </li></ul><ul><ul><li>Write appropriate portions of your application in Groovy and/or Java </li></ul></ul><ul><li>Dynamic Language Features </li></ul><ul><ul><li>Pure OO </li></ul></ul><ul><ul><li>Syntax Sugar </li></ul></ul><ul><ul><li>Dynamic typing </li></ul></ul><ul><ul><li>Closures </li></ul></ul><ul><ul><li>Metaprogramming </li></ul></ul>
  24. 24. DEMO <ul><li>JUG Meeting App </li></ul><ul><ul><li>Create Meetings </li></ul></ul><ul><ul><li>Create Attendees </li></ul></ul><ul><ul><li>Associate Attendees w/ Meetings </li></ul></ul><ul><ul><li>Conduct Prize Drawings </li></ul></ul>
  25. 25. Dynamic Languages Summary <ul><li>JVM integration means zero loss of Java investment (developer knowledge, infrastructure) </li></ul><ul><li>Powerful language features increase developer productivity </li></ul><ul><li>Frameworks designed for rapid, agile development of web applications </li></ul>
  26. 26. Q/A <ul><li>Questions??? </li></ul>
  27. 27. Resources <ul><li>http://ruby-lang.org </li></ul><ul><li>http://jruby.codehaus.org </li></ul><ul><li>http://rubyonrails.org </li></ul><ul><li>http://groovy.codehaus.org </li></ul><ul><li>http://grails.codehaus.org </li></ul><ul><li>http://memphisjug-dynamiclanguages-oct07.googlecode.com </li></ul>