Download - Scala vs Ruby
2
3
4
5
6
7
<relationships> <ejb-relation> <ejb-relation-name>a-b</ejb-relation-name> <ejb-relationship-role> <!-- A => B --> <ejb-relationship-role-name>a2b</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source> <ejb-name>A</ejb-name> </relationship-role-source> <cmr-field> <cmr-field-name>b</cmr-field-name> </cmr-field> </ejb-relationship-role> <ejb-relationship-role> <!-- B => A --> <ejb-relationship-role-name>b2a</ejb-relationship-role-name> <multiplicity>One</multiplicity> <relationship-role-source> <ejb-name>B</ejb-name> </relationship-role-source> </ejb-relationship-role> </ejb-relation></relationships>
8
9
Functionalprogramming
10
Functionalprogramming
APIs
10
Functionalprogramming
APIs
gems
10
Functionalprogramming
APIs
gemsEasy to use
10
11
Functionalprogramming ?
12
Functionalprogramming ?
12
Functionalprogramming ?
APIs ?
12
Functionalprogramming ?
APIs ?
12
Functionalprogramming ?
APIs ?
gems ?
12
Functionalprogramming ?
APIs ?
gems ?
12
Functionalprogramming ?
APIs ?
gems ?Easy to use ?
12
Functionalprogramming ?
APIs ?
gems ?Easy to use ?
12
VS
13
VSFIGHT13
VSDRAWSort 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 meet people
let’s deploy
14
15
LET’S TALK ABOUT LANGUAGES
15
16
BEST THING ABOUT
THE
SCALA & RUBY16
No
at the end of lines
17
No
at the end of lines;
17
No
at the end of lines;
Scala1
Ruby1
17
18
λ18
list.filter(_ % 2 == 0)
list.filter { e: Int => (e % 2 == 0))}
19
list.filter(_ % 2 == 0)
list.select do |e| e % 2 == 0end
list.filter { e: Int => (e % 2 == 0))}
19
list.filter(_ % 2 == 0)
list.select do |e| e % 2 == 0end
list.filter { e: Int => (e % 2 == 0))}
Scala2
Ruby2
19
TYPES !
20
STATICTYPES !
20
var hash = new HashMap[Int, String]
STATICTYPES !
20
var hash = new HashMap[Int, String]
STATICTYPES !
hash = Hash.newhash = 3
20
var hash = new HashMap[Int, String]
STATICTYPES !
hash = Hash.newhash = 3
20
var hash = new HashMap[Int, String]
STATICTYPES !Scala
2Ruby
2hash = Hash.newhash = 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] endend
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] endend
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] endend
Scala3
Ruby2
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 !" endend
24
puts "a".to_s # => a
class String def to_s "Monkey !" end def my_method "Patch !" endend
puts "a".to_s # => Monkey !
24
puts "a".to_s # => a
class String def to_s "Monkey !" end def my_method "Patch !" endend
puts "a".to_s # => Monkey !
puts "a".my_method # => Patch !
24
25
Implicit !
25
class MySuperString(original: String) { def myMethod = "Patch !"}
Implicit !
25
class MySuperString(original: String) { def myMethod = "Patch !"}
Implicit !
implicit def string2super(x: String) = new MySuperString(x)
25
class MySuperString(original: String) { def myMethod = "Patch !"}
Implicit !
println("a".myMethod) // => Patch !
implicit def string2super(x: String) = new MySuperString(x)
25
class MySuperString(original: String) { def myMethod = "Patch !"}
Implicit !
println("a".myMethod) // => Patch !
implicit def string2super(x: String) = new MySuperString(x)
Scala3
Ruby3
25
Dynamic calls
26
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
Dynamic calls
26
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
Dynamic calls
animal = Animal.new
animal.qualk # => Animal says : qualks !animal.say("hello") # => Animal wants to say hello
26
27
Scala 2.9
27
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 } }
Scala 2.9
27
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 Animalanimal.qualk // => Animal says qualkanimal.say("hello") // => Animal wants to say hello
Scala 2.9
27
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 Animalanimal.qualk // => Animal says qualkanimal.say("hello") // => Animal wants to say hello
Scala 2.9
27
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 Animalanimal.qualk // => Animal says qualkanimal.say("hello") // => Animal wants to say hello
Scala 2.9
Scala4
Ruby4
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" endend
class IncludeModule include PimpMyClassend
IncludeModule.new.my_method
29
Modules !module PimpMyClass def my_method puts "my_method" endend
class IncludeModule include PimpMyClassend
IncludeModule.new.my_method
Scala5
Ruby5
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; endend
31
class Duck def quack; end def walk; endend
class Platypus def quack; end def walk; endend
31
class Duck def quack; end def walk; endend
class Platypus def quack; end def walk; endend
def act_as_a_duck animal animal.quack animal.walkend
31
class Duck def quack; end def walk; endend
class Platypus def quack; end def walk; endend
def act_as_a_duck animal animal.quack animal.walkend
duck = Duck.newplatypus = 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 = ...}
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)
Scala6
Ruby6
32
≃33
Only learn the syntax≃
33
34
LET’S FRAMEWORKISE
34
35
rSpec
Test::Unit
35
UNIT TESTING
36
UNIT TESTING
test "my test" do array = [1, 2, 3] assert_equal 1, array.firstend
36
UNIT TESTING
test "my test" do array = [1, 2, 3] assert_equal 1, array.firstend
@Test def myTest() { val array = List(1, 2, 3) assert(array(0) === 1)}
36
SPEC TESTING
37
SPEC TESTING
describe "Get of Array" do it "first returns the first element" do array = [1, 2, 3] array.first.should == 1 endend
37
SPEC TESTING
describe "Get of Array" do it "first returns the first element" do array = [1, 2, 3] array.first.should == 1 endend
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
rSpec
Test::Unit
39
rSpec
Test::Unit
Scala7
Ruby7
39
40
40
40
40
41
24 000gems
41
gems
12 000for Rails
41
gems
12 000for Rails
41
gems
12 000for Rails
Scala7
Ruby8
41
42
Actors in Ruby ?
43
Don’t try this at home !
43
Don’t try this at home !
Scala8
Ruby8
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
rails new myappheroku create myappgit push heroku master
Scala8
Ruby9
http://myapp.heroku.com
46
47
47
47
47
47
47
47
47
0
20
40
60
80
2,07
39,74
70,74
Source : http://shootout.alioth.debian.org
Average performance(less is better)
48
0
20
40
60
80
2,07
39,74
70,74
Scala JRuby Ruby 1.9
Source : http://shootout.alioth.debian.org
Average performance(less is better)
48
0
20
40
60
80
2,07
39,74
70,74
Scala JRuby Ruby 1.9
Source : http://shootout.alioth.debian.org
Average performance(less is better)
Scala9
Ruby9
48
Do not talk of Ruby
to an admin49
Do not talk of Ruby
to an adminNeither 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
Scala9
Ruby9
54
?
?55
?
?55
56