SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
Java vs Ruby : a quick and fair comparison
      About the pros and cons of two popular programming languages



                                                          Jean-Baptiste Escoyez




Thursday 19 February 2009                                                         1
Java vs Ruby : a quick and unfair comparison
      About the elegance of Ruby
      About the performance of Java
      And how they can live together

                                        Jean-Baptiste Escoyez




Thursday 19 February 2009                                       2
Ruby is interpreted, Java is compiled (before being interpreted)

       >ruby my_program.rb                                                   >javac MyProgram.java
                                                                             >java MyProgram


      • Code can be loaded at runtime


      • Code is easily accessible


      • Difficult to ship closed-source software


      • Speed performance issues




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                                            3
Ruby use dynamic typing

      • Values have type, variables not                                      def len(list)
                                                                               x=0
                                                                               list.each do |element|
      • Decrease language complexity                                             x += 1
                                                                               end
                                                                             end
            - No type declaration
                                                                             public static int len(List list)
            - No type casting                                                {
                                                                               int x = 0;
                                                                               Iterator listIterator =
      • Increase flexibility                                                    list.iterator();
                                                                               while(listIterator.hasNext()){
                                                                                 x += 1;
      • Errors appears at run-time                                             }
                                                                             }




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                                                       4
Ruby syntax is terse

      • Example 1 : The empty program




      • Java




      • Ruby




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    5
Ruby syntax is terse

      • Example 1 : The empty program




                                Class Test {
      • Java                      public static void main(String[] args){}
                                }



      • Ruby




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    5
Ruby syntax is terse
      • Example 2 : Basic getters and setters

                            Class Circle
      • Java                  private Coordinate center, float radius;

                                public void setCenter(Coordinate center){
                                  this.center = center;
                                }

                                public Coordinate getCenter(){
                                  return center;
                                }

                                public void setRadius(float radius){
                                  this.radius = radius;
                                }

                                public Coordinate getRadius(){
                                  return radius;
                                }
                            }

                            class Circle
      • Ruby                  attr_accessor :center, :radius
                            end

      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    6
Ruby syntax is terse
      • Example 3 : Playing with lists


      • Java                List<String> languages = new LinkedList<String>();
                            languages.add(quot;Javaquot;);
                            languages.add(quot;Rubyquot;);
                            languages.add(quot;Pythonquot;);
                            languages.add(quot;Perlquot;);

      • Ruby                stuff = []
                            stuff << quot;Javaquot;, quot;Rubyquot;, quot;Pythonquot;


                            stuff = [quot;Javaquot;, quot;Rubyquot;, quot;Pythonquot;]


                            stuff = %w(Java Ruby Python)




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                        7
Everything is an object (really everything!)
       >3.times             { puts          quot;Hello FOSDEM !quot; }
       => Hello             FOSDEM          !
       => Hello             FOSDEM          !
       => Hello             FOSDEM          !


       >self.class
       => Object

       >1.class
       => Fixnum




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    8
Core classes can be extended easily

      • A program which makes you crazy

         class Fixnum
           def +(i)
             self - i
           end
         end

         >1 + 1
         => 0




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    9
require ‘activesupport’

      • Java                   if ( 1 % 2 == 1 ) System.err.println(quot;Odd!quot;)
                               => Odd!


      • Ruby                   if 11.odd?; print quot;Odd!
                               => Odd!

      • Java                   System.out.println(quot;Running time: quot; + 
                                        (3600 + 15 * 60 + 10) + quot;secondsquot;);

      • Ruby                   puts quot;Running time: 
                               #{1.hour + 15.minutes + 10.seconds} secondsquot;



      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                     10
Blocks


              >find_integer([quot;aquot;,1, 4, 2,quot;9quot;,quot;cquot;]){|e| e.odd?}
              => 1



               >def find_integer(array)
               > for element in array
               >    if element.is_a?(Integer) && yield element
               >      return element
               >    end
               > end
               >end




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    11
Tidbits of metaprogramming

      • Execution of given code

                             >eval(quot;puts 'Hi FOSDEM'quot;)
                             => Hi FOSDEM

      • Class extension

                             >speaker = Class.new
                             >speaker.class_eval do
                             > def hello_fosdem
                             >    puts “Hello FOSDEM!”
                             > end
                             >end
                             >jean_baptiste = speaker.new
                             >jean_baptiste.hello_fosdem
                             => “Hello FOSDEM!”

      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    12
Going a bit further

      • Defining methods

                            >people = [quot;stevequot;, quot;aurelienquot;]
                            >speaker = Class.new
                            >speaker.class_eval do
                            > people.each do |person|
                            >    define_method(quot;hello_#{person}quot;){
                            >      puts quot;Hello #{person}quot;
                            >    }
                            > end
                            >end
                            >jean_baptiste = speaker.new
                            >jean_baptiste.methods - Object.methods
                            => [quot;hello_stevequot;, quot;hello_aurelienquot;]
                            >jean_baptiste.hello_steve
                            => “Hello steve”

      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    13
Summary

      • Ruby is elegant

      • Ruby is meaningful

      • Ruby is flexible

      • Ruby is easily extensible

      • Ruby is terse




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    14
Summary

      • Ruby is elegant

      • Ruby is meaningful

      • Ruby is flexible

      • Ruby is easily extensible

      • Ruby is terse

                                                      Is that all ???
                                                     What about Java?
      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    14
Java win on performance field




                            Source : http://shootout.alioth.debian.org/u32q/benchmark.php
      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                                   15
On a business point of view

      • Java is a well-known technology

      • Lots of developments have been made with it

      • Easy to find experts

      • Still not that much available Ruby developers

      • Opensource fear




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    16
Solution: make them collaborate !




      •JRuby : Demo



      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    17
Conclusion

      • Languages wars do not make sens

      • Ruby is great for its terseness, readability and flexibility

      • Java is great for its performances

      • JRuby makes them talk together

      • Ruby + Java is a great combo




      Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez

Thursday 19 February 2009                                                    18
Thank you!
      Questions?


                            References :
                            http://www.rubyrailways.com/sometimes-less-is-more/
                            http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html
                            http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=java&lang2=ruby
                            http://ola-bini.blogspot.com/2008/04/pragmatic-static-typing.html




Thursday 19 February 2009                                                                                        19

Weitere ähnliche Inhalte

Was ist angesagt?

Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268Ramamohan Chokkam
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersMiles Sabin
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming LanguageNicolò Calcavecchia
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmerselliando dias
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmerselliando dias
 
2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritancebergel
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOPAnton Keks
 
Clojure talk at Münster JUG
Clojure talk at Münster JUGClojure talk at Münster JUG
Clojure talk at Münster JUGAlex Ott
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to ScalaBrian Hsu
 
The ruby programming language
The ruby programming languageThe ruby programming language
The ruby programming languagepraveen0202
 
Java Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsJava Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsAnton Keks
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To GrailsEric Berry
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaDerek Chen-Becker
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsAnton Keks
 
Java Course 2: Basics
Java Course 2: BasicsJava Course 2: Basics
Java Course 2: BasicsAnton Keks
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to ClojureRenzo Borgatti
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Agora Group
 
Modularization of Legacy Features by Relocation and Reconceptualization: How ...
Modularization of Legacy Features by Relocation and Reconceptualization: How ...Modularization of Legacy Features by Relocation and Reconceptualization: How ...
Modularization of Legacy Features by Relocation and Reconceptualization: How ...Andrzej Olszak
 

Was ist angesagt? (20)

Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268Automatically generating-json-from-java-objects-java-objects268
Automatically generating-json-from-java-objects-java-objects268
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Introduction to Ruby Programming Language
Introduction to Ruby Programming LanguageIntroduction to Ruby Programming Language
Introduction to Ruby Programming Language
 
Clojure - An Introduction for Java Programmers
Clojure - An Introduction for Java ProgrammersClojure - An Introduction for Java Programmers
Clojure - An Introduction for Java Programmers
 
Clojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp ProgrammersClojure - An Introduction for Lisp Programmers
Clojure - An Introduction for Lisp Programmers
 
2008 Sccc Inheritance
2008 Sccc Inheritance2008 Sccc Inheritance
2008 Sccc Inheritance
 
Java Course 3: OOP
Java Course 3: OOPJava Course 3: OOP
Java Course 3: OOP
 
Clojure talk at Münster JUG
Clojure talk at Münster JUGClojure talk at Münster JUG
Clojure talk at Münster JUG
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
How big is your data
How big is your dataHow big is your data
How big is your data
 
The ruby programming language
The ruby programming languageThe ruby programming language
The ruby programming language
 
Java Course 4: Exceptions & Collections
Java Course 4: Exceptions & CollectionsJava Course 4: Exceptions & Collections
Java Course 4: Exceptions & Collections
 
