SlideShare a Scribd company logo
Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
Isolated
Can I do this without affecting anything else?
Testable
Is it doing what it is supposed to do?
Traceable
Why did we do this?
Readable
What does it try do and how?
Discoverable
Where is this done?
A lab around the principles and practices for writing maintainable code (2019)
Application
Application
Presentation Layer
Domain Layer
Data Layer
Application
Component ComponentComponent Component Component
Component Component Component Component
Component Component Component Component
Application
Functional Slice Functional Slice Functional Slice Functional Slice
Composition
Architectural boundaries
protected by PR expert
review
Each component
owns/exposes its
reference data
Does not
depend on
anything
except for
curated
shared APIs
Owns
schema and
storage
(may use
shared
database
abstraction)
DRY within
component,
not outside
May use an
internal
container
Event
Sourcing &
CQRS are
component-
specific
concerns
Does not
touch other
components
’ data
directly
Shared Services
Connects the
components and
serves as anti-
corruption layer
Only services you
really think should
not be duplicated
Designed according to
Dependency Inversion Principle
Covers
front-end
and back-
end
Component
is the scope
of unit &
integration
tests
Align folder
structure
with
boundaries
Defines the
contracts
for the host
as well as
any services
it exposes
A lab around the principles and practices for writing maintainable code (2019)
No generic
interfaces
Hide the
“internals”
Composition
over
inheritance
Avoid
inheritance
Small and
focused
interfaces
Or delegates
Avoid bi-
directional
relationships
Design Patterns
“name” a common
solution
Internal/private
by default
First-class
collections
and
primitives
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
Long method
Not
immediately
clear what it
does
Magic
character
Deeply
nested “ifs”
Single entry,
single exit
Static mutable state
Magic key
Multiple dots
Magic keys
Single entry,
single exit
No idea what to do
if this fails
Encapsulates
concerns
A lab around the principles and practices for writing maintainable code (2019)
Too much
coupling?
Clear
algorithm
(Still) static mutable
state
Name
captures the
purpose
Same level of
abstraction
Methods
ordered by
execution
(a.k.a. reads
like a book)
Magic string?
Should never
happen, but is a
valid path
Because
type is
obvious
Captures what it
tries to
accomplish
Captures what it
does
Pretty clear, right?
Not so clear on
Github Pull
Requests
Jetbrains Rider /
Resharper to the
rescue
Superfluous
documentation
Nice, but a bit too
much for a private
method?
The name is clear
enough, isn’t it?
using (var scope = new AssertionScope())
var depth = GetDepthOfObjectGraph();
var displayValue = GetDisplayValueOf(context);
var valueString = GetDisplayValueOf(context);
var dataType = row.GetColumnType(columnIndex);
var searchColumnsSql = BuildSearchColumnsSql(Columns);
var results = RunSearchQuery(searchColumnsSql);
var indexInSpan = 0;
var longIndexInSpan = 1;
Use explicit type if
type is relevant
What kind of
results?
Did the author
consider the
maximum size?
Use explicit type if
type is relevant
var
Too many fields?
Too many fields?
First-class collection
Well-named and
discoverable
UTC? Local?
Random?
Where is this
coming from?
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
Unstructured Manual
Testing
User Interface Tests
HTTP Tests
Integration Tests
Unit Tests
Any structured
tests should be
automated
Generic code is
tested separately
“Unit” =
(architectural)
boundary
Do not accept
unstable UI tests
Only for UI
scenarios we
can’t cover with
integration tests.
Only for non-UI
scenarios we
can’t cover with
integration tests.
Application
Functional Slice Functional Slice Functional Slice Functional Slice
Composition
Shared Services
Hide what’s not
important
Show what is
important
Only if you can’t
make them clear
otherwise
Use in-line literals
Crystal-clear
cause…
…and effect
Names that explain
the expected
functional behavior
But be careful with
base-classes
!DRY
A lab around the principles and practices for writing maintainable code (2019)
git checkout master
git cob my-branch
git save
git amend
git amend
git undo
git commit –m “Some functional change”
git commit –m “Refactor something”
git commit –m “Deprecate something”
git commit –-fixup “Some functional change”
git rebase –i master
A lab around the principles and practices for writing maintainable code (2019)
// SMELL a smell code description
// REFACTOR an idea for refactoring
// NOTE a comment explaining a part of the code
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
A lab around the principles and practices for writing maintainable code (2019)
Quality
Definition of
Done
Work Breakdown
Design Log
Small PRs
Focused
Commits
Continuous
Refactoring
Review Speed
Review by non-
team member
Productivity
Natural Cause of
Refactoring
Review
Thoroughness
Traceability
Clean Source Control
History
Knowledge
Sharing
Tech Meetings
Red Hot
Developer
Readable Code
Good Unit
Tests
Dennis Doomen
@ddoomen
Dennis Doomen | @ddoomen | The Continuous Improver

More Related Content

PDF
Unit test documentation
PPT
Nguyenvandungb seminar
PPTX
Test driven development in .Net - 2010 + Eclipse
PPTX
Working with Legacy Code
PPTX
Good Unit Tests Ask For Quality Code
PPTX
Unit Testing And Mocking
PPTX
Unit Tests And Automated Testing
PPTX
Mock driven development using .NET
Unit test documentation
Nguyenvandungb seminar
Test driven development in .Net - 2010 + Eclipse
Working with Legacy Code
Good Unit Tests Ask For Quality Code
Unit Testing And Mocking
Unit Tests And Automated Testing
Mock driven development using .NET

What's hot (20)

PDF
Unit Testing Fundamentals
PPTX
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
PPTX
Unit Testing Concepts and Best Practices
PPTX
Unit Testing Full@
PPTX
Unit Testing
PPTX
Code quality
PPTX
An Introduction to Unit Testing
PPTX
Moq presentation
PPTX
Unit testing - the hard parts
PPTX
Test Driven Development - The art of fearless programming
PPTX
UNIT TESTING
PPTX
Unit Testing
PPTX
TDD with Visual Studio 2010
PDF
Unit Testing Done Right
PPTX
Unit tests & TDD
PPTX
Best practices unit testing
PDF
Unit Testing
PPTX
Understanding Unit Testing
PPTX
Software quality with Code Contracts and PEX - CodeCamp16oct2010
PPTX
Testing the untestable
Unit Testing Fundamentals
Roy Osherove on Unit Testing Good Practices and Horrible Mistakes
Unit Testing Concepts and Best Practices
Unit Testing Full@
Unit Testing
Code quality
An Introduction to Unit Testing
Moq presentation
Unit testing - the hard parts
Test Driven Development - The art of fearless programming
UNIT TESTING
Unit Testing
TDD with Visual Studio 2010
Unit Testing Done Right
Unit tests & TDD
Best practices unit testing
Unit Testing
Understanding Unit Testing
Software quality with Code Contracts and PEX - CodeCamp16oct2010
Testing the untestable
Ad

Similar to A lab around the principles and practices for writing maintainable code (2019) (20)

