0
Java vs Ruby : a quick and fair comparison
      About the pros and cons of two popular programming languages



         ...
Java vs Ruby : a quick and unfair comparison
      About the elegance of Ruby
      About the performance of Java
      An...
Ruby is interpreted, Java is compiled (before being interpreted)

       >ruby my_program.rb                              ...
Ruby use dynamic typing

      • Values have type, variables not                                      def len(list)
      ...
Ruby syntax is terse

      • Example 1 : The empty program




      • Java




      • Ruby




      Java vs Ruby : a q...
Ruby syntax is terse

      • Example 1 : The empty program




                                Class Test {
      • Java ...
Ruby syntax is terse
      • Example 2 : Basic getters and setters

                            Class Circle
      • Java ...
Ruby syntax is terse
      • Example 3 : Playing with lists


      • Java                List<String> languages = new Lin...
Everything is an object (really everything!)
       >3.times             { puts          quot;Hello FOSDEM !quot; }
      ...
Core classes can be extended easily

      • A program which makes you crazy

         class Fixnum
           def +(i)
  ...
require ‘activesupport’

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


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



    ...
Tidbits of metaprogramming

      • Execution of given code

                             >eval(quot;puts 'Hi FOSDEM'quot;...
Going a bit further

      • Defining methods

                            >people = [quot;stevequot;, quot;aurelienquot;]
...
Summary

      • Ruby is elegant

      • Ruby is meaningful

      • Ruby is flexible

      • Ruby is easily extensible

...
Summary

      • Ruby is elegant

      • Ruby is meaningful

      • Ruby is flexible

      • Ruby is easily extensible

...
Java win on performance field




                            Source : http://shootout.alioth.debian.org/u32q/benchmark.php...
On a business point of view

      • Java is a well-known technology

      • Lots of developments have been made with it
...
Solution: make them collaborate !




      •JRuby : Demo



      Java vs Ruby : a quick and unfair comparison - Jean-Bap...
Conclusion

      • Languages wars do not make sens

      • Ruby is great for its terseness, readability and flexibility

...
Thank you!
      Questions?


                            References :
                            http://www.rubyrailways...
Upcoming SlideShare
Loading in...5
×

Ruby vs Java

49,621

Published on

A quick and unfair comparison of Ruby and Java.

Published in: Technology
4 Comments
21 Likes
Statistics
Notes
  • One of the key advantages of Java is its IDE support, especially large project refactoring and completion. Many of these features are impossible in a dynamically typed language. And not to forget that in a large project you find many errors upfront. So yes, Ruby is more terse but I think in Eclipse or other modern IDEs writing robust software is faster.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Slide 4, you can write for (final int i : list) { x++;} without the iterator, so your demonstration is a bit more fair.. ;)
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • No entiendo ingles.... help me please :(
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The usage of imagery in this presentation is really effective. You've done a fantastic job here friend.
    Sharika
    http://winkhealth.com http://financewink.com
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
49,621
On Slideshare
0
From Embeds
0
Number of Embeds
14
Actions
Shares
0
Downloads
475
Comments
4
Likes
21
Embeds 0
No embeds

No notes for slide

Transcript of "Ruby vs Java"

  1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 19. Solution: make them collaborate ! •JRuby : Demo Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 17
  20. 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. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×