Introduction To Grails
Introduction To GrailsIntroduction To Grails
Introduction To Grails
 
A Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to ScalaA Brief, but Dense, Intro to Scala
A Brief, but Dense, Intro to Scala
 
Java Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & EncodingsJava Course 7: Text processing, Charsets & Encodings
Java Course 7: Text processing, Charsets & Encodings
 
Java Course 2: Basics
Java Course 2: BasicsJava Course 2: Basics
Java Course 2: Basics
 
Introduction to Clojure
Introduction to ClojureIntroduction to Clojure
Introduction to Clojure
 
Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011Terence Barr - jdk7+8 - 24mai2011
Terence Barr - jdk7+8 - 24mai2011
 
Core java
Core javaCore java
Core java
 
Modularization of Legacy Features by Relocation and Reconceptualization: How ...
Modularization of Legacy Features by Relocation and Reconceptualization: How ...Modularization of Legacy Features by Relocation and Reconceptualization: How ...
Modularization of Legacy Features by Relocation and Reconceptualization: How ...
 

Andere mochten auch

Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java ProgrammersMike Bowler
 
PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonHaim Michael
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#Sagar Pednekar
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMatt Aimonetti
 
Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.Justin Lin
 
BDD. Gherkin+Ruby или автотесты для гуманитариев
BDD. Gherkin+Ruby или автотесты для гуманитариевBDD. Gherkin+Ruby или автотесты для гуманитариев
BDD. Gherkin+Ruby или автотесты для гуманитариевSQALab
 
Ошибка выживших
Ошибка выжившихОшибка выживших
Ошибка выжившихSQALab
 
Criação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao AgileCriação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao AgileRobson Agapito Correa
 
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]GoIT
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with RubyKeith Pitty
 
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)Marcio Sfalsin
 
