Scala vs Ruby
Upcoming SlideShare
Loading in...5
×
 

Scala vs Ruby

on

  • 40,115 views

A comparison between the programming languages Scala and Ruby

A comparison between the programming languages Scala and Ruby

Statistics

Views

Total Views
40,115
Views on SlideShare
38,417
Embed Views
1,698

Actions

Likes
74
Downloads
461
Comments
13

19 Embeds 1,698

http://francescoagati.wordpress.com 1173
http://www.scoop.it 197
https://twitter.com 96
http://paper.li 64
http://forum.rubyonrails.pl 61
http://paper.dev 19
url_unknown 18
http://192.168.6.184 18
http://wix.dapulse.com 12
http://wushaobo.info 10
http://www.lifeyun.com 10
http://www.techgig.com 6
http://www.slideshare.net 4
http://translate.googleusercontent.com 3
http://us-w1.rockmelt.com 3
http://wix.local.host:3000 1
http://www.hanrss.com 1
https://francescoagati.wordpress.com 1
https://forum.rubyonrails.pl 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

15 of 13 Post a comment

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • I think, you must compare ruby with groovy, not scala.
    Are you sure you want to
    Your message goes here
    Processing…
  • It's already possible to easly create Play heroku apps:
    http://www.playframework.org/documentation/2.0/ProductionHeroku
    heroku create --stack cedar
    Are you sure you want to
    Your message goes here
    Processing…
  • Good One . . .
    Are you sure you want to
    Your message goes here
    Processing…
  • What about helma (http://www.helma.org/) and RingoJS (http://www.ringojs.org/)? If Java is for morons ... what is (server sided) javascript then for?
    Are you sure you want to
    Your message goes here
    Processing…
  • Here's a Ruby/Scala comparison checklist I whipped up a while back.

    http://stackoverflow.com/questions/2351433/questions-about-scala-from-a-rubyist/2351607#2351607
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Scala vs Ruby Scala vs Ruby Presentation Transcript

  • SCALA VS RUBY Rémy-Christophe Schermesser rcs@octo.com @El_Picador 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • <relationships> <ejb-relation> <ejb-relation-name>a-b</ejb-relation-name> <ejb-relationship-role> <!-- A => B --> <ejb-relationship-role-name>a2b</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source> <ejb-name>A</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>b</cmr-field-name> </cmr-field> </ejb-relationship-role> <ejb-relationship-role> <!-- B => A --> <ejb-relationship-role-name>b2a</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source> <ejb-name>B</ejb-name> </relationship-role-source> </ejb-relationship-role> </ejb-relation></relationships> 8
  • 9
  • Functionalprogramming 10
  • Functional APIsprogramming 10
  • Functional APIsprogramming gems 10
  • Functional APIsprogrammingEasy to use gems 10
  • 11
  • Functionalprogramming ? 12
  • Functionalprogramming ? 12
  • Functional APIs ?programming ? 12
  • Functional APIs ?programming ? 12
  • Functional APIs ?programming ? gems ? 12
  • Functional APIs ?programming ? gems ? 12
  • Functional APIs ?programming ?Easy to use ? gems ? 12
  • Functional APIs ?programming ?Easy to use ? gems ? 12
  • VS 13
  • FIGHT VS 13
  • DRAW VS Sort of ... 13
  • WHY A DRAW ? 14
  • WHY A DRAW ? let’s talk about languages 14
  • WHY A DRAW ? let’s talk about languageslet’s frameworkise 14
  • WHY A DRAW ? let’s talk about languageslet’s frameworkise let’s deploy 14
  • WHY A DRAW ? let’s talk about languageslet’s frameworkise let’s deploylet’s meet people 14
  • 15
  • LET’S TALK ABOUT LANGUAGES 15
  • 16
  • THEBEST THING ABOUTSCALA & RUBY 16
  • Noat the end of lines 17
  • No ;at the end of lines 17
  • Scala No Ruby 1 ; 1at the end of lines 17
  • 18
  • λ 18
  • list.filter(_ % 2 == 0) list.filter { e: Int => (e % 2 == 0)) } 19
  • list.filter(_ % 2 == 0) list.filter { e: Int => (e % 2 == 0)) } list.select do |e| e % 2 == 0 end 19
  • list.filter(_ % 2 == 0) Scala list.filter { } Ruby e: Int => (e % 2 == 0)) 2 2 list.select do |e| e % 2 == 0 end 19
  • TYPES ! 20
  • TYPES ! STATIC 20
  • TYPES ! STATICvar hash = new HashMap[Int, String] 20
  • TYPES ! STATICvar hash = new HashMap[Int, String] hash = Hash.new hash = 3 20
  • TYPES ! STATICvar hash = new HashMap[Int, String] hash = Hash.new hash = 3 20
  • TYPES ! STATIC Scala Ruby 2 2var hash = new HashMap[Int, String] hash = Hash.new hash = 3 20
  • PATTERNMATCHING 21
  • PATTERN MATCHINGdef matchTest(x: Any): Any = x match { case 1 => "one" case "two" => 2 case y: Int => "scala.Int" case 2 :: tail => tail} 21
  • gem install case 22
  • gem install caserequire casedef matchTest x case x when 1 "one" when "two" 2 when Case::All[Integer] "ruby.Integer" when Case::Array[2, Case::Any] x[1..-1] endend 22
  • gem install caserequire casedef matchTest x case x when 1 "one" when "two" 2 when Case::All[Integer] "ruby.Integer" when Case::Array[2, Case::Any] x[1..-1] endend 22
  • gem install caserequire case Scaladef matchTest x case x when 1 Ruby 3 2 "one" when "two" 2 when Case::All[Integer] "ruby.Integer" when Case::Array[2, Case::Any] x[1..-1] endend 22
  • MONKEYPATCHING 23
  • puts "a".to_s # => a 24
  • puts "a".to_s # => aclass String def to_s "Monkey !" end def my_method "Patch !" endend 24
  • puts "a".to_s # => aclass String def to_s "Monkey !" end def my_method "Patch !" endendputs "a".to_s # => Monkey ! 24
  • puts "a".to_s # => aclass String def to_s "Monkey !" end def my_method "Patch !" endendputs "a".to_s # => Monkey !puts "a".my_method # => Patch ! 24
  • 25
  • Implicit ! 25
  • Implicit !class MySuperString(original: String) { def myMethod = "Patch !"} 25
  • Implicit !class MySuperString(original: String) { def myMethod = "Patch !"}implicit def string2super(x: String) = new MySuperString(x) 25
  • Implicit !class MySuperString(original: String) { def myMethod = "Patch !"}implicit def string2super(x: String) = new MySuperString(x)println("a".myMethod) // => Patch ! 25
  • Implicit ! Scala Rubyclass MySuperString(original: String) {} def myMethod = "Patch !" 3 3implicit def string2super(x: String) = new MySuperString(x)println("a".myMethod) // => Patch ! 25
  • Dynamic calls 26
  • Dynamic callsclass Animal def method_missing name, *args if args.empty? puts "Animal says " + name.to_s else puts "Animal wants to " + name.to_s + args.join(", ") end self endend 26
  • Dynamic callsclass Animal def method_missing name, *args if args.empty? puts "Animal says " + name.to_s else puts "Animal wants to " + name.to_s + args.join(", ") end self endend animal = Animal.new animal.qualk # => Animal says : qualks ! animal.say("hello") # => Animal wants to say hello 26
  • 27
  • Scala 2.9 27
  • Scala 2.9class Animal extends Dynamic { def _select_(name: String) = println("Animal says " + name) def _invoke_(name: String, args: Any*) = { println("Animal wants to " + name + args.mkString(", ")) this }} 27
  • Scala 2.9class Animal extends Dynamic { def _select_(name: String) = println("Animal says " + name) def _invoke_(name: String, args: Any*) = { println("Animal wants to " + name + args.mkString(", ")) this }} val animal = new Animal animal.qualk // => Animal says qualk animal.say("hello") // => Animal wants to say hello 27
  • Scala 2.9class Animal extends Dynamic { def _select_(name: String) = println("Animal says " + name) def _invoke_(name: String, args: Any*) = { println("Animal wants to " + name + args.mkString(", ")) this }} val animal = new Animal animal.qualk // => Animal says qualk animal.say("hello") // => Animal wants to say hello 27
  • Scala 2.9 Scalaclass Animal extends Dynamic { Ruby def _select_(name: String) = println("Animal says " + name) def _invoke_(name: String, args: Any*) = { 4 4 println("Animal wants to " + name + args.mkString(", ")) this }} val animal = new Animal animal.qualk // => Animal says qualk animal.say("hello") // => Animal wants to say hello 27
  • Traits ! trait PimpMyClass { def myMethod = println("myMethod") } class IncludeTrait extends PimpMyClass (new IncludeTrait).myMethod 28
  • Traits ! trait PimpMyClass { def myMethod = println("myMethod") } class IncludeTrait extends PimpMyClass (new IncludeTrait).myMethod 28
  • Modules ! module PimpMyClass def my_method puts "my_method" end end class IncludeModule include PimpMyClass end IncludeModule.new.my_method 29
  • Modules ! Scala module PimpMyClass def my_method Ruby puts "my_method" 5 5 end end class IncludeModule include PimpMyClass end IncludeModule.new.my_method 29
  • DUCKTYPING 30
  • DUCK TYPINGIt quacks ! 30
  • DUCK TYPINGIt quacks !It walks ! 30
  • DUCK TYPINGIt quacks !It walks ! 30
  • class Duck def quack; end def walk; endend 31
  • class Duck def quack; end def walk; end class Platypusend def quack; end def walk; end end 31
  • class Duck def quack; end def walk; end class Platypus end def quack; end def walk; end enddef act_as_a_duck animal animal.quack animal.walkend 31
  • class Duck def quack; end def walk; end class Platypus end def quack; end def walk; end enddef act_as_a_duck animal animal.quack animal.walk duck = Duck.newend platypus = Platypus.new act_as_a_duck(duck) act_as_a_duck(platypus) 31
  • class Duck { def quack = ... def walk = ...} 32
  • class Duck { def quack = ... def walk = ... class Platypus {} def quack = ... def walk = ... } 32
  • class Duck { def quack = ... def walk = ... class Platypus { } def quack = ... def walk = ... }def ActAsADuck(a: { def quack; def walk })= { a.quack a.walk} 32
  • class Duck { def quack = ... def walk = ... class Platypus { } def quack = ... def walk = ... }def ActAsADuck(a: { def quack; def walk })= { a.quack a.walk} val duck = new Duck val platypus = new Platypus ActAsADuck(duck) ActAsADuck(platypus) 32
  • class Duck { def quack = ... def walk = ... Scala Ruby class Platypus { } def quack = ... def walk = ... }} 6 a.quack a.walk 6def ActAsADuck(a: { def quack; def walk })= { val duck = new Duck val platypus = new Platypus ActAsADuck(duck) ActAsADuck(platypus) 32
  • ≃ 33
  • ≃Only learn the syntax 33
  • 34
  • LET’S FRAMEWORKISE 34
  • 35
  • Test::Unit rSpec 35
  • UNIT TESTING 36
  • test "my test" do array = [1, 2, 3] assert_equal 1, array.firstend UNIT TESTING 36
  • test "my test" do array = [1, 2, 3] assert_equal 1, array.firstend UNIT TESTING @Test def myTest() { val array = List(1, 2, 3) assert(array(0) === 1) } 36
  • SPEC TESTING 37
  • describe "Get of Array" do it "first returns the first element" do array = [1, 2, 3] array.first.should == 1 endend SPEC TESTING 37
  • describe "Get of Array" do it "first returns the first element" do array = [1, 2, 3] array.first.should == 1 endend SPEC TESTING describe("Get of List") { it("(0) returns the first element") { val array = List(1, 2, 3) array(0) should be 1 } } 37
  • BDD TESTINGFeature: The user can get an element off an array Scenario: first is invoked on the array Given a non-empty array When first is invoked on the array Then the first element should be returned 38
  • BDD TESTINGFeature: The user can get an element off an array Scenario: first is invoked on the array Given a non-empty array When first is invoked on the array Then the first element should be returned 38
  • Test::Unit rSpec 39
  • Test::UnitScala Ruby rSpec 7 7 39
  • 40
  • 40
  • 40
  • 40
  • 41
  • 24 000 gems 41
  • for Rails12 000 gems 41
  • for Rails12 000 gems 41
  • for RailsScala 000 12 Ruby 7 8 gems 41
  • 42
  • Actors in Ruby ? 43
  • Don’t try this at home ! 43
  • Scala try RubyDon’t this at 8home ! 8 43
  • 44
  • 45
  • LET’S DEPLOY 45
  • 46
  • rails new myappheroku create myappgit push heroku master 46
  • rails new myappheroku create myappgit push heroku master http://myapp.heroku.com 46
  • Scala Ruby 8 rails new myapp heroku create myapp9 git push heroku master http://myapp.heroku.com 46
  • 47
  • 47
  • 47
  • 47
  • 47
  • 47
  • 47
  • 47
  • 80 60 40 70,74 39,74 20 2,07 0Average performance (less is better) Source : http://shootout.alioth.debian.org 48
  • Scala JRuby Ruby 1.9 80 60 40 70,74 39,74 20 2,07 0Average performance (less is better) Source : http://shootout.alioth.debian.org 48
  • Scala JRuby Ruby 1.9 80 Scala Ruby 60 9 39,74 9 70,74 20 40 2,07 0Average performance (less is better) Source : http://shootout.alioth.debian.org 48
  • Do not talk of Ruby to an admin 49
  • Do not talk of Ruby to an admin Neither of Java 49
  • 50
  • LET’S MEET PEOPLE 50
  • 51
  • 51
  • 52
  • 52
  • «Most Java Programmers are Morons» 53
  • «Most Java Programmers are Morons» © Rails community 53
  • Scala Ruby 9 9 54
  • ? ? 55
  • ? ? 55
  • 56