Comparing groovy and_j_ruby(neal_ford)

1,376
-1

Published on

Presentation of Neal Ford on JavaOne 2010

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,376
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Comparing groovy and_j_ruby(neal_ford)

  1. 1. ThoughtWorks comparing groovy & jruby * * please check all knives, guns, pitchforks, and torches at the door NEAL FORD software architect / meme wrangler ThoughtWorks nford@thoughtworks.com 3003 Summit Boulevard, Atlanta, GA 30319 www.nealford.com www.thoughtworks.com blog: memeagora.blogspot.com twitter: neal4d
  2. 2. housekeeping ask questions at the end (insane amount of material!) download slides from nealford.com download samples from github.com/nealford
  3. 3. agenda: syntax closures eigenclass approaches meta-programming framework approach
  4. 4. geek fu test:
  5. 5. Groovy dynamicizes JRuby brings Ruby to the Java platform TM the Java platform TM
  6. 6. differences & observations
  7. 7. syntax
  8. 8. sigils
  9. 9. this.name vs @name
  10. 10. auto-encapsulation?
  11. 11. Perl !!!!!!!!!
  12. 12. Ruby has some Perl-isms... ...with significant differences
  13. 13. closures
  14. 14. passing closures
  15. 15. auto-blocks
  16. 16. passing closures
  17. 17. everything except... in Java™, everything is an object... ...except primitives and nulls in Groovy, everything is an object... except null in JRuby, everything is an object.
  18. 18. null is null ?. handles protected reference person?.address?.street
  19. 19. nil is an instance of NilClass
  20. 20. switch/case statement
  21. 21. === isCase()
  22. 22. “spread” operator
  23. 23. “elvis” operator
  24. 24. side effects of encapsulating Java™
  25. 25. things added to Object
  26. 26. supporting collections
  27. 27. really? really!
  28. 28. JRuby additions JRuby adds artifacts to “Rubify” Java™ ArrayList Fixnum ...but doesn’t add collection stuff to Object
  29. 29. Groovy is (kind of) optionally typed
  30. 30. search exists on Stack but not on ArrayList or List!
  31. 31. interfaces & mixins
  32. 32. Groovy & interfaces allows you to interact with Java™ interfaces can wrap proxies around them if needed “fake out” interfaces via closures using as
  33. 33. be careful when implementing with a map: NullPointerException if you forget a method
  34. 34. Ruby has no interfaces mixin first appeared in symbolic logic’s flavors system named after ice cream mix-ins not a form of specialization a way to collect functionality
  35. 35. comparisons
  36. 36. comparisons
  37. 37. comparisons
  38. 38. violating handshakes
  39. 39. mixins in Groovy, interfaces in JRuby
  40. 40. interfaces in JRuby?
  41. 41. meta-programming
  42. 42. mostly parity (functionally) very different implementations
  43. 43. executable declarations much of Ruby’s infrastructure is meta- programming meta-programming methods: attr_reader, attr_writer, attr_accessor include private, protected, public
  44. 44. AST transformations
  45. 45. implementation
  46. 46. optional inclusion
  47. 47. conditional method
  48. 48. attributes
  49. 49. hook methods
  50. 50. sticky attributes private, protected, public
  51. 51. eigenclass
  52. 52. adding methods via proxies
  53. 53. Groovy’s eigenclass
  54. 54. framework approach
  55. 55. encapsulate & extend
  56. 56. Groovy & Grails leverage the existing industrial strength Java™ stack encapsulate best-of-breed frameworks use Groovy to simplify and humanize them encapsulate, then build up
  57. 57. abstraction layers via meta || dsl
  58. 58. Ruby tends to build things as abstraction layers atop Ruby using meta-programming & dsl techniques Ruby on Rails = software factories + dsl’s Ruby language is always 1 abstraction layer down lightweight abstraction layers
  59. 59. case study: builders
  60. 60. GroovyObjectSupport BuilderSupport MarkupBuilder
  61. 61. builder
  62. 62. builder works via method_missing but what about this?
  63. 63. the problem: how do you inherit from object... ...with inheriting from object?
  64. 64. Jim Weirich’s 1.8 BlankSlate Object BasicObject BlankSlate Builder Recorder Builder Recorder Recorder 1.9 BasicObject
  65. 65. different philosophies Groovy encapsulates and builds up Ruby either builds abstractions with dsl’s via meta-programming
  66. 66. summary
  67. 67. the good unparalleled Java™ integration willing to evolve the language the real JDK™ 2.0! building up from best-of-breed
  68. 68. the bad fast changing at the core single runtime platform never spread out of the Java™ community framework approach?
  69. 69. def name public String getName() public void setName(String name)
  70. 70. the good well established (older than Java™) virtually effortless meta-programming futuristic framework approach truly cross platform, for the new definition of platform interpreted, then jit-ted
  71. 71. the bad some impedance mismatch with Java™ (smaller all the time) yet another language to learn unfamiliar frameworks you have to switch to a new community you have to learn to think like a Ruby-ist
  72. 72. ThoughtWorks ?’s please fill out the session evaluations samples at github.com/nealford NEAL FORD software architect / meme wrangler ThoughtWorks nford@thoughtworks.com This work is licensed under the Creative Commons 3003 Summit Boulevard, Atlanta, GA 30319 www.nealford.com Attribution-Share Alike 3.0 License. www.thoughtworks.com blog: memeagora.blogspot.com http://creativecommons.org/licenses/by-sa/3.0/us/ twitter: neal4d
  73. 73. ThoughtWorks resources Cow in the Road photo by Sophia Huda, from Flickr, under a Creative Commons license groovy web site http://groovy.codehaus.org jruby site http://jruby.codehaus.org ola bini’s blog http://olabini.blogspot.com/ charles nutter’s blog http://headius.blogspot.com/
  74. 74. ThoughtWorks resources jeff brown’s blog http://javajeff.blogspot.com/ graeme rocher’s blog http://graemerocher.blogspot.com/ aboutGroovy http://aboutGroovy.com venkat subramaniam’s blog http://www.agiledeveloper.com/blog/

×