Ruby and DCI

10
Ruby and DCI You’re doing it wrong Simon Courtois - @happynoff

description

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

Transcript of Ruby and DCI

Page 1: Ruby and DCI

Ruby and DCIYou’re doing it wrong

Simon Courtois - @happynoff

Page 2: Ruby and DCI

DCI ?

Data (domain model)

Context

Interaction (roles)

Page 3: Ruby and DCI

Exampleclass User < A

ctiveRecord::Base

end

def tweet_name

TwitterLib.send_tweet("My

name is #{name}")

end

user = User.find(42)user.tweet_name

Page 4: Ruby and DCI

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

Page 5: Ruby and DCI

Performance ?

Tony Arcieri@bascule

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

Page 6: Ruby and DCI

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

Page 7: Ruby and DCI

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

Page 8: Ruby and DCI

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

Page 9: Ruby and DCI

Questions ?Simon Courtois - @happynoff

Page 10: Ruby and DCI

Thanks !Simon Courtois - @happynoff