SlideShare a Scribd company logo
1 of 66
Download to read offline
Why would a Java Shop
 want to use Ruby?
              Keith Pitty
      Open Source Developers’ Conference
                  Brisbane
             29 November 2007
About Keith
•    Programming professionally since 1983
    •      Early experience on mainframes
    •      Smalltalk was my first OO language
    •      Employed by a Java consultancy since 2000
    •      Fascinated by Ruby and Rails since 2004
•    Enjoy sampling a wide range of beers


    Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Java




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Java
public class print {
    public static void main(String[] args) {
        System.out.println(quot;Hi, I'm Javaquot;);
    }
}




     Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby

                    #!/usr/bin/env ruby

                    puts quot;Hi, I'm Rubyquot;




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
No!!!
 •       This is not a language war!
       •      Java and Ruby both have their
              strengths
       •      I’m not interested in Ruby
              “beating” Java
 •       The question is:
       •      Can Ruby help Java programmers?

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Java
   •       Most popular language (21.7%)
         •       TIOBE PCI, September 2007
   •       Mature platform
   •       Trusted in the “enterprise”
   •       Has reached a plateau
   •       “The new COBOL”

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby
•     Tenth most popular language (2.1%)
•     Marked increase in popularity since
      mid-2006 due to Ruby on Rails
•     Matz’s original motivation:
    •       a scripting language
          •       more powerful than Perl
          •       more object-oriented than Python

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Why Ruby?
               (Quote Part 1)
   “I don’t believe there would be any real technical
 benefit. There may be a productivity boost, but when
you consider how much time is used by developers, QA,
etc... to bring in a new technology, chances are the net
              [benefit] won’t be that great.”



     Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Why Ruby?
          (Quote Part 2)
 “I think the best argument for Ruby is that
your developers want it. If the developers are
  yearning for new technology, it’s probably
 worth considering. Happy developers code
            more and code better.”

                                          Norman Richards, JBoss


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Perspectives
                •       Vendors
                •       Open source contributors
                •       Managers
                •       Business owners
                •       Developers


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby: Why not?
   •       How widespread is knowledge of
           Ruby within the Java community?
         •       In my experience, there is
                 limited awareness
   •       On the other hand:
         •       Ruby may have benefits that are
                 complementary to Java

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Potential Ruby
              Benefits
•      Ruby skills may complement Java skills
•      Learning Ruby may be interesting,
       broadening a programmer’s thinking
•      Happier programmers
•      Quicker time to market


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Enough Preamble

   •       What does Ruby have to offer
           people in Java development shops?
   •       Let’s explore some specifics...




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby Scripts


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby Scripts
•   Scripts help with repetitive tasks
    •    Shell scripts, SQL scripts, Ant scripts
•   Sometimes the logic lends itself to a general
    purpose language
    •    Can run a Java application via a shell script
    •    A Ruby script is interpreted directly and is
         more concise

    Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby Script Example

   •       Deleting files within a given
           directory according to given
           criteria
         •       e.g. older than a given time



Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby Script Example*
  #!/usr/bin/env ruby
  def delete_if(dir)
    Dir.chdir(dir) do
      Dir.foreach(*.*) do |entry|
        next if File.stat(entry).directory?
        if yield entry
          File.unlink(entry)
        end
      end
    end
  end

  delete_if(quot;/tmpquot;) { |f| File.mtime(f) <
  Time.local(2007,10,29,0,0,0) }


* See Hal Fulton’s “The Ruby Way”
   Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Rake and Internal DSLs


 Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Rake
•       Ruby-based build language
•       Developed by Jim Weirach
•       Similar to make and ant

•       An internal Domain Specific Language
      •      make and ant are external DSLs



Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Regular Rake Tasks
           task :init do
             # init actions
           end

           task :compile => [:init] do
             # compile actions
           end

