Magic words to turn a “bad” code into a “good” one

Magic words to turn a “bad” code into a “good” one

Hi there! Have you already got your Hogwarts invitation? No? I have something fabulous! Insight from one of the lessons called “How to save your code” or whatever.

I’m going to share ideas on how to turn your project from horrible to fabulous. Turn a bad codebase full of a huge amount of bugs and weak architecture into an efficient and consistent one.

PS We all know that it’s possible to write from scratch, but it’s not the case all the time and is too obvious to cover in my article

Do we care about code?

Imagine the project that somebody initialized years ago. There for sure were plenty of “hot fixes”, TODOs, and technical debts. And another one — the top priority project with a huge budget. The app generates income for businesses and has many useful features.

Which project will you care about more?

If your answer — is second, time to reprioritize yourself.

Remember the first string of this article? “Developers”! We are eager to be developers, not coders, so we should care about all the code we support. Let’s fight for the best quality of code and make sure we do 100% for that! That’s indeed the true path of any developer.

Now let’s look at my checklist for bad codeed projects. Here is how you can prolong its life for years!

1. Linters

Make sure you have all the linters and configs correct.

  • Eslint(js)

  • Prettier(js)

  • Stylelint(e.g. scss, css, sass)

This is the least that would help you all the way long. Don’t be lazy and spend plenty of time creating suitable configs. They are your closest friends, not enemies!

2. Understand the core

Before starting the next huge changes you should be 1000% aware of the core functionality. Understand how main functions work and write some amount of tests to cover use cases. It helps you to understand whether you broke everything and in the best case, where to look for a fix.

Remember: Don’t ever start rewriting without even basic test coverage!

3. Start review and implement DRY, KISS, SOLID

I recommend starting reading Clean Code by Robert C. Martin during or even before. Or re-read again, I’m sure it could give you a lot of fresh ideas on how to make your code better. But don’t try to do it all at once!

4. Small commits

Divide your changes into small logical commits to prevent mess when you have to revert some unwanted changes.

5. One step to clean code each commit

There should be a rule of yours to make even small change which improves readability. Rename strange names or break complicated functions into smaller ones. Whatever! Do it each commit without exception.

Your goal is to read code as fast, easy, and obvious as possible, so work on it!

6. Cover each new bug you fixed with the test.

Do it right after fixing, it in the same branch. Do not ever postpone it! Always make sure you do all you can. So what you can do now? I hope you will use my list as a checklist and then share your opinion in the comments. And subscribe of course, more soon :)

Hope this article was helpful for you!

I wish you to always love your code!

See you! :)