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
Top Related