DEV Community

Maxim Nosov ✪
Maxim Nosov ✪

Posted on

Code refactoring

Hi !

Today I've been working on my project and did the code refactoring. It turns out there are so many things that could be improved. Code is not always written within the rules.

Refactoring

For now, I know 4 things that must be refactored:

  • Change the variable names (to make it clear what they are here for)

  • Extract certain logic and put into function, so that we are able to reuse it and if we have an error, we just need to fix one function

  • Improve code readability, because sometimes we just write a lot of code, and we want to make it work, but we don't really care about the readability, though it's very important if other people will work on your code. We don't want the programmers to feel the pain when they try to understand our code :)

  • Splitting the code into multiple functions. That's a very good approach, since we don't go along with just one index.js file, containing 1000 lines of code. We have 5 files and each of them not big and very easy to manage.

After I've done multiple commits in a refactoring branch, where each commit held only one refactor(e.g. extract logic into function), I had to do rebase all commits into one.

Overall

I didn't break any functionality, hence code refactoring was successful, but there is always a way to improve :)

Top comments (0)