Tricks for Isolated Architecture in Ruby - Sergey Kukunin

Ruby Meditation
Ruby MeditationRuby Meditation
Tricks for Isolated
Architecture in Ruby
Ruby Meditation #15, May 13 2017
I am Sergiy
And I’ve been searching a silver bullet for a while
BTW, my twitter is @sergey_kukunin
Hello!
I work at , Lviv
Tricks for Isolated Architecture in Ruby - Sergey Kukunin
The Humble Programmer
“we shall be able to design and implement the
kind of systems that are now straining our
programming ability, at the expense of only a few
percent in man-years of what they cost us now,
and that besides that, these systems will be
virtually free of bugs”
by Edsger W. Dijkstra, 1972, http://bit.ly/2pHGbhF
The Humble Programmer
● intellectually manageable programs
● proof of correctness
● the amount of intellectual effort depends on
the program length
● the influence of the tool we are trying to use
upon our own thinking habits
● hierarchy
The Humble Programmer
“In computer programming our basic building
block has an associated time grain of less than a
microsecond, but our program may take hours of
computation time. I do not know of any other
technology covering a ratio of 1010
or more”
Two values of software
The secondary value of software is its behavior.
1
Defined by Uncle Bob Martin in episode 9 (‘The Single Responsibility
Principle’) of his CleanCoders video series
The primary value of
software is that it’s soft.
The ability of software to tolerate and facilitate such ongoing change is
the primary value of software.
2
Conclusions
● Programming is complicated
● Programming is risky
● Programming is expensive
That’s why we should care about what we write.
Symptoms of Rotting Design
◉ Rigidity - the tendency for software to be difficult to change
◉ Fragility - the tendency of the software to break in many places every
time it is changed
◉ Immobility - the inability to reuse software from other projects or from
parts of the same project
◉ Viscosity - two forms: viscosity of the design, and viscosity of the
environment
http://bit.ly/2rawutr
Other criterias
◉ Deployability
◉ Developability
◉ Comprehensibility
Every technique has own advantages and
overhead. Sometimes, a technique doesn’t fit.
You’re the one who is solely responsible for
the code quality of your project.
Disclaimer:
“
The main enemy of software is
complexity. To remain
maintainable, software should be
simple.
Complexity grows as
application grows1
The biggest impact is made
by solution modularity
Analyze of Sorting algorithms
Bubble sort = O(N2
)
When N = 60, N2
= 3600
If we divide an array into two halves
we’ll have 2 * (N/2)2
= 2 * (302
) = 1800
Divide and Conquer
Divide and Conquer
Single Responsibility Principle
● Definition of responsibility
○ Should have only one reason to change file
● Works on class level as well as on module level
● + Decreases rigidity
● + Necessary step for modularity
Examples of SRP
● Localization
● Thread handling
● HTML/CSS/JS
● Interactors
Rely on interface, not on
implementation
Example of interface
The less a module knows about siblings,
the more independent it is.
Keep encapsulation
Law of Demeter
might indicates that current class knows too
much. Does this look better?
Dependency Inversion Principle
● High-level policy should not be dependent
upon low-level detail
● Main trick for decoupling
● + Decreases rigidity
● + Improves modularity/deployability
● + Better testing
● - Lines of code overhead
How it works: DI
How it works: DI
Dependency Injection
Isn’t this violation of
encapsulation?
Integration of modules
IoC
1 ● Separates the application from the main.
● Fixes dependencies order.
● Decouples modules and classes.
● Decreases rigidity of the application.
Should be iterative, small and often
Constant Refactoring
Boyscout Rule
Functional programming
Because functions are data
First-class functions
Composability
Immutability
First-class tests
● Tests are proof of correctness
● They make you feel safe while refactoring
● Tests drive better design
● Tests should be trustful
● Tests should be fast
Test-driven development
1. You are not allowed to write any production
code unless it is to make a failing unit test pass.
2. You are not allowed to write any more of a
unit test than is sufficient to fail; and
compilation failures are failures.
3. You are not allowed to write any more
production code than is sufficient to pass the
one failing unit test.
Tricks for Isolated Architecture in Ruby - Sergey Kukunin
“
The only way to keep it simple is
to make composition of
abstractions
Simple software is
readable software2
We read code even when we write code
Micro-level
◉ Small classes
◉ Small methods
◉ Intention-revealing
methods
◉ Consistent indentation
Readability
Macro-level
◉ Ubiquitous language
◉ Unified model
◉ Domain-driven design
DDD separates
domain-related code
from platform-related
2
Domain layer: dry-types
1 ● Prevention of illegal state
● Types algebra
● Immutability
● Blazing fast
Application layer: CQS
1 defines application boundaries: data inside are trusted
Infrastructure layer
1 ● Independent implementations of 3rd-party
services
● The easiest to extract to a gem
● Persistence is here
UI layer
1 ● An interface for interactive for the application
● HTTP delivery mechanism
● Validation is tied to an interface, not to an entity
● dry-validation
Persistence layer: ROM
1 ● Adapters
● Relations
● Mappers
● Repositories
Other advices
◉ Prefer instance methods over class methods
◉ Avoid singletons and global state
◉ Prefer pure functions
Real experience
Any questions ?
You can find me at
◉ @sergey_kukunin
◉ sergiy@maticinsurance.com
Thanks!
1 of 53

