comparing groovy and jruby - oracle.com · groovy dynamicizes the java tm platform jruby brings...

104
ThoughtWorks ThoughtWorks 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

Upload: phungtu

Post on 12-Feb-2019

221 views

Category:

Documents


0 download

TRANSCRIPT

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

housekeepingask questions at the end (insane amount of material!)

download slides from nealford.com

download samples from github.com/nealford

eigenclass approaches

syntax

closures

framework approach

meta-programming

agenda:

geek fu test:

Groovy dynamicizesthe JavaTM platform

JRuby brings Ruby tothe JavaTM platform

strong

staticdynamic

weak

strong

staticdynamic

weak

differences & observations

syntax

sigils

this.name

@name

vs

auto-encapsulation?

Perl !!!!!!!!!

Ruby has some Perl-isms...

...with significant differences

closures

passing closures

auto-blocks

passing closures

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...

null is null

?. handles protected reference

person?.address?.street

nil is an instance of NilClass

switch/case statement

=== isCase()

“spread” operator

“elvis” operator

side effects of encapsulating

Java™

things added to Object

supporting collections

really? really!

JRuby adds artifacts to “Rubify” Java™

...but doesn’t add collection stuff to Object

JRuby additions

ArrayList

Fixnum

Groovy is optionally typed

search exists on Stack

but not on ArrayListor List!

interfaces & mixins

“fake out” interfaces via closures using as

allows you to interact with Java™ interfaces

can wrap proxies around them if needed

Groovy & interfaces

be careful when implementing with a map:NullPointerException if you forget a method

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

comparisons

comparisons

comparisons

violating handshakes

mixins in Groovy,interfaces in JRuby

interfaces in JRuby?

meta-programming

mostly parity (functionally)

very different implementations

attr_reader, attr_writer, attr_accessor

much of Ruby’s infrastructure is meta-programming

meta-programming methods:

private, protected, public

include

executable declarations

AST transformations

implementation

optional inclusion

conditional method

attributes

hook methods

sticky attributes

private, protected, public

eigenclass

adding methods via proxies

Groovy’s eigenclass

framework approach

encapsulate & extend

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

abstractionlayersviameta || dsl

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

case study: builders

GroovyObjectSupport

BuilderSupport

MarkupBuilder

builder

builder works via method_missing

but what about this?

the problem:

how do you inherit from object...

...with inheriting from object?

BlankSlate

Recorder

Jim Weirich’s BlankSlate1.8

1.9BasicObject

BasicObject

Recorder

Object

RecorderBuilder Builder

abstractions with dsl’s

Groovy encapsulates and builds up

Ruby either builds

via meta-programming

different philosophies

summary

the real JDK™ 2.0!

unparalleled Java™ integration

willing to evolve the language

building up from best-of-breed

the good

never spread out of the Java™ community

fast changing at the core

single runtime platform

framework approach?

the bad

def name

public String getName()public void setName(String name)

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

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

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

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/

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/