SlideShare a Scribd company logo
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code
Working Effectively With Legacy Code

More Related Content

PDF
Living With Legacy Code
PDF
Testing Legacy Rails Apps
PPT
Php Debugger
PDF
TDD, BDD and mocks
PPT
TDD, BDD, RSpec
PDF
Unit-testing and E2E testing in JS
DOC
Debugging over tcp and http
PDF
AngularJS Unit Test
Living With Legacy Code
Testing Legacy Rails Apps
Php Debugger
TDD, BDD and mocks
TDD, BDD, RSpec
Unit-testing and E2E testing in JS
Debugging over tcp and http
AngularJS Unit Test

What's hot (20)

ODP
Bring the fun back to java
PDF
Unit Testing for Great Justice
KEY
How To Test Everything
PDF
Intro to Unit Testing in AngularJS
PPTX
Clean Code
PDF
vJUG - The JavaFX Ecosystem
PDF
The Art of Unit Testing - Towards a Testable Design
PDF
Dart for Java Developers
PDF
Why Your Test Suite Sucks - PHPCon PL 2015
PPTX
Laravel Unit Testing
PDF
Design patterns revisited with PHP 5.3
PPTX
Node.JS error handling best practices
PDF
Painless JavaScript Testing with Jest
PDF
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
PPT
Unit Testing in iOS
PDF
AngularJS Unit Testing w/Karma and Jasmine
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
PDF
Test-Driven Development of AngularJS Applications
ODP
Unit Testing and Coverage for AngularJS
ZIP
Test
Bring the fun back to java
Unit Testing for Great Justice
How To Test Everything
Intro to Unit Testing in AngularJS
Clean Code
vJUG - The JavaFX Ecosystem
The Art of Unit Testing - Towards a Testable Design
Dart for Java Developers
Why Your Test Suite Sucks - PHPCon PL 2015
Laravel Unit Testing
Design patterns revisited with PHP 5.3
Node.JS error handling best practices
Painless JavaScript Testing with Jest
Evolving a Clean, Pragmatic Architecture at JBCNConf 2019
Unit Testing in iOS
AngularJS Unit Testing w/Karma and Jasmine
Intro To JavaScript Unit Testing - Ran Mizrahi
Test-Driven Development of AngularJS Applications
Unit Testing and Coverage for AngularJS
Test
Ad

Viewers also liked (20)

PDF
PHP 7.1 : elegance of our legacy
PDF
Dealing with Legacy PHP Applications
PDF
Dealing With Legacy PHP Applications
PPTX
Working with Legacy Code
PPTX
Triumph Over Legacy Code with Unit Testing
PPTX
Automation and Technical Debt
PDF
Adding Unit Test To Legacy Code
PDF
Unit testing legacy code
PDF
Working With Legacy Code
PDF
Transforming legacy PHP applications with Symfony2 and Varnish
PDF
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
PPTX
XPDays Ukraine: Legacy
PPTX
XP Days Ukraine 2014 - Refactoring legacy code
PPTX
ITGM#4 Технический долг 2.0
PDF
From Legacy to DDD in PHP | Tech Talks | Privalia
PPTX
Club of anonimous developers "Refactoring: Legacy code"
PPTX
Legacy: как победить в гонке (Joker)
PPTX
Unit testing - the hard parts
PPT
Working Effectively With Legacy Code
PDF
Refactoring 101
PHP 7.1 : elegance of our legacy
Dealing with Legacy PHP Applications
Dealing With Legacy PHP Applications
Working with Legacy Code
Triumph Over Legacy Code with Unit Testing
Automation and Technical Debt
Adding Unit Test To Legacy Code
Unit testing legacy code
Working With Legacy Code
Transforming legacy PHP applications with Symfony2 and Varnish
Pimp legacy PHP apps with Apigility - TrueNorthPHP 2014
XPDays Ukraine: Legacy
XP Days Ukraine 2014 - Refactoring legacy code
ITGM#4 Технический долг 2.0
From Legacy to DDD in PHP | Tech Talks | Privalia
Club of anonimous developers "Refactoring: Legacy code"
Legacy: как победить в гонке (Joker)
Unit testing - the hard parts
Working Effectively With Legacy Code
Refactoring 101
Ad