PPTX
A lab around the principles and practices for writing maintainable code
PPT
Intro To AOP
PPT
Stopping the Rot - Putting Legacy C++ Under Test
ODP
Grails unit testing
PPTX
Back-2-Basics: .NET Coding Standards For The Real World (2011)
PPT
Testing And Drupal
PDF
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
PPT
Ef Poco And Unit Testing
PDF
Test Driven Development
ODP
Effective unit testing
PPTX
Implementing DDD with C#
PDF
Java Code Review Checklist
PPTX
Back-2-Basics: .NET Coding Standards For The Real World
KEY
Client Side Unit Testing
PPTX
Back-2-Basics: .NET Coding Standards For The Real World
PPT
How to ace your .NET technical interview :: .Net Technical Check Tuneup
PPTX
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
TXT
Salesforce integration questions
PPT
Working Effectively With Legacy Code
A lab around the principles and practices for writing maintainable code
Intro To AOP
Stopping the Rot - Putting Legacy C++ Under Test
Grails unit testing
Back-2-Basics: .NET Coding Standards For The Real World (2011)
Testing And Drupal
Play with Testing on Android - Gilang Ramadhan (Academy Content Writer at Dic...
Ef Poco And Unit Testing
Test Driven Development
Effective unit testing
Implementing DDD with C#
Java Code Review Checklist
Back-2-Basics: .NET Coding Standards For The Real World
Client Side Unit Testing
Back-2-Basics: .NET Coding Standards For The Real World
How to ace your .NET technical interview :: .Net Technical Check Tuneup
Design Pattern Mastery - Momentum Dev Con 19 Apr 2018
Salesforce integration questions
Working Effectively With Legacy Code
Ad

More from Dennis Doomen (20)

PDF
15 Years of Insights from a TDD Practitioner (NDC Oslo)
PPTX
Using Boundary-Driven Development to beat code complexity
PPTX
Getting a grip on your code dependencies (2023-10)
PPTX
Tools and practices to help you deal with legacy code
PPTX
What you can learn from an open-source project with 250 million downloads
PPTX
Getting a grip on your code dependencies
PPTX
My Laws of Test Driven Development (2023)
PPTX
Design patterns for Event Sourcing in .NET
PPTX
Automate Infrastructure with Pulumi and C#
PPTX
What is the right unit in unit testing (UpdateConf 2022)
PPTX
Slow Event Sourcing (re)projections - Just make them faster!
PPTX
50 things software teams should not do.pptx
PPTX
What is the right "unit" in unit testing and why it is not a class?
PPTX
How to Practice TDD Without Shooting Yourself in the Foot
PPTX
Decomposing the Monolith using modern-day .NET and a touch of microservices
PPTX
Event Sourcing from the Trenches (DDD Europe 2020)
PPTX
Practical introduction to DDD, CQRS and Event Sourcing
PPTX
How to practice TDD without shooting yourself in the foot
PPTX
Decomposing the Monolith (Riga Dev Days 2019)
PPTX
Lessons learned from two decades of professional software development
15 Years of Insights from a TDD Practitioner (NDC Oslo)
Using Boundary-Driven Development to beat code complexity
Getting a grip on your code dependencies (2023-10)
Tools and practices to help you deal with legacy code
What you can learn from an open-source project with 250 million downloads
Getting a grip on your code dependencies
My Laws of Test Driven Development (2023)
Design patterns for Event Sourcing in .NET
Automate Infrastructure with Pulumi and C#
What is the right unit in unit testing (UpdateConf 2022)
Slow Event Sourcing (re)projections - Just make them faster!
50 things software teams should not do.pptx
What is the right "unit" in unit testing and why it is not a class?
How to Practice TDD Without Shooting Yourself in the Foot
Decomposing the Monolith using modern-day .NET and a touch of microservices
Event Sourcing from the Trenches (DDD Europe 2020)
Practical introduction to DDD, CQRS and Event Sourcing
How to practice TDD without shooting yourself in the foot
Decomposing the Monolith (Riga Dev Days 2019)
Lessons learned from two decades of professional software development

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPT
Teaching material agriculture food technology
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Big Data Technologies - Introduction.pptx
Network Security Unit 5.pdf for BCA BBA.
Dropbox Q2 2025 Financial Results & Investor Presentation
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Teaching material agriculture food technology
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Programs and apps: productivity, graphics, security and other tools
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Empathic Computing: Creating Shared Understanding
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Big Data Technologies - Introduction.pptx

A lab around the principles and practices for writing maintainable code (2019)

  • 1. Dennis Doomen | @ddoomen | Aviva Solutions | The Continuous Improver
  • 7. Isolated Can I do this without affecting anything else? Testable Is it doing what it is supposed to do? Traceable Why did we do this? Readable What does it try do and how? Discoverable Where is this done?
  • 11. Application Component ComponentComponent Component Component Component Component Component Component Component Component Component Component
  • 12. Application Functional Slice Functional Slice Functional Slice Functional Slice Composition Architectural boundaries protected by PR expert review Each component owns/exposes its reference data Does not depend on anything except for curated shared APIs Owns schema and storage (may use shared database abstraction) DRY within component, not outside May use an internal container Event Sourcing & CQRS are component- specific concerns Does not touch other components ’ data directly Shared Services Connects the components and serves as anti- corruption layer Only services you really think should not be duplicated Designed according to Dependency Inversion Principle Covers front-end and back- end Component is the scope of unit & integration tests Align folder structure with boundaries Defines the contracts for the host as well as any services it exposes
  • 14. No generic interfaces Hide the “internals” Composition over inheritance Avoid inheritance Small and focused interfaces Or delegates Avoid bi- directional relationships Design Patterns “name” a common solution Internal/private by default First-class collections and primitives
  • 17. Long method Not immediately clear what it does Magic character Deeply nested “ifs” Single entry, single exit Static mutable state Magic key Multiple dots Magic keys Single entry, single exit No idea what to do if this fails Encapsulates concerns
  • 19. Too much coupling? Clear algorithm (Still) static mutable state Name captures the purpose Same level of abstraction Methods ordered by execution (a.k.a. reads like a book)
  • 20. Magic string? Should never happen, but is a valid path Because type is obvious
  • 21. Captures what it tries to accomplish Captures what it does
  • 22. Pretty clear, right? Not so clear on Github Pull Requests Jetbrains Rider / Resharper to the rescue
  • 23. Superfluous documentation Nice, but a bit too much for a private method? The name is clear enough, isn’t it?
  • 24. using (var scope = new AssertionScope()) var depth = GetDepthOfObjectGraph(); var displayValue = GetDisplayValueOf(context); var valueString = GetDisplayValueOf(context); var dataType = row.GetColumnType(columnIndex); var searchColumnsSql = BuildSearchColumnsSql(Columns); var results = RunSearchQuery(searchColumnsSql); var indexInSpan = 0; var longIndexInSpan = 1; Use explicit type if type is relevant What kind of results? Did the author consider the maximum size? Use explicit type if type is relevant var
  • 31. Unstructured Manual Testing User Interface Tests HTTP Tests Integration Tests Unit Tests Any structured tests should be automated Generic code is tested separately “Unit” = (architectural) boundary Do not accept unstable UI tests Only for UI scenarios we can’t cover with integration tests. Only for non-UI scenarios we can’t cover with integration tests.
  • 32. Application Functional Slice Functional Slice Functional Slice Functional Slice Composition Shared Services
  • 33. Hide what’s not important Show what is important Only if you can’t make them clear otherwise Use in-line literals Crystal-clear cause… …and effect Names that explain the expected functional behavior But be careful with base-classes !DRY
  • 35. git checkout master git cob my-branch git save git amend git amend git undo git commit –m “Some functional change” git commit –m “Refactor something” git commit –m “Deprecate something” git commit –-fixup “Some functional change” git rebase –i master
  • 37. // SMELL a smell code description // REFACTOR an idea for refactoring // NOTE a comment explaining a part of the code
  • 44. Quality Definition of Done Work Breakdown Design Log Small PRs Focused Commits Continuous Refactoring Review Speed Review by non- team member Productivity Natural Cause of Refactoring Review Thoroughness Traceability Clean Source Control History Knowledge Sharing Tech Meetings Red Hot Developer Readable Code Good Unit Tests
  • 45. Dennis Doomen @ddoomen Dennis Doomen | @ddoomen | The Continuous Improver

Editor's Notes

  • #38: Understand the context of when a tool, practice or principle applies and when not. Don't reject it because of misuse (e.g. IoC, OR/M, DRY, TDD).
  • #40: Understand the context of when a tool, practice or principle applies and when not. Don't reject it because of misuse (e.g. IoC, OR/M, DRY, TDD).
  • #42: Understand the context of when a tool, practice or principle applies and when not. Don't reject it because of misuse (e.g. IoC, OR/M, DRY, TDD).