Recommended

Talk: Practical, Pluggable Types by
Talk: Practical, Pluggable TypesTalk: Practical, Pluggable Types
Talk: Practical, Pluggable TypesMarcus Denker
514 views47 slides
Practical, Pluggable Types by
Practical, Pluggable TypesPractical, Pluggable Types
Practical, Pluggable TypesMarcus Denker
586 views20 slides
Test driven development with sonarQube by
Test driven development with sonarQubeTest driven development with sonarQube
Test driven development with sonarQubeNanthakumar Suvethan
481 views14 slides
Structured Software Design by
Structured Software DesignStructured Software Design
Structured Software DesignGiorgio Zoppi
77 views34 slides
Excavating the knowledge of our ancestors by
Excavating the knowledge of our ancestorsExcavating the knowledge of our ancestors
Excavating the knowledge of our ancestorsUwe Friedrichsen
2.7K views95 slides
Create first android app with MVVM Architecture by
Create first android app with MVVM ArchitectureCreate first android app with MVVM Architecture
Create first android app with MVVM Architecturekhushbu thakker
181 views27 slides

More Related Content

Similar to Tricks for Isolated Architecture in Ruby - Sergey Kukunin

Lecture1 cst205 cst281-oop by
Lecture1 cst205 cst281-oopLecture1 cst205 cst281-oop
Lecture1 cst205 cst281-oopktuonlinenotes
403 views17 slides
No silver bullet summary (paper) by
No silver bullet summary (paper)No silver bullet summary (paper)
No silver bullet summary (paper)shakeel khan
2K views19 slides
Software Development in 21st Century by
Software Development in 21st CenturySoftware Development in 21st Century
Software Development in 21st CenturyHenry Jacob
618 views33 slides
Path dependent-development (PyCon India) by
Path dependent-development (PyCon India)Path dependent-development (PyCon India)
Path dependent-development (PyCon India)ncoghlan_dev
424 views33 slides
What is xp by
What is xpWhat is xp
What is xpSimone Federici
617 views26 slides
Sepm t1 by
Sepm t1Sepm t1
Sepm t1sapariyapiyushluck
411 views6 slides

Similar to Tricks for Isolated Architecture in Ruby - Sergey Kukunin(20)

No silver bullet summary (paper) by shakeel khan
No silver bullet summary (paper)No silver bullet summary (paper)
No silver bullet summary (paper)
shakeel khan2K views
Software Development in 21st Century by Henry Jacob
Software Development in 21st CenturySoftware Development in 21st Century
Software Development in 21st Century
Henry Jacob618 views
Path dependent-development (PyCon India) by ncoghlan_dev
Path dependent-development (PyCon India)Path dependent-development (PyCon India)
Path dependent-development (PyCon India)
ncoghlan_dev424 views
STM-UNIT-1.pptx by nischal55
STM-UNIT-1.pptxSTM-UNIT-1.pptx
STM-UNIT-1.pptx
nischal5516 views
Software Engineering Methodologies by Nesrine Shokry
Software Engineering MethodologiesSoftware Engineering Methodologies
Software Engineering Methodologies
Nesrine Shokry1.4K views
Software Engineering with Objects (M363) Final Revision By Kuwait10 by Kuwait10
Software Engineering with Objects (M363) Final Revision By Kuwait10Software Engineering with Objects (M363) Final Revision By Kuwait10
Software Engineering with Objects (M363) Final Revision By Kuwait10
Kuwait1065K views
Modeling on the Web by Icinetic
Modeling on the WebModeling on the Web
Modeling on the Web
Icinetic1.7K views
Keeping code clean by Brett Child
Keeping code cleanKeeping code clean
Keeping code clean
Brett Child1.2K views
Best Practices For Writing Super Readable Code by AnsviaLab
Best Practices For Writing Super Readable CodeBest Practices For Writing Super Readable Code
Best Practices For Writing Super Readable Code
AnsviaLab1.5K views

More from Ruby Meditation

Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30 by
Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30Ruby Meditation
207 views22 slides
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky... by
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Ruby Meditation
462 views141 slides
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29 by
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Ruby Meditation
210 views49 slides
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ... by
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Ruby Meditation
1.6K views59 slides
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 by
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 Ruby Meditation
366 views23 slides
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28 by
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28Ruby Meditation
459 views20 slides

