SlideShare a Scribd company logo
VictorRentea.ro
21
victor.rentea@gmail.com ♦ ♦ @victorrentea ♦ VictorRentea.ro
Victor Rentea
VictorRentea.ro
Recorded Talks, Blog, Video Courses, ...
Independent Trainer
Founder of
Bucharest Software Craftsmanship Community
Java Champion
❤️ Simple Design, Refactoring, Unit Testing ❤️
Technical Training
500 days
(200+ online)
2000 devs
8 years 50+ companies
Reach out
to me:
Hibernate
Spring Func Prog
Java Performance
Reactive Prog
Design Patterns
Pragmatic DDD
Clean Code
Refactoring
Unit Testing
TDD
any
lang
@victorrentea
Intense
More: VictorRentea.ro
Workshops: victorrentea.teachable.com
24
CODE
25 © VictorRentea.ro
a training by
Refactoring
What must we do every single day?
What’s that?
26 © VictorRentea.ro
a training by
Simplify existing code
without changing its external behavior
Refactoring
DO NOT BREAK
PRODUCTION
27 © VictorRentea.ro
a training by
29 © VictorRentea.ro
a training by
I'm afraid to refactor
because we don't have tests
It's impossible to test a
200-lines method!
The Vicious Circle of Legacy Code
Pair Programming
(80% less bugs)
Coding Katas!
TDD Practice
30 © VictorRentea.ro
a training by
Safe Refactoring Tips
Next IDE Refactoring Fails Stress
Don't Break Compilation
(unless exploring)
Automated Refactoring
as much as you can
Decompose Large Changes
into small, safe moves
Use Quick-fix
to keep your focus on the design
(Alt-Enter / ⌥-Enter)
31 © VictorRentea.ro
a training by
Time
TIME FRAME
SPEED
32 © VictorRentea.ro
a training by
"I don't have time. I'm too busy"
Being busy is a form of laziness
- Tim Ferriss
Habits of Efficient Developers
by Daniel Lebrero
Stop! and Reflect.
Focus on what matters.
33 © VictorRentea.ro
a training by
Improve Your Focus
Turn off desktop/mobile notifications
Automate Stuff
Pomodoro 25/5
No morning inbox
Max 30 min meetings
 Digital Detox
Master your IDE ➔
Get your brain to focus
Chris Bailey
IntelliJ Productivity Tips
Victor Rentea
35 © VictorRentea.ro
a training by
Time
TIME FRAME
SPEED
36 © VictorRentea.ro
a training by
Estimates
37 © VictorRentea.ro
a training by
Emotionally Involved
38 © VictorRentea.ro
a training by
Ever-changing Requirements
40 © VictorRentea.ro
a training by
NO
41 © VictorRentea.ro
a training by
technical
functional (complex requirements)
iterations
(the point of Agile)
prototype/POC
Estimations Risks
42 © VictorRentea.ro
a training by
Time & Fear ☺
43 © VictorRentea.ro
a training by
The Best way to understand code is to Refactor it
44 © VictorRentea.ro
a training by
You lost it! You got carried away...
45 © VictorRentea.ro
a training by
3 hours later, you commit:
code improvements
refactoring
I gotta leave
Major changes
46 © VictorRentea.ro
a training by
47 © VictorRentea.ro
a training by
48 © VictorRentea.ro
a training by
Explore
49 © VictorRentea.ro
a training by
Exploratory Refactoring
Discover
Timeboxed: eg 15 min.
Revert.
Ctrl -
Missing from our Practice:
50 © VictorRentea.ro
a training by
refactoring idea
Long-lived Feature Branch
Source Control
51 © VictorRentea.ro
a training by
Merge Conflicts
Top annoying things in Dev's life:
➢ Interruptions
➢ Refactoring Tests
➢ Long meetings, and
52 © VictorRentea.ro
a training by
Trunk Based Development
(requires maturity & discipline)
Git Flow
(merge conflicts, redo-refactor)
Long Branches Inhibit Refactoring
if (easyBoxReturnFeature) {
// feature under develop
}
Feature Toggle
+ incremental DB migrations
Preliminary Refactoring
(separate Pull-Request)
53 © VictorRentea.ro
a training by
54 © VictorRentea.ro
a training by
Micro-commits
Break a large change set into:
Large + Safe Automated Refactoring
Manual Refactoring
Adding Behavior
+ Easier Code Review + Less Bugs
- Prior Exploration Needed
to identify the steps
A Commit Message Notation: https://github.com/RefactoringCombos/ArlosCommitNotation
Separate
Commits, or
Preparatory
refactoring PR
56 © VictorRentea.ro
a training by
What Stops Refactoring: Recap
Fear
➔ tests, pair programming
➔ practice
Time
➔ Proper estimates
➔ Improve Effectiveness
Rushing
even without time pressure
Lack of Consensus
➔ team design brainstorm
Huge PR - Rejected
➔ Trust
➔ Micro-Commits
Fear of Breaking some Eggs
to make the omelet
Merge Conflicts
➔ short-lived branches
➔ trunk-based
YOLO-driven developer
A. Make it fun, play together
B. Legacy Experience TM
Lack of Skills
extract a method ?!!
➔ Learn Code Smells
Unknown Code
Refactoring = Learning
VictorRentea.ro
57
Worse
Code
(hours-days)
Initial Chaos
Code
Quality
Time
You are here
The Deepest, most impactful refactoring starts with making a bigger mess
"You have to break some eggs
to make an omelet"
Wow!
I see a deep refactoring
eg. join two 100-lines method➔ one 200-lines method
VictorRentea.ro
58
Worse
Code
(hours-days)
Code
Quality
Time
You are here
The Strength to Revert
(despite emotional involvement)
Ctrl-
A day without no Ctrl-Z
is a day you didn't learned anything
... and the speed to get to some conclusions fast
You need
VictorRentea.ro
60
Code Smells
“If it stinks, change it.”
— Grandma Beck, discussing childrearing philosophy
VictorRentea.ro
61
Large Method
God Class
Too Many Parameters
Data Clumps
(String, String, Long) ➔ Address
> 20 lines
> 200 lines
> 4
All numbers are arbitrary. Find your own comfort zone
65 © VictorRentea.ro
a training by
Enrich your Domain Language
by Discovering Value Objects
Simplify your code
Constraints Methods Reuse in larger Entities
VictorRentea.ro
66
Speculative Generality
Middle Man
person.getAge()
int getAge() {
return bio.getAge();
}
person.getBio().getAge()
Data Classes
get/set mania ➔ OOP
Feature Envy
Function ❤️ the state of an object
Primitive Obsession
➔ PhoneNumber, OrderId, enum
➔ 💋 KISS Principle
VictorRentea.ro
67
Primitive Obsession
Map<Long, List<Long>> customerIdToOrderIds
redeemCoupon(Long, Long, String)
68 © VictorRentea.ro
a training by
Map<Long, List<Long>> customerIdToOrderIds
Map<CustomerId, List<OrderId>> orders
redeemCoupon(Long, Long, String)
redeemCoupon(CustomerId, CouponId, PhoneNumber)
Micro-Types
VictorRentea.ro
69
Primitive Obsession
Make concepts explicit
by introducing new small classes
Even if it's a single
String → PhoneNumber
Long → CustomerId → ID type:
@Value
class CustomerId {
Long id;
}
Escape the
70 © VictorRentea.ro
a training by
Map<Long, List<Long>> customerIdToOrderIds
If the only usage of a map is:
for (Long customerId : map.keySet()) {
List<Long> orderIds = map.get(customerId);
...
}
Code Smell: Iterating over Map Keys
List<CustomerOrderIds>
You might be missing an abstraction (class):
class CustomerOrderIds {
private Long customerId;
private List<Long> orderId;
...
}
(or entries)
VictorRentea.ro
71
VictorRentea.ro
72
Divergent Changes
Duplicated Code
Shotgun Surgery
m()
Is it a bug or a feature?
<>
DRY SRP
Is terrible when changes
VictorRentea.ro
73
switch
repeated switches loops
for (e : list) {
A();
B();
}
list.stream()...A..
list.stream()...B..
vs Polymorphism
vs "functional" switch in java17
vs enum with logic/Function refs
VictorRentea.ro
74
Long-Lived
Temporary Field
x.setX(1);
x.doStuff();
out = x.getY();
Temporal Coupling
out = x.doStuff(1);
Mutable Data
+ Multi-Threading =
reads from X field
and writes to Y field
VictorRentea.ro
75
Code Smells Sheet
Defeating the Evil starts with Naming It
76 © VictorRentea.ro
a training by
Code Smells Sheet
Defeating the Evil starts with Naming It
https://sourcemaking.com/refactoring/smells
Long Method
God Class
Data Clumps
Long Parameter List
Primitive Obsession
Data Class
Feature Envy
Middle Man
Duplicated Code
Shotgun Surgery
Divergent Code
Repeated Switches
Loops
Temporary Field
Long-Lived Mutable Data
Speculative Generality
Comments
Chapter 3
Many more + Solutions in
or: https://sourcemaking.com/refactoring/smells
VictorRentea.ro
blog, best talks, training offer
@VictorRentea
The End
victorrentea.ro/community
Join me:
Stay into
The Light
sourcemaking.com/refactoring
First Half + Ch. 17 Ch.3 Code Smells For rookies Coding Katas
kata-log.rocks/refactoring
cleancoders.com
refactoring.guru
Share your thoughts
The Beginning

More Related Content

PDF
Extreme Professionalism - Software Craftsmanship
PDF
Refactoring Games - 15 things to do after Extract Method
PDF
The Proxy Fairy, and The Magic of Spring Framework
PPTX
Clean Code - The Next Chapter
PPTX
Extreme Professionalism - Software Craftsmanship
PDF
TDD Mantra
PPTX
Functional Patterns with Java8 @Bucharest Java User Group
PPTX
Functional Patterns with Java8 at Devoxx UK - Slides
Extreme Professionalism - Software Craftsmanship
Refactoring Games - 15 things to do after Extract Method
The Proxy Fairy, and The Magic of Spring Framework
Clean Code - The Next Chapter
Extreme Professionalism - Software Craftsmanship
TDD Mantra
Functional Patterns with Java8 @Bucharest Java User Group
Functional Patterns with Java8 at Devoxx UK - Slides

What's hot (20)

PPTX
Clean Pragmatic Architecture - Avoiding a Monolith
PPTX
Clean Code
PDF
Hibernate and Spring - Unleash the Magic
PDF
Clean pragmatic architecture @ devflix
PPTX
The Art of Clean code
PPTX
Clean Lambdas at JBCNConf by Victor Rentea
PPTX
Clean Code with Java 8 - Functional Patterns and Best Practices
PDF
Clean architecture - Protecting the Domain
PPTX
A Tale About the Evil Partial Mock and Separation by Layers of Abstractions
PDF
Unit Testing like a Pro - The Circle of Purity
PDF
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
PDF
Clean Lambdas & Streams in Java8
PPTX
Functional Programming Patterns with Java 8 (at Devoxx BE)
PDF
Don't Be Mocked by your Mocks - Best Practices using Mocks
PDF
Refactoring Asynchronous TypeScript Code
PDF
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
PDF
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
PDF
Definitive Guide to Working With Exceptions in Java
PPT
Clean Code summary
PPTX
Spring @Transactional Explained
Clean Pragmatic Architecture - Avoiding a Monolith
Clean Code
Hibernate and Spring - Unleash the Magic
Clean pragmatic architecture @ devflix
The Art of Clean code
Clean Lambdas at JBCNConf by Victor Rentea
Clean Code with Java 8 - Functional Patterns and Best Practices
Clean architecture - Protecting the Domain
A Tale About the Evil Partial Mock and Separation by Layers of Abstractions
Unit Testing like a Pro - The Circle of Purity
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
Clean Lambdas & Streams in Java8
Functional Programming Patterns with Java 8 (at Devoxx BE)
Don't Be Mocked by your Mocks - Best Practices using Mocks
Refactoring Asynchronous TypeScript Code
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Definitive Guide to Working With Exceptions in Java
Clean Code summary
Spring @Transactional Explained
Ad

Similar to Refactoring blockers and code smells @jNation 2021 (20)

