How to Improve your Code With easy Refactorings
Refactorings are amazing to grow and improve our code
Refactorings are amazing to grow and improve our code
TL;DR: Let’s start addressing our code smells
I have been writing a series on Code Smells for a long time.
There are a lot of (possible) problems
Let's go for the solutions!
Refactoring 002 - Extract Method
Refactoring 003 - Extract Constant
Refactoring 004 - Remove Unhandled Exceptions
Refactoring 005 - Replace Comment with Function Name
Refactoring 006 - Rename Result Variables
Refactoring 007 - Extract Class
Refactoring 008 - Convert Variables to Constant
Refactoring 009 - Protect Public Attributes
Refactoring 010 - Extract Method Object
Refactoring 011 - Replace Comments with Tests
Refactoring 012 - Reify Associative Arrays
TL;DR: Convert your key/value into full behavioral objects
Refactoring 015 - Remove NULL
TL;DR: Use the Null Object Pattern to eliminate null checks and simplify your code.
Refactoring 016 - Build With The Essence
TL;DR: Pass essential attributes during object creation to reduce mutability and eliminate getters and setters.
Refactoring 017 - Convert Attributes to Sets
TL;DR: Using sets for attributes simplifies your code and makes state management easier
Refactoring 020 - Transform Static Functions
TL;DR: Replace static functions with object interactions.
Refactoring 021 - Remove Dead Code
TL;DR: Eliminate unused functions, constants, and "just-in-case" code.
Refactoring 022 - Extract Common Ancestor
TL;DR: Extract a common abstract class to mimic real-world structure.
Refactoring 023 - Replace Inheritance with Delegation
TL;DR: Replace restrictive inheritance hierarchies with flexible object delegation
Refactoring 024 - Replace Global Variables with Dependency Injection
TL;DR: Replace global variables with dependency injection to improve testability and reduce coupling. 💉
Refactoring 025 - Decompose Regular Expressions
TL;DR: You can break down a complex validation regex into smaller parts to test each part individually and report accurate errors.
Refactoring 026 - Migrate Global Console Input to Declarative Function
TL;DR: Extract input logic into separate functions to make your code testable, with regressions and more maintainable.
Refactoring 027 - Remove Getters
Refactoring 028 - Replace Consecutive IDs with Dark Keys
TL;DR: Replace sequential IDs in your models with UUIDs to prevent IDOR vulnerabilities and discourage scraping.
Photo by No Revisions on Unsplash
Part of the objective of this series of articles is to generate spaces for debate and discussion on software design.