Ruby and DCI

Post on 18-Dec-2014

922 views 2 download

description

Slides de mon talk à Paris.rb le 07/01/13.

Transcript of Ruby and DCI

Ruby and DCIYou’re doing it wrong

Simon Courtois - @happynoff

DCI ?

Data (domain model)

Context

Interaction (roles)

Exampleclass User < A

ctiveRecord::Base

end

def tweet_name

TwitterLib.send_tweet("My

name is #{name}")

end

user = User.find(42)user.tweet_name

Example

module TwitterUser

end

def tweet_name TwitterLib.send_tweet("My name is #{name}")end

user = User.find(42)

user.tweet_nameuser.extend(TwitterUser)

class User < ActiveRecord::B

ase

end

Performance ?

Tony Arcieri@bascule

http://tonyarcieri.com/dci-in-ruby-is-completely-broken

Performance ?

Local - Ok

Global - What ?!

Benchmark.ips do |bm| bm.report("without dci") { ExampleClass.new.foo } bm.report("with dci") do obj = ExampleClass.new obj.extend(ExampleMixin) obj.foo endend

Ruby’s cache

Ruby VMs cache methods

« These caches remain valid so long as we don’t see new types and the class hierarchy doesn’t change. »

Tony Arceria

Alternativeclass User < A

ctiveRecord::Base

end

class TwitterUser < SimpleDelegator def tweet_name TwitterLib.send_tweet("My name is #{name}") endend

user = User.find(42)

tw_user.tweet_nametw_user = TwitterUser.new(user)

Evan Light

Questions ?Simon Courtois - @happynoff

Thanks !Simon Courtois - @happynoff