           task :build =>
           [:init, :compile] do
             # build actions
           end


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Extending Rake*
  def copyTask srcGlob, targetDirSuffix, taskSymbol
    targetDir = File.join BUILD_DIR, targetDirSuffix
    mkdir_p targetDir, QUIET
    FileList[srcGlob].each do |f|
      target = File.join targetDir, File.basename(f)
      file target => [f] do |t|
        cp f, target
      end
      task taskSymbol => target
    end
  end

  copyTask 'articles/*.gif', 'articles', :articles




   * see Martin Fowler’s rake article
Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Internal DSLs
                •       Other Ruby internal
                        DSLs:
                      •       buildr
                      •       capistrano
                      •       ...
                      •       create your own!


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Buildr
•    a build system for Java apps
•    encompasses Maven and Ant
•    written in Ruby
•    based on Rake
•    uses Antwrap to configure and run Ant tasks
•    extensible in Ruby

    Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Capistrano
   •       Created by Jamis Buck
   •       Originally to “ease the pain of
           deploying Rails applications”
   •       Exposes simple commands
   •       Once project has been “capified”
         •       $ cap deploy

   •       Useful beyond Rails

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Capistrano Example
desc quot;Copy production database config file.quot;
namespace :deploy do
  task :after_update_code, :roles => :app do
    db_config = quot;#{shared_path}/config/database.yml.productionquot;
    run quot;cp #{db_config} #{release_path}/config/database.ymlquot;
  end
end




        Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Metaprogramming


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Metaprogramming
•    Very powerful feature of Ruby
•    Dynamic programming
•    Methods: method_missing, define_method,
     module_eval, class_eval, instance_eval,
     self.included, self.inherited, extend


•    Callable objects: procs, lambdas, blocks
•    Modifying the singleton class: class                               <<


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
method_missing
                  class Roman
                    def roman_to_int(str)
                      # ...
                    end

                    def method_missing(methId)
                      str = methId.id2name
                      roman_to_int(str)
                    end
                  end

                  r = Roman.new
                  r.iv    #=> 4
                  r.xxiii #=> 23
                  r.mm    #=> 2000


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
More Examples?

   •       Open source Ruby frameworks
         •       e.g. Ruby on Rails web application
                 framework
               •       many examples of
                       metaprogramming to be found
                       in the Rails source code

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby on Rails



Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Ruby on Rails
   •       Web application framework released by
           David Heinemeier Hansson in 2004
   •       Extracted from the Basecamp application
   •       The killer app for Ruby
   •       “Convention over Configuration”
   •       Code generators

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Rails Example
 $ rails beers


    Creates directory
    structure for new
    project




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Generating a
                    Resource
$ ./script/generate scaffold_resource beer name:string


     Creates a model, a controller, and a set of
     templates that's ready to use as the
     starting point for your REST-like,
     resource-oriented application.



     Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Migration
      class CreateBeers < ActiveRecord::Migration
        def self.up
          create_table :beers do |t|
            t.column :name, :string
          end
        end

        def self.down
          drop_table :beers
        end
      end



Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Running Migrations
 $ rake db:migrate

    == CreateBeers: migrating
    =====================================================
    -- create_table(:beers)
       -> 0.0735s
    == CreateBeers: migrated (0.0737s)
    ============================================




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Model

       class Beer < ActiveRecord::Base
         has_many :votes
       end




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
View (new.rhtml)
          <h1>New beer</h1>

          <%= error_messages_for :beer %>

          <% form_for(:beer, :url => beers_path) do |f| %>
            <p>
              <b>Name</b><br />
              <%= f.text_field :name %>
            </p>

            <p>
              <%= submit_tag quot;Createquot; %>
            </p>
          <% end %>

          <%= link_to 'Back', beers_path %>



Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Controller
          class BeersController < ApplicationController

            def new
              @beer = Beer.new
            end

            def create
              @beer = Beer.new(params[:beer])
              respond_to do |format|
                if @beer.save
                  flash[:notice] = 'Beer was successfully created.'
                  format.html { redirect_to beer_url(@beer) }
                else
                  format.html { render :action => quot;newquot; }
                end
              end
            end

