Ruby vs Java

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    3 Favorites

    Ruby vs Java - Presentation Transcript

    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(\"Java\"); languages.add(\"Ruby\"); languages.add(\"Python\"); languages.add(\"Perl\"); • Ruby stuff = [] stuff << \"Java\", \"Ruby\", \"Python\" stuff = [\"Java\", \"Ruby\", \"Python\"] 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 \"Hello FOSDEM !\" } => 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(\"Odd!\") => Odd! • Ruby if 11.odd?; print \"Odd! => Odd! • Java System.out.println(\"Running time: \" + \\ (3600 + 15 * 60 + 10) + \"seconds\"); • Ruby puts \"Running time: \\ #{1.hour + 15.minutes + 10.seconds} seconds\" Java vs Ruby : a quick and unfair comparison - Jean-Baptiste Escoyez Thursday 19 February 2009 10
    12. Blocks >find_integer([\"a\",1, 4, 2,\"9\",\"c\"]){|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(\"puts 'Hi FOSDEM'\") => 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 = [\"steve\", \"aurelien\"] >speaker = Class.new >speaker.class_eval do > people.each do |person| > define_method(\"hello_#{person}\"){ > puts \"Hello #{person}\" > } > end >end >jean_baptiste = speaker.new >jean_baptiste.methods - Object.methods => [\"hello_steve\", \"hello_aurelien\"] >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

    + BelightedBelighted, 9 months ago

    custom

    3714 views, 3 favs, 4 embeds more stats

    A quick and unfair comparison of Ruby and Java.

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 3714
      • 3655 on SlideShare
      • 59 from embeds
    • Comments 0
    • Favorites 3
    • Downloads 69
    Most viewed embeds
    • 49 views on http://www.net4java.com
    • 6 views on http://zero.andrisetiawan.info
    • 3 views on http://r-quadrant.blogspot.com
    • 1 views on http://209.85.173.132

    more

    All embeds
    • 49 views on http://www.net4java.com
    • 6 views on http://zero.andrisetiawan.info
    • 3 views on http://r-quadrant.blogspot.com
    • 1 views on http://209.85.173.132

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories