- Refactoring
- Techniques: organizing data
Techniques: organizing data
Refactorings that give data a name, a type and a single purpose: replace primitives and magic numbers, encapsulate fields and collections.
5 guides34 min in totalRefactoring
The guides, in order
Read them top to bottom: each one builds on the ones before. The ones you've read carry a check.
- Introduce Parameter Object: Bundle Parameters That Travel TogetherHow to replace a group of parameters that always appear together with a single object, step by step, in TypeScript, Python and PHP.7 min readStart here
- Preserve Whole Object: Pass the Object, Not Its FieldsLearn how to replace several values pulled out of one object with the object itself, shortening parameter lists and keeping related data together.7 min read
- Replace Temp with Query: Turn Local Variables into MethodsLearn how to replace a temporary variable with a method that computes it, so the logic can be reused, named and tested.7 min read
- Split Variable: One Name per PurposeLearn how to split a variable that is reassigned for unrelated purposes into separate, well-named variables, with TypeScript, Python and PHP examples.6 min read
- Replace Primitive with Object: Give Rule-Bearing Values a TypeLearn how to turn a raw string or number that carries rules, such as an email address, into a small validated type that owns those rules.7 min read
About this group
- What you'll find
- Replace temp with query, split variable, replace primitive with object, introduce parameter object and preserve whole object.
- It's for you if…
- your functions take loose strings and numbers that are really money, emails or ranges.
- How each guide works
- Smell guides cover the signs, an example, why it happens, the treatment with its refactorings, what you gain and when it's not worth fixing. Technique guides show the problem, the code before and after, the steps, which smells it removes, its benefits and its cautions.
More groups in Refactoring
- Smells: bloatCode smells in code that has grown so much it can no longer be understood at a glance.See the 5 guides
- Smells: rigidityCode smells where one change forces many others, far away: divergent change, shotgun surgery, and the refactorings that cure them.See the 3 guides
- Smells: couplingCode smells in pieces that know too much about each other: feature envy, inappropriate intimacy, message chains, and how to decouple them.See the 5 guides
- Smells: dead weightCode smells in code that adds nothing: duplicated, unused or speculative.See the 6 guides
- Smells: misused abstractionsCode smells where inheritance, types or conditionals are used against the grain.See the 4 guides
- Techniques: composing functionsRefactorings that split long functions into named pieces, or undo pieces that add nothing.See the 7 guides
- Techniques: simplifying callsRefactorings that make a function's signature say what it does and make it easy to use correctly.See the 4 guides
- Techniques: simplifying conditionalsRefactorings that make conditional logic readable at a glance: guard clauses, decomposed conditions and polymorphism instead of switches.See the 5 guides
- Techniques: moving featuresRefactorings that move each responsibility to the class or module where it belongs.See the 5 guides