          end


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
More about Rails
•      There’s much more about Rails to explore
     •      But that’s another topic
•      We’ve touched upon some appealing
       aspects
•      Development is much quicker!
•      But ...

    Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Java Perspective

•     What if ...
    •       Java provides where Ruby doesn’t?
•     What about ...
    •       deploying Rails apps?



Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Java and Ruby




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
JRuby


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
JRuby
•    Java implementation of Ruby
•    Major advantages:
    •     Java libraries can be used with Ruby syntax
    •     Deploy Rails apps on Java app servers
         •      via WAR files


    Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Invoking Java from Ruby
         require 'java'

         m = java.util.HashMap.new

         m.put quot;Streamquot;, quot;Rubyquot;
         m.put quot;Topicquot;, quot;JRubyquot;

         iter = m.keySet.iterator
         while iter.hasNext
           key = iter.next
           puts quot;#{key}=#{m.get(key)}quot;
         end


 Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Some JRuby Capabilities

•      Implement Java interfaces via import or impl

•      Extend Java classes
•      Use Ruby methods on Java collections
       courtesy of Ruby mixins
•      Use JavaUtilities.extend_proxy to add
       methods to Java types

    Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Java DOM and XSLT*
 require 'java'
 require 'stringio'

 TransformerFactory = javax.xml.transform.TransformerFactory
 StreamSource = javax.xml.transform.stream.StreamSource
 StreamResult = javax.xml.transform.stream.StreamResult

 f = TransformerFactory.new_instance
 t = f.new_transformer
 StreamSource.new(java.io.FileReader.new(ARGV[1]))
 s = StringIO.new
 t.transform StreamSource.new(java.io.FileReader.new(ARGV[0])),
               StreamResult.new(org.jruby.util.IOOutputStream.new(s))
 puts s.string


* see Ola Bini’s book
   Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
JRuby on Rails



Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
JRuby on Rails:
                    JDBC
•   Download JDBC
    driver                                     development:
                                                 adapter: jdbc
                                                 driver: com.mysql.jdbc.Driver


•   Add to CLASSPATH                             url: jdbc:mysql://localhost/
                                               beers_development
                                                 username: test


•
                                                 password: test
    Configure config/
    database.yml


•   Update config/                             require 'jdbc_adapter'

    environment.rb                             Rails::Initializer.run do |config|




     Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Deploying JRuby on
  Rails Applications
   •       Option 1:
         •       Pack of Mongrels inside one JVM
   •       Option 2:
         •       Bundle as WAR and deploy
                 inside Tomcat


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Pack of Mongrels
•      Familiar to Rails developers
•      Install mongrel_jcustler Gem

•      Configure pack using mongrel_rails

•      Start pack using mongrel_rails

•      Configure load balancing proxy
       support and virtual host in Apache

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Deploying via a WAR
   •       Install GoldSpike plug-in in Rails app
   •       Configure app with correct driver for
           JDBC connections (in config/war.rb)

   •       Use jruby rake task to create WAR
   •       Deploy WAR
   •       Configure Apache

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Installing GoldSpike

jruby script/plugin install -x
  svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike




          Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
JDBC Driver Config


maven_library 'mysql', 'mysql-connector-java', '5.0.4'




     Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Create WAR


       jruby -S rake war:standalone:create




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Deploy WAR