PDF
Software Craftsmanship @Code Camp Festival 2022.pdf
PDF
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
PDF
From Mess To Masterpiece - JFokus 2017
PPTX
Refactoring workshop
PPTX
Mariusz Sieraczkiewicz - Natural course of refactoring
PDF
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
PPTX
Improving the Design of Existing Software
PDF
Keeping code clean
PDF
Natural course of refactoring - Mix-IT Lyon 2014
PPTX
Code Refactoring
PDF
Développeur: Quelles compétences clés faut-il maîtriser pour être meilleur?
PDF
How to improve the quality of your application
PDF
So You Want to Start Refactoring?
PDF
Managing and evolving JavaScript Code
PDF
How I help others to level up technical practices
PPT
Refactoring Tips by Martin Fowler
PDF
Pure functions and immutable objects @dev nexus 2021
PDF
Technical Mentoring, What works and not
PDF
Refactoring PHP
PPTX
Improving the Quality of Existing Software
Software Craftsmanship @Code Camp Festival 2022.pdf
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
From Mess To Masterpiece - JFokus 2017
Refactoring workshop
Mariusz Sieraczkiewicz - Natural course of refactoring
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Improving the Design of Existing Software
Keeping code clean
Natural course of refactoring - Mix-IT Lyon 2014
Code Refactoring
Développeur: Quelles compétences clés faut-il maîtriser pour être meilleur?
How to improve the quality of your application
So You Want to Start Refactoring?
Managing and evolving JavaScript Code
How I help others to level up technical practices
Refactoring Tips by Martin Fowler
Pure functions and immutable objects @dev nexus 2021
Technical Mentoring, What works and not
Refactoring PHP
Improving the Quality of Existing Software
Ad

More from Victor Rentea (18)

