SlideShare uma empresa Scribd logo
1 de 33
Baixar para ler offline
Working with legacy code

        Andrea Polci
Legacy code: definition



“source code inherited from someone else and source
 code inherited from an older version of the software”
                      (wikipedia)

                 “code without tests”
                  (Michael Feathers)
Legacy code: caracteristics
●   Poor architecture
●   Stratification of modifications
●   Non-uniform coding styles
●   Poor written documentation
●   “Oral” documentation lost
●   No tests
●   Extremely valuable!
    ●   Only successful code become legacy code
Why we have legacy code?
● More and more features
● Shortcuts and hacks


● Developer rotation


● Development team growth


    ●   less communication
Why we need to change legacy
              code?
● New functionality
● Bug


● Refactoring


● Optimization
Options
●   Start from scratch?
●   Look for a new Job?
●   May be we need
    Rambo?
●   Or Mc Gyver?
●   May be we need
    some “tools” to work
    effectively with
    legacy code
Test

●   They gives feedback       ●   What about legacy
    on changes                    code?
●   Different kind of tests       ●   To modify it we need
                                      tests
    ●   Unit
                                  ●   To write test we need
    ●   Integration                   to modify the code
    ●   Functional
An algorithm
1) Identify what to change
2) Identify what to test
3) Break dependencies
4) Write the tests
5) Modify and refactoring
What to change

1) Identify what to change
   ●   Do we have enough knowledge to choose where
       to make changes?
   ●   Sometimes we need to modify many different
       places just to make a simple change.
2) Identify what to test
3) Break dependencies
4) Write the tests
5) Modify and refactoring
I don't understand the code

●   Note/Sketching
●   Listing Markup
●   Scratch Refactoring
●   Write tests
●   Delete Unused Code
    ●   There is the repository for that
I don't understand the structure
●   Long lived applications tend to loose structure
    ●   It takes long time to understand the big picture
    ●   There is no big picture
    ●   The team is in emergency mode and lose sight of the
        big picture
●   It's important that every developer understand the
    big picture or the code will diverge from the
    architecture
    ●   Tell the story of the system
    ●   Naked CRC
    ●   Conversation Scrutiny
What to test
1) Identify what to change
2) Identify what to test
   •   Can be an hard work
   •   Effect analisys
   •   How much time do we have?
3) Break dependencies
4) Write the tests
5) Modify and refactoring
I don't have the time to test
●   Be careful!
●   Sometimes there is no other option
●   Don't make it worse!
    ●   Try to isolate new (tested) code from legacy code
    ●   Sprout method/class
    ●   Wrap method/class
Sprout method
public class ProductLablePrinter{
  …
  public void printLabel(int productId) {
    String barcode;
    …
    // compute barcode
    …
    // print barcode
  }
}
Sprout method
public class ProductLablePrinter{
  …
  public void printLabel(int productId) {
    String barcode;
    …
    // compute barcode
    …

        logPrinted(barcode);

        // print barcode
    }

    protected void logBarcode(String barcode) {
      // My code
    }


}
Break Dependencies
1) Identify what to change
2) Identify what to test
3) Break dependencies
   ●   How do I put a class in a test harness?
   ●   How I know I'm not breaking anything?
4) Write the tests
5) Modify and refactoring
Sensing & Separation
●   Sensing:
    we break dependencies to sense when we can't
    access values our code computes
●   Separation:
    we break dependencies to separate when we
    can't even get a piece of code into a test
    harness to run
Sensing & Separation: Example


public class ProductLablePrinter{
  …
  Public void printBarcode(int productId) {
    String barcode;
    …
    // compute barcode
    …
    // print barcode;
  }
}
Seam

●   Seam:
    a place where you can alter behavior of your
    program without editing in that place
●   Enabling Point:
    Every seam has an enabling point, a place
    where you can make the decision to use one
    behaviour or another
●   Looking for existings seams in legacy code
    allow us to break dependencies (for sensing
    or separation) without refactoring.
Different kind of Seams

●   Preprocessor seams

●   Link seam

