SlideShare une entreprise Scribd logo
1  sur  10
Refactoring
By Rabeya Bashri
Refactoring
What is Refactoring
Why should we use Refactoring
When should we use Refactoring
When should not we use Refactoring
Why Refactoring works
Problem with Refactoring
Some Scenario
Conclusion
What is Refactoring
 a disciplined technique, used for restructuring an existing body of code
 altering its internal structure without changing its external behavior
 Its heart is a series of small behavior preserving transformations. Each
transformation does little, but a sequence of transformations can produce a
significant restructuring.
 Refactoring (noun): a change made to the internal structure of software to
make it easier to understand and cheaper to modify without changing its
observable behavior.
 Refactor (verb): to restructure software by applying a series of refactorings
without changing its observable behavior.
 it provides a technique for cleaning up code in a more efficient and
controlled manner.
Why should we use Refactoring
 Refactoring Improves the Design of Software
 It becomes harder to see the design by reading the code.
 Regular refactoring helps code retain its shape.
 Poorly designed code usually takes more code to do the same things, often
because the code quite literally does the same thing in several places. Thus an
important aspect of improving design is to eliminate duplicate code.
 By eliminating the duplicates, you ensure that the code says everything once
and only once, which is the essence of good design.
 Refactoring Makes Software Easier to Understand
 It does matter if it takes a programmer a week to make a change that would
have taken only an hour if programmer had understood your code.
 Refactoring Helps You Find Bugs
 Refactoring helps programmer be much more effective at writing robust code.
 Refactoring Helps You Program Faster
 a good design is essential for rapid software development.
 Without a good design, you can progress quickly for a while, but soon the poor
design starts to slow you down. You spend time finding and fixing bugs instead
of adding new function. Changes take longer as you try to understand the
system and find the duplicate code.
When should we use Refactoring
 refactoring is not an activity you set aside time to do. Refactoring is
something you do all the time in little bursts. You don’t decide to
refactor, you refactor because you want to do something else, and
refactoring helps you do that other thing.
 The Rule of Three
 Refactor When You Add Function
 Refactor When You Need to Fix a Bug
 Refactor As You Do a Code Review
When should not we use Refactoring
 A clear sign of the need to rewrite is when the current code
just does not work. You may discover this only by trying to
test it and discovering that the code is so full of bugs that you
cannot stablilize it. Remember, code has to work mostly
correctly before you refactor.
 The other time you should avoid refactoring is when you are
close to a deadline. At that point the productivity gain from
refactoring would appear after the deadline and thus be too
late.
Why Refactoring works
 What is it that makes programs hard to work with? Four
things I can think of as I am typing this are as follows:
Programs that are hard to read are hard to modify.
Programs that have duplicated logic are hard
to modify.
Programs that require additional behavior that
requires you to change running code are hard
to modify.
Programs with complex conditional logic are hard
to modify.
 So, we want programs that are easy to read, that have
all logic specified in one and only one place, that do not
allow changes to endanger existing behavior, and that
allow conditional logic to be expressed as simply
as possible.
Problem with Refactoring
 Databases
 One problem area for refactoring is databases. Most business
applications are tightly coupled to the database schema that supports
them.That’s one reason that the database is difficult to change.
 Another reason is data migration. Even if you have carefully layered
your system to minimize the dependencies between the database
schema and the object model, changing the database schema forces
you to migrate the data, which can be a long and fraught task.
 Changing Interfaces
 Something that is disturbing about refactoring is that many of the
refactorings do change an interface.
 Design Changes That Are Difficult to Refactor
Considerable scenario for refactoring
 Duplicate Code
 Long Method
 Larger Class
 Long Parameter List
Conclusion
Refactoring is the process of taking a running program and
adding to its value, not by changing its behavior but by giving
it more of these qualities that enable us to continue
developing at speed.

Contenu connexe

Similaire à Refactoring

