Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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 --> ...
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                  ...
WHY A DRAW ?             let’s talk about languageslet’s frameworkise                       let’s deploylet’s meet people ...
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|        ...
list.filter(_ % 2 == 0)   Scala       list.filter {       }                    Ruby         e: Int => (e % 2 == 0))    2  ...
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    ...
TYPES !              STATICvar hash =  new HashMap[Int, String]                hash = Hash.new                hash = 3    ...
TYPES ! STATIC  Scala Ruby   2     2var hash =  new HashMap[Int, String]                hash = Hash.new                has...
PATTERNMATCHING           21
PATTERN MATCHINGdef matchTest(x: Any): Any =  x match {    case 1 => "one"    case "two" => 2    case y: Int => "scala.Int...
gem install case                   22
gem install caserequire casedef matchTest x  case x  when 1    "one"  when "two"    2  when Case::All[Integer]    "ruby.In...
gem install caserequire casedef matchTest x  case x  when 1    "one"  when "two"    2  when Case::All[Integer]    "ruby.In...
gem install caserequire case Scaladef matchTest x  case x  when 1                        Ruby  3                      2   ...
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...
puts "a".to_s # => aclass String  def to_s    "Monkey !"  end  def my_method    "Patch !"  endendputs "a".to_s # => Monkey...
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 My...
Implicit !class MySuperString(original: String) {  def myMethod = "Patch !"}implicit def string2super(x: String) =  new My...
Implicit !  Scala                  Rubyclass MySuperString(original: String) {}  def myMethod = "Patch !"   3             ...
Dynamic calls                26
Dynamic callsclass Animal  def method_missing name, *args    if args.empty?      puts "Animal says " + name.to_s    else  ...
Dynamic callsclass Animal  def method_missing name, *args    if args.empty?      puts "Animal says " + name.to_s    else  ...
27
Scala 2.9            27
Scala 2.9class Animal extends Dynamic {  def _select_(name: String) = println("Animal says " + name)    def _invoke_(name:...
Scala 2.9class Animal extends Dynamic {  def _select_(name: String) = println("Animal says " + name)    def _invoke_(name:...
Scala 2.9class Animal extends Dynamic {  def _select_(name: String) = println("Animal says " + name)    def _invoke_(name:...
Scala 2.9        Scalaclass Animal extends Dynamic {                                          Ruby  def _select_(name: Str...
Traits ! trait PimpMyClass {   def myMethod = println("myMethod") } class IncludeTrait extends PimpMyClass (new IncludeTra...
Traits ! trait PimpMyClass {   def myMethod = println("myMethod") } class IncludeTrait extends PimpMyClass (new IncludeTra...
Modules !    module PimpMyClass      def my_method        puts "my_method"      end    end    class IncludeModule      inc...
Modules !  Scala    module PimpMyClass      def my_method   Ruby        puts "my_method"   5                   5      end ...
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 wal...
class Duck   def quack; end   def walk; end       class Platypus end                     def quack; end                   ...
class Duck   def quack; end   def walk; end        class Platypus end                      def quack; end                 ...
class Duck {  def quack = ...  def walk = ...}                    32
class Duck {  def quack = ...  def walk = ...    class Platypus {}                     def quack = ...                    ...
class Duck {   def quack = ...   def walk = ...     class Platypus { }                      def quack = ...               ...
class Duck {   def quack = ...   def walk = ...     class Platypus { }                      def quack = ...               ...
class Duck {   def quack = ...   def walk = ...    Scala                 Ruby                      class Platypus { }     ...
≃    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() {        v...
SPEC TESTING               37
describe "Get of Array" do  it "first returns the first element" do    array = [1, 2, 3]    array.first.should == 1  enden...
describe "Get of Array" do  it "first returns the first element" do    array = [1, 2, 3]    array.first.should == 1  enden...
BDD TESTINGFeature: The user can get an element off an array Scenario: first is invoked on the array  Given a non-empty arr...
BDD TESTINGFeature: The user can get an element off an array Scenario: first is invoked on the array  Given a non-empty arr...
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           ...
47
47
47
47
47
47
47
47
80                                            60                                          40                        70,74 ...
Scala        JRuby           Ruby 1.9                                                   80                                ...
Scala        JRuby           Ruby 1.9                                                   80    Scala                    Rub...
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
Upcoming SlideShare
Loading in …5
×

Scala vs Ruby

56,046 views

Published on

A comparison between the programming languages Scala and Ruby

Published in: Technology
  • Hi All, We are planning to start new Salesforce Online batch on this week... If any one interested to attend the demo please register in our website... For this batch we are also provide everyday recorded sessions with Materials. For more information feel free to contact us : siva@keylabstraining.com. For Course Content and Recorded Demo Click Here : http://www.keylabstraining.com/salesforce-online-training-hyderabad-bangalore
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Ruby (Oprah's Book Club 2.0) --- http://amzn.to/1R7bSvB
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Sterling Silver Created Ruby and Created White Sapphire Wrapped Heart Pendant Necklace, 18" --- http://amzn.to/1TYeO01
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • The Ruby Programming Language --- http://amzn.to/1PkaYX4
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • I think, you must compare ruby with groovy, not scala.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Scala vs Ruby

  1. 1. SCALA VS RUBY Rémy-Christophe Schermesser rcs@octo.com @El_Picador 1
  2. 2. 2
  3. 3. 3
  4. 4. 4
  5. 5. 5
  6. 6. 6
  7. 7. 7
  8. 8. <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. 9. 9
  10. 10. Functionalprogramming 10
  11. 11. Functional APIsprogramming 10
  12. 12. Functional APIsprogramming gems 10
  13. 13. Functional APIsprogrammingEasy to use gems 10
  14. 14. 11
  15. 15. Functionalprogramming ? 12
  16. 16. Functionalprogramming ? 12
  17. 17. Functional APIs ?programming ? 12
  18. 18. Functional APIs ?programming ? 12
  19. 19. Functional APIs ?programming ? gems ? 12
  20. 20. Functional APIs ?programming ? gems ? 12
  21. 21. Functional APIs ?programming ?Easy to use ? gems ? 12
  22. 22. Functional APIs ?programming ?Easy to use ? gems ? 12
  23. 23. VS 13
  24. 24. FIGHT VS 13
  25. 25. DRAW VS Sort of ... 13
  26. 26. WHY A DRAW ? 14
  27. 27. WHY A DRAW ? let’s talk about languages 14
  28. 28. WHY A DRAW ? let’s talk about languageslet’s frameworkise 14
  29. 29. WHY A DRAW ? let’s talk about languageslet’s frameworkise let’s deploy 14
  30. 30. WHY A DRAW ? let’s talk about languageslet’s frameworkise let’s deploylet’s meet people 14
  31. 31. 15
  32. 32. LET’S TALK ABOUT LANGUAGES 15
  33. 33. 16
  34. 34. THEBEST THING ABOUTSCALA & RUBY 16
  35. 35. Noat the end of lines 17
  36. 36. No ;at the end of lines 17
  37. 37. Scala No Ruby 1 ; 1at the end of lines 17
  38. 38. 18
  39. 39. λ 18
  40. 40. list.filter(_ % 2 == 0) list.filter { e: Int => (e % 2 == 0)) } 19
  41. 41. list.filter(_ % 2 == 0) list.filter { e: Int => (e % 2 == 0)) } list.select do |e| e % 2 == 0 end 19
  42. 42. list.filter(_ % 2 == 0) Scala list.filter { } Ruby e: Int => (e % 2 == 0)) 2 2 list.select do |e| e % 2 == 0 end 19
  43. 43. TYPES ! 20
  44. 44. TYPES ! STATIC 20
  45. 45. TYPES ! STATICvar hash = new HashMap[Int, String] 20
  46. 46. TYPES ! STATICvar hash = new HashMap[Int, String] hash = Hash.new hash = 3 20
  47. 47. TYPES ! STATICvar hash = new HashMap[Int, String] hash = Hash.new hash = 3 20
  48. 48. TYPES ! STATIC Scala Ruby 2 2var hash = new HashMap[Int, String] hash = Hash.new hash = 3 20
  49. 49. PATTERNMATCHING 21
  50. 50. PATTERN MATCHINGdef matchTest(x: Any): Any = x match { case 1 => "one" case "two" => 2 case y: Int => "scala.Int" case 2 :: tail => tail} 21
  51. 51. gem install case 22
  52. 52. 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
  53. 53. 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
  54. 54. 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
  55. 55. MONKEYPATCHING 23
  56. 56. puts "a".to_s # => a 24
  57. 57. puts "a".to_s # => aclass String def to_s "Monkey !" end def my_method "Patch !" endend 24
  58. 58. puts "a".to_s # => aclass String def to_s "Monkey !" end def my_method "Patch !" endendputs "a".to_s # => Monkey ! 24
  59. 59. 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
  60. 60. 25
  61. 61. Implicit ! 25
  62. 62. Implicit !class MySuperString(original: String) { def myMethod = "Patch !"} 25
  63. 63. Implicit !class MySuperString(original: String) { def myMethod = "Patch !"}implicit def string2super(x: String) = new MySuperString(x) 25
  64. 64. Implicit !class MySuperString(original: String) { def myMethod = "Patch !"}implicit def string2super(x: String) = new MySuperString(x)println("a".myMethod) // => Patch ! 25
  65. 65. Implicit ! Scala Rubyclass MySuperString(original: String) {} def myMethod = "Patch !" 3 3implicit def string2super(x: String) = new MySuperString(x)println("a".myMethod) // => Patch ! 25
  66. 66. Dynamic calls 26
  67. 67. 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
  68. 68. 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
  69. 69. 27
  70. 70. Scala 2.9 27
  71. 71. 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
  72. 72. 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
  73. 73. 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
  74. 74. 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
  75. 75. Traits ! trait PimpMyClass { def myMethod = println("myMethod") } class IncludeTrait extends PimpMyClass (new IncludeTrait).myMethod 28
  76. 76. Traits ! trait PimpMyClass { def myMethod = println("myMethod") } class IncludeTrait extends PimpMyClass (new IncludeTrait).myMethod 28
  77. 77. Modules ! module PimpMyClass def my_method puts "my_method" end end class IncludeModule include PimpMyClass end IncludeModule.new.my_method 29
  78. 78. 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
  79. 79. DUCKTYPING 30
  80. 80. DUCK TYPINGIt quacks ! 30
  81. 81. DUCK TYPINGIt quacks !It walks ! 30
  82. 82. DUCK TYPINGIt quacks !It walks ! 30
  83. 83. class Duck def quack; end def walk; endend 31
  84. 84. class Duck def quack; end def walk; end class Platypusend def quack; end def walk; end end 31
  85. 85. 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
  86. 86. 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
  87. 87. class Duck { def quack = ... def walk = ...} 32
  88. 88. class Duck { def quack = ... def walk = ... class Platypus {} def quack = ... def walk = ... } 32
  89. 89. class Duck { def quack = ... def walk = ... class Platypus { } def quack = ... def walk = ... }def ActAsADuck(a: { def quack; def walk })= { a.quack a.walk} 32
  90. 90. 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
  91. 91. 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
  92. 92. ≃ 33
  93. 93. ≃Only learn the syntax 33
  94. 94. 34
  95. 95. LET’S FRAMEWORKISE 34
  96. 96. 35
  97. 97. Test::Unit rSpec 35
  98. 98. UNIT TESTING 36
  99. 99. test "my test" do array = [1, 2, 3] assert_equal 1, array.firstend UNIT TESTING 36
  100. 100. 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
  101. 101. SPEC TESTING 37
  102. 102. describe "Get of Array" do it "first returns the first element" do array = [1, 2, 3] array.first.should == 1 endend SPEC TESTING 37
  103. 103. 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
  104. 104. 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
  105. 105. 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
  106. 106. Test::Unit rSpec 39
  107. 107. Test::UnitScala Ruby rSpec 7 7 39
  108. 108. 40
  109. 109. 40
  110. 110. 40
  111. 111. 40
  112. 112. 41
  113. 113. 24 000 gems 41
  114. 114. for Rails12 000 gems 41
  115. 115. for Rails12 000 gems 41
  116. 116. for RailsScala 000 12 Ruby 7 8 gems 41
  117. 117. 42
  118. 118. Actors in Ruby ? 43
  119. 119. Don’t try this at home ! 43
  120. 120. Scala try RubyDon’t this at 8home ! 8 43
  121. 121. 44
  122. 122. 45
  123. 123. LET’S DEPLOY 45
  124. 124. 46
  125. 125. rails new myappheroku create myappgit push heroku master 46
  126. 126. rails new myappheroku create myappgit push heroku master http://myapp.heroku.com 46
  127. 127. Scala Ruby 8 rails new myapp heroku create myapp9 git push heroku master http://myapp.heroku.com 46
  128. 128. 47
  129. 129. 47
  130. 130. 47
  131. 131. 47
  132. 132. 47
  133. 133. 47
  134. 134. 47
  135. 135. 47
  136. 136. 80 60 40 70,74 39,74 20 2,07 0Average performance (less is better) Source : http://shootout.alioth.debian.org 48
  137. 137. 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
  138. 138. 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
  139. 139. Do not talk of Ruby to an admin 49
  140. 140. Do not talk of Ruby to an admin Neither of Java 49
  141. 141. 50
  142. 142. LET’S MEET PEOPLE 50
  143. 143. 51
  144. 144. 51
  145. 145. 52
  146. 146. 52
  147. 147. «Most Java Programmers are Morons» 53
  148. 148. «Most Java Programmers are Morons» © Rails community 53
  149. 149. Scala Ruby 9 9 54
  150. 150. ? ? 55
  151. 151. ? ? 55
  152. 152. 56

×