●   Object seam
Object seam: Example
public class ProductLablePrinter{
  …
  public void printLabel(int productId) {
    String barcode;
    …
    // compute barcode
    …
    printBarcode(barcode);
  }

    protected void printBarcode(String barcode) {
      // access to printer
    }
}

Public void testPrintBarcode() {
  ProductLablePrinter plp = new ProductLabelPrinter(){
    String lastPrinted = null;
    protected void printBarcode(String barcode) {lastPrinted=barcode;}
  }

    // … test code
}
I can't get this class into a Test

●   Objects of the class can't be created easily
    ●   Parameters we have to pass to the constructor
    ●   Hidden dependencies
●   The test harness won't easily build with the
    class in it
●   The constructor we need to use has bad side
    effects
●   Significant work happens in the constructor
    and we need to sense it
Example (1)
public void testLabelPrinter() {
    new LabelPrinter();
}


The constructor LabelPrinter is undefined
Example (2)
public class LabelPrinter {
  public LabelPrinter(Printer prn, Warehose wh) {
    …
    this.printer = prn;
    if(!this.printer.isOnline()) {
      throw new …
    }
  }
}

public void testLabelPrinter() {
  Printer prn = new Printer(“stampante”);
  Warehouse wh = new Warehouse(“magazzino1”);
  LabelPrinter labPrint = new LabelPrinter(prn, wh);
}

public class Printer {
  boolean isOnline(){ … }
  void startJob() { … }
  void printLine(String line) { … }
  void endJob() { … }
}
Example (3)
public interface PrinterInterface {
  boolean isOnline();
  void startJob();
  void printLine(String line);
  void endJob();
}

public class Printer implements PrinterInterface {
  …
}

public class LabelPrinter {
  public LabelPrinter(PrinterInterface prn, Warehose wh) {
    ...
  }
}
I can't run this method in a test
●   Method not accessible to the test
●   It's hard to construct the parameters
●   Side effects (database, access to
    hardware, ecc.)
●   Need to sense through objects used by the
    method
Test
1) Identify what to change
2) Identify what to test
3) Break dependencies
4) Write the tests
5) Modify and refactoring
Modify and refactoring
1) Identify what to change
2) Identify what to test
3) Break dependencies
4) Write the tests
5) Modify and refactoring
   ●   TDD
   ●   Programming by difference
Making changes takes too much
                time
●   Understanding
    ●   How can we increase our understanding of the code?
●   Lag Time
    ●   It takes to much time to see the effect of changes and
        this slow down the development
    ●   Built time
    ●   Slow tests
    ●   No unit tests
    ●   Often to solve this we need to break dependecies
Tools
●   Authomatic refactoring tools
    ●   Can we trust them?
●   Mock Objects
●   Unit test harnesses
    ●   JUnit
●   Other test harnesses
    ●   Non-unit tests
Conclusions
●   No “silver bullet” here
●   It's an hard work but (usually) not
    impossible
●   At first it will seems overwhelming, but
    things will get better as the number of
    tests increase
●   Be pragmatic!
Questions?
References
●   Workking Effectively with Legacy Code,
    Michael C. Feathers
●   Joel on Software: Things you should never do,
    part I
      http://www.joelonsoftware.com/articles/fog0000000069.html

●   Michael Dubakov: Refactoring vs Rewrite
      http://www.targetprocess.com/blog/2009/11/refactoring-vs-rewrite.html

Mais conteúdo relacionado

Mais procurados

Agile QA presentation
Agile QA presentationAgile QA presentation
Agile QA presentationCarl Bruiners
 
Software Quality Assurance
Software Quality AssuranceSoftware Quality Assurance
Software Quality AssuranceSachithra Gayan
 
Software maintenance Unit5
Software maintenance  Unit5Software maintenance  Unit5
Software maintenance Unit5Mohammad Faizan
 