         cp beers.war $TOMCAT_HOME/webapps




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Conclusion
•    Ruby offers some interesting benefits
•    Ruby on Rails offers quick development
     for CRUD web apps
•    JRuby enables Ruby apps to call Java code
•    JRuby enables deployment of Rails apps
     via WAR files to Java app servers


Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Resources
   •       Ola Bini. Practical JRuby on Rails Web
           2.0 Projects. Apress, 2007
   •       David A. Black. Ruby for Rails.
           Manning, 2006
   •       http://buildr.rubyforge.org
   •       http://www.capify.org
   •       http://jruby.codehaus.org

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Resources (ctd.)
•     Martin Fowler. RailsConf2007 => http://
      martinfowler.com/bliki/
      RailsConf2007.html
•     Martin Fowler. Using the Rake Build
      Language => http://martinfowler.com/
      articles/rake.html
•     Hal Fulton. The Ruby Way. Addison-
      Wesley, 2007

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Resources (ctd)
   •       David Heinemeier Hansson. Sun
           surprises at RailsConf Europe 2007
           => http://www.loudthinking.com/
           posts/11-sun-surprises-at-railsconf-
           europe-2007
   •       Brian Marick. Everyday Scripting with
           Ruby: For Teams, Testers and You.
           Pragmatic Programmers, 2006

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Resources (ctd)
   •       http://mongrel.rubyforge.org
   •       Keith Pitty. Why is Ruby such a good
           language for Rails? => http://
           keithpitty.org/presentations/ruby/
           WhyRubyForRails.pdf
   •       http://rubyonrails.org
   •       http://www.tiobe.com/tpci.htm

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Photo Credits
   •       Bored Cow: http://flickr.com/
           photos/kevincollins/122302356/
   •       Leopard getting ready to drop out
           of tree: http://flickr.com/photos/
           at_large/399149551/
   •       Origami heart: http://flickr.com/
           photos/teagrrl/4802517/

Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007
Thanks for listening!