[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e Webdriver
[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e Webdriver[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e Webdriver
[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e WebdriverJúlio de Lima
 
Java vs .net
Java vs .netJava vs .net
Java vs .netTech_MX
 

Andere mochten auch (20)

MacRuby, an introduction
MacRuby, an introductionMacRuby, an introduction
MacRuby, an introduction
 
Ruby For Java Programmers
Ruby For Java ProgrammersRuby For Java Programmers
Ruby For Java Programmers
 
Java vs. Ruby
Java vs. RubyJava vs. Ruby
Java vs. Ruby
 
PHP, Java EE & .NET Comparison
PHP, Java EE & .NET ComparisonPHP, Java EE & .NET Comparison
PHP, Java EE & .NET Comparison
 
Difference between Java and c#
Difference between Java and c#Difference between Java and c#
Difference between Java and c#
 
MacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meetMacRuby - When objective-c and Ruby meet
MacRuby - When objective-c and Ruby meet
 
Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.Understanding Typing. Understanding Ruby.
Understanding Typing. Understanding Ruby.
 
BDD. Gherkin+Ruby или автотесты для гуманитариев
BDD. Gherkin+Ruby или автотесты для гуманитариевBDD. Gherkin+Ruby или автотесты для гуманитариев
BDD. Gherkin+Ruby или автотесты для гуманитариев
 
Ошибка выживших
Ошибка выжившихОшибка выживших
Ошибка выживших
 
Ruby 1.9
Ruby 1.9Ruby 1.9
Ruby 1.9
 
Seu site voando
Seu site voandoSeu site voando
Seu site voando
 
Apresentação sobre JRuby
Apresentação sobre JRubyApresentação sobre JRuby
Apresentação sobre JRuby
 
Criação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao AgileCriação de uma equipe de QAs, do Waterfall ao Agile
Criação de uma equipe de QAs, do Waterfall ao Agile
 
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
QA Automation Battle: Java vs Python vs Ruby [09.04.2015]
 
PHP versus Java
PHP versus JavaPHP versus Java
PHP versus Java
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with Ruby
 
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
Jruby, o melhor de 2 mundos (MacGyver + ChuckNorris)
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e Webdriver
[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e Webdriver[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e Webdriver
[38º GURU SP] Automação de Testes Web em Ruby com Cucumber e Webdriver
 
Java vs .net
Java vs .netJava vs .net
Java vs .net
 

Ähnlich wie Ruby vs Java

Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvmdeimos
 
J Ruby Power On The Jvm
J Ruby Power On The JvmJ Ruby Power On The Jvm
J Ruby Power On The JvmQConLondon2008
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming IntroductionAnthony Brown
 
JRuby - Java version of Ruby
JRuby - Java version of RubyJRuby - Java version of Ruby
JRuby - Java version of RubyUday Bhaskar
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyelliando dias
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBHiro Asari
 
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)jaxLondonConference
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Thomas Lundström
 
javascript teach
javascript teachjavascript teach
javascript teachguest3732fa
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_Whiteguest3732fa
 
Minicurso Ruby e Rails
Minicurso Ruby e RailsMinicurso Ruby e Rails
Minicurso Ruby e RailsSEA Tecnologia
 
Bitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBrian Sam-Bodden
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Touroscon2007
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2rubyMarc Chung
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0Jan Sifra
 

Ähnlich wie Ruby vs Java (20)

Ola Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The JvmOla Bini J Ruby Power On The Jvm
Ola Bini J Ruby Power On The Jvm
 
J Ruby Power On The Jvm
J Ruby Power On The JvmJ Ruby Power On The Jvm
J Ruby Power On The Jvm
 
Ruby Programming Introduction
Ruby Programming IntroductionRuby Programming Introduction
Ruby Programming Introduction
 
JRuby - Java version of Ruby
JRuby - Java version of RubyJRuby - Java version of Ruby
JRuby - Java version of Ruby
 
JRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRubyJRoR Deploying Rails on JRuby
JRoR Deploying Rails on JRuby
 
BeJUG JavaFx In Practice
BeJUG JavaFx In PracticeBeJUG JavaFx In Practice
BeJUG JavaFx In Practice
 
Using Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRBUsing Java from Ruby with JRuby IRB
Using Java from Ruby with JRuby IRB
 
JRuby Basics
JRuby BasicsJRuby Basics
JRuby Basics
 
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)Real-world polyglot programming on the JVM  - Ben Summers (ONEIS)
Real-world polyglot programming on the JVM - Ben Summers (ONEIS)
 
Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)Ruby for C#-ers (ScanDevConf 2010)
Ruby for C#-ers (ScanDevConf 2010)
 
javascript teach
javascript teachjavascript teach
javascript teach
 
JSBootcamp_White
JSBootcamp_WhiteJSBootcamp_White
JSBootcamp_White
 
Minicurso Ruby e Rails
Minicurso Ruby e RailsMinicurso Ruby e Rails
Minicurso Ruby e Rails
 
Intro to J Ruby
Intro to J RubyIntro to J Ruby
Intro to J Ruby
 
Bitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRubyBitter Java, Sweeten with JRuby
Bitter Java, Sweeten with JRuby
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Ruby
RubyRuby
Ruby
 
J Ruby Whirlwind Tour
J Ruby Whirlwind TourJ Ruby Whirlwind Tour
J Ruby Whirlwind Tour
 
Hacking with ruby2ruby
Hacking with ruby2rubyHacking with ruby2ruby
Hacking with ruby2ruby
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0
 

Kürzlich hochgeladen

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URLRuncy Oommen
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Will Schroeder
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.YounusS2
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationIES VE
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 

Kürzlich hochgeladen (20)

Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
Designing A Time bound resource download URL
Designing A Time bound resource download URLDesigning A Time bound resource download URL
Designing A Time bound resource download URL
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
Apres-Cyber - The Data Dilemma: Bridging Offensive Operations and Machine Lea...
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.Basic Building Blocks of Internet of Things.
Basic Building Blocks of Internet of Things.
 
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve DecarbonizationUsing IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
Using IESVE for Loads, Sizing and Heat Pump Modeling to Achieve Decarbonization
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 

Ruby vs Java

  • 1. Java vs Ruby : a quick and fair comparison About the pros and cons of two popular programming languages Jean-Baptiste Escoyez Thursday 19 February 2009 1
  • 2. Java vs Ruby : a quick and unfair comparison About the elegance of Ruby About the performance of Java And how they can live together Jean-Baptiste Escoyez Thursday 19 February 2009 2
  • 3. Ruby is interpreted, Java is compiled (before being interpreted) >ruby my_program.rb >javac MyProgram.java >java MyProgram • Code can be loaded at runtime • Code is easily accessible • Difficult to ship closed-source software • Speed performance issues Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 3
  • 4. Ruby use dynamic typing • Values have type, variables not def len(list) x=0 list.each do |element| • Decrease language complexity x += 1 end end - No type declaration public static int len(List list) - No type casting { int x = 0; Iterator listIterator = • Increase flexibility list.iterator(); while(listIterator.hasNext()){ x += 1; • Errors appears at run-time } } Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 4
  • 5. Ruby syntax is terse • Example 1 : The empty program • Java • Ruby Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 5
  • 6. Ruby syntax is terse • Example 1 : The empty program Class Test { • Java public static void main(String[] args){} } • Ruby Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 5
  • 7. Ruby syntax is terse • Example 2 : Basic getters and setters Class Circle • Java private Coordinate center, float radius; public void setCenter(Coordinate center){ this.center = center; } public Coordinate getCenter(){ return center; } public void setRadius(float radius){ this.radius = radius; } public Coordinate getRadius(){ return radius; } } class Circle • Ruby attr_accessor :center, :radius end Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 6
  • 8. Ruby syntax is terse • Example 3 : Playing with lists • Java List<String> languages = new LinkedList<String>(); languages.add(quot;Javaquot;); languages.add(quot;Rubyquot;); languages.add(quot;Pythonquot;); languages.add(quot;Perlquot;); • Ruby stuff = [] stuff << quot;Javaquot;, quot;Rubyquot;, quot;Pythonquot; stuff = [quot;Javaquot;, quot;Rubyquot;, quot;Pythonquot;] stuff = %w(Java Ruby Python) Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 7
  • 9. Everything is an object (really everything!) >3.times { puts quot;Hello FOSDEM !quot; } => Hello FOSDEM ! => Hello FOSDEM ! => Hello FOSDEM ! >self.class => Object >1.class => Fixnum Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 8
  • 10. Core classes can be extended easily • A program which makes you crazy class Fixnum def +(i) self - i end end >1 + 1 => 0 Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 9
  • 11. require ‘activesupport’ • Java if ( 1 % 2 == 1 ) System.err.println(quot;Odd!quot;) => Odd! • Ruby if 11.odd?; print quot;Odd! => Odd! • Java System.out.println(quot;Running time: quot; + (3600 + 15 * 60 + 10) + quot;secondsquot;); • Ruby puts quot;Running time: #{1.hour + 15.minutes + 10.seconds} secondsquot; Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 10
  • 12. Blocks >find_integer([quot;aquot;,1, 4, 2,quot;9quot;,quot;cquot;]){|e| e.odd?} => 1 >def find_integer(array) > for element in array > if element.is_a?(Integer) && yield element > return element > end > end >end Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 11
  • 13. Tidbits of metaprogramming • Execution of given code >eval(quot;puts 'Hi FOSDEM'quot;) => Hi FOSDEM • Class extension >speaker = Class.new >speaker.class_eval do > def hello_fosdem > puts “Hello FOSDEM!” > end >end >jean_baptiste = speaker.new >jean_baptiste.hello_fosdem => “Hello FOSDEM!” Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 12
  • 14. Going a bit further • Defining methods >people = [quot;stevequot;, quot;aurelienquot;] >speaker = Class.new >speaker.class_eval do > people.each do |person| > define_method(quot;hello_#{person}quot;){ > puts quot;Hello #{person}quot; > } > end >end >jean_baptiste = speaker.new >jean_baptiste.methods - Object.methods => [quot;hello_stevequot;, quot;hello_aurelienquot;] >jean_baptiste.hello_steve => “Hello steve” Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 13
  • 15. Summary • Ruby is elegant • Ruby is meaningful • Ruby is flexible • Ruby is easily extensible • Ruby is terse Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 14
  • 16. Summary • Ruby is elegant • Ruby is meaningful • Ruby is flexible • Ruby is easily extensible • Ruby is terse Is that all ??? What about Java? Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 14
  • 17. Java win on performance field Source : http://shootout.alioth.debian.org/u32q/benchmark.php Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 15
  • 18. On a business point of view • Java is a well-known technology • Lots of developments have been made with it • Easy to find experts • Still not that much available Ruby developers • Opensource fear Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 16
  • 19. Solution: make them collaborate ! •JRuby : Demo Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 17
  • 20. Conclusion • Languages wars do not make sens • Ruby is great for its terseness, readability and flexibility • Java is great for its performances • JRuby makes them talk together • Ruby + Java is a great combo Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 18
  • 21. Thank you! Questions? References : http://www.rubyrailways.com/sometimes-less-is-more/ http://www.javaworld.com/javaworld/jw-07-2006/jw-0717-ruby.html http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=java&lang2=ruby http://ola-bini.blogspot.com/2008/04/pragmatic-static-typing.html Thursday 19 February 2009 19