Principlesinrefactoring 090906230021-phpapp01
Principlesinrefactoring 090906230021-phpapp01Principlesinrefactoring 090906230021-phpapp01
Principlesinrefactoring 090906230021-phpapp01Sopheak Sem
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure rupeshchanchal
 
The Power Of Refactoring (4developers Krakow)
The Power Of Refactoring (4developers Krakow)The Power Of Refactoring (4developers Krakow)
The Power Of Refactoring (4developers Krakow)Stefan Koopmanschap
 
Software design.edited (1)
Software design.edited (1)Software design.edited (1)
Software design.edited (1)FarjanaAhmed3
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedElizabeth Quinn-Woods
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedMadeline Gauthier
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedK. Dachos
 
Devops Explained & Best Practices
Devops Explained & Best PracticesDevops Explained & Best Practices
Devops Explained & Best PracticesShikhaKonda
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHPAdam Culp
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfMindfire LLC
 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)Stefan Koopmanschap
 
Top 10 React Development Tools to Choose in 2023.pptx
Top 10 React Development Tools to Choose in 2023.pptxTop 10 React Development Tools to Choose in 2023.pptx
Top 10 React Development Tools to Choose in 2023.pptx75waytechnologies
 
Test driven development and react js application go hand in hand
Test driven development and react js application go hand in handTest driven development and react js application go hand in hand
Test driven development and react js application go hand in handKaty Slemon
 
Agile Values, Principles and Practices
Agile Values, Principles and PracticesAgile Values, Principles and Practices
Agile Values, Principles and Practicesjackcrews
 
Refactoring, A First Example
Refactoring, A First ExampleRefactoring, A First Example
Refactoring, A First ExampleVorleak Chy
 
7 Tools To Make React Development Faster and More Efficient
7 Tools To Make React Development Faster and More Efficient7 Tools To Make React Development Faster and More Efficient
7 Tools To Make React Development Faster and More EfficientNarola Infotech
 

Similaire à Refactoring (20)

Principlesinrefactoring 090906230021-phpapp01
Principlesinrefactoring 090906230021-phpapp01Principlesinrefactoring 090906230021-phpapp01
Principlesinrefactoring 090906230021-phpapp01
 
Refactoring 2 The Max
Refactoring 2 The MaxRefactoring 2 The Max
Refactoring 2 The Max
 
Put to the Test
Put to the TestPut to the Test
Put to the Test
 
Software Development Standard Operating Procedure
Software Development Standard Operating Procedure Software Development Standard Operating Procedure
Software Development Standard Operating Procedure
 
The Power Of Refactoring (4developers Krakow)
The Power Of Refactoring (4developers Krakow)The Power Of Refactoring (4developers Krakow)
The Power Of Refactoring (4developers Krakow)
 
Software design.edited (1)
Software design.edited (1)Software design.edited (1)
Software design.edited (1)
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever Changed
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever Changed
 
Coding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever ChangedCoding With JRebel - Java Forever Changed
Coding With JRebel - Java Forever Changed
 
Extreme programming
Extreme programmingExtreme programming
Extreme programming
 
Devops Explained & Best Practices
Devops Explained & Best PracticesDevops Explained & Best Practices
Devops Explained & Best Practices
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHP
 
How can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdfHow can JAVA Performance tuning speed up applications.pdf
How can JAVA Performance tuning speed up applications.pdf
 
The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)The Power Of Refactoring (php|tek 09)
The Power Of Refactoring (php|tek 09)
 
Top 10 React Development Tools to Choose in 2023.pptx
Top 10 React Development Tools to Choose in 2023.pptxTop 10 React Development Tools to Choose in 2023.pptx
Top 10 React Development Tools to Choose in 2023.pptx
 
Test driven development and react js application go hand in hand
Test driven development and react js application go hand in handTest driven development and react js application go hand in hand
Test driven development and react js application go hand in hand
 
Agile Values, Principles and Practices
Agile Values, Principles and PracticesAgile Values, Principles and Practices
Agile Values, Principles and Practices
 