                    http://keithpitty.com




Why would a Java Shop want to use Ruby?   Keith Pitty   OSDC, 29 November 2007

More Related Content

What's hot

How to develop Jenkins plugin using to ruby and Jenkins.rb
How to develop Jenkins plugin using to ruby and Jenkins.rbHow to develop Jenkins plugin using to ruby and Jenkins.rb
How to develop Jenkins plugin using to ruby and Jenkins.rbHiroshi SHIBATA
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Toolfilmprog
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyelliando dias
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the worldHiroshi SHIBATA
 
20140626 red dotrubyconf2014
20140626 red dotrubyconf201420140626 red dotrubyconf2014
20140626 red dotrubyconf2014Hiroshi SHIBATA
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesHiroshi SHIBATA
 
Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Shaer Hassan
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for RubyHiroshi SHIBATA
 
How to test code with mruby
How to test code with mrubyHow to test code with mruby
How to test code with mrubyHiroshi SHIBATA
 
Extending Ruby using C++
Extending Ruby using C++Extending Ruby using C++
Extending Ruby using C++Tristan Penman
 

What's hot (11)

How to develop Jenkins plugin using to ruby and Jenkins.rb
How to develop Jenkins plugin using to ruby and Jenkins.rbHow to develop Jenkins plugin using to ruby and Jenkins.rb
How to develop Jenkins plugin using to ruby and Jenkins.rb
 
Rake: Not Your Father's Build Tool
Rake: Not Your Father's Build ToolRake: Not Your Father's Build Tool
Rake: Not Your Father's Build Tool
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
 
How to distribute Ruby to the world
How to distribute Ruby to the worldHow to distribute Ruby to the world
How to distribute Ruby to the world
 
20140626 red dotrubyconf2014
20140626 red dotrubyconf201420140626 red dotrubyconf2014
20140626 red dotrubyconf2014
 
Large-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 MinutesLarge-scaled Deploy Over 100 Servers in 3 Minutes
Large-scaled Deploy Over 100 Servers in 3 Minutes
 
Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09Ror Seminar With agilebd.org on 23 Jan09
Ror Seminar With agilebd.org on 23 Jan09
 
The details of CI/CD environment for Ruby
The details of CI/CD environment for RubyThe details of CI/CD environment for Ruby
The details of CI/CD environment for Ruby
 
MacRuby
MacRubyMacRuby
MacRuby
 
How to test code with mruby
How to test code with mrubyHow to test code with mruby
How to test code with mruby
 
Extending Ruby using C++
Extending Ruby using C++Extending Ruby using C++
Extending Ruby using C++
 

Viewers also liked

Clio Final Project 12 10 07
Clio Final Project 12 10 07Clio Final Project 12 10 07
Clio Final Project 12 10 07guest74fc66
 
Seeds And Art
Seeds And ArtSeeds And Art
Seeds And Artcrisman
 
RVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerRVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerKeith Pitty
 
What\'s new in Rails 2.1
What\'s new in Rails 2.1What\'s new in Rails 2.1
What\'s new in Rails 2.1Keith Pitty
 
The Only Way to Test!
The Only Way to Test!The Only Way to Test!
The Only Way to Test!Keith Pitty
 
Very Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian ProjectVery Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian Projectyouthelectronix
 

Viewers also liked (8)

Clio Final Project 12 10 07
Clio Final Project 12 10 07Clio Final Project 12 10 07
Clio Final Project 12 10 07
 
BudgetLevyCycle07
BudgetLevyCycle07BudgetLevyCycle07
BudgetLevyCycle07
 
Seeds And Art
Seeds And ArtSeeds And Art
Seeds And Art
 
RVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby TrackerRVM, Bundler and Ruby Tracker
RVM, Bundler and Ruby Tracker
 
Ruby Australia
Ruby AustraliaRuby Australia
Ruby Australia
 
What\'s new in Rails 2.1
What\'s new in Rails 2.1What\'s new in Rails 2.1
What\'s new in Rails 2.1
 
The Only Way to Test!
The Only Way to Test!The Only Way to Test!
The Only Way to Test!
 
Very Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian ProjectVery Hue: A Report on the Vietnamese Librarian Project
Very Hue: A Report on the Vietnamese Librarian Project
 

Similar to Why would a Java shop want to use Ruby?

The story of language development
The story of language developmentThe story of language development
The story of language developmentHiroshi SHIBATA
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLBarry Jones
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overviewThomas Asikis
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Hiroshi SHIBATA
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Charles Nutter
 
Crate - ruby based standalone executables
Crate - ruby based standalone executablesCrate - ruby based standalone executables
Crate - ruby based standalone executablesJeremy Hinegardner
 
0201710897
02017108970201710897
0201710897guru50
 
Make your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On RailsMake your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On RailsNataly Tkachuk
 
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT CompilationHighly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT CompilationMatthew Gaudet
 
Ruby on rails探索
Ruby on rails探索Ruby on rails探索
Ruby on rails探索Mu Chun Wang
 
Ruby confhighlights
Ruby confhighlightsRuby confhighlights
Ruby confhighlightsClaire Tran
 
A Ct Os Story
A Ct Os StoryA Ct Os Story
A Ct Os StoryRobbert
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 

Similar to Why would a Java shop want to use Ruby? (20)

The story of language development
The story of language developmentThe story of language development
The story of language development
 
Exploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQLExploring Ruby on Rails and PostgreSQL
Exploring Ruby on Rails and PostgreSQL
 
Ruby on Rails - An overview
Ruby on Rails -  An overviewRuby on Rails -  An overview
Ruby on Rails - An overview
 
Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0Gemification for Ruby 2.5/3.0
Gemification for Ruby 2.5/3.0
 
Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016Ruby Performance - The Last Mile - RubyConf India 2016
Ruby Performance - The Last Mile - RubyConf India 2016
 
Crate - ruby based standalone executables
Crate - ruby based standalone executablesCrate - ruby based standalone executables
Crate - ruby based standalone executables
 
0201710897
02017108970201710897
0201710897
 
Real World Technologies
Real World TechnologiesReal World Technologies
Real World Technologies
 
Make your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On RailsMake your app idea a reality with Ruby On Rails
Make your app idea a reality with Ruby On Rails
 
Ruby - The Hard Bits
Ruby - The Hard BitsRuby - The Hard Bits
Ruby - The Hard Bits
 
Initiation à Ruby on Rails
Initiation à Ruby on RailsInitiation à Ruby on Rails
Initiation à Ruby on Rails
 
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT CompilationHighly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
 
Practical JRuby
Practical JRubyPractical JRuby
Practical JRuby
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
 
Ruby on rails探索
Ruby on rails探索Ruby on rails探索
Ruby on rails探索
 
Ruby confhighlights
Ruby confhighlightsRuby confhighlights
Ruby confhighlights
 
A Ct Os Story
A Ct Os StoryA Ct Os Story
A Ct Os Story
 
Ruby with cucmber
Ruby with cucmberRuby with cucmber
Ruby with cucmber
 
Why ruby
Why rubyWhy ruby
Why ruby
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Why would a Java shop want to use Ruby?

