refactoring
Restructuring working code to make it clearer or easier to change without changing what it does.
In more detail
Refactoring improves names, splits long functions and removes duplication while behaviour stays the same. Tests make it safe, because they show at once if behaviour changed.
Examples
The course refactors a monolithic alert with boolean props into composable subcomponents; visual tests confirm nothing changed on screen.In the browser: In the course you refactor a loop that mixes DOM reads and writes into one that batches them, keeping the result identical but avoiding layout thrashing.Explicit generic types let Java tools refactor code automatically.The course refactors its mad lib program into small functions such as getKeys and tellStory.Many course exercises are refactors: moving a hook out of a condition, replacing an Effect with a derived value or turning a render prop into a custom hook.Related terms
- composition — Building a component out of smaller components that the consumer assembles, instead of configuring one big component with flags.
- visual regression testing — Testing that takes screenshots of components and compares them pixel by pixel with approved baseline images to catch unintended visual changes.
- unit test — An automated check of one small piece of code, such as a single function, that runs quickly and on its own.
- test suite — A collection of tests run together to check a piece of software.
- layout thrashing — Slowing a page by repeatedly changing styles and then reading sizes, forcing the browser to recalculate layout again and again.
- batching — Doing many similar pieces of work together in one operation, such as loading all needed owners with one query instead of one query each.
- React Server Components — React components that run only on the server, sending their rendered result to the browser without shipping their code.
- Client Component — A component whose code is also sent to the browser so it can use state, effects and event handlers.
- function — A named, reusable block of code that takes inputs, called arguments, and can return a result.
- antipattern — A common way of solving a problem that looks reasonable but causes bugs or extra work.
- custom hook — Your own function whose name starts with use and that calls other hooks, packaging stateful logic so several components can reuse it.
- regression test — A test run to check that behaviour which used to work still works after a change.
- implementation detail — How code happens to be arranged inside, as opposed to the behaviour a caller can observe.
- automated test — A small program that runs part of your code and checks that it did what you claimed it would.
- language service — The part of TypeScript that editors talk to for live errors, hover information, auto-complete, renames and quick fixes.
- static type checking — Checking that values are used consistently with their declared types by analysing code without running it.
Taught in
- The Request And The Response — AI Engineering: LLM Apps, RAG & Agents
- Planning, Memory And Many Agents — AI Engineering: LLM Apps, RAG & Agents
- Component API Ergonomics: Composition vs Boolean Config Props — Design Systems & Component Engineering
- Visual Regression Testing: Playwright & Snapshot Differencing — Design Systems & Component Engineering
- Testing Strategies And The Test Pyramid — DevOps & Site Reliability Engineering
- Unit Testing with xUnit and NSubstitute — Modern .NET Core, C# & Enterprise Microservices
- Layout, Reflow, Paint And GPU Compositing Layers — Frontend Architecture & Web Platform
- Generics And Collections — Modern Java: Virtual Threads & High-Throughput Services
- Fluent Assertions With AssertJ — Modern Java: Virtual Threads & High-Throughput Services
- Server Components: Async Execution & Constraints — Next.js 15 & Modern App Router Architecture
- Serialization Boundaries: Props & Server Guardrails — Next.js 15 & Modern App Router Architecture
- Granular Suspense: Resolving Waterfall Bottlenecks — Next.js 15 & Modern App Router Architecture
- Async Data Fetching: Parallel Requests & Preloading — Next.js 15 & Modern App Router Architecture
- Mad Libs Revisited: The Whole Program — Hands-on Python: Complete Video Course & Book
- Component Purity: Pure Functions, Idempotence And Side Effects — React 19 & Modern Component Architecture
- Diffing Algorithm: Element Type Shifts And Subtree Tear Down — React 19 & Modern Component Architecture
- Avoiding Effect Antipatterns: Derived State And Events — React 19 & Modern Component Architecture
- useImperativeHandle: Controlled Ref Forwarding Boundaries — React 19 & Modern Component Architecture
- useContext in Depth: Scoping, Consumer Subscription Costs — React 19 & Modern Component Architecture
- Higher-Order Components And Render Props: Tradeoff Analysis — React 19 & Modern Component Architecture
- Rules of Hooks: Call Order, Hook Lists, And Fiber Storage — React 19 & Modern Component Architecture
- The React Compiler: Automated Memoization Under The Hood — React 19 & Modern Component Architecture
- Dynamic Scanning — Application Security & Threat Modeling for Engineers
- The Cost And Value Of A Test — Automated Testing, TDD & Quality Engineering
- Why Over-Mocking Breeds False Positives — Automated Testing, TDD & Quality Engineering
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- Type Annotations, Type Inference And Contextual Typing — Production TypeScript
- Verify Your Environment: Running tsc And Bun TypeScript — Production TypeScript
- never: The Bottom Type And Exhaustive Switch Checking — Production TypeScript
- Generic Constraints: extends, keyof And Indexed Access — Production TypeScript
References
- React: thinking in React
- refactoring.com
- Martin Fowler: Refactoring definition
- dev.java: Generics
- Next.js 15 docs: Server and Client Components
- Python tutorial: defining functions
- VS Code: Refactoring
- VS Code: Refactoring TypeScript