Continuous Integration
When working on your project for quite some time you might notice that there are a lot of similarities between the function that might even look like just a duplication of codes or poor naming convention or even bloated classes and methods, when that happen it means it’s time to REFACTORING
REFACTOR
Refactor is a disciplined technique on which we are restructuring an existing codes, altering its internal structure without changing its external behavior.
Refactoring is intended to improve the attributes of the codes such as its readability and reduced its complexity, this will also improve its maintainability.
IMPORTANT
The act of refactoring isn’t some kind of special task that would show in the project plan, but rather a regular activity that would benefit the project greatly in the long term.
Now you might be wondering, WHEN do we need to refactor? To answer this there is actually a set of pointers that could help you, these pointers are called “Code Smells”
CODE SMELLS
Code smells can sometimes be called as “poor structure” and it’s smell is quick to spot, however not all code smells indicate a problem but they are often an indicator of the actual problem.
Here are some list of Code Smells that might help you
Bloaters
Bloaters are code, method and classes that have increased to such a massive proportions that they are hard to work with. This smells usually shows up after the project has accumulated over time as the program evolve.
- Long method
- Long class
- Long parameter list
Object-Oriented Abusers
These are incomplete or incorrect application of the object-oriented principle.
- Temporary Field
- Switch statements
Dispensables
Dispensables are something pointless, that the absent of it would actually make the code cleaner, more efficient and easier to understand.
- Comments
- Duplicate codes
- Dead code
- Lazy class
Here is an example from our project Moodah of refactoring
At the beginning we would condense all of our backend works into 1 file called schema.ts, but overtime it has accumulated over 200 lines just from the first sprint alone
We’ve realised that there will be over than 1000 lines at the end if we are to keep going like this, so our devs proposed to us a refactor to the codes by dividing them into separate files to be more tidy and easily modified.
This is now after we have refactor the codes
CONCLUSION
Refactor isn’t just another word for cleaning up the codes, but rather it defines ones technique on improving the health of the code-base. By constantly on the lookout for refactoring you can not only help yourself but other people as well, a good refactoring could give a code the life it needed to survive the long-term for everyone.