3 mistakes to avoid as a developer

This blog post is about the 3 things that you as a developer are tempted to do. You underestimate the repercussions of the changes we make in code. It seems like a small change at first but leads on to days of wasted time trying to get the project back to working.

In this blog post, I want to address these 3 mistakes you can make and how you can avoid them. I have personally faced problems because of these mistakes in the past. I hope it will help you too. Let’s dive in:

1- Upgrading Packages:

A common task of a developer’s daily work is installing packages and libraries to aid in commonly used features. If you are working on a front-end project you might be using npm, yarn package managers, and pip, composer, and so on for server-side projects.

These packages and libraries are constantly updated by their respective developers. Sometimes it contains some minor bug fixes and sometimes they can introduce breaking changes.

You might not keep a check on the latest versions for all packages every day. But, someday you will. You might notice that many packages have a newer version. You might be tempted to change the version number and install the latest code assuming it’s the latest so it must work right out of the box.

Unfortunately, that’s not the case every time. Some packages might be incompatible with each other, which leads to a broken project.

Hence, DO NOT upgrade all of your project packages all at once.

What to do?

  • Start with the least used package/library in the project. Upgrade to the latest version and test that specific feature that uses the package. 
  • IMPORTANT: Commit the changes with a proper version message. Eg: Upgrade plugin XXX to version x.x.x
  • Pick the next package, upgrade it and test the application again.
  • Repeat this process for every package. 
  • Be extra careful when upgrading packages that are most widely used in a project.

2- Prettify/Beautify Project Files:

This might not be a common issue but I want to mention it here. If you are using code prettifier right from the beginning of the project, you might not run into issues. But, if you introduce it at a later stage, you need to make sure you don’t run into unwanted issues.

Code prettifiers are a great tool and make your code look uniform across the team. Again, as a developer, you might be tempted to code prettify the whole project all at once. That’s what you want right, pretty code.

But, wait. An interesting thing about prettifiers is that they will format your code in a way you cannot predict. It will try to avoid horizontal scroll, add line breaks in code, etc. Prettifiers can sometimes mess your code. It can add some formatting that is not expected.

Sometimes, it messes up the if conditions and ternary operator, resulting in unexpected bugs. These issues are very hard to find and can take up a lot of your time if occurred in several places.

What to do?

  • Do not run prettier/beautify on the entire project. 
  • You might be working on 3-4 files at a time. Prettify only files that you are currently working on.
  • You can configure your editor to prettify code on every save. 
  • Keep committing your prettified files to version control after ensuring that the changes are working fine. 

3- Refactoring:

The problem with refactoring is with understanding refactoring. Firstly, there is a difference between refactoring and redoing. The most common things I hear are “I am refactoring the code, because I want to make it better”, etc. I am guilty of doing that in the past as well.

Usually, you will notice refactoring looks something like rebuilding the whole thing over again differently. Here, differently is the keyword. Sure, it might be a better way to build a feature but that cannot be defined as refactoring.

“code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior.” – 

Wikipedia

What to do?

IMO, you can perform refactoring more easily if your codebase has good test coverage. Performing refactoring can easily mess up code at several places. You might attempt to keep your code DRY(Don’t Repeat Yourself) without actually verifying all edge cases. Hence, automation testing helps.

If your codebase does not have good test coverage, try to keep your refactoring to a minimum. Also, try to use refactoring extensions for your IDE to ease the process. And more importantly, answer this question:

Are you going to refactor the code or redo the code?

I hope this will help you understand some common mistakes we as developers make which consume a lot of our time in fixing things. If you have any other points or things that you think developers can avoid, please comment below.

Happy Coding!!! 🙂

Leave a Reply