SlideShare une entreprise Scribd logo
1  sur  152
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptNone
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real Worldosfameron
 
Groovy presentation
Groovy presentationGroovy presentation
Groovy presentationManav Prasad
 
Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)Being functional in PHP (DPC 2016)
Being functional in PHP (DPC 2016)David de Boer
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and ClosuresSandip Kumar
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Jonas Bonér
 
PHP Performance Trivia
PHP Performance TriviaPHP Performance Trivia
PHP Performance TriviaNikita Popov
 
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 LambdasRyan Knight
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecLoïc Descotte
 
Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?Is Haskell an acceptable Perl?
Is Haskell an acceptable Perl?osfameron
 
Functional Principles for OO Developers
Functional Principles for OO DevelopersFunctional Principles for OO Developers
Functional Principles for OO Developersjessitron
 
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?Nikita Popov
 
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
 
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?"Fwdays
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
PHP Language Trivia
PHP Language TriviaPHP Language Trivia
PHP Language TriviaNikita Popov
 

Tendances (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
 

Similaire à Scala vs Ruby

Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
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 developersMatthew Farwell
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Seductions of Scala
Seductions of ScalaSeductions of Scala
Seductions of ScalaDean Wampler
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)William Narmontas
 
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 2Kirill Rozov
 
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 streamRuslan Shevchenko
 
あたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみるあたかも自然言語を書くようにコーディングしてみる
あたかも自然言語を書くようにコーディングしてみるKazuya Numata
 
Threequals - Case Equality in Ruby
Threequals - Case Equality in RubyThreequals - Case Equality in Ruby
Threequals - Case Equality in RubyLouis Scoras
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
Laziness in Swift
Laziness in Swift Laziness in Swift
Laziness in Swift SwiftWro
 
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 ModulesWorkhorse Computing
 
Perl training-in-navi mumbai
Perl training-in-navi mumbaiPerl training-in-navi mumbai
Perl training-in-navi mumbaivibrantuser
 

Similaire à 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
 

Dernier

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfpanagenda
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 

Dernier (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdfSo einfach geht modernes Roaming fuer Notes und Nomad.pdf
So einfach geht modernes Roaming fuer Notes und Nomad.pdf
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 

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