SlideShare a Scribd company logo
1 of 49
Download to read offline
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

What's hot

Clean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithClean Pragmatic Architecture - Avoiding a Monolith
Clean Pragmatic Architecture - Avoiding a MonolithVictor Rentea
 
Hibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicHibernate and Spring - Unleash the Magic
Hibernate and Spring - Unleash the MagicVictor Rentea
 
Clean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixClean pragmatic architecture @ devflix
Clean pragmatic architecture @ devflixVictor Rentea
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean codeVictor Rentea
 
Clean Lambdas at JBCNConf by Victor Rentea
Clean Lambdas at JBCNConf by Victor RenteaClean Lambdas at JBCNConf by Victor Rentea
Clean Lambdas at JBCNConf by Victor RenteaVictor Rentea
 
Clean Code with Java 8 - Functional Patterns and Best Practices
Clean Code with Java 8 - Functional Patterns and Best PracticesClean Code with Java 8 - Functional Patterns and Best Practices
Clean Code with Java 8 - Functional Patterns and Best PracticesVictor Rentea
 
Clean architecture - Protecting the Domain
Clean architecture - Protecting the DomainClean architecture - Protecting the Domain
Clean architecture - Protecting the DomainVictor Rentea
 
A Tale About the Evil Partial Mock and Separation by Layers of Abstractions
A Tale About the Evil Partial Mock and Separation by Layers of AbstractionsA Tale About the Evil Partial Mock and Separation by Layers of Abstractions
A Tale About the Evil Partial Mock and Separation by Layers of AbstractionsVictor Rentea
 
Unit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityUnit Testing like a Pro - The Circle of Purity
Unit Testing like a Pro - The Circle of PurityVictor Rentea
 
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021The Proxy Fairy and the Magic of Spring @JAX Mainz 2021
The Proxy Fairy and the Magic of Spring @JAX Mainz 2021Victor Rentea
 
Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Clean Lambdas & Streams in Java8
Clean Lambdas & Streams in Java8Victor Rentea
 
Functional Programming Patterns with Java 8 (at Devoxx BE)
Functional Programming Patterns with Java 8 (at Devoxx BE)Functional Programming Patterns with Java 8 (at Devoxx BE)
Functional Programming Patterns with Java 8 (at Devoxx BE)Victor Rentea
 
Don't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using MocksDon't Be Mocked by your Mocks - Best Practices using Mocks
Don't Be Mocked by your Mocks - Best Practices using MocksVictor Rentea
 
Refactoring Asynchronous TypeScript Code
Refactoring Asynchronous TypeScript CodeRefactoring Asynchronous TypeScript Code
Refactoring Asynchronous TypeScript CodeVictor Rentea
 
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...
Engaging Isolation - What I've Learned Delivering 250 Webinar Hours during CO...Victor Rentea
 
Evolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideEvolving a Clean, Pragmatic Architecture - A Craftsman's Guide
Evolving a Clean, Pragmatic Architecture - A Craftsman's GuideVictor Rentea
 
Definitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaDefinitive Guide to Working With Exceptions in Java
Definitive Guide to Working With Exceptions in JavaVictor Rentea
 
Clean Code summary
Clean Code summaryClean Code summary
Clean Code summaryJan de Vries
 
Spring @Transactional Explained
Spring @Transactional ExplainedSpring @Transactional Explained
Spring @Transactional ExplainedVictor Rentea
 

What's hot (20)

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

Similar to Refactoring blockers and code smells @jNation 2021

The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignVictor Rentea
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfVictor Rentea
 
Testing Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfTesting Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfVictor Rentea
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteVictor Rentea
 
The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxVictor Rentea
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxVictor Rentea
 
Евгений Руднев: "Programmers Approach to Error Handling"
Евгений Руднев: "Programmers Approach to Error Handling"Евгений Руднев: "Programmers Approach to Error Handling"
Евгений Руднев: "Programmers Approach to Error Handling"Anna Shymchenko
 
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Victor Rentea
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Victor Rentea
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable ObjectsVictor Rentea
 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop Itzik Saban
 
