Refactoring is changing already existing code that you've written and making it better. This could involve changing the logic in your application so that less memory is used when you run your program or refactoring could involve something as small as changing variable names to make them more descriptive.
The reason why refactoring your codebase is important is because it allows the code that you have written to be better maintained over time and it makes it easier for other developers to understand what your code does if you're working in a team on a project.
Here I've listed some of the ways that software development teams refactor their codebase:
Reducing the size of the code
Restructuring confusing code into simpler code
Cleaning up code to make it tidier
Removing redundant, unused code and comments
Doing away with unnecessary repetitions
Combining similar code
Creating reusable code
Breaking up long functions into simpler, manageable bits
DRY:
DRY stands for don't repeat yourself which is a principle in software development for stopping as much repetition of code as possible and using better developer practices in the software development lifecycle.
The reason why DRY is important is mainly because of readability and reusability. DRY code is more organised and there is less of it which makes it easier for a developer to read. By merging multiple repeating code instances into one single instance, the individual instances can then be easily reused all over the project making the code reusable.
There are a few ways that you can write DRY code. The implementations might be different for you depending on what technologies and frameworks but here are the general principles:
Write reusable functions for repeated tasks
Iterate over duplicated tasks
If there is a set of operations planned in a specific order, we can create a loop to iterate over those operations.
Information for this blog was inspired by:
https://deegloo.com/the-great-importance-of-keeping-the-code-dry/