Quality Attributes In Software Architecture & Design Patterns
Quality Attributes In Software Architecture & Design PatternsQuality Attributes In Software Architecture & Design Patterns
Quality Attributes In Software Architecture & Design PatternsGatte Ravindranath
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design PrinciplesAndreas Enbohm
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
S.D.L.C (Software Development Life Cycle.)
S.D.L.C (Software Development Life Cycle.)S.D.L.C (Software Development Life Cycle.)
S.D.L.C (Software Development Life Cycle.)Jayesh Buwa
 
Software development life cycle (SDLC)
Software development life cycle (SDLC)Software development life cycle (SDLC)
Software development life cycle (SDLC)Simran Kaur
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarAbir Mohammad
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testingHadi Fadlallah
 
Software Testing 101
Software Testing 101Software Testing 101
Software Testing 101QA Hannah
 

Mais procurados (20)

Agile QA presentation
Agile QA presentationAgile QA presentation
Agile QA presentation
 
Software Quality Assurance
Software Quality AssuranceSoftware Quality Assurance
Software Quality Assurance
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
Waterfall model in SDLC
Waterfall model in SDLCWaterfall model in SDLC
Waterfall model in SDLC
 
STLC
STLCSTLC
STLC
 
Software maintenance Unit5
Software maintenance  Unit5Software maintenance  Unit5
Software maintenance Unit5
 
Quality Attributes In Software Architecture & Design Patterns
Quality Attributes In Software Architecture & Design PatternsQuality Attributes In Software Architecture & Design Patterns
Quality Attributes In Software Architecture & Design Patterns
 
Sdlc
SdlcSdlc
Sdlc
 
Automation testing
Automation testingAutomation testing
Automation testing
 
SOLID Design Principles
SOLID Design PrinciplesSOLID Design Principles
SOLID Design Principles
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
S.D.L.C (Software Development Life Cycle.)
S.D.L.C (Software Development Life Cycle.)S.D.L.C (Software Development Life Cycle.)
S.D.L.C (Software Development Life Cycle.)
 
Java keywords
Java keywordsJava keywords
Java keywords
 
Software development life cycle (SDLC)
Software development life cycle (SDLC)Software development life cycle (SDLC)
Software development life cycle (SDLC)
 
Solid principles
Solid principlesSolid principles
Solid principles
 
Learn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat ShahriyarLearn Java with Dr. Rifat Shahriyar
Learn Java with Dr. Rifat Shahriyar
 
Testing methodology
Testing methodologyTesting methodology
Testing methodology
 
Introduction to software testing
Introduction to software testingIntroduction to software testing
Introduction to software testing
 
Software Testing 101
Software Testing 101Software Testing 101
Software Testing 101
 

Destaque

Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy CodeEyal Golan
 
Software Operation Knowledge
Software Operation KnowledgeSoftware Operation Knowledge
Software Operation KnowledgeDevnology
 
Legacy: как победить в гонке (Joker)
Legacy: как победить в гонке (Joker)Legacy: как победить в гонке (Joker)
Legacy: как победить в гонке (Joker)Victor_Cr
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Victor_Cr
 
LetsGrow SOLID Software development
LetsGrow SOLID Software developmentLetsGrow SOLID Software development
LetsGrow SOLID Software developmentPatrick Kalkman
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestSeb Rose
 
Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Daum DNA
 
Dealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsDealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsClinton Dreisbach
 
PHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacyPHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacyDamien Seguy
 
Dealing With Legacy PHP Applications
Dealing With Legacy PHP ApplicationsDealing With Legacy PHP Applications
Dealing With Legacy PHP ApplicationsViget Labs
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Codescidept
 
Transforming legacy PHP applications with Symfony2 and Varnish
Transforming legacy PHP applications with Symfony2 and VarnishTransforming legacy PHP applications with Symfony2 and Varnish
Transforming legacy PHP applications with Symfony2 and VarnishCraig Marvelley
 
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014Michelangelo van Dam
 
XPDays Ukraine: Legacy
XPDays Ukraine: LegacyXPDays Ukraine: Legacy
XPDays Ukraine: LegacyVictor_Cr
 
