Page 1
ThoughtWorksThoughtWorks
NEAL FORD software architect / meme wrangler
ThoughtWorks
[email protected] 3003 Summit Boulevard, Atlanta, GA 30319
www.nealford.com
www.thoughtworks.com
blog: memeagora.blogspot.com
twitter: neal4d
comparing groovy & jruby *
* please check all knives, guns, pitchforks, and torches at the door
Page 2
housekeepingask questions at the end (insane amount of material!)
download slides from nealford.com
download samples from github.com/nealford
Page 3
eigenclass approaches
syntax
closures
framework approach
meta-programming
agenda:
Page 5
Groovy dynamicizesthe JavaTM platform
JRuby brings Ruby tothe JavaTM platform
Page 6
strong
staticdynamic
weak
strong
staticdynamic
weak
Page 8
differences & observations
Page 11
this.name
@name
vs
Page 14
auto-encapsulation?
Page 18
Ruby has some Perl-isms...
...with significant differences
Page 27
in Groovy, everything is an object...
in Java™, everything is an object...
...except primitives and nulls
in JRuby, everything is an object
except null
everything except...
Page 28
null is null
?. handles protected reference
person?.address?.street
Page 29
nil is an instance of NilClass
Page 31
switch/case statement
Page 35
“spread” operator
Page 37
side effects of encapsulating
Java™
Page 38
things added to Object
Page 39
supporting collections
Page 41
JRuby adds artifacts to “Rubify” Java™
...but doesn’t add collection stuff to Object
JRuby additions
ArrayList
Fixnum
Page 42
Groovy is optionally typed
Page 44
search exists on Stack
but not on ArrayListor List!
Page 45
interfaces & mixins
Page 46
“fake out” interfaces via closures using as
allows you to interact with Java™ interfaces
can wrap proxies around them if needed
Groovy & interfaces
Page 48
be careful when implementing with a map:NullPointerException if you forget a method
Page 49
named after ice cream mix-ins
mixin
first appeared in symbolic logic’s flavors system
a way to collect functionality
not a form of specialization
Ruby has no interfaces
Page 56
violating handshakes
Page 57
mixins in Groovy,interfaces in JRuby
Page 59
interfaces in JRuby?
Page 62
mostly parity (functionally)
very different implementations
Page 63
attr_reader, attr_writer, attr_accessor
much of Ruby’s infrastructure is meta-programming
meta-programming methods:
private, protected, public
include
executable declarations
Page 64
AST transformations
Page 67
optional inclusion
Page 68
conditional method
Page 71
sticky attributes
private, protected, public
Page 73
adding methods via proxies
Page 75
Groovy’s eigenclass
Page 76
framework approach
Page 77
encapsulate & extend
Page 78
use Groovy to simplify and humanize them
leverage the existing industrial strength Java™ stack
encapsulate best-of-breed frameworks
encapsulate, then build up
Groovy & Grails
Page 80
abstractionlayersviameta || dsl
Page 81
Ruby on Rails = software factories + dsl’s
tends to build things as abstraction layers atop Ruby using meta-programming & dsl techniques
lightweight abstraction layers
Ruby language is always 1 abstraction layer down
Ruby
Page 82
case study: builders
Page 83
GroovyObjectSupport
BuilderSupport
MarkupBuilder
Page 86
builder works via method_missing
but what about this?
Page 88
the problem:
how do you inherit from object...
...with inheriting from object?
Page 89
BlankSlate
Recorder
Jim Weirich’s BlankSlate1.8
1.9BasicObject
BasicObject
Recorder
Object
RecorderBuilder Builder
Page 91
abstractions with dsl’s
Groovy encapsulates and builds up
Ruby either builds
via meta-programming
different philosophies
Page 95
the real JDK™ 2.0!
unparalleled Java™ integration
willing to evolve the language
building up from best-of-breed
the good
Page 96
never spread out of the Java™ community
fast changing at the core
single runtime platform
framework approach?
the bad
Page 97
def name
public String getName()public void setName(String name)
Page 99
futuristic framework approach
well established (older than Java™)
virtually effortless meta-programming
interpreted, then jit-ted
truly cross platform, for the new definition of platform
the good
Page 100
unfamiliar frameworks
some impedance mismatch with Java™ (smaller all the time)
yet another language to learn
you have to learn to think like a Ruby-ist
you have to switch to a new community
the bad
Page 102
ThoughtWorks
This work is licensed under the Creative Commons Attribution-Share Alike 3.0 License.
http://creativecommons.org/licenses/by-sa/3.0/us/
?’splease fill out the session evaluationssamples at github.com/nealford
NEAL FORD software architect / meme wrangler
ThoughtWorks
[email protected] 3003 Summit Boulevard, Atlanta, GA 30319
www.nealford.com
www.thoughtworks.com
blog: memeagora.blogspot.com
twitter: neal4d
Page 103
resources
ThoughtWorks
groovy web sitehttp://groovy.codehaus.org
jruby sitehttp://jruby.codehaus.org
Cow in the Road photo by Sophia Huda, from Flickr, under a Creative Commons license
charles nutter’s bloghttp://headius.blogspot.com/
ola bini’s bloghttp://olabini.blogspot.com/
Page 104
resources
ThoughtWorks
graeme rocher’s bloghttp://graemerocher.blogspot.com/
aboutGroovyhttp://aboutGroovy.com
jeff brown’s bloghttp://javajeff.blogspot.com/
venkat subramaniam’s bloghttp://www.agiledeveloper.com/blog/