SlideShare a Scribd company logo
Eurosport
Benjamin Baumann - @zentiltoutou
https://github.com/bbaumann/Kodakademi
19/06/2017
Refactoring !
• What’s refactoring?
« Refactoring is the process of changing a software system in such a
way that it does not alter the external behavior of the code yet
improves its internal structure ».
« Improving the design of existing code »
Refactor vs refactoring
Hard, Error Prone, Risky
Requires Energy + Time
Save time on the long term, avoid bugs
Refactoring !
• Why refactoring?
- Make the code easier to understand
- Make the code cheaper to modify
- Reassert the code structure/design
- Find bugs
- Write the code faster
Refactoring !
• When refactoring?
- The rule of three
- When adding a feature
- When fixing a bug
- During code reviews
Refactoring !
• When NOT refactoring?
- Close to a deadline
- Code does not work at all
- Divide code in small components
- For each component, choose refactor or rewrite
- Not enough data on what is the code doing
- Importance of tests, specs, knowledge
- When refactoring implies changing external behaviour
Code smells !
• Practical case
Eurosport's Kodakademi #2
Refactoring : exterminate duplicate code
• DRY! Don’t Repeat Yourself.
• Understanding the code : why is
it duplicated? Why are they not
exactly the same?
• Modifying the code : may forget
to change the duplicate
• What to do ? Extract Method +
Template Method.
Bad smells !
• Duplicate code
• Long method
• Large class
• Long parameter list
• Switch statements and abuse of conditional statements
• Dead code
How to refactor effectively!
• Write and use functional tests (Jenkins !)
• Refactor often (every day!)
• Make small changes step by step and commit them atomically
• Believe in your tools and methods, even if transitional code is ugly
« Refactoring is like doing a surgery while keeping the patient able to
work on his daily chores »
“Make small changes continuously, seizing opportunities to remold
portions of a system when the time is right.”
Some refactoring recipes
• Extract Method
• Introduce explaining variable
• Remove assignments to parameters
• Move Method
• Extract Class
• Replace magic number with symbolic constant
• Encapsulate collections
Good Practices
• Self explanatory naming (variables, methods, class…)
• DRY !
• Run « Code Metrics » & « Code Analysis »
• Don’t abuse of « if » and « switch »
• 1. Short methods. 2. Shorter methods. « rule of screen »
• Interface/Contract and layers
• Single Responsability!
Single Responsability
• SOLID
• Single Responsability
• Open/Closed
• LID
• « A CLASS SHOULD HAVE
ONLY ONE REASON
TO CHANGE »
Single Responsability : Why ?
• CHANGES !
• « Multi responsabilities lead
to multi changes, changes
lead to problems, problems
lead to anger, anger leads to
the dark side »
Single Responsability : Exemple
• List.cs : 1137 hairy loc
• Enumerator.cs : 4 fields, 67 loc . Shared with other collections
OOP Principles from Single Responsability
• Separate your code by layers
• Program to interfaces, not implementations
• Depend on abstraction. Do not depend on concrete classes
• Strive for loosely coupled designs between objects that interact
• Least Knowledge : « talk only to your immediate friends »
Using Single Responsability
• SOLID and design patterns are Tools
• Need to know when and how to use them
• Carpenter’s metaphore
• What NOT to do : « Creating random
boundaries between objects, using
patterns wherever you can »
Single Responsability : Clean Architecture
• Separate your code by
layers
• Put abstraction in the
inner layers
• Put implementation
details in the outer layers
• Dependencies can only
point inward, never
outward
Exemple
• 5 concepts !
• App
• Config
• S3
• Flysystem
• Eloquent ORM)
• Different languages
• Like reading a book which
switches languages
Exemple
• Remove what is not application focussed
(storing/getting users + images)
• Create interfaces (integration points)
• Use tools
Clean Architecture : Benefits
• Independent of Frameworks (=tools, not core)
• Testable (Business Logic can be tested without the UI)
• Independant of UI
• Independant of Database
• Independant of any external agency
• Independant of everything
• Loose coupling !
Conlusion
• Keep It Simple Stupid (KISS)
• Refactor whenever you have time
• Refactor little step by step
• A class should have only one reason to change
• Keep core/entities free of dependencies
• Use tools with caution
Shamefully copied from
• https://dev.to/barryosull/cleaning-up-your-codebase-with-a-clean-
architecture
• https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean-
architecture.html