XP Days Ukraine 2014 - Refactoring legacy code
XP Days Ukraine 2014 - Refactoring legacy codeXP Days Ukraine 2014 - Refactoring legacy code
XP Days Ukraine 2014 - Refactoring legacy codeDmytro Mindra
 
ITGM#4 Технический долг 2.0
ITGM#4 Технический долг 2.0ITGM#4 Технический долг 2.0
ITGM#4 Технический долг 2.0Maxim Shulga
 
From Legacy to DDD in PHP | Tech Talks | Privalia
From Legacy to DDD in PHP | Tech Talks | PrivaliaFrom Legacy to DDD in PHP | Tech Talks | Privalia
From Legacy to DDD in PHP | Tech Talks | PrivaliaJordi Vila Gallardo
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Metadata and ontologies
Metadata and ontologiesMetadata and ontologies
Metadata and ontologiesDavid Lamas
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101Adam Culp
 

Destaque (20)

Working with Legacy Code
Working with Legacy CodeWorking with Legacy Code
Working with Legacy Code
 
Software Operation Knowledge
Software Operation KnowledgeSoftware Operation Knowledge
Software Operation Knowledge
 
Legacy: как победить в гонке (Joker)
Legacy: как победить в гонке (Joker)Legacy: как победить в гонке (Joker)
Legacy: как победить в гонке (Joker)
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"
 
LetsGrow SOLID Software development
LetsGrow SOLID Software developmentLetsGrow SOLID Software development
LetsGrow SOLID Software development
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기Devon 2011-b-5 효과적인 레거시 코드 다루기
Devon 2011-b-5 효과적인 레거시 코드 다루기
 
Dealing with Legacy PHP Applications
Dealing with Legacy PHP ApplicationsDealing with Legacy PHP Applications
Dealing with Legacy PHP Applications
 
PHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacyPHP 7.1 : elegance of our legacy
PHP 7.1 : elegance of our legacy
 
Dealing With Legacy PHP Applications
Dealing With Legacy PHP ApplicationsDealing With Legacy PHP Applications
Dealing With Legacy PHP Applications
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Transforming legacy PHP applications with Symfony2 and Varnish
Transforming legacy PHP applications with Symfony2 and VarnishTransforming legacy PHP applications with Symfony2 and Varnish
Transforming legacy PHP applications with Symfony2 and Varnish
 
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
 
XPDays Ukraine: Legacy
XPDays Ukraine: LegacyXPDays Ukraine: Legacy
XPDays Ukraine: Legacy
 
XP Days Ukraine 2014 - Refactoring legacy code
XP Days Ukraine 2014 - Refactoring legacy codeXP Days Ukraine 2014 - Refactoring legacy code
XP Days Ukraine 2014 - Refactoring legacy code
 
ITGM#4 Технический долг 2.0
ITGM#4 Технический долг 2.0ITGM#4 Технический долг 2.0
ITGM#4 Технический долг 2.0
 
From Legacy to DDD in PHP | Tech Talks | Privalia
From Legacy to DDD in PHP | Tech Talks | PrivaliaFrom Legacy to DDD in PHP | Tech Talks | Privalia
From Legacy to DDD in PHP | Tech Talks | Privalia
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Metadata and ontologies
Metadata and ontologiesMetadata and ontologies
Metadata and ontologies
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 

Semelhante a Working With Legacy Code

Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your codePascal Larocque
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code cleanBrett Child
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With PytestEddy Reyes
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkPeter Kofler
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Conceptswesovi
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)Nacho Cougil
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)Nacho Cougil
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowAdam Doyle
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleikram_ahamed
 
Test Driven Development with PHP
Test Driven Development with PHPTest Driven Development with PHP
Test Driven Development with PHPRogério Vicente
 
Introduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerIntroduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerNaoto Ono
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaEddy Reyes
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testingdn
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testingmalcolmt
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekNacho Cougil
 
Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Peter Kofler
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowKathy Brown
 

Semelhante a Working With Legacy Code (20)