  • 1. Why would a Java Shop want to use Ruby? Keith Pitty Open Source Developers’ Conference Brisbane 29 November 2007
  • 2. About Keith • Programming professionally since 1983 • Early experience on mainframes • Smalltalk was my first OO language • Employed by a Java consultancy since 2000 • Fascinated by Ruby and Rails since 2004 • Enjoy sampling a wide range of beers Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 3. Java Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 4. Ruby Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 5. Java public class print { public static void main(String[] args) { System.out.println(quot;Hi, I'm Javaquot;); } } Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 6. Ruby #!/usr/bin/env ruby puts quot;Hi, I'm Rubyquot; Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 7. No!!! • This is not a language war! • Java and Ruby both have their strengths • I’m not interested in Ruby “beating” Java • The question is: • Can Ruby help Java programmers? Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 8. Java • Most popular language (21.7%) • TIOBE PCI, September 2007 • Mature platform • Trusted in the “enterprise” • Has reached a plateau • “The new COBOL” Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 9. Ruby • Tenth most popular language (2.1%) • Marked increase in popularity since mid-2006 due to Ruby on Rails • Matz’s original motivation: • a scripting language • more powerful than Perl • more object-oriented than Python Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 10. Why Ruby? (Quote Part 1) “I don’t believe there would be any real technical benefit. There may be a productivity boost, but when you consider how much time is used by developers, QA, etc... to bring in a new technology, chances are the net [benefit] won’t be that great.” Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 11. Why Ruby? (Quote Part 2) “I think the best argument for Ruby is that your developers want it. If the developers are yearning for new technology, it’s probably worth considering. Happy developers code more and code better.” Norman Richards, JBoss Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 12. Perspectives • Vendors • Open source contributors • Managers • Business owners • Developers Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 13. Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 14. Ruby: Why not? • How widespread is knowledge of Ruby within the Java community? • In my experience, there is limited awareness • On the other hand: • Ruby may have benefits that are complementary to Java Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 15. Potential Ruby Benefits • Ruby skills may complement Java skills • Learning Ruby may be interesting, broadening a programmer’s thinking • Happier programmers • Quicker time to market Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 16. Enough Preamble • What does Ruby have to offer people in Java development shops? • Let’s explore some specifics... Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 17. Ruby Scripts Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 18. Ruby Scripts • Scripts help with repetitive tasks • Shell scripts, SQL scripts, Ant scripts • Sometimes the logic lends itself to a general purpose language • Can run a Java application via a shell script • A Ruby script is interpreted directly and is more concise Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 19. Ruby Script Example • Deleting files within a given directory according to given criteria • e.g. older than a given time Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 20. Ruby Script Example* #!/usr/bin/env ruby def delete_if(dir) Dir.chdir(dir) do Dir.foreach(*.*) do |entry| next if File.stat(entry).directory? if yield entry File.unlink(entry) end end end end delete_if(quot;/tmpquot;) { |f| File.mtime(f) < Time.local(2007,10,29,0,0,0) } * See Hal Fulton’s “The Ruby Way” Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 21. Rake and Internal DSLs Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 22. Rake • Ruby-based build language • Developed by Jim Weirach • Similar to make and ant • An internal Domain Specific Language • make and ant are external DSLs Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 23. Regular Rake Tasks task :init do # init actions end task :compile => [:init] do # compile actions end task :build => [:init, :compile] do # build actions end Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 24. Extending Rake* def copyTask srcGlob, targetDirSuffix, taskSymbol targetDir = File.join BUILD_DIR, targetDirSuffix mkdir_p targetDir, QUIET FileList[srcGlob].each do |f| target = File.join targetDir, File.basename(f) file target => [f] do |t| cp f, target end task taskSymbol => target end end copyTask 'articles/*.gif', 'articles', :articles * see Martin Fowler’s rake article Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 25. Internal DSLs • Other Ruby internal DSLs: • buildr • capistrano • ... • create your own! Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 26. Buildr • a build system for Java apps • encompasses Maven and Ant • written in Ruby • based on Rake • uses Antwrap to configure and run Ant tasks • extensible in Ruby Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 27. Capistrano • Created by Jamis Buck • Originally to “ease the pain of deploying Rails applications” • Exposes simple commands • Once project has been “capified” • $ cap deploy • Useful beyond Rails Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 28. Capistrano Example desc quot;Copy production database config file.quot; namespace :deploy do task :after_update_code, :roles => :app do db_config = quot;#{shared_path}/config/database.yml.productionquot; run quot;cp #{db_config} #{release_path}/config/database.ymlquot; end end Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 29. Metaprogramming Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 30. Metaprogramming • Very powerful feature of Ruby • Dynamic programming • Methods: method_missing, define_method, module_eval, class_eval, instance_eval, self.included, self.inherited, extend • Callable objects: procs, lambdas, blocks • Modifying the singleton class: class << Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 31. method_missing class Roman def roman_to_int(str) # ... end def method_missing(methId) str = methId.id2name roman_to_int(str) end end r = Roman.new r.iv #=> 4 r.xxiii #=> 23 r.mm #=> 2000 Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 32. More Examples? • Open source Ruby frameworks • e.g. Ruby on Rails web application framework • many examples of metaprogramming to be found in the Rails source code Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 33. Ruby on Rails Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 34. Ruby on Rails • Web application framework released by David Heinemeier Hansson in 2004 • Extracted from the Basecamp application • The killer app for Ruby • “Convention over Configuration” • Code generators Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 35. Rails Example $ rails beers Creates directory structure for new project Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 36. Generating a Resource $ ./script/generate scaffold_resource beer name:string Creates a model, a controller, and a set of templates that's ready to use as the starting point for your REST-like, resource-oriented application. Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 37. Migration class CreateBeers < ActiveRecord::Migration def self.up create_table :beers do |t| t.column :name, :string end end def self.down drop_table :beers end end Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 38. Running Migrations $ rake db:migrate == CreateBeers: migrating ===================================================== -- create_table(:beers) -> 0.0735s == CreateBeers: migrated (0.0737s) ============================================ Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 39. Model class Beer < ActiveRecord::Base has_many :votes end Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 40. View (new.rhtml) <h1>New beer</h1> <%= error_messages_for :beer %> <% form_for(:beer, :url => beers_path) do |f| %> <p> <b>Name</b><br /> <%= f.text_field :name %> </p> <p> <%= submit_tag quot;Createquot; %> </p> <% end %> <%= link_to 'Back', beers_path %> Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 41. Controller class BeersController < ApplicationController def new @beer = Beer.new end def create @beer = Beer.new(params[:beer]) respond_to do |format| if @beer.save flash[:notice] = 'Beer was successfully created.' format.html { redirect_to beer_url(@beer) } else format.html { render :action => quot;newquot; } end end end end Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 42. More about Rails • There’s much more about Rails to explore • But that’s another topic • We’ve touched upon some appealing aspects • Development is much quicker! • But ... Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 43. Java Perspective • What if ... • Java provides where Ruby doesn’t? • What about ... • deploying Rails apps? Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 44. Java and Ruby Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 45. JRuby Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 46. JRuby • Java implementation of Ruby • Major advantages: • Java libraries can be used with Ruby syntax • Deploy Rails apps on Java app servers • via WAR files Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 47. Invoking Java from Ruby require 'java' m = java.util.HashMap.new m.put quot;Streamquot;, quot;Rubyquot; m.put quot;Topicquot;, quot;JRubyquot; iter = m.keySet.iterator while iter.hasNext key = iter.next puts quot;#{key}=#{m.get(key)}quot; end Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 48. Some JRuby Capabilities • Implement Java interfaces via import or impl • Extend Java classes • Use Ruby methods on Java collections courtesy of Ruby mixins • Use JavaUtilities.extend_proxy to add methods to Java types Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 49. Java DOM and XSLT* require 'java' require 'stringio' TransformerFactory = javax.xml.transform.TransformerFactory StreamSource = javax.xml.transform.stream.StreamSource StreamResult = javax.xml.transform.stream.StreamResult f = TransformerFactory.new_instance t = f.new_transformer StreamSource.new(java.io.FileReader.new(ARGV[1])) s = StringIO.new t.transform StreamSource.new(java.io.FileReader.new(ARGV[0])), StreamResult.new(org.jruby.util.IOOutputStream.new(s)) puts s.string * see Ola Bini’s book Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 50. JRuby on Rails Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 51. JRuby on Rails: JDBC • Download JDBC driver development: adapter: jdbc driver: com.mysql.jdbc.Driver • Add to CLASSPATH url: jdbc:mysql://localhost/ beers_development username: test • password: test Configure config/ database.yml • Update config/ require 'jdbc_adapter' environment.rb Rails::Initializer.run do |config| Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 52. Deploying JRuby on Rails Applications • Option 1: • Pack of Mongrels inside one JVM • Option 2: • Bundle as WAR and deploy inside Tomcat Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 53. Pack of Mongrels • Familiar to Rails developers • Install mongrel_jcustler Gem • Configure pack using mongrel_rails • Start pack using mongrel_rails • Configure load balancing proxy support and virtual host in Apache Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 54. Deploying via a WAR • Install GoldSpike plug-in in Rails app • Configure app with correct driver for JDBC connections (in config/war.rb) • Use jruby rake task to create WAR • Deploy WAR • Configure Apache Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 55. Installing GoldSpike jruby script/plugin install -x svn://rubyforge.org/var/svn/jruby-extras/trunk/rails-integration/plugins/goldspike Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 56. JDBC Driver Config maven_library 'mysql', 'mysql-connector-java', '5.0.4' Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 57. Create WAR jruby -S rake war:standalone:create Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 58. Deploy WAR cp beers.war $TOMCAT_HOME/webapps Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 59. Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 60. Conclusion • Ruby offers some interesting benefits • Ruby on Rails offers quick development for CRUD web apps • JRuby enables Ruby apps to call Java code • JRuby enables deployment of Rails apps via WAR files to Java app servers Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 61. Resources • Ola Bini. Practical JRuby on Rails Web 2.0 Projects. Apress, 2007 • David A. Black. Ruby for Rails. Manning, 2006 • http://buildr.rubyforge.org • http://www.capify.org • http://jruby.codehaus.org Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 62. Resources (ctd.) • Martin Fowler. RailsConf2007 => http:// martinfowler.com/bliki/ RailsConf2007.html • Martin Fowler. Using the Rake Build Language => http://martinfowler.com/ articles/rake.html • Hal Fulton. The Ruby Way. Addison- Wesley, 2007 Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 63. Resources (ctd) • David Heinemeier Hansson. Sun surprises at RailsConf Europe 2007 => http://www.loudthinking.com/ posts/11-sun-surprises-at-railsconf- europe-2007 • Brian Marick. Everyday Scripting with Ruby: For Teams, Testers and You. Pragmatic Programmers, 2006 Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 64. Resources (ctd) • http://mongrel.rubyforge.org • Keith Pitty. Why is Ruby such a good language for Rails? => http:// keithpitty.org/presentations/ruby/ WhyRubyForRails.pdf • http://rubyonrails.org • http://www.tiobe.com/tpci.htm Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 65. Photo Credits • Bored Cow: http://flickr.com/ photos/kevincollins/122302356/ • Leopard getting ready to drop out of tree: http://flickr.com/photos/ at_large/399149551/ • Origami heart: http://flickr.com/ photos/teagrrl/4802517/ Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007
  • 66. Thanks for listening! http://keithpitty.com Why would a Java Shop want to use Ruby? Keith Pitty OSDC, 29 November 2007