Refactoring, A First Example
Refactoring, A First ExampleRefactoring, A First Example
Refactoring, A First Example
 
7 Tools To Make React Development Faster and More Efficient
7 Tools To Make React Development Faster and More Efficient7 Tools To Make React Development Faster and More Efficient
7 Tools To Make React Development Faster and More Efficient
 
DevOps
DevOps DevOps
DevOps
 

Dernier

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Refactoring

  • 2. Refactoring What is Refactoring Why should we use Refactoring When should we use Refactoring When should not we use Refactoring Why Refactoring works Problem with Refactoring Some Scenario Conclusion
  • 3. What is Refactoring  a disciplined technique, used for restructuring an existing body of code  altering its internal structure without changing its external behavior  Its heart is a series of small behavior preserving transformations. Each transformation does little, but a sequence of transformations can produce a significant restructuring.  Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.  Refactor (verb): to restructure software by applying a series of refactorings without changing its observable behavior.  it provides a technique for cleaning up code in a more efficient and controlled manner.
  • 4. Why should we use Refactoring  Refactoring Improves the Design of Software  It becomes harder to see the design by reading the code.  Regular refactoring helps code retain its shape.  Poorly designed code usually takes more code to do the same things, often because the code quite literally does the same thing in several places. Thus an important aspect of improving design is to eliminate duplicate code.  By eliminating the duplicates, you ensure that the code says everything once and only once, which is the essence of good design.  Refactoring Makes Software Easier to Understand  It does matter if it takes a programmer a week to make a change that would have taken only an hour if programmer had understood your code.  Refactoring Helps You Find Bugs  Refactoring helps programmer be much more effective at writing robust code.  Refactoring Helps You Program Faster  a good design is essential for rapid software development.  Without a good design, you can progress quickly for a while, but soon the poor design starts to slow you down. You spend time finding and fixing bugs instead of adding new function. Changes take longer as you try to understand the system and find the duplicate code.
  • 5. When should we use Refactoring  refactoring is not an activity you set aside time to do. Refactoring is something you do all the time in little bursts. You don’t decide to refactor, you refactor because you want to do something else, and refactoring helps you do that other thing.  The Rule of Three  Refactor When You Add Function  Refactor When You Need to Fix a Bug  Refactor As You Do a Code Review
  • 6. When should not we use Refactoring  A clear sign of the need to rewrite is when the current code just does not work. You may discover this only by trying to test it and discovering that the code is so full of bugs that you cannot stablilize it. Remember, code has to work mostly correctly before you refactor.  The other time you should avoid refactoring is when you are close to a deadline. At that point the productivity gain from refactoring would appear after the deadline and thus be too late.
  • 7. Why Refactoring works  What is it that makes programs hard to work with? Four things I can think of as I am typing this are as follows: Programs that are hard to read are hard to modify. Programs that have duplicated logic are hard to modify. Programs that require additional behavior that requires you to change running code are hard to modify. Programs with complex conditional logic are hard to modify.  So, we want programs that are easy to read, that have all logic specified in one and only one place, that do not allow changes to endanger existing behavior, and that allow conditional logic to be expressed as simply as possible.
  • 8. Problem with Refactoring  Databases  One problem area for refactoring is databases. Most business applications are tightly coupled to the database schema that supports them.That’s one reason that the database is difficult to change.  Another reason is data migration. Even if you have carefully layered your system to minimize the dependencies between the database schema and the object model, changing the database schema forces you to migrate the data, which can be a long and fraught task.  Changing Interfaces  Something that is disturbing about refactoring is that many of the refactorings do change an interface.  Design Changes That Are Difficult to Refactor
  • 9. Considerable scenario for refactoring  Duplicate Code  Long Method  Larger Class  Long Parameter List
  • 10. Conclusion Refactoring is the process of taking a running program and adding to its value, not by changing its behavior but by giving it more of these qualities that enable us to continue developing at speed.