Similar to Working Effectively With Legacy Code (20)

PDF
Ruby on Rails na Unip
PPTX
Cart creation-101217222728-phpapp01
PDF
OSDC 2009 Rails Turtorial
PPT
What's new in Rails 2?
PDF
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
PDF
Rails 2.3 and Rack - NHRuby Feb 2009
PDF
Flex With Rubyamf
PDF
Integrating Flex And Rails With Ruby Amf
PPT
Intro to Ruby on Rails
PPT
Boston Computing Review - Ruby on Rails
ODP
Fixture Replacement Plugins
PDF
td_mxc_rubyrails_shin
PDF
td_mxc_rubyrails_shin
PPT
Intro to Rails ActiveRecord
PPT
Ruby On Rails
PDF
Ruby on Rails - Introduction
PPT
Ruby On Rails Tutorial
PDF
Perusing the Rails Source Code
PDF
Rails MVC by Sergiy Koshovyi
PDF
Ecossistema Rails Campus Party 09
Ruby on Rails na Unip
Cart creation-101217222728-phpapp01
OSDC 2009 Rails Turtorial
What's new in Rails 2?
Pragmatic Patterns of Ruby on Rails - Ruby Kaigi2009
Rails 2.3 and Rack - NHRuby Feb 2009
Flex With Rubyamf
Integrating Flex And Rails With Ruby Amf
Intro to Ruby on Rails
Boston Computing Review - Ruby on Rails
Fixture Replacement Plugins
td_mxc_rubyrails_shin
td_mxc_rubyrails_shin
Intro to Rails ActiveRecord
Ruby On Rails
Ruby on Rails - Introduction
Ruby On Rails Tutorial
Perusing the Rails Source Code
Rails MVC by Sergiy Koshovyi
Ecossistema Rails Campus Party 09

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
A Presentation on Artificial Intelligence
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Machine Learning_overview_presentation.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
August Patch Tuesday
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Approach and Philosophy of On baking technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
PDF
Mushroom cultivation and it's methods.pdf
PPT
Teaching material agriculture food technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Per capita expenditure prediction using model stacking based on satellite ima...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A Presentation on Artificial Intelligence
Spectroscopy.pptx food analysis technology
Machine Learning_overview_presentation.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Group 1 Presentation -Planning and Decision Making .pptx
August Patch Tuesday
MIND Revenue Release Quarter 2 2025 Press Release
Approach and Philosophy of On baking technology
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction
Mushroom cultivation and it's methods.pdf
Teaching material agriculture food technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Heart disease approach using modified random forest and particle swarm optimi...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Editor's Notes

  • #4: The length of time doesn’t matter. It could be 3 weeks
  • #6: Code might be unfactored because you weren’t good enough to see the refactorings earlier.
  • #7: No tests - how do you have confidence? You could have well-designed code with no tests... “clean room”...falcon circling the sky then strikes Bad design Dependencies (Rails makes you not care. Stuff like const_missing is great but hides pain points, association chains)
  • #9: The more debt you have, the harder it is to adapt to changing requirements. Systems become large, it’s important for them to be designed and architected such that you can reason about subsystems. Eventually, programmers want the Big Rewrite. We’ve both advocated for the Big Rewrite on a project that hadn’t even launched yet.
  • #10: *** Choosing Rails   - Pros: we know them   - Cons: Locked into Ruby (issue when you need to have multithreaded code).  Opinionated - when your business expands past those opinions, must pay down debt.  Example: AR assumes one database.  Need to write libraries/rearchitect to support clustering *** Choosing mediawiki   - Pros: Easy to get the site up and running   - Cons: Difficult to extend, difficult to scale   - Result: Spent a year+ replacing it piece-by-piece with Rails *** Using ActiveScaffold   -  Pros: Get scaffolding quickly and easily   - Cons: Internal code is a mess, untested, difficult to extend *** Code you write   - Not refactoring / writing tests - Poorly tested code is almost as bad as not testing at all.
  • #11: has_many =>  has_many :through  (clear migration path) one database server => multiple database servers (requires community to create new tools. no clear migration path out of the box)
  • #12: ** Could spend six months designing the system so that it supports all the functionality and has extensibility points *** We know that doesn't actually work *** Plus you don't have working software * Agile approach   ** Do simple things to add value right now   ** Technical debt is central to Agile development - embrace it
  • #13: ** TATFT   - Testing allows you to refactor   - Refactoring pays down debt   - Virtuous cycle => Testing makes refactoring possible, refactoring makes testing easier ** RATFT   - Antipattern: red/green deploy Just because you have tests for your 70 line controller method, doesn't mean it's good or that you're done.   - red/green/REFACTOR deploy   - Get to green, take the time to make your code nice.  You should spend equal or more time refactoring than making your tests green. AboutUs: 2-3 deployments per day. No staging.
  • #15: Legacy systems provide existing value.  The foremost requirement when making changes to a system is not to lose the existing value. Automated tests provide the safety net.
  • #16: * You need to write tests, what do you do? Unit Tests or Acceptance Tests? A. Acceptance (originally called functional) Cuke: - Uses full rails stack. - Tests multiple requests in a single test. - Hits multiple models and controllers, session, external services, etc. * What's the point? - 1 cucumber test covers the same amount of code as 25 unit tests - Level of abstraction - reasoning about usage of the system, as opposed to one tiny little piece out of context - Captures existing system functionality
  • #19: Whenever you add code, examine areas that use the code, write tests to exercise those areas (just in time) (Kanban for the ninjas out there) Characterization tests - let you know how the system behaves currently. May even expose bugs but you don’t fix them just yet! Make a note or a story in tracker and move on. ** Pushback - Writing tests is too hard.  No it's not - No, really, it is too hard
  • #20: ** Silo code - Push it behind a webservice.  Write simple integration tests.  Example: AboutUs uses mediawiki as a parsing engine.  Easy to write Rails-app level tests for transformations, then push it off to mediawiki service - Don’t touch it after you silo it. - Rails 3: mountable apps
  • #22: ActiveSupport does a looooooot of stuff
  • #23: ** Use existing frameworks - resource_controller ** Write your own - Pivotal's authorization system (can_create, can_update auto-called from controller) ** Extraction is a very valid refactoring technique.
  • #27: * How many actions have people written that were like this?
  • #29: * Added one method (load_model) * Got behavior for free
  • #31: * Con isn’t really a con. New Ruby programmers won’t stay new for long * If they learn this, they’ll start to write code this way
  • #34: * I didn’t realize how easy that was until I did it from scratch * It “just worked”
  • #35: *This is considdered by most people as a “clean/skinny” controller.
  • #36: Why refactor? So you can do this We realize that legacy controllers aren’t even this clean. We never said it would be easy. Refactor your code, then you can make it sex This is the goal
  • #42: Transactions in the controller are an anti-pattern.
  • #47: No explicit transactions You can use a framework Code is tougher to understand due to indirection
  • #50: Transaction semantics without an explicit transaction Account and project focused on domain responsibilities AccountRegistration provides natural point for stuff like sending a verification email (also helps with testing) AccountRegistration can get sophisticated without muddling model - validates_associated project and video, if you want You could write a script to clean up AccountRegistration records when they’re no longer needed, depending on domain
  • #54: * Problems with this test ** Magic number (california sales tax) ** coupled to TaxCalculator implementation
  • #55: * Can use a mock or a simpler fake object * Every Java programmer asks “what library to use for DI” * Ruby programmers say “don’t use it” * Misses the point. Don’t use a framework. Use Ruby
  • #56: * Problem: this will break all clients
  • #59: Learn the hooks (inherit, included, etc) Understand how has_many works - it’s not magic! This lets you be very creative and have fun Working Effectively...gives you concrete strategies for getting a code base under test