Ruby and DCI

Simon Courtois
Simon CourtoisCTO Founder at PDFMonkey
Ruby and DCI
You’re doing it wrong
   Simon Courtois - @happynoff
DCI ?


Data (domain model)

Context

Interaction (roles)
Example
                          d::Base
           < A ctiveRecor
class User                                      e}")
  def tweet _name             My nam e is #{nam
               .se nd_tweet("
    TwitterLib
  end
end




user = User.find(42)
user.tweet_name
Example
                      cor   d::Base
           < ActiveRe
class User



end
                                  module TwitterUser
                                    def tweet_name
                                      TwitterLib.send_tweet("M
                                                               y name is #{name}")
                                    end
                                  end




user = User.find(42)
user.extend(TwitterUser)
user.tweet_name
Performance ?
http://tonyarcieri.com/dci-in-ruby-is-completely-broken



                                             Tony Arcieri
                                             @bascule
Performance ?
Benchmark.ips do |bm|
  bm.report("without dci") { ExampleClass.new.foo }
  bm.report("with dci") do
    obj = ExampleClass.new
    obj.extend(ExampleMixin)
    obj.foo
  end
end




                Local - Ok

                Global - What ?!
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
Alternative
                      cor   d::Base
           < ActiveRe
class User
                                                            Evan Light
end
                                  class TwitterUser < Simp
                                                           leDelegator
                                    def tweet_name
                                      TwitterLib.send_tweet("M
                                                               y name is #{name}")
                                    end
                                  end




user = User.find(42)
tw_user = TwitterUser.new(user)
tw_user.tweet_name
Questions ?
Simon Courtois - @happynoff
Thanks !
Simon Courtois - @happynoff
1 of 10

Recommended

Pooja Sharma , BCA Third Year by
Pooja Sharma , BCA Third YearPooja Sharma , BCA Third Year
Pooja Sharma , BCA Third YearDezyneecole
25 views15 slides
Lecture03 inheritance by
Lecture03 inheritanceLecture03 inheritance
Lecture03 inheritanceHariz Mustafa
719 views35 slides
inheritance c++ by
inheritance c++inheritance c++
inheritance c++Muraleedhar Sundararajan
18.9K views32 slides
Chap4 oop class (php) part 2 by
Chap4 oop class (php) part 2Chap4 oop class (php) part 2
Chap4 oop class (php) part 2monikadeshmane
11 views30 slides
C++ Multiple Inheritance by
C++ Multiple InheritanceC++ Multiple Inheritance
C++ Multiple Inheritanceharshaltambe
2.2K views17 slides
OOPS Basics With Example by
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With ExampleThooyavan Venkatachalam
2.5K views46 slides

More Related Content

Similar to Ruby and DCI

The Future of Rubymotion by
The Future of RubymotionThe Future of Rubymotion
The Future of RubymotionClay Allsopp
1.3K views12 slides
Python_Unit_2 OOPS.pptx by
Python_Unit_2  OOPS.pptxPython_Unit_2  OOPS.pptx
Python_Unit_2 OOPS.pptxChhaviCoachingCenter
4 views86 slides
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up... by
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Tudor Dragan
94 views59 slides
Rails Database Migrations - RORLab Season 3-3 by
Rails Database Migrations - RORLab Season 3-3Rails Database Migrations - RORLab Season 3-3
Rails Database Migrations - RORLab Season 3-3창훈 정
1.1K views30 slides
History of C# by
History of C#History of C#
History of C#aschlapsi
913 views48 slides
Cleaning your architecture with android architecture components by
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture componentsDebora Gomez Bertoli
456 views48 slides

Similar to Ruby and DCI(10)

The Future of Rubymotion by Clay Allsopp
The Future of RubymotionThe Future of Rubymotion
The Future of Rubymotion
Clay Allsopp1.3K views
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up... by Tudor Dragan
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Tudor Dragan94 views
Rails Database Migrations - RORLab Season 3-3 by 창훈 정
Rails Database Migrations - RORLab Season 3-3Rails Database Migrations - RORLab Season 3-3
Rails Database Migrations - RORLab Season 3-3
창훈 정1.1K views
History of C# by aschlapsi
History of C#History of C#
History of C#
aschlapsi913 views
Cleaning your architecture with android architecture components by Debora Gomez Bertoli
Cleaning your architecture with android architecture componentsCleaning your architecture with android architecture components
Cleaning your architecture with android architecture components
Active Support Core Extensions (1) by RORLAB
Active Support Core Extensions (1)Active Support Core Extensions (1)
Active Support Core Extensions (1)
RORLAB721 views
Ruby: Beyond the Basics by Michael Koby
Ruby: Beyond the BasicsRuby: Beyond the Basics
Ruby: Beyond the Basics
Michael Koby553 views
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love by André Oriani
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveWriting Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
André Oriani100 views

More from Simon Courtois

Conseils pour un lancement Product Hunt réussi by
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussiSimon Courtois
72 views28 slides
Organize your assets with Rails by
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with RailsSimon Courtois
761 views51 slides
Speed your Rails app creation with templates by
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templatesSimon Courtois
783 views25 slides
Dependency sorting in Ruby with TSort by
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSortSimon Courtois
942 views16 slides
How Unidecoder Transliterates UTF-8 to ASCII by
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCIISimon Courtois
782 views34 slides
Get Slim! by
Get Slim!Get Slim!
Get Slim!Simon Courtois
2.2K views23 slides

More from Simon Courtois(16)

Conseils pour un lancement Product Hunt réussi by Simon Courtois
Conseils pour un lancement Product Hunt réussiConseils pour un lancement Product Hunt réussi
Conseils pour un lancement Product Hunt réussi
Simon Courtois72 views
Organize your assets with Rails by Simon Courtois
Organize your assets with RailsOrganize your assets with Rails
Organize your assets with Rails
Simon Courtois761 views
Speed your Rails app creation with templates by Simon Courtois
Speed your Rails app creation with templatesSpeed your Rails app creation with templates
Speed your Rails app creation with templates
Simon Courtois783 views
Dependency sorting in Ruby with TSort by Simon Courtois
Dependency sorting in Ruby with TSortDependency sorting in Ruby with TSort
Dependency sorting in Ruby with TSort
Simon Courtois942 views
How Unidecoder Transliterates UTF-8 to ASCII by Simon Courtois
How Unidecoder Transliterates UTF-8 to ASCIIHow Unidecoder Transliterates UTF-8 to ASCII
How Unidecoder Transliterates UTF-8 to ASCII
Simon Courtois782 views
Multi tenant/lang application with Ruby on Rails by Simon Courtois
Multi tenant/lang application with Ruby on RailsMulti tenant/lang application with Ruby on Rails
Multi tenant/lang application with Ruby on Rails
Simon Courtois1.7K views
REST with Her (and let Her take care of the REST) by Simon Courtois
REST with Her (and let Her take care of the REST)REST with Her (and let Her take care of the REST)
REST with Her (and let Her take care of the REST)
Simon Courtois3.2K views
Pourquoi Ruby on Rails ça déchire ? by Simon Courtois
Pourquoi Ruby on Rails ça déchire ?Pourquoi Ruby on Rails ça déchire ?
Pourquoi Ruby on Rails ça déchire ?
Simon Courtois4.9K views

Recently uploaded

Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveNetwork Automation Forum
21 views35 slides
Vertical User Stories by
Vertical User StoriesVertical User Stories
Vertical User StoriesMoisés Armani Ramírez
11 views16 slides
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
15 views15 slides
virtual reality.pptx by
virtual reality.pptxvirtual reality.pptx
virtual reality.pptxG036GaikwadSnehal
11 views15 slides
Scaling Knowledge Graph Architectures with AI by
Scaling Knowledge Graph Architectures with AIScaling Knowledge Graph Architectures with AI
Scaling Knowledge Graph Architectures with AIEnterprise Knowledge
24 views15 slides
Five Things You SHOULD Know About Postman by
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About PostmanPostman
27 views43 slides

Recently uploaded(20)

Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive by Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab15 views
Five Things You SHOULD Know About Postman by Postman
Five Things You SHOULD Know About PostmanFive Things You SHOULD Know About Postman
Five Things You SHOULD Know About Postman
Postman27 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada130 views
PharoJS - Zürich Smalltalk Group Meetup November 2023 by Noury Bouraqadi
PharoJS - Zürich Smalltalk Group Meetup November 2023PharoJS - Zürich Smalltalk Group Meetup November 2023
PharoJS - Zürich Smalltalk Group Meetup November 2023
Noury Bouraqadi120 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 views
1st parposal presentation.pptx by i238212
1st parposal presentation.pptx1st parposal presentation.pptx
1st parposal presentation.pptx
i2382129 views
Data-centric AI and the convergence of data and model engineering: opportunit... by Paolo Missier
Data-centric AI and the convergence of data and model engineering:opportunit...Data-centric AI and the convergence of data and model engineering:opportunit...
Data-centric AI and the convergence of data and model engineering: opportunit...
Paolo Missier34 views
HTTP headers that make your website go faster - devs.gent November 2023 by Thijs Feryn
HTTP headers that make your website go faster - devs.gent November 2023HTTP headers that make your website go faster - devs.gent November 2023
HTTP headers that make your website go faster - devs.gent November 2023
Thijs Feryn19 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... by Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker26 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院

Ruby and DCI

  • 1. Ruby and DCI You’re doing it wrong Simon Courtois - @happynoff
  • 2. DCI ? Data (domain model) Context Interaction (roles)
  • 3. Example d::Base < A ctiveRecor class User e}") def tweet _name My nam e is #{nam .se nd_tweet(" TwitterLib end end user = User.find(42) user.tweet_name
  • 4. Example cor d::Base < ActiveRe class User end module TwitterUser def tweet_name TwitterLib.send_tweet("M y name is #{name}") end end user = User.find(42) user.extend(TwitterUser) user.tweet_name
  • 6. Performance ? Benchmark.ips do |bm| bm.report("without dci") { ExampleClass.new.foo } bm.report("with dci") do obj = ExampleClass.new obj.extend(ExampleMixin) obj.foo end end Local - Ok Global - What ?!
  • 7. 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
  • 8. Alternative cor d::Base < ActiveRe class User Evan Light end class TwitterUser < Simp leDelegator def tweet_name TwitterLib.send_tweet("M y name is #{name}") end end user = User.find(42) tw_user = TwitterUser.new(user) tw_user.tweet_name
  • 10. Thanks ! Simon Courtois - @happynoff