jruby: what, why, howdo it now! - oraclejava technology implementation of ruby language...
TRANSCRIPT
JRuby: What, Why, How...Do it Now!
Thomas E Enebo, JRuby Core DeveloperCharles Oliver Nutter, JRuby Core DeveloperTS-5416
2008 JavaOneSM Conference | java.sun.com/javaone | 2
Learn how awesome JRuby isLearn how much nicer Java™ technology-based APIs can beGet a taste for NetBeans™ Ruby and RailsAsk those burning questions you have
2008 JavaOneSM Conference | java.sun.com/javaone | 3
The JRuby Guys
Charles Oliver Nutter and Thomas EneboLongtime Java code developers (10+ yrs each)Engineers at Sun Microsystems for 1 yrFull-time JRuby developersAlso working on Java Virtual Machine (JVM) dynlang supportWide range of past experience• C, C++, C#, Perl, Python, Delphi, Lisp, Scheme• Java Platform, Enterprise Edition (Java EE) and Java Platform,
Micro Edition (Java ME), JINI™ (JINI), WS technologies
2008 JavaOneSM Conference | java.sun.com/javaone | 4
What is Ruby?Dynamically-typed pure object-oriented programming languageFocus on simplicity, productivity, and “fun”InterpretedOpen source, written in CImplementation is the SpecificationCreated 1993 by Yukihiro “Matz” Matsumoto“More powerful than Perl and more OO than Python”Very active community, wide range of apps
2008 JavaOneSM Conference | java.sun.com/javaone | 5
Ruby Quick Tour: Objects EverywherePure Object-Oriented LanguageLook mom...No primitives
7.class => Fixnum“hello”.length => 53.times { |i| puts “#{i}: No place like home” } => 1: No place like home 2: No place like home 3: No place like home
2008 JavaOneSM Conference | java.sun.com/javaone | 6
Ruby Quick Tour: Sweet SugarSyntactical sugar• Strings: “foo”• Arrays: ['one', 1, Ein.new]• Associative Arrays: {'a' => 3, 'b' => 4}• Regular Expressions: /^foo.*bar/
2008 JavaOneSM Conference | java.sun.com/javaone | 7
Ruby Quick Tour: Dynamic TypingDynamically-Typed Language (Duck-Typing)• “If it quacks like a duck and waddles like a duck then ...”
def make_it_waddle(waddler) waddler.waddleend
make_it_waddle(Duck.new) make_it_waddle(Penguin.new)make_it_waddle(Octopus.new)
2008 JavaOneSM Conference | java.sun.com/javaone | 8
Ruby Quick Tour: Classes and ModulesRuby classes are like Java classesRuby modules “mixin” behavior
module ShapeStuff def diameter return 2 * @radius endend
class Circle include ShapeStuff ...endCircle.new(4).diameter => 8
2008 JavaOneSM Conference | java.sun.com/javaone | 9
Ruby Quick Tour: BlocksAnonymous methods you can pass around and invoke• Add block to be invoked on end of method call• Removes repetitive code
• list.each { |element| ... do something ...}• Internalizes transactional code
• File.open(fname) {|file| line = file.gets ...}• Makes nice APIs
2008 JavaOneSM Conference | java.sun.com/javaone | 10
Ruby Quick Tour: MetaprogrammingOpen Classes• Dynamically generate class/module• Modify existing class/module
• Add, remove, alias, or replace methods• include a module• Add or remove class or instance variables
Special handler methods• method_missing• const_missing
2008 JavaOneSM Conference | java.sun.com/javaone | 11
JRubyJava technology implementation of Ruby language• “It's just Ruby!”
Started in 2002, open source, many contributors• Ola Bini, Marcin Mielzinsky, Nick Sieger, Bill Dortch, Vladimir
Sizikov, MenTaLguYAiming for compatibility with current Ruby version• Ruby 1.8.6 patchlevel 111 (114 was just released)
Improvements on Ruby• Native threading, better performance
Plays nice with Java technology• Call to Ruby from Java technology via JSR223, BSF, Spring• Use Java classes from Ruby (e.g. Script Java)
2008 JavaOneSM Conference | java.sun.com/javaone | 12
Interactive Ruby
2008 JavaOneSM Conference | java.sun.com/javaone | 13
What are People Doing with JRuby?Swing GUI development• Makes Swing much nicer to use, easier to handle
Tooling for IDEs• JRuby's parser enables NetBeans, Eclipse communities
Graphics• Ruby + graphics = cool demos
JRuby on Rails• Better deployment options, better performance
2008 JavaOneSM Conference | java.sun.com/javaone | 14
Swing GUI DevelopmentSwing API is very large, complex• Ruby magic simplifies most of the tricky bits
Java language is very verbose• Ruby makes Swing actually fun
No consistent cross-platform GUI library for Ruby• Swing works everywhere Java technology does (everywhere)
No fire-and-forget execution• No dependencies: any script works on any JRuby install
2008 JavaOneSM Conference | java.sun.com/javaone | 15
Swing in Ruby
2008 JavaOneSM Conference | java.sun.com/javaone | 16
Swing OptionsCheri - http://cheri.rubyforge.org/• Builder-like DSL syntax
Profligacy - http://ihate.rubyforge.org/profligacy/• Rubified layout expression language• Trivial event binding without listeners
MonkeyBars - http://monkeybars.rubyforge.org/• Leverage GUI builders• MVC structure
2008 JavaOneSM Conference | java.sun.com/javaone | 17
Cheriinclude Cheri::Swing
frame = swing.frame("Swing builders!") { |form| size 300, 300 box_layout form, :Y_AXIS content_pane { background :WHITE }
button("Event binding is nice") { |btn| on_click { btn.text = "You clicked me!" } }}
frame.visible = true
2008 JavaOneSM Conference | java.sun.com/javaone | 18
Profligacyclass ProfligacyDemo import javax.swing.* include Profligacy def initialize layout = "[<translate][*input][>result]" @ui = Swing::LEL.new(JFrame, layout) {|cmps, ints| cmps.translate = JButton.new("Translate") cmps.input = JtextField.new; cmps.result = JLabel.new
translator = proc {|id, evt| original = @ui.input.text translation = MyTranslator.translate(original) @ui.result.text = translation }
ints.translate = {:action => translator}...
2008 JavaOneSM Conference | java.sun.com/javaone | 19
Monkeybarsclass RssController < Monkeybars::Controller set_view "RssView" set_model "RssModel" close_action :exit add_listener :type => :mouse, :components => ["goButton", "articleList"] def go_button_mouse_released(view_state, event) model.feed_url = view_state.feed_url content = Kernel.open(model.feed_url).read @rss = RSS::Parser.parse(content, false) model.articles = @rss.items.map {|art| art.title} update_view ... ...
2008 JavaOneSM Conference | java.sun.com/javaone | 20
JRuby Enables ToolingJRuby's parser used by most Ruby IDEs• NetBeans Ruby Support• Eclipse RDT/RadRails/Aptana, DLTK, 3rd Rail• IntelliJ (not parser, but other areas)• Jedit
NetBeans community is the best right now
2008 JavaOneSM Conference | java.sun.com/javaone | 21
NetBeans Project Teaser
2008 JavaOneSM Conference | java.sun.com/javaone | 22
NetBeans Ruby TalksLAB-8400: Developing (J)Ruby on Rails Applications with the NetBeans™ IDE• Tuesday, 3:20PM-5:20PM
TS-5249: The NetBeans™ Ruby IDE: You Thought Rails Development Was Fun Before• Wednesday, 2:50PM-3:50PM
2008 JavaOneSM Conference | java.sun.com/javaone | 23
Pretty Graphics!“Processing is an open source programming language and environment for people who want to program images, animation, and interactions.”• Basically a cool Java library for 2D graphics
Ruby-Processing wraps Processing with JRuby• Cool, rubified 2D graphics environment for you• Eye-candy demos for us• Thanks to Jeremy Ashkenas for putting these together
2008 JavaOneSM Conference | java.sun.com/javaone | 24
Processing: Pretty Graphics
2008 JavaOneSM Conference | java.sun.com/javaone | 25
Introducing Ruby on Rails
A Full-stack MVC web development frameworkOpen Source (MIT), Many ContributorsWritten in RubySingle-Threaded designFirst released in 2004 by David Heinemeier HanssonRuby and Rails book sales are outselling Perl book salesShipping with “Leopard”
2008 JavaOneSM Conference | java.sun.com/javaone | 26
Ruby on Rails Precepts
Convention over Configuration• Why punish the common cases?• Encourages standard practices• Everything simpler and smaller
Don't Repeat Yourself (DRY)• Framework written around minimizing repetition• Repetitive code harmful to adaptability
Agile Development Environment• No recompile, deploy, restart cycles• Simple tools to generate code quickly• Testing built into framework
2008 JavaOneSM Conference | java.sun.com/javaone | 27
Why JRuby on Rails
Greatly simplified application development• “Less Rails code than Java application configuration”
Create applications quicklyDeployment to Java application servers (GlassFish)Easy Integration with existing Java TechnologyBetter performance, scaling
2008 JavaOneSM Conference | java.sun.com/javaone | 28
Rails Quick Tour: Components
ActiveRecord• Data-driven ORM
ActionPack• View and controller support
ActiveResource• RESTful exposure of resources
ActionMailer• Email
ActiveSupport• Unicode, json, miscellaneous helpers
2008 JavaOneSM Conference | java.sun.com/javaone | 29
Ruby on Rails Demo
2008 JavaOneSM Conference | java.sun.com/javaone | 30
Production JRuby on Rails
Oracle's Mix – digg-like social customer site• mix.oracle.com
Sun's MediaCast – file distribution portal• mediacast.sun.com
ThoughtWorks' Mingle – collaborative project mgmt• mingle.thoughtworks.com
Sonar – code/project analysis tool• sonar.hortis.ch
More on the way!
2008 JavaOneSM Conference | java.sun.com/javaone | 31
JRuby on Rails TalksTS-4806: JRuby on Rails: Web Development Evolved• Wednesday, 1:30PM-2:30PM
TS-6490: JRuby on Rails Deployment: What They Didn’t Tell You• Thursday, 10:50AM-11:50AM
BOF-5111: Scripting in GlassFish™ Project• Tuesday, 8:30PM-9:20PM
LAB-8400: Developing (J)Ruby on Rails Applications with the NetBeans™ IDE• Tuesday, 3:20PM-5:20PM
TS-5249: The NetBeans™ Ruby IDE: You Thought Rails Development Was Fun Before• Wednesday, 2:50PM-3:50PM
2008 JavaOneSM Conference | java.sun.com/javaone | 32
Other JRuby and Ruby-related TalksPAN-5345: The Script Bowl: A Rapid-Fire Comparison of Scripting Languages• Wednesday, 9:30AM-10:30AM
BOF-4807: JRuby at ThoughtWorks• Wednesday, 7:30PM-8:30PM
TS-4868: From Java™ Technology to Ruby...and Back• Thursday, 4:10PM-5:10PM
BOF-6554: PHP, Ruby and friends - going mobile• Thursday, 8:30PM-9:20PM
TS-6050: Comparing JRuby and Groovy• Wednesday, 1:30PM-2:30PM• Friday, 1:30PM-2:30PM
2008 JavaOneSM Conference | java.sun.com/javaone | 33
Summary
JRuby gives Java technology access to the Ruby language• Powerful, terse, and a whole lot of fun!
JRuby gives Java developers access to Ruby on Rails• The way web development should be• Driving force behind the “new way” in web frameworks
Many People are using JRuby today• Production ready• Fast• ...and still moving forward!
2008 JavaOneSM Conference | java.sun.com/javaone | 34
Thomas E Enebo, JRuby Core DeveloperCharles Oliver Nutter, JRuby Core Developer
TS-5416