Refactoring
Refactoring is the disciplined restructuring of existing software to improve its internal qualities while preserving its externally observable behavior.
Test Driven: Practical TDD and Acceptance TDD for Java Developers
A disciplined technique for changing a program's internal structure without changing its observable behavior.
- How it is used
- Supports evolutionary design as the final step of the test-driven development cycle.
- How deep it goes
- Defines behavior-preserving transformations and works through small-step method extraction and a larger design switchover.
- Examples
- Uses a template engine’s missing-value check, parser switchover, and test-code duplication as refactoring opportunities.
- What you can do after
- Practice identifying design problems and applying small behavior-preserving changes while checking tests.
Read how Test Driven: Practical TDD and Acceptance TDD for Java Developers explains refactoring →
Practices of the Python Pro
Refactoring is the process of changing a software system's internal design without changing its externally observable behavior.
- How it is used
- Uses incremental design improvement to keep evolving Python systems readable, maintainable, performant, and easier to change.
- How deep it goes
- Explains motivations, timing, decomposition, abstraction, and short Python transformations, but stops short of a comprehensive refactoring catalog.
- Examples
- Demonstrates state-capital extraction, Greeter restructuring, frequency counting, checkout decomposition, conditional mapping, and decoupled command messaging.
- What you can do after
- Apply it via Python by extracting responsibilities, replacing rigid conditionals, choosing clearer built-ins, and preserving existing behavior during change.
Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform
Refactoring is the disciplined restructuring of an implementation without changing its externally observable behavior.
- How it is used
- Restructures IaC monoliths to isolate conflicts, reduce deployment time, limit blast radius, and meet security standards.
- How deep it goes
- Explains definitions, technical debt, dependency ordering, state imports, verification, cleanup, and failure containment without detailing every provider operation.
- Examples
- Uses GCP IAM extraction, separate directories and state, Terraform plans, and dependency-ordered project, network, database, server, load balancer, and DNS configurations.
- What you can do after
- Apply refactoring via Terraform by copying configurations, importing resources, validating plans, removing old state, and repeating by dependency order.
Data-Oriented Programming in Java
Refactoring is the restructuring of existing software without changing its externally observable behavior.
- How it is used
- Uses refactoring to move legacy object-oriented and imperative code toward explicit data-oriented boundaries.
- How deep it goes
- Develops analysis, invariant-driven modeling, algebraic transformations, and side-effect separation rather than treating refactoring as code cleanup.
- Examples
- Uses a nullable Status representation, late-fee processing, and a legacy shopping-cart service.
- What you can do after
- Apply it to identify concrete flaws, encode invariants in types, and isolate data loading from business logic.
Read how Data-Oriented Programming in Java explains refactoring →
"Looks Good to Me"
AI-assisted restructuring of code directly within a code-review workflow while proposing an immediately integrable change.
- How it is used
- Deploys AI-assisted refactoring inside pull-request review to address feedback and improve proposed changes.
- How deep it goes
- Explains targeted and extended suggestions, but defers final decisions and contextual judgment to humans.
- Examples
- Uses What The Diff’s singleton suggestion and Qodo’s /improve and --extended commands as concrete workflows.
- What you can do after
- Apply it via What The Diff or Qodo to propose review changes, then validate and integrate suitable patches.
Refactoring to Rust
A software-engineering process of restructuring existing code to improve qualities such as performance or maintainability without replacing the whole system.
- How it is used
- Targets existing application bottlenecks for incremental improvement without a wholesale rewrite.
- How deep it goes
- Defines refactoring against rewriting and explains small deployments, test reuse, and integration through a PyO3 example.
- Examples
- Uses a Python Mandelbrot function moved to Rust and exposed through PyO3.
- What you can do after
- Apply refactoring via PyO3 to integrate a Rust function into a Python application.
Shipping Go: Develop, deliver, discuss, design, and go again
Refactoring is the restructuring of existing source code to improve its internal design without changing its externally observable behavior.
- How it is used
- Simplifies code or tests after a passing test so the next small change is easier to make.
- How deep it goes
- Works through a test-structure change and its verification, rather than a broad catalog of refactoring techniques.
- Examples
- Uses Go translation tests that replace repeated assertions with cases for English, German, Finnish, and Dutch.
- What you can do after
- Practice/perform it by simplifying a passing test or implementation and rerunning tests before adding another behavior case.
Read how Shipping Go: Develop, deliver, discuss, design, and go again explains refactoring →
The Art of Code
Refactoring is the restructuring of existing code to improve its design or clarity without changing its externally observable behavior.
- How it is used
- Uses refactoring to clarify complex business logic and reveal structure in legacy code.
- How deep it goes
- Works through iterative restructuring and provides extraction criteria and risk questions, while treating readability as a matter of judgment.
- Examples
- Uses an email-reminder method and an exercise restructuring a long method.
- What you can do after
- Evaluate and understand when restructuring improves clarity and when change risks call for caution.
Coding with AI
Code refactoring is the restructuring of existing source code to improve its internal organization without changing its externally observable behavior.
- How it is used
- Uses AI to inspect existing code, propose maintainability improvements, generate tests, and compare implementation trade-offs.
- How deep it goes
- Descends from a brief definition to worked Python changes and verification, while stopping short of guaranteeing generated code correctness.
- Examples
- Demonstrates session-aware question retrieval, shared database cursors, import correction, browser refresh behavior, console output, and generated tests.
- What you can do after
- Diagnose/debug with it by reviewing AI suggestions, preserving behavior, testing edge cases, and validating application and database state.
Grokking Simplicity
The systematic restructuring of existing code without changing its externally observable behavior.
- How it is used
- Uses behavior-preserving restructuring to separate calculations from actions and improve reuse, testing, and maintenance.
- How deep it goes
- Works through extraction, explicit inputs and outputs, code smells, callbacks, loop rewrites, and small-step decomposition.
- Examples
- Demonstrates shopping-cart totals, duplicated field setters, nested loops, array windows, callbacks, and functional map and reduce chains.
- What you can do after
- Apply it via incremental transformations that expose data flow, remove duplication, replace loops, and reduce bug-prone mutable state.
The Quick Python Book, Fourth Edition
Refactoring is the systematic restructuring of existing source code to improve its internal qualities without changing its externally observable behavior.
- How it is used
- Uses refactoring to shorten Python code and reorganize existing text-processing programs into functions and packages.
- How deep it goes
- Works through prompts, alternative implementations, resource trade-offs, and debugging generated function-based code.
- Examples
- Uses a file word counter, a text-cleaning and frequency-counting program, and a filesystem script.
- What you can do after
- Apply it via Copilot or Colaboratory by supplying existing code and a specific restructuring goal, then inspecting the result.
Read how The Quick Python Book, Fourth Edition explains refactoring →
Software Testing with Generative AI
Refactoring is the restructuring of existing source code to improve its internal design without changing its externally observable behavior.
- How it is used
- Uses refactoring within TDD to improve production code while preserving passing checks.
- How deep it goes
- Explains the red/green/refactor sequence and risk-led review, but does not detail named refactoring transformations.
- Examples
- Uses a Java Timesheet implementation, AI-generated accuracy and consistency risks, and the red/green/refactor cycle.
- What you can do after
- Apply it via TDD and unit-checking tools while using human judgment to verify AI-identified risks.
Read how Software Testing with Generative AI explains refactoring →
The Art of Unit Testing 3e
Refactoring is changing the internal structure of code without changing its externally observable functionality.
- How it is used
- Uses refactoring to improve maintainability while preserving functionality, including when preparing legacy code for unit tests.
- How deep it goes
- Defines refactoring and gives incremental testing guidance, but defers in-depth techniques and gotchas.
- Examples
- Illustrates method renaming and splitting, plus integration tests around an XML configuration manager before changes.
- What you can do after
- Practice/perform small refactoring steps, checking existing behavior with tests and using integration tests before changing untested legacy code.
Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu
Internal refactoring is structural change confined within a program or module that preserves its external behavior and interfaces.
- How it is used
- Makes Terraform modules easier to maintain and extend while keeping internal changes mostly invisible to users.
- How deep it goes
- Defines the interface boundary and gives file-reorganization guidance, plan expectations, and test checks; it does not provide a full refactoring procedure.
- Examples
- Uses grouped networking, load-balancing, and logging variables, plus splitting an oversized main.tf by function.
- What you can do after
- Practice/perform internal module reorganization and check for unintended changes with tests and a Terraform plan.
Python How-To
Refactoring is the restructuring of existing code to improve its design or maintainability without changing its externally observable behavior.
- How it is used
- Guides maintainability work by removing duplication, clarifying class responsibilities, and consolidating repeated test setup.
- How deep it goes
- Explains the behavior-preserving goal and demonstrates extraction in formatting, testing, and class design without discussing implementation internals.
- Examples
- Demonstrates repeated f-string formatting, a parameterized formatting function, a split class design, and unittest setUp.
- What you can do after
- Apply it by extracting repeated formatting or test setup and separating classes whose responsibilities have become mixed.
Bootstrapping Microservices, Second Edition: With Docker, Kubernetes, GitHub Actions, and Terraform
Continuous refactoring is the repeated restructuring of software during development without changing its externally observable behavior.
- How it is used
- Uses continuous restructuring to keep software simple during development and to convert monoliths into microservices incrementally.
- How deep it goes
- Explains iterative steps, testing, natural seams, and delivery constraints, but defers detailed conversion tactics to individual monoliths.
- Examples
- Shows simple architectural design, incremental monolith extraction, natural seams, and Terraform code refactoring.
- What you can do after
- Apply refactoring through small tested changes while preserving a working product and preparing components for extraction.
Build Financial Software with Generative AI (From Scratch)
Refactoring is the restructuring of existing code to improve its organization or maintainability without changing its externally observable behavior.
- How it is used
- Uses restructuring to clarify application components, simplify internal syntax, and reduce repeated test code during incremental development.
- How deep it goes
- Walks through extraction, simplification, and test generalization, but stops short of prescribing a comprehensive refactoring catalog.
- Examples
- Demonstrates navigation extraction, BDD-style syntax cleanup, regular-expression replacement, and generalized ACH exception tests.
- What you can do after
- Apply it via Next.js, Material UI, Python test code, or database-processing code to make existing implementations clearer and easier to test.
Read how Build Financial Software with Generative AI (From Scratch) explains refactoring →
Build High Value Software Systems
Refactoring is the restructuring of existing software without changing its externally observable behavior.
- How it is used
- Improves internal code structure while preserving externally observable behavior.
- How deep it goes
- Defines behavior-preserving restructuring and gives common transformations, without detailing a step-by-step refactoring procedure.
- Examples
- Uses renaming, method extraction, polymorphism, and function relocation as examples.
- What you can do after
- Evaluate whether a change targets code structure or workflow, and identify legacy constraints that must remain intact.
Read how Build High Value Software Systems explains refactoring →
Simple Object-Oriented Design: Create clean, maintainable applications
Refactoring is the disciplined transformation of existing software structure without changing its externally observable behavior.
- How it is used
- Controls growing software complexity by continually improving object-oriented design as needs and understanding change.
- How deep it goes
- Explains planning, small-step practice, renaming, extraction, encapsulation, and redesign timing through a worked conditional example.
- Examples
- Uses a billing-system redesign and an employee update-email conditional rewritten into named decision methods.
- What you can do after
- Practice/perform incremental structural improvements that clarify code, localize rules, and address complexity before it becomes entrenched.
Learn AI-Assisted Python Programming, Second Edition
Code refactoring is the restructuring of existing code to improve its readability or maintainability without changing its intended behavior.
- How it is used
- Organizes growing programs into clearer, more maintainable functions while preserving behavior.
- How deep it goes
- Explains decomposition and reorganization through examples, but stops short of detailed implementation internals.
- Examples
- Uses order processing, word extraction, signature calculation, and configurable feature weights.
- What you can do after
- Apply it by splitting functions, extracting repeated tasks, relocating decisions, and checking that behavior remains unchanged.
Read how Learn AI-Assisted Python Programming, Second Edition explains refactoring →
Software Architecture Decision-Making
Refactoring is the disciplined restructuring of existing code without changing its externally observable behavior.
- How it is used
- Keeps future change cheap while limiting unnecessary disturbance during delivery work.
- How deep it goes
- Defines deliberate cleanup, minimal change, and the scout rule, but stops short of procedural refactoring mechanics.
- Examples
- Contrasts hard-coded assumptions, separated business logic, isolated integrations, and cleanup mixed with unrelated work.
- What you can do after
- Apply it by preserving likely paths for change while deferring abstractions that solve only hypothetical problems.
Read how Software Architecture Decision-Making explains refactoring →
Rust Servers, Services, and Apps
Code refactoring is the restructuring of existing source code without changing its externally observable behavior.
- How it is used
- Applies structural changes to a Rust web project while preserving its externally observable behavior.
- How deep it goes
- Walks through file moves, module declarations, import updates, compilation, and tests, but does not detail behavioral refactoring.
- Examples
- Uses handler relocation, folder-based module grouping, updated imports, cargo check, and cargo test.
- What you can do after
- Apply it to reorganize a Rust project and verify the result through compilation and tests.
Read how Rust Servers, Services, and Apps explains refactoring →
Vibe Engineering
Refactoring is the restructuring of existing code to improve its design or understandability without intentionally changing its externally observable behavior.
- How it is used
- Uses refactoring to convert verified exploratory or AI-produced code into code the team understands and owns.
- How deep it goes
- Explains refactoring as a human-guided workflow stage and applies it incrementally, without detailing specific code transformations.
- Examples
- Uses legacy migration across REST, data, and UI layers, including relational-to-NoSQL migration and staged pull requests.
- What you can do after
- Practice refactoring by reshaping verified working code, reviewing AI assistance, and organizing modernization into auditable increments.
The Well-Grounded Python Developer: How the pros use Python and Flask
Refactoring is restructuring existing code to improve its design or maintainability while preserving its intended behavior.
- How it is used
- Improves maintainability by separating responsibilities and preserving flexibility for later reuse.
- How deep it goes
- Explains separation and function extraction through practical examples, without detailing a broader refactoring catalog.
- Examples
- Uses a calculation-formatting-output split and the extraction of long functions into focused functions or class methods.
- What you can do after
- Apply refactoring by splitting mixed responsibilities, extracting focused functions, and grouping related operations into classes when appropriate.
Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi
The systematic restructuring of existing software code without changing its externally observable behavior.
- How it is used
- Simplifies a robot motor library while preserving its public movement functions and arguments.
- How deep it goes
- Explains shared-logic extraction, parameter passing, wrappers, and library reuse, but does not develop broader refactoring techniques.
- Examples
- Uses repeated DC-motor movement code, a centralized movement function, directional wrappers, and commonmotor.py.
- What you can do after
- Apply it via Python functions to simplify motor-control code without altering callers or robot movement behavior.
Read how Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi explains refactoring →
The Coder Cafe
Refactoring is the restructuring of existing code to improve its readability, maintainability, or design without changing its intended behavior.
- How it is used
- Applies small structural changes to improve everyday code readability and maintainability without halting feature development.
- How deep it goes
- Demonstrates practical readability refactorings and tradeoffs, but stops short of detailed behavior-preservation procedures or implementation internals.
- Examples
- Uses a coffee-shop notification condition, named condition variables, function extraction, parameter-count risks, and readability review practices.
- What you can do after
- Evaluate and improve code readability by naming conditions, extracting focused functions, and balancing clarity against performance needs.
Functional Design and Architecture: Examples in Haskell
Refactoring is the disciplined restructuring of existing code without intentionally changing its externally observable behavior.
- How it is used
- Uses restructuring to recover maintainability when code has accumulated incorrect dependencies, inappropriate responsibilities, or inconsistent domain representations.
- How deep it goes
- Descends from recognizing design decay to changing data types, declarations, names, and module boundaries, without detailing testing or behavioral verification.
- Examples
- Uses hardware descriptions, component passports, vendor declarations, magic constants, naming inconsistencies, and invalid component combinations.
- What you can do after
- Apply it via Haskell or Scala type systems and functional approaches to make substantial model and naming changes safer.
Read how Functional Design and Architecture: Examples in Haskell explains refactoring →
Think Like a Software Engineering Manager
Refactoring is the restructuring of software code to improve its internal quality without changing its externally intended behavior.
- How it is used
- Uses refactoring to reduce technical debt while balancing product-feature delivery.
- How deep it goes
- Defines refactoring through technical-debt management and supplies review questions, but stops short of implementation techniques.
- Examples
- Uses deadline-driven shortcuts, duplicate code, incomplete features, design reviews, and future architectural revision as examples.
- What you can do after
- Evaluate technical debt by questioning duplication, modularity, review quality, testing, documentation, and system-wide effects.
Read how Think Like a Software Engineering Manager explains refactoring →
Grokking Software Architecture
Refactoring is the disciplined restructuring of existing code without changing its externally observable behavior.
- How it is used
- Improves internal code structure while preserving external behavior, especially when coupling reveals brittle change points.
- How deep it goes
- Defines refactoring and connects it to coupling and encapsulation through an example, without giving a general procedure.
- Examples
- Uses a user-report client and data service to contrast repeated low-level requests with a high-level aggregation call.
- What you can do after
- Diagnose tight coupling with a conversation-versus-interrogation test and identify code as a refactoring candidate.
Read how Grokking Software Architecture explains refactoring →
Also covered in
- AI for Everyday IT
- The Creative Programmer
- Write Powerful Rust Macros
- F# in Action: A Revised Edition of Get Programming with F#
- Graph Neural Networks in Action
- Learn Docker in a Month of Lunches, Second Edition
- Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
- Tiny Python Projects: Learn coding and testing with puzzles and games
- Code Like a Pro in Rust
- Modern Angular
- Build and Orchestrator in Go (From Scratch)
- Experimentation for Engineers
What to know first
- functionA function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
- PythonPython is a high-level, general-purpose, dynamically typed programming language with readable syntax and support for multiple programming paradigms.
- software testingSoftware testing is the systematic evaluation of software under specified inputs or conditions to assess its behavior against expected results or requirements and identify defects.
- moduleA module is a cohesive unit of code or computation that groups related functionality within a larger system and defines a scope or boundary for organizing or sharing it.
Related concepts
- continuous improvementcontrasts with · Continuous improvement is a recurring process in which outcomes or feedback guide successive changes intended to improve a system, process, or result.
- test-driven developmentused by · Test-driven development is a software development practice in which tests specify expected behavior and guide incremental implementation, typically being written before the corresponding code.
- code duplicationaddresses · Code duplication is the presence of the same or substantially similar implementation logic in multiple locations within a software system.
- complexityaddresses · Complexity is the degree to which interacting elements or factors make a system or problem difficult to understand, predict, change, operate, or solve.
- functionuses · A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
Questions about refactoring
What is refactoring?
Refactoring is the disciplined restructuring of existing software to improve its internal qualities while preserving its externally observable behavior.
Which Manning books explain refactoring?
Test Driven: Practical TDD and Acceptance TDD for Java Developers, Practices of the Python Pro, Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform, Data-Oriented Programming in Java, "Looks Good to Me", Refactoring to Rust, Shipping Go: Develop, deliver, discuss, design, and go again, The Art of Code and 21 more.
What should I know before learning refactoring?
Manning books that teach refactoring usually introduce function, Python, software testing and module first.
What is the difference between refactoring and continuous improvement?
Refactoring is the disciplined restructuring of existing software to improve its internal qualities while preserving its externally observable behavior. Continuous improvement is a recurring process in which outcomes or feedback guide successive changes intended to improve a system, process, or result.
What kinds of refactoring are there?
Kinds of refactoring include replace inheritance with delegation.
What is refactoring also called?
Refactoring is also called refactor.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




