More Related Content

PPTX
Clean Code Talk (draft)
PPTX
Automated Testing but like for PowerShell (April 2012)
PPTX
How To Write a Testable Code
PPTX
Value of Unit Testing
PPTX
Refactoring
PPTX
Coding Standard And Code Review
PPTX
Type mock isolator
PPTX
Основы функционального JS
Clean Code Talk (draft)
Automated Testing but like for PowerShell (April 2012)
How To Write a Testable Code
Value of Unit Testing
Refactoring
Coding Standard And Code Review
Type mock isolator
Основы функционального JS

What's hot (20)

PPT
TDD In Practice
PDF
Metaprogramming Go
KEY
Overview of Testing Talks at Pycon
PDF
Fast Web Applications with Go
PPTX
Generating unit tests based on user logs
PDF
To Patch or Custom: How to decide when to patch a contrib module or go custom...
PPTX
Specification by example
PPTX
Hard Coding as a design approach
PDF
Fast end-to-end-tests
PDF
RubyConf China 2015 - Rails off assets pipeline
PPTX
Exploratory testing
PDF
RubyConf Taiwan 2016 - Large scale Rails applications
PPTX
You Live, You Learn, Then You Get Perforce Swarm
PPTX
Career Options for CS/IT/IS graduates
KEY
Ruby Concurrency Realities
PPTX
Real life unit testing tools and practices
PPTX
Test-Driven Sitecore
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
PPTX
Just startcoding
TDD In Practice
Metaprogramming Go
Overview of Testing Talks at Pycon
Fast Web Applications with Go
Generating unit tests based on user logs
To Patch or Custom: How to decide when to patch a contrib module or go custom...
Specification by example
Hard Coding as a design approach
Fast end-to-end-tests
RubyConf China 2015 - Rails off assets pipeline
Exploratory testing
RubyConf Taiwan 2016 - Large scale Rails applications
You Live, You Learn, Then You Get Perforce Swarm
Career Options for CS/IT/IS graduates
Ruby Concurrency Realities
Real life unit testing tools and practices
Test-Driven Sitecore
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Just startcoding
Ad

Similar to Eurosport's Kodakademi #2 (20)

PPTX
Refactoring
PDF
Refactoring
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
PDF
Refactoring 2 The Max
PDF
Refactoring 2TheMax (con ReSharper)
PPTX
SAD10 - Refactoring
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
PDF
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
PPTX
Code Refactoring
ODP
Refactoring: Improving the design of existing code
PDF
Code refactoring workshop (in Javascript)
PPT
Code Refactoring
PDF
Patterns, Code Smells, and The Pragmattic Programmer
PPTX
Code refactoring
PDF
Clean Code. An Agile Guide to Software Craft Kameron H.
PDF
Code refactoring
PDF
Bade Smells in Code
PDF
WordCamp US: Clean Code
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
PDF
Quick Intro to Clean Coding
Refactoring
Refactoring
Clean Code. An Agile Guide to Software Craft Kameron H.
Refactoring 2 The Max
Refactoring 2TheMax (con ReSharper)
SAD10 - Refactoring
Clean Code. An Agile Guide to Software Craft Kameron H.
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
Code Refactoring
Refactoring: Improving the design of existing code
Code refactoring workshop (in Javascript)
Code Refactoring
Patterns, Code Smells, and The Pragmattic Programmer
Code refactoring
Clean Code. An Agile Guide to Software Craft Kameron H.
Code refactoring
Bade Smells in Code
WordCamp US: Clean Code
Writing Better Code - Helping Developers make Decisions.pptx
Quick Intro to Clean Coding
Ad

Recently uploaded (20)

PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Cost to Outsource Software Development in 2025
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
L1 - Introduction to python Backend.pptx
PDF
top salesforce developer skills in 2025.pdf
PPTX
history of c programming in notes for students .pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
assetexplorer- product-overview - presentation
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Transform Your Business with a Software ERP System
Odoo Companies in India – Driving Business Transformation.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Cost to Outsource Software Development in 2025
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Digital Systems & Binary Numbers (comprehensive )
Operating system designcfffgfgggggggvggggggggg
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Wondershare Filmora 15 Crack With Activation Key [2025
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
L1 - Introduction to python Backend.pptx
top salesforce developer skills in 2025.pdf
history of c programming in notes for students .pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
assetexplorer- product-overview - presentation
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Transform Your Business with a Software ERP System

Eurosport's Kodakademi #2

  • 1. Eurosport Benjamin Baumann - @zentiltoutou https://github.com/bbaumann/Kodakademi 19/06/2017
  • 2. Refactoring ! • What’s refactoring? « Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code yet improves its internal structure ». « Improving the design of existing code » Refactor vs refactoring Hard, Error Prone, Risky Requires Energy + Time Save time on the long term, avoid bugs
  • 3. Refactoring ! • Why refactoring? - Make the code easier to understand - Make the code cheaper to modify - Reassert the code structure/design - Find bugs - Write the code faster
  • 4. Refactoring ! • When refactoring? - The rule of three - When adding a feature - When fixing a bug - During code reviews
  • 5. Refactoring ! • When NOT refactoring? - Close to a deadline - Code does not work at all - Divide code in small components - For each component, choose refactor or rewrite - Not enough data on what is the code doing - Importance of tests, specs, knowledge - When refactoring implies changing external behaviour
  • 6. Code smells ! • Practical case
  • 8. Refactoring : exterminate duplicate code • DRY! Don’t Repeat Yourself. • Understanding the code : why is it duplicated? Why are they not exactly the same? • Modifying the code : may forget to change the duplicate • What to do ? Extract Method + Template Method.
  • 9. Bad smells ! • Duplicate code • Long method • Large class • Long parameter list • Switch statements and abuse of conditional statements • Dead code
  • 10. How to refactor effectively! • Write and use functional tests (Jenkins !) • Refactor often (every day!) • Make small changes step by step and commit them atomically • Believe in your tools and methods, even if transitional code is ugly « Refactoring is like doing a surgery while keeping the patient able to work on his daily chores » “Make small changes continuously, seizing opportunities to remold portions of a system when the time is right.”
  • 11. Some refactoring recipes • Extract Method • Introduce explaining variable • Remove assignments to parameters • Move Method • Extract Class • Replace magic number with symbolic constant • Encapsulate collections
  • 12. Good Practices • Self explanatory naming (variables, methods, class…) • DRY ! • Run « Code Metrics » & « Code Analysis » • Don’t abuse of « if » and « switch » • 1. Short methods. 2. Shorter methods. « rule of screen » • Interface/Contract and layers • Single Responsability!
  • 13. Single Responsability • SOLID • Single Responsability • Open/Closed • LID • « A CLASS SHOULD HAVE ONLY ONE REASON TO CHANGE »
  • 14. Single Responsability : Why ? • CHANGES ! • « Multi responsabilities lead to multi changes, changes lead to problems, problems lead to anger, anger leads to the dark side »
  • 15. Single Responsability : Exemple • List.cs : 1137 hairy loc • Enumerator.cs : 4 fields, 67 loc . Shared with other collections
  • 16. OOP Principles from Single Responsability • Separate your code by layers • Program to interfaces, not implementations • Depend on abstraction. Do not depend on concrete classes • Strive for loosely coupled designs between objects that interact • Least Knowledge : « talk only to your immediate friends »
  • 17. Using Single Responsability • SOLID and design patterns are Tools • Need to know when and how to use them • Carpenter’s metaphore • What NOT to do : « Creating random boundaries between objects, using patterns wherever you can »
  • 18. Single Responsability : Clean Architecture • Separate your code by layers • Put abstraction in the inner layers • Put implementation details in the outer layers • Dependencies can only point inward, never outward
  • 19. Exemple • 5 concepts ! • App • Config • S3 • Flysystem • Eloquent ORM) • Different languages • Like reading a book which switches languages
  • 20. Exemple • Remove what is not application focussed (storing/getting users + images) • Create interfaces (integration points) • Use tools
  • 21. Clean Architecture : Benefits • Independent of Frameworks (=tools, not core) • Testable (Business Logic can be tested without the UI) • Independant of UI • Independant of Database • Independant of any external agency • Independant of everything • Loose coupling !
  • 22. Conlusion • Keep It Simple Stupid (KISS) • Refactor whenever you have time • Refactor little step by step • A class should have only one reason to change • Keep core/entities free of dependencies • Use tools with caution
  • 23. Shamefully copied from • https://dev.to/barryosull/cleaning-up-your-codebase-with-a-clean- architecture • https://8thlight.com/blog/uncle-bob/2012/08/13/the-clean- architecture.html