Dynamic Languages on the JVM

27
Dynamic Languages on the JVM Groovy, Grails, JRuby, and JRuby on Rails Matt Stine Memphis/Mid-South JUG October 18, 2007

Transcript of Dynamic Languages on the JVM

Page 1: Dynamic Languages on the JVM

Dynamic Languages on the JVM

Groovy, Grails, JRuby, and JRuby on Rails

Matt StineMemphis/Mid-South JUG

October 18, 2007

Page 2: Dynamic Languages on the JVM

Dynamic Languages "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." - Wikipedia

Page 3: Dynamic Languages on the JVM

Examples of Dynamic Languages: Ruby

Created by Yukihiro “matz” Matsumoto First released in 1995 Currently at version 1.8.6 http://www.ruby-lang.org

Groovy Project founded by James Strachan and Bob

McWhirter in 2003 Became JSR-241 in 2004 Currently at version 1.1-RC-1 http://groovy.codehaus.org

Page 4: Dynamic Languages on the JVM

DL Quick Feature Tour Absolutely everything is an object – no

primitives! 7.class => java.lang.Integer

Lots of syntactical sugar for lists, maps, ranges, regular expressions, etc.

def numbers = [1,2,3] // a list def ages = 18..65 // a range def currencies = [USD: “US Dollar”, GBP: “Pounds”, EUR: “Euros”]

Dynamic typing Blocks / Closures

3.times {println it} Metaprogramming

Dynamically generate classes Modify existing classes Special dispatching to pretend things exist

Page 5: Dynamic Languages on the JVM

Metaprogramming (Groovy)

Page 6: Dynamic Languages on the JVM

DL for the Web

Ruby = Ruby on RailsFull-stack MVC web development

frameworkOpen Source (MIT)First released in 2004 by David

Heinemeier HanssonCurrently at version 1.2.4

(2.0 coming soon!!!)Ruby and Rails books are outselling

Perl bookshttp://rubyonrails.org

Page 7: Dynamic Languages on the JVM

DL for the WebGroovy = Grails

(formerly “Groovy on Rails”)

Model View Controller (MVC) action-based web framework

Open Source (Apache 2.0)First released in early 2006 by Graeme

Rocher, Guillaume LaForge, and Steven Devijver

Currently at version 0.6(1.0 coming soon!!!)

Now backed by a company, G2one, formed by authors (October 2007).

http://grails.org

Page 8: Dynamic Languages on the JVM

DL Web Framework SimilaritiesConvention over configuration

Why punish the common cases?Encourages standard practicesEverything simpler and smaller

Don’t Repeat Yourself (DRY)Frameworks written around

minimizing repetitionRepetitive code harmful to

adaptability

Page 9: Dynamic Languages on the JVM

DL Web Framework SimilaritiesAgile development environment

No recompile, deploy, restart cyclesSimple tools to generate code quicklyTesting built into the frameworks

Full StackAll technologies necessary to build

persistence, service, and web layers fully integrated.

Page 10: Dynamic Languages on the JVM

What does all of this have to do with Java?!?!?!

Both of these languages are

FIRST CLASS CITIZENS on the Java Virtual

Machine!

Page 11: Dynamic Languages on the JVM

JRuby

Started in 2002 Java platform implementation of

Ruby languageOpen source, many active

contributors, including full-time Sun employees

Currently at version 1.0.1Fully compatible with Ruby 1.8.5

(including Rails!)http://jruby.codehaus.org

Page 12: Dynamic Languages on the JVM

JRuby

Integrates with Java technologyCall to Ruby from Java technology via

JSR 223, BSF, SpringUse Java class files from Ruby (e.g.

Script Java)Growing set of external projects

based on JRubyJRuby-extras (GoldSpike,

ActiveRecord-JDBC, Mongrel-JRuby, Mongrel-JCluster, …)

Page 13: Dynamic Languages on the JVM

Why JRuby?

JRuby over RubyStrong likelihood it will be faster soonBetter scalability with native

threadingNative Unicode supportCompilationIntegration with Java librariesEasier path to getting Ruby in the

enterprise

Page 14: Dynamic Languages on the JVM

Why JRuby?

JRuby over Java technologyLanguage features

Blocks, modules, metaprogramming, dynamic-typing

Ruby applications/librariesRails, Rspec, Rake, Raven, other

R’s

Page 15: Dynamic Languages on the JVM

Why JRuby on Rails? “Less Rails code that Java application

configuration.” Growing excited community of developers Makes small apps trivial to create Deployment to Java application servers Java technology production environments are

pervasive Easier to switch framework vs. whole architecture Lower barrier to entry

Broader, more scalable database support Integration w/ Java technology libs, legacy

services

Page 16: Dynamic Languages on the JVM

JRuby on Rails: Java EE PlatformPool database connectionsAccess any JNDI resourceAccess any Java EE platform TLA:

Java Persistence API (JPA)Java Management Extensions (JMX)Enterprise JavaBeans™ (EJB™)Java Message Service (JMS) APISOAP/WSDL/SOA

Page 17: Dynamic Languages on the JVM

JRuby on Rails: Deployment

Use goldspike plugin to build WAR file

Deploy to any Java EE App Server

Page 18: Dynamic Languages on the JVM

DEMO

JUG Meeting AppCreate MeetingsCreate AttendeesAssociate Attendees w/

MeetingsConduct Prize Drawings

Page 19: Dynamic Languages on the JVM

Groovy

Written specifically for the JVM (JSR-241)

Generates bytecode for the JVM and supports both static and dynamic typing

A runtime and library (GDK) extension to Java

Expressive Java-like syntaxSame object model as Java (a

Groovy object is a Java object!)

Page 20: Dynamic Languages on the JVM

Groovy

Same mechanisms for:Class extension and interface

implementationMethod overloadingJavaBean™ creation (with a twist!)

But brings the dynamic features of Ruby, Python, and Smalltalk to a Java friendly environment

Page 21: Dynamic Languages on the JVM

Based on solid foundationsGroovySpring and Spring MVCHibernateQuartzSitemeshEmbedded Jetty and HSQLDB

And, of course, Java™ technology

Grails

Page 22: Dynamic Languages on the JVM

Why Groovy/Grails?

Simplicity and flexibility All the power of the underlying frameworks

is available to you, but you don’t have to use it!

Mindshare integration Developers have no need to abandon their

existing Java knowledge

API integration Groovy/Grails provides elegant extensions to

existing good APIs (GORM).

Page 23: Dynamic Languages on the JVM

Why Groovy/Grails?

Blended Development Approach Write appropriate portions of your

application in Groovy and/or Java

Dynamic Language Features Pure OO Syntax Sugar Dynamic typing Closures Metaprogramming

Page 24: Dynamic Languages on the JVM

DEMO

JUG Meeting AppCreate MeetingsCreate AttendeesAssociate Attendees w/

MeetingsConduct Prize Drawings

Page 25: Dynamic Languages on the JVM

Dynamic Languages SummaryJVM integration means zero loss of

Java investment (developer knowledge, infrastructure)

Powerful language features increase developer productivity

Frameworks designed for rapid, agile development of web applications

Page 26: Dynamic Languages on the JVM

Q/A

Questions???

Page 27: Dynamic Languages on the JVM

Resources

http://ruby-lang.org http://jruby.codehaus.org http://rubyonrails.org http://groovy.codehaus.org http://grails.codehaus.org http://memphisjug-dynamiclanguages-o

ct07.googlecode.com