PDF
Top REST API Desgin Pitfalls @ Devoxx 2024
PDF
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
PDF
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
PDF
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
PDF
Microservice Resilience Patterns @VoxxedCern'24
PDF
Distributed Consistency.pdf
PDF
Testing Microservices @DevoxxBE 23.pdf
PPTX
From Web to Flux @DevoxxBE 2023.pptx
PPTX
Test-Driven Design Insights@DevoxxBE 2023.pptx
PDF
Profiling your Java Application
PPTX
OAuth in the Wild
PPTX
The tests are trying to tell you something@VoxxedBucharest.pptx
PPTX
Vertical Slicing Architectures
PDF
Unit testing - 9 design hints
PDF
Integration testing with spring @JAX Mainz
PDF
Integration testing with spring @snow one
PDF
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
PDF
Pure Functions and Immutable Objects
Top REST API Desgin Pitfalls @ Devoxx 2024
The Joy of Testing - Deep Dive @ Devoxx Belgium 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Microservice Resilience Patterns @VoxxedCern'24
Distributed Consistency.pdf
Testing Microservices @DevoxxBE 23.pdf
From Web to Flux @DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
Profiling your Java Application
OAuth in the Wild
The tests are trying to tell you something@VoxxedBucharest.pptx
Vertical Slicing Architectures
Unit testing - 9 design hints
Integration testing with spring @JAX Mainz
Integration testing with spring @snow one
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Pure Functions and Immutable Objects

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Understanding Forklifts - TECH EHS Solution
PDF
medical staffing services at VALiNTRY
PDF
System and Network Administraation Chapter 3
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
L1 - Introduction to python Backend.pptx
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Transform Your Business with a Software ERP System
PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
Essential Infomation Tech presentation.pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Digital Strategies for Manufacturing Companies
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Understanding Forklifts - TECH EHS Solution
medical staffing services at VALiNTRY
System and Network Administraation Chapter 3
How to Migrate SBCGlobal Email to Yahoo Easily
L1 - Introduction to python Backend.pptx
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Transform Your Business with a Software ERP System
Operating system designcfffgfgggggggvggggggggg
Essential Infomation Tech presentation.pptx
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Digital Strategies for Manufacturing Companies
Wondershare Filmora 15 Crack With Activation Key [2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms II-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus

Refactoring blockers and code smells @jNation 2021

  • 1. VictorRentea.ro 21 victor.rentea@gmail.com ♦ ♦ @victorrentea ♦ VictorRentea.ro
  • 2. Victor Rentea VictorRentea.ro Recorded Talks, Blog, Video Courses, ... Independent Trainer Founder of Bucharest Software Craftsmanship Community Java Champion ❤️ Simple Design, Refactoring, Unit Testing ❤️
  • 3. Technical Training 500 days (200+ online) 2000 devs 8 years 50+ companies Reach out to me: Hibernate Spring Func Prog Java Performance Reactive Prog Design Patterns Pragmatic DDD Clean Code Refactoring Unit Testing TDD any lang @victorrentea Intense More: VictorRentea.ro Workshops: victorrentea.teachable.com
  • 5. 25 © VictorRentea.ro a training by Refactoring What must we do every single day? What’s that?
  • 6. 26 © VictorRentea.ro a training by Simplify existing code without changing its external behavior Refactoring DO NOT BREAK PRODUCTION
  • 8. 29 © VictorRentea.ro a training by I'm afraid to refactor because we don't have tests It's impossible to test a 200-lines method! The Vicious Circle of Legacy Code Pair Programming (80% less bugs) Coding Katas! TDD Practice
  • 9. 30 © VictorRentea.ro a training by Safe Refactoring Tips Next IDE Refactoring Fails Stress Don't Break Compilation (unless exploring) Automated Refactoring as much as you can Decompose Large Changes into small, safe moves Use Quick-fix to keep your focus on the design (Alt-Enter / ⌥-Enter)
  • 10. 31 © VictorRentea.ro a training by Time TIME FRAME SPEED
  • 11. 32 © VictorRentea.ro a training by "I don't have time. I'm too busy" Being busy is a form of laziness - Tim Ferriss Habits of Efficient Developers by Daniel Lebrero Stop! and Reflect. Focus on what matters.
  • 12. 33 © VictorRentea.ro a training by Improve Your Focus Turn off desktop/mobile notifications Automate Stuff Pomodoro 25/5 No morning inbox Max 30 min meetings  Digital Detox Master your IDE ➔ Get your brain to focus Chris Bailey IntelliJ Productivity Tips Victor Rentea
  • 13. 35 © VictorRentea.ro a training by Time TIME FRAME SPEED
  • 14. 36 © VictorRentea.ro a training by Estimates
  • 15. 37 © VictorRentea.ro a training by Emotionally Involved
  • 16. 38 © VictorRentea.ro a training by Ever-changing Requirements
  • 17. 40 © VictorRentea.ro a training by NO
  • 18. 41 © VictorRentea.ro a training by technical functional (complex requirements) iterations (the point of Agile) prototype/POC Estimations Risks
  • 19. 42 © VictorRentea.ro a training by Time & Fear ☺
  • 20. 43 © VictorRentea.ro a training by The Best way to understand code is to Refactor it
  • 21. 44 © VictorRentea.ro a training by You lost it! You got carried away...
  • 22. 45 © VictorRentea.ro a training by 3 hours later, you commit: code improvements refactoring I gotta leave Major changes
  • 23. 46 © VictorRentea.ro a training by
  • 24. 47 © VictorRentea.ro a training by
  • 25. 48 © VictorRentea.ro a training by Explore
  • 26. 49 © VictorRentea.ro a training by Exploratory Refactoring Discover Timeboxed: eg 15 min. Revert. Ctrl - Missing from our Practice:
  • 27. 50 © VictorRentea.ro a training by refactoring idea Long-lived Feature Branch Source Control
  • 28. 51 © VictorRentea.ro a training by Merge Conflicts Top annoying things in Dev's life: ➢ Interruptions ➢ Refactoring Tests ➢ Long meetings, and
  • 29. 52 © VictorRentea.ro a training by Trunk Based Development (requires maturity & discipline) Git Flow (merge conflicts, redo-refactor) Long Branches Inhibit Refactoring if (easyBoxReturnFeature) { // feature under develop } Feature Toggle + incremental DB migrations Preliminary Refactoring (separate Pull-Request)
  • 30. 53 © VictorRentea.ro a training by
  • 31. 54 © VictorRentea.ro a training by Micro-commits Break a large change set into: Large + Safe Automated Refactoring Manual Refactoring Adding Behavior + Easier Code Review + Less Bugs - Prior Exploration Needed to identify the steps A Commit Message Notation: https://github.com/RefactoringCombos/ArlosCommitNotation Separate Commits, or Preparatory refactoring PR
  • 32. 56 © VictorRentea.ro a training by What Stops Refactoring: Recap Fear ➔ tests, pair programming ➔ practice Time ➔ Proper estimates ➔ Improve Effectiveness Rushing even without time pressure Lack of Consensus ➔ team design brainstorm Huge PR - Rejected ➔ Trust ➔ Micro-Commits Fear of Breaking some Eggs to make the omelet Merge Conflicts ➔ short-lived branches ➔ trunk-based YOLO-driven developer A. Make it fun, play together B. Legacy Experience TM Lack of Skills extract a method ?!! ➔ Learn Code Smells Unknown Code Refactoring = Learning
  • 33. VictorRentea.ro 57 Worse Code (hours-days) Initial Chaos Code Quality Time You are here The Deepest, most impactful refactoring starts with making a bigger mess "You have to break some eggs to make an omelet" Wow! I see a deep refactoring eg. join two 100-lines method➔ one 200-lines method
  • 34. VictorRentea.ro 58 Worse Code (hours-days) Code Quality Time You are here The Strength to Revert (despite emotional involvement) Ctrl- A day without no Ctrl-Z is a day you didn't learned anything ... and the speed to get to some conclusions fast You need
  • 35. VictorRentea.ro 60 Code Smells “If it stinks, change it.” — Grandma Beck, discussing childrearing philosophy
  • 36. VictorRentea.ro 61 Large Method God Class Too Many Parameters Data Clumps (String, String, Long) ➔ Address > 20 lines > 200 lines > 4 All numbers are arbitrary. Find your own comfort zone
  • 37. 65 © VictorRentea.ro a training by Enrich your Domain Language by Discovering Value Objects Simplify your code Constraints Methods Reuse in larger Entities
  • 38. VictorRentea.ro 66 Speculative Generality Middle Man person.getAge() int getAge() { return bio.getAge(); } person.getBio().getAge() Data Classes get/set mania ➔ OOP Feature Envy Function ❤️ the state of an object Primitive Obsession ➔ PhoneNumber, OrderId, enum ➔ 💋 KISS Principle
  • 39. VictorRentea.ro 67 Primitive Obsession Map<Long, List<Long>> customerIdToOrderIds redeemCoupon(Long, Long, String)
  • 40. 68 © VictorRentea.ro a training by Map<Long, List<Long>> customerIdToOrderIds Map<CustomerId, List<OrderId>> orders redeemCoupon(Long, Long, String) redeemCoupon(CustomerId, CouponId, PhoneNumber) Micro-Types
  • 41. VictorRentea.ro 69 Primitive Obsession Make concepts explicit by introducing new small classes Even if it's a single String → PhoneNumber Long → CustomerId → ID type: @Value class CustomerId { Long id; } Escape the
  • 42. 70 © VictorRentea.ro a training by Map<Long, List<Long>> customerIdToOrderIds If the only usage of a map is: for (Long customerId : map.keySet()) { List<Long> orderIds = map.get(customerId); ... } Code Smell: Iterating over Map Keys List<CustomerOrderIds> You might be missing an abstraction (class): class CustomerOrderIds { private Long customerId; private List<Long> orderId; ... } (or entries)
  • 44. VictorRentea.ro 72 Divergent Changes Duplicated Code Shotgun Surgery m() Is it a bug or a feature? <> DRY SRP Is terrible when changes
  • 45. VictorRentea.ro 73 switch repeated switches loops for (e : list) { A(); B(); } list.stream()...A.. list.stream()...B.. vs Polymorphism vs "functional" switch in java17 vs enum with logic/Function refs
  • 46. VictorRentea.ro 74 Long-Lived Temporary Field x.setX(1); x.doStuff(); out = x.getY(); Temporal Coupling out = x.doStuff(1); Mutable Data + Multi-Threading = reads from X field and writes to Y field
  • 47. VictorRentea.ro 75 Code Smells Sheet Defeating the Evil starts with Naming It
  • 48. 76 © VictorRentea.ro a training by Code Smells Sheet Defeating the Evil starts with Naming It https://sourcemaking.com/refactoring/smells Long Method God Class Data Clumps Long Parameter List Primitive Obsession Data Class Feature Envy Middle Man Duplicated Code Shotgun Surgery Divergent Code Repeated Switches Loops Temporary Field Long-Lived Mutable Data Speculative Generality Comments Chapter 3 Many more + Solutions in or: https://sourcemaking.com/refactoring/smells
  • 49. VictorRentea.ro blog, best talks, training offer @VictorRentea The End victorrentea.ro/community Join me: Stay into The Light sourcemaking.com/refactoring First Half + Ch. 17 Ch.3 Code Smells For rookies Coding Katas kata-log.rocks/refactoring cleancoders.com refactoring.guru Share your thoughts The Beginning