SlideShare ist ein Scribd-Unternehmen logo
1 von 152
Downloaden Sie, um offline zu lesen
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
Functional
programming




              10
Functional   APIs
programming




                     10
Functional   APIs
programming


              gems


                     10
Functional   APIs
programming


Easy to use   gems


                     10
11
Functional
programming ?




                12
Functional
programming ?




                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 languages

let’s frameworkise




                                          14
WHY A DRAW ?

             let’s talk about languages

let’s frameworkise

                       let’s deploy


                                          14
WHY A DRAW ?

             let’s talk about languages

let’s frameworkise

                       let’s deploy
let’s meet people
                                          14
15
LET’S TALK ABOUT
  LANGUAGES



                   15
16
THE
BEST THING ABOUT
SCALA & RUBY
                   16
No

at the end of lines

                      17
No
        ;
at the end of lines

                      17
Scala No Ruby
 1     ; 1
at 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 !              STATIC


var hash =
  new HashMap[Int, String]




                               20
TYPES !              STATIC


var hash =
  new HashMap[Int, String]

                hash = Hash.new
                hash = 3
                                  20
TYPES !              STATIC


var hash =
  new HashMap[Int, String]

                hash = Hash.new
                hash = 3
                                  20
TYPES ! STATIC
  Scala Ruby
   2     2
var hash =
  new HashMap[Int, String]

                hash = Hash.new
                hash = 3
                                  20
PATTERN
MATCHING




           21
PATTERN
 MATCHING
def 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 case

require 'case'

def 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]
  end
end
                                   22
gem install case

require 'case'

def 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]
  end
end
                                   22
gem install case

require 'case'


 Scala
def 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]
  end
end
                                   22
MONKEY
PATCHING




           23
puts "a".to_s # => a




                       24
puts "a".to_s # => a

class String
  def to_s
    "Monkey !"
  end

  def my_method
    "Patch !"
  end
end




                       24
puts "a".to_s # => a

class String
  def to_s
    "Monkey !"
  end

  def my_method
    "Patch !"
  end
end

puts "a".to_s # => Monkey !



                              24
puts "a".to_s # => a

class String
  def to_s
    "Monkey !"
  end

  def my_method
    "Patch !"
  end
end

puts "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                  Ruby
class MySuperString(original: String) {

}
  def myMethod = "Patch !"



   3                      3
implicit def string2super(x: String) =
  new MySuperString(x)



println("a".myMethod) // => Patch !


                                          25
Dynamic calls




                26
Dynamic calls
class 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
  end

end




                                                              26
Dynamic calls
class 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
  end

end


         animal = Animal.new

         animal.qualk # => Animal says : qualks !
         animal.say("hello") # => Animal wants to say hello


                                                              26
27
Scala 2.9




            27
Scala 2.9
class 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.9
class 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
class 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
        Scala
class 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
DUCK
TYPING




         30
DUCK
              TYPING



It quacks !




                       30
DUCK
              TYPING



It quacks !
It walks !



                       30
DUCK
              TYPING



It quacks !
It walks !



                       30
class Duck
  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
                   end




                                      31
class Duck
   def quack; end
   def walk; end       class Platypus
 end                     def quack; end
                         def walk; end
                       end


def act_as_a_duck animal
  animal.quack
  animal.walk
end




                                          31
class Duck
   def quack; end
   def walk; end        class Platypus
 end                      def quack; end
                          def walk; end
                        end


def act_as_a_duck animal
  animal.quack
  animal.walk      duck = Duck.new
end                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
                           6
def 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.first
end


         UNIT TESTING




                                36
test "my test" do
  array = [1, 2, 3]
  assert_equal 1, array.first
end


         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
  end
end



            SPEC TESTING




                                            37
describe "Get of Array" do
  it "first returns the first element" do
    array = [1, 2, 3]
    array.first.should == 1
  end
end



            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 TESTING

Feature: 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 TESTING

Feature: 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::Unit

Scala   Ruby
          rSpec
 7       7

                     39
40
40
40
40
41
24 000
 gems
         41
for Rails

12 000
 gems
             41
for Rails

12 000
 gems
             41
for Rails
Scala 000
  12    Ruby
 7       8
    gems
               41
42
Actors in Ruby ?

                   43
Don’t try this at
   home !
                    43
Scala try Ruby
Don’t      this at
  8home ! 8

                     43
44
45
LET’S DEPLOY




               45
46
rails new myapp
heroku create myapp
git push heroku master




                         46
rails new myapp
heroku create myapp
git 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
                                      0

Average 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
                                          0

Average 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
                                          0

Average 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

Weitere ähnliche Inhalte

Was ist angesagt?

CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
None
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
Sandip Kumar
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 

Was ist angesagt? (20)

CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Scala
ScalaScala
Scala
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentation
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Coffee Script
Coffee ScriptCoffee Script
Coffee Script
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance Trivia
 
What You Need to Know about Lambdas
What You Need to Know about LambdasWhat You Need to Know about Lambdas
What You Need to Know about Lambdas
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developers
 
Beyond java8
Beyond java8Beyond java8
Beyond java8
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
JavaScript Basics and Trends
JavaScript Basics and TrendsJavaScript Basics and Trends
JavaScript Basics and Trends
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language Trivia
 

Ähnlich wie Scala vs Ruby

Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbai
vibrantuser
 

Ähnlich wie Scala vs Ruby (20)

Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Scala @ TomTom
Scala @ TomTomScala @ TomTom
Scala @ TomTom
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Seductions of Scala
Seductions of ScalaSeductions of Scala
Seductions of Scala
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
JDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation streamJDays Lviv 2014:  Java8 vs Scala:  Difference points & innovation stream
JDays Lviv 2014: Java8 vs Scala: Difference points & innovation stream
 
Codeware
CodewareCodeware
Codeware
 
あたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみるあたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみる
 
Threequals - Case Equality in Ruby
Threequals - Case Equality in RubyThreequals - Case Equality in Ruby
Threequals - Case Equality in Ruby
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
1.2 scala basics
1.2 scala basics1.2 scala basics
1.2 scala basics
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 
Laziness in Swift
Laziness in Swift Laziness in Swift
Laziness in Swift
 
Scala intro workshop
Scala intro workshopScala intro workshop
Scala intro workshop
 
Wheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility ModulesWheels we didn't re-invent: Perl's Utility Modules
Wheels we didn't re-invent: Perl's Utility Modules
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbai
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Scala vs Ruby

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