Test driven development - Zombie proof your code
Test driven development - Zombie proof your codeTest driven development - Zombie proof your code
Test driven development - Zombie proof your code
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
TDD in Python With Pytest
TDD in Python With PytestTDD in Python With Pytest
TDD in Python With Pytest
 
Writing Tests with the Unity Test Framework
Writing Tests with the Unity Test FrameworkWriting Tests with the Unity Test Framework
Writing Tests with the Unity Test Framework
 
Software Testing Basic Concepts
Software Testing Basic ConceptsSoftware Testing Basic Concepts
Software Testing Basic Concepts
 
Spock pres
Spock presSpock pres
Spock pres
 
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
 
Indy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-muleIndy meetup#7 effective unit-testing-mule
Indy meetup#7 effective unit-testing-mule
 
Test Driven Development with PHP
Test Driven Development with PHPTest Driven Development with PHP
Test Driven Development with PHP
 
Introduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debuggerIntroduction of Tools for providing rich user experience in debugger
Introduction of Tools for providing rich user experience in debugger
 
TDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and GomegaTDD in Go with Ginkgo and Gomega
TDD in Go with Ginkgo and Gomega
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
 
Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)Deliberate Practice, New Learning Styles (2015)
Deliberate Practice, New Learning Styles (2015)
 
Top Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To KnowTop Tips Every Notes Developer Needs To Know
Top Tips Every Notes Developer Needs To Know
 

Último

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
"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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Último (20)

Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
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
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
"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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Working With Legacy Code

  • 1. Working with legacy code Andrea Polci
  • 2. Legacy code: definition “source code inherited from someone else and source code inherited from an older version of the software” (wikipedia) “code without tests” (Michael Feathers)
  • 3. Legacy code: caracteristics ● Poor architecture ● Stratification of modifications ● Non-uniform coding styles ● Poor written documentation ● “Oral” documentation lost ● No tests ● Extremely valuable! ● Only successful code become legacy code
  • 4. Why we have legacy code? ● More and more features ● Shortcuts and hacks ● Developer rotation ● Development team growth ● less communication
  • 5. Why we need to change legacy code? ● New functionality ● Bug ● Refactoring ● Optimization
  • 6. Options ● Start from scratch? ● Look for a new Job? ● May be we need Rambo? ● Or Mc Gyver? ● May be we need some “tools” to work effectively with legacy code
  • 7. Test ● They gives feedback ● What about legacy on changes code? ● Different kind of tests ● To modify it we need tests ● Unit ● To write test we need ● Integration to modify the code ● Functional
  • 8. An algorithm 1) Identify what to change 2) Identify what to test 3) Break dependencies 4) Write the tests 5) Modify and refactoring
  • 9. What to change 1) Identify what to change ● Do we have enough knowledge to choose where to make changes? ● Sometimes we need to modify many different places just to make a simple change. 2) Identify what to test 3) Break dependencies 4) Write the tests 5) Modify and refactoring
  • 10. I don't understand the code ● Note/Sketching ● Listing Markup ● Scratch Refactoring ● Write tests ● Delete Unused Code ● There is the repository for that
  • 11. I don't understand the structure ● Long lived applications tend to loose structure ● It takes long time to understand the big picture ● There is no big picture ● The team is in emergency mode and lose sight of the big picture ● It's important that every developer understand the big picture or the code will diverge from the architecture ● Tell the story of the system ● Naked CRC ● Conversation Scrutiny
  • 12. What to test 1) Identify what to change 2) Identify what to test • Can be an hard work • Effect analisys • How much time do we have? 3) Break dependencies 4) Write the tests 5) Modify and refactoring
  • 13. I don't have the time to test ● Be careful! ● Sometimes there is no other option ● Don't make it worse! ● Try to isolate new (tested) code from legacy code ● Sprout method/class ● Wrap method/class
  • 14. Sprout method public class ProductLablePrinter{ … public void printLabel(int productId) { String barcode; … // compute barcode … // print barcode } }
  • 15. Sprout method public class ProductLablePrinter{ … public void printLabel(int productId) { String barcode; … // compute barcode … logPrinted(barcode); // print barcode } protected void logBarcode(String barcode) { // My code } }
  • 16. Break Dependencies 1) Identify what to change 2) Identify what to test 3) Break dependencies ● How do I put a class in a test harness? ● How I know I'm not breaking anything? 4) Write the tests 5) Modify and refactoring
  • 17. Sensing & Separation ● Sensing: we break dependencies to sense when we can't access values our code computes ● Separation: we break dependencies to separate when we can't even get a piece of code into a test harness to run
  • 18. Sensing & Separation: Example public class ProductLablePrinter{ … Public void printBarcode(int productId) { String barcode; … // compute barcode … // print barcode; } }
  • 19. Seam ● Seam: a place where you can alter behavior of your program without editing in that place ● Enabling Point: Every seam has an enabling point, a place where you can make the decision to use one behaviour or another ● Looking for existings seams in legacy code allow us to break dependencies (for sensing or separation) without refactoring.
  • 20. Different kind of Seams ● Preprocessor seams ● Link seam ● Object seam
  • 21. Object seam: Example public class ProductLablePrinter{ … public void printLabel(int productId) { String barcode; … // compute barcode … printBarcode(barcode); } protected void printBarcode(String barcode) { // access to printer } } Public void testPrintBarcode() { ProductLablePrinter plp = new ProductLabelPrinter(){ String lastPrinted = null; protected void printBarcode(String barcode) {lastPrinted=barcode;} } // … test code }
  • 22. I can't get this class into a Test ● Objects of the class can't be created easily ● Parameters we have to pass to the constructor ● Hidden dependencies ● The test harness won't easily build with the class in it ● The constructor we need to use has bad side effects ● Significant work happens in the constructor and we need to sense it
  • 23. Example (1) public void testLabelPrinter() { new LabelPrinter(); } The constructor LabelPrinter is undefined
  • 24. Example (2) public class LabelPrinter { public LabelPrinter(Printer prn, Warehose wh) { … this.printer = prn; if(!this.printer.isOnline()) { throw new … } } } public void testLabelPrinter() { Printer prn = new Printer(“stampante”); Warehouse wh = new Warehouse(“magazzino1”); LabelPrinter labPrint = new LabelPrinter(prn, wh); } public class Printer { boolean isOnline(){ … } void startJob() { … } void printLine(String line) { … } void endJob() { … } }
  • 25. Example (3) public interface PrinterInterface { boolean isOnline(); void startJob(); void printLine(String line); void endJob(); } public class Printer implements PrinterInterface { … } public class LabelPrinter { public LabelPrinter(PrinterInterface prn, Warehose wh) { ... } }
  • 26. I can't run this method in a test ● Method not accessible to the test ● It's hard to construct the parameters ● Side effects (database, access to hardware, ecc.) ● Need to sense through objects used by the method
  • 27. Test 1) Identify what to change 2) Identify what to test 3) Break dependencies 4) Write the tests 5) Modify and refactoring
  • 28. Modify and refactoring 1) Identify what to change 2) Identify what to test 3) Break dependencies 4) Write the tests 5) Modify and refactoring ● TDD ● Programming by difference
  • 29. Making changes takes too much time ● Understanding ● How can we increase our understanding of the code? ● Lag Time ● It takes to much time to see the effect of changes and this slow down the development ● Built time ● Slow tests ● No unit tests ● Often to solve this we need to break dependecies
  • 30. Tools ● Authomatic refactoring tools ● Can we trust them? ● Mock Objects ● Unit test harnesses ● JUnit ● Other test harnesses ● Non-unit tests
  • 31. Conclusions ● No “silver bullet” here ● It's an hard work but (usually) not impossible ● At first it will seems overwhelming, but things will get better as the number of tests increase ● Be pragmatic!
  • 33. References ● Workking Effectively with Legacy Code, Michael C. Feathers ● Joel on Software: Things you should never do, part I http://www.joelonsoftware.com/articles/fog0000000069.html ● Michael Dubakov: Refactoring vs Rewrite http://www.targetprocess.com/blog/2009/11/refactoring-vs-rewrite.html