More from Ruby Meditation(20)

Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30 by Ruby Meditation
Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30Is this Legacy or Revenant Code? - Sergey Sergyenko  | Ruby Meditation 30
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
Ruby Meditation207 views
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky... by Ruby Meditation
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Ruby Meditation462 views
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29 by Ruby Meditation
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Ruby Meditation210 views
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ... by Ruby Meditation
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
Ruby Meditation1.6K views
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 by Ruby Meditation
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28 How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
Ruby Meditation366 views
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28 by Ruby Meditation
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
Ruby Meditation459 views
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh... by Ruby Meditation
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Ruby Meditation462 views
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby... by Ruby Meditation
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Ruby Meditation475 views
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio... by Ruby Meditation
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
Ruby Meditation320 views
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or... by Ruby Meditation
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
Ruby Meditation285 views
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27 by Ruby Meditation
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
Ruby Meditation1.1K views
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26 by Ruby Meditation
New features in Rails 6 -  Nihad Abbasov (RUS) | Ruby Meditation 26New features in Rails 6 -  Nihad Abbasov (RUS) | Ruby Meditation 26
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Ruby Meditation577 views
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26 by Ruby Meditation
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Ruby Meditation299 views
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (... by Ruby Meditation
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Ruby Meditation455 views
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26 by Ruby Meditation
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Ruby Meditation204 views
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25 by Ruby Meditation
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Ruby Meditation577 views
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita... by Ruby Meditation
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Ruby Meditation511 views
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me... by Ruby Meditation
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Ruby Meditation299 views
Rails App performance at the limit - Bogdan Gusiev by Ruby Meditation
Rails App performance at the limit - Bogdan GusievRails App performance at the limit - Bogdan Gusiev
Rails App performance at the limit - Bogdan Gusiev
Ruby Meditation418 views
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23 by Ruby Meditation
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Ruby Meditation179 views

Recently uploaded

Perth MeetUp November 2023 by
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023 Michael Price
15 views44 slides
Throughput by
ThroughputThroughput
ThroughputMoisés Armani Ramírez
36 views11 slides
Java Platform Approach 1.0 - Picnic Meetup by
Java Platform Approach 1.0 - Picnic MeetupJava Platform Approach 1.0 - Picnic Meetup
Java Platform Approach 1.0 - Picnic MeetupRick Ossendrijver
25 views39 slides
Special_edition_innovator_2023.pdf by
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdfWillDavies22
16 views6 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
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
28 views73 slides

Recently uploaded(20)

Perth MeetUp November 2023 by Michael Price
Perth MeetUp November 2023 Perth MeetUp November 2023
Perth MeetUp November 2023
Michael Price15 views
Special_edition_innovator_2023.pdf by WillDavies22
Special_edition_innovator_2023.pdfSpecial_edition_innovator_2023.pdf
Special_edition_innovator_2023.pdf
WillDavies2216 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
Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma17 views
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum... by NUS-ISS
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
Beyond the Hype: What Generative AI Means for the Future of Work - Damien Cum...
NUS-ISS34 views
Future of Learning - Yap Aye Wee.pdf by NUS-ISS
Future of Learning - Yap Aye Wee.pdfFuture of Learning - Yap Aye Wee.pdf
Future of Learning - Yap Aye Wee.pdf
NUS-ISS41 views
Future of Learning - Khoong Chan Meng by NUS-ISS
Future of Learning - Khoong Chan MengFuture of Learning - Khoong Chan Meng
Future of Learning - Khoong Chan Meng
NUS-ISS33 views
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV by Splunk
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
.conf Go 2023 - How KPN drives Customer Satisfaction on IPTV
Splunk88 views
Understanding GenAI/LLM and What is Google Offering - Felix Goh by NUS-ISS
Understanding GenAI/LLM and What is Google Offering - Felix GohUnderstanding GenAI/LLM and What is Google Offering - Felix Goh
Understanding GenAI/LLM and What is Google Offering - Felix Goh
NUS-ISS41 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri15 views
Combining Orchestration and Choreography for a Clean Architecture by ThomasHeinrichs1
Combining Orchestration and Choreography for a Clean ArchitectureCombining Orchestration and Choreography for a Clean Architecture
Combining Orchestration and Choreography for a Clean Architecture
ThomasHeinrichs169 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb12 views
RADIUS-Omnichannel Interaction System by RADIUS
RADIUS-Omnichannel Interaction SystemRADIUS-Omnichannel Interaction System
RADIUS-Omnichannel Interaction System
RADIUS15 views
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor... by Vadym Kazulkin
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
How to reduce cold starts for Java Serverless applications in AWS at JCON Wor...
Vadym Kazulkin75 views
The details of description: Techniques, tips, and tangents on alternative tex... by BookNet Canada
The details of description: Techniques, tips, and tangents on alternative tex...The details of description: Techniques, tips, and tangents on alternative tex...
The details of description: Techniques, tips, and tangents on alternative tex...
BookNet Canada121 views

Tricks for Isolated Architecture in Ruby - Sergey Kukunin

  • 1. Tricks for Isolated Architecture in Ruby Ruby Meditation #15, May 13 2017
  • 2. I am Sergiy And I’ve been searching a silver bullet for a while BTW, my twitter is @sergey_kukunin Hello!
  • 3. I work at , Lviv
  • 5. The Humble Programmer “we shall be able to design and implement the kind of systems that are now straining our programming ability, at the expense of only a few percent in man-years of what they cost us now, and that besides that, these systems will be virtually free of bugs” by Edsger W. Dijkstra, 1972, http://bit.ly/2pHGbhF
  • 6. The Humble Programmer ● intellectually manageable programs ● proof of correctness ● the amount of intellectual effort depends on the program length ● the influence of the tool we are trying to use upon our own thinking habits ● hierarchy
  • 7. The Humble Programmer “In computer programming our basic building block has an associated time grain of less than a microsecond, but our program may take hours of computation time. I do not know of any other technology covering a ratio of 1010 or more”
  • 8. Two values of software The secondary value of software is its behavior. 1 Defined by Uncle Bob Martin in episode 9 (‘The Single Responsibility Principle’) of his CleanCoders video series
  • 9. The primary value of software is that it’s soft. The ability of software to tolerate and facilitate such ongoing change is the primary value of software. 2
  • 10. Conclusions ● Programming is complicated ● Programming is risky ● Programming is expensive That’s why we should care about what we write.
  • 11. Symptoms of Rotting Design ◉ Rigidity - the tendency for software to be difficult to change ◉ Fragility - the tendency of the software to break in many places every time it is changed ◉ Immobility - the inability to reuse software from other projects or from parts of the same project ◉ Viscosity - two forms: viscosity of the design, and viscosity of the environment http://bit.ly/2rawutr
  • 12. Other criterias ◉ Deployability ◉ Developability ◉ Comprehensibility
  • 13. Every technique has own advantages and overhead. Sometimes, a technique doesn’t fit. You’re the one who is solely responsible for the code quality of your project. Disclaimer:
  • 14. “ The main enemy of software is complexity. To remain maintainable, software should be simple.
  • 16. The biggest impact is made by solution modularity
  • 17. Analyze of Sorting algorithms Bubble sort = O(N2 ) When N = 60, N2 = 3600 If we divide an array into two halves we’ll have 2 * (N/2)2 = 2 * (302 ) = 1800
  • 20. Single Responsibility Principle ● Definition of responsibility ○ Should have only one reason to change file ● Works on class level as well as on module level ● + Decreases rigidity ● + Necessary step for modularity
  • 21. Examples of SRP ● Localization ● Thread handling ● HTML/CSS/JS ● Interactors
  • 22. Rely on interface, not on implementation
  • 24. The less a module knows about siblings, the more independent it is. Keep encapsulation
  • 25. Law of Demeter might indicates that current class knows too much. Does this look better?
  • 26. Dependency Inversion Principle ● High-level policy should not be dependent upon low-level detail ● Main trick for decoupling ● + Decreases rigidity ● + Improves modularity/deployability ● + Better testing ● - Lines of code overhead
  • 30. Isn’t this violation of encapsulation?
  • 32. IoC 1 ● Separates the application from the main. ● Fixes dependencies order. ● Decouples modules and classes. ● Decreases rigidity of the application.
  • 33. Should be iterative, small and often Constant Refactoring
  • 36. Because functions are data First-class functions
  • 39. First-class tests ● Tests are proof of correctness ● They make you feel safe while refactoring ● Tests drive better design ● Tests should be trustful ● Tests should be fast
  • 40. Test-driven development 1. You are not allowed to write any production code unless it is to make a failing unit test pass. 2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures. 3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.
  • 42. “ The only way to keep it simple is to make composition of abstractions
  • 43. Simple software is readable software2 We read code even when we write code
  • 44. Micro-level ◉ Small classes ◉ Small methods ◉ Intention-revealing methods ◉ Consistent indentation Readability Macro-level ◉ Ubiquitous language ◉ Unified model ◉ Domain-driven design
  • 46. Domain layer: dry-types 1 ● Prevention of illegal state ● Types algebra ● Immutability ● Blazing fast
  • 47. Application layer: CQS 1 defines application boundaries: data inside are trusted
  • 48. Infrastructure layer 1 ● Independent implementations of 3rd-party services ● The easiest to extract to a gem ● Persistence is here
  • 49. UI layer 1 ● An interface for interactive for the application ● HTTP delivery mechanism ● Validation is tied to an interface, not to an entity ● dry-validation
  • 50. Persistence layer: ROM 1 ● Adapters ● Relations ● Mappers ● Repositories
  • 51. Other advices ◉ Prefer instance methods over class methods ◉ Avoid singletons and global state ◉ Prefer pure functions
  • 53. Any questions ? You can find me at ◉ @sergey_kukunin ◉ sergiy@maticinsurance.com Thanks!