(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and backDavid Rodenas
 
Code quality
Code qualityCode quality
Code qualityProvectus
 
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineThe Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineMonica Beckwith
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agilityelliando dias
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certificationKadharBashaJ
 
Advanced developer day 3
Advanced developer   day 3Advanced developer   day 3
Advanced developer day 3Jorge Ferreira
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019Paulo Clavijo
 

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

The Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable DesignThe Art of Unit Testing - Towards a Testable Design
The Art of Unit Testing - Towards a Testable Design
 
Software Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdfSoftware Craftsmanship @Code Camp Festival 2022.pdf
Software Craftsmanship @Code Camp Festival 2022.pdf
 
Testing Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdfTesting Microservices @DevoxxBE 23.pdf
Testing Microservices @DevoxxBE 23.pdf
 
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening KeynoteClean Code @Voxxed Days Cluj 2023 - opening Keynote
Clean Code @Voxxed Days Cluj 2023 - opening Keynote
 
The tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptxThe tests are trying to tell you something@VoxxedBucharest.pptx
The tests are trying to tell you something@VoxxedBucharest.pptx
 
Test-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptxTest-Driven Design Insights@DevoxxBE 2023.pptx
Test-Driven Design Insights@DevoxxBE 2023.pptx
 
Tech talks#6: Code Refactoring
Tech talks#6: Code RefactoringTech talks#6: Code Refactoring
Tech talks#6: Code Refactoring
 
Евгений Руднев: "Programmers Approach to Error Handling"
Евгений Руднев: "Programmers Approach to Error Handling"Евгений Руднев: "Programmers Approach to Error Handling"
Евгений Руднев: "Programmers Approach to Error Handling"
 
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
Definitive Guide to Working With Exceptions in Java - takj at Java Champions ...
 
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
 
Pure Functions and Immutable Objects
Pure Functions and Immutable ObjectsPure Functions and Immutable Objects
Pure Functions and Immutable Objects
 
Refactoring workshop
Refactoring workshop Refactoring workshop
Refactoring workshop
 
(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back(automatic) Testing: from business to university and back
(automatic) Testing: from business to university and back
 
Code quality
Code qualityCode quality
Code quality
 
Refactoring legacy code
Refactoring legacy codeRefactoring legacy code
Refactoring legacy code
 
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual MachineThe Performance Engineer's Guide to Java (HotSpot) Virtual Machine
The Performance Engineer's Guide to Java (HotSpot) Virtual Machine
 
Polyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better AgilityPolyglot and Poly-paradigm Programming for Better Agility
Polyglot and Poly-paradigm Programming for Better Agility
 
How to crack java script certification
How to crack java script certificationHow to crack java script certification
How to crack java script certification
 
Advanced developer day 3
Advanced developer   day 3Advanced developer   day 3
Advanced developer day 3
 
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019Breaking Dependencies Legacy Code -  Cork Software Crafters - September 2019
Breaking Dependencies Legacy Code - Cork Software Crafters - September 2019
 

More from Victor Rentea

Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Victor Rentea
 
Distributed Consistency.pdf
Distributed Consistency.pdfDistributed Consistency.pdf
Distributed Consistency.pdfVictor Rentea
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxVictor Rentea
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing ArchitecturesVictor Rentea
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzVictor Rentea
 
Integration testing with spring @snow one
Integration testing with spring @snow oneIntegration testing with spring @snow one
Integration testing with spring @snow oneVictor Rentea
 
Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Victor Rentea
 

More from Victor Rentea (8)

Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24Microservice Resilience Patterns @VoxxedCern'24
Microservice Resilience Patterns @VoxxedCern'24
 
Distributed Consistency.pdf
Distributed Consistency.pdfDistributed Consistency.pdf
Distributed Consistency.pdf
 
From Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptxFrom Web to Flux @DevoxxBE 2023.pptx
From Web to Flux @DevoxxBE 2023.pptx
 
OAuth in the Wild
OAuth in the WildOAuth in the Wild
OAuth in the Wild
 
Vertical Slicing Architectures
Vertical Slicing ArchitecturesVertical Slicing Architectures
Vertical Slicing Architectures
 
Integration testing with spring @JAX Mainz
Integration testing with spring @JAX MainzIntegration testing with spring @JAX Mainz
Integration testing with spring @JAX Mainz
 
Integration testing with spring @snow one
Integration testing with spring @snow oneIntegration testing with spring @snow one
Integration testing with spring @snow one
 
Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021Pure functions and immutable objects @dev nexus 2021
Pure functions and immutable objects @dev nexus 2021
 

Recently uploaded

eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native BuildpacksVish Abrams
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfBrain Inventory
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 

Recently uploaded (20)

eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native Buildpacks
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
Why Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdfWhy Choose Brain Inventory For Ecommerce Development.pdf
Why Choose Brain Inventory For Ecommerce Development.pdf
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 

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