Engineering
Refactoring
Learn Refactoring with the Practica AI Coach
The Practica AI Coach helps you improve in Refactoring by using your current work challenges as opportunities to improve. The AI Coach will ask you questions, instruct you on concepts and tactics, and give you feedback as you make progress.Curated Learning Resources
- Summary and Criticism of Fowler’s “Refactoring”In this article, Mark summarizes Martin Fowler's book "Refactoring: Improving the Design of Existing Code". The book has become a vital resource in the field of software engineering for over two decades. Refactoring, the practice of improving existing software code without changing its functionality, is explained in the book with numerous examples and patterns. The article emphasizes the importance of regular refactoring to prevent code deterioration and maintainability issues. Code can atrophy due to changing environments or the need for additional functionality, leading to decreased effectiveness and increased complexity. Mark provides an example from the book that demonstrates the refactoring process. Fowler suggests breaking up large functions, decoupling data processing from printing and calculation, and using polymorphism to simplify conditional logic. The article also mentions the significance of automated testing to ensure the code remains functional after each refactoring step. Mark concludes by acknowledging some criticisms of the book and the need for a nuanced discussion on challenges and functional programming principles in refactoring.
- Rub a dub dubFogBUGZ started as an experiment but grew popular over time. The code base became messy and difficult to improve. Instead of rewriting the code from scratch, Joel decided to do a thorough refactoring by cleaning up the code without adding new features. This refactoring took three weeks and involved separating HTML from logic, removing hard-coded values, and restructuring the code. Joel argues that this refactoring approach saved time compared to a complete rewrite while still improving the code and fixing bugs. The schedule was predictable and the code is now easier to add new features to. He recommends refactoring tools to make such code cleanups more efficient.
- Fleet Management at Spotify (Part 3): Fleet-wide RefactoringSpotify manages its software across thousands of repositories. They created tools to enable refactoring code across all repos at once, called fleet-wide refactoring. They use a BOM to manage dependencies and Fleetshift to generate code changes and pull requests across repos. They introduced automerging to automatically merge changes as long as tests pass. They monitor post-merge health to catch issues. They use gradual rollouts for riskier changes. These tools have reduced the time to adopt new library releases from 200+ days to under 7 days. More teams are embracing the fleet-first mindset and using Fleetshift. However, they aim to improve the tools to make fleet-wide changes easier and support monorepos.
- Five Steps for Managing Legacy CodeLegacy code is unavoidable and can be frustrating to work with. There are steps teams can take to manage legacy code more effectively. First, accept that legacy code exists and define it clearly based on characteristics that make it hard to work on, not just age. Prioritize updates based on how often the code needs to change. Make incremental improvements where possible instead of risky big rewrites. When rewrites are necessary, scope them as tightly as possible and deploy changes incrementally behind Feature Flags. Managing legacy code well over time can improve code quality while minimizing disruption.
Related Skills
- Prioritization for Engineering
- Incident Response
- Product Development Flows
- Generative AI
- Engineering Director Role
- Tech Lead Role
- Security Principles
- Security Leadership
- Tech Talks
- Engineering Career Ladders
- Code Reviews
- Data Modeling
- Intro to Eng Management
- Testing & Quality
- Software Design Docs
- Microservices
- Web Engineering
- Hiring Engineers
- Clean Code
- CTO's Role
- Software Architecture
- Estimation
- Senior Engineer
- Documentation
- Technical Debt
- Mentorship for Engineers
- Product-Focused Engineering
- Asking for Help
- Scoping
- Configuration at Scale
- Principal Engineer
- On-Call Rotation
- Structuring Engineering Teams
- Debugging
- Continuous Deployment
- Reliability Leadership
- Reliability Principles
- VP Engineering Role
- Tech Writing
- Monitoring & Observability
- Terminals and Systems
- Mobile Engineering
- Pair Programming
- Onboarding Engineers
- Development Velocity