Avoid These 5 Common Mistakes to Write Better Code

Viet Nguyen
Geek Culture
Published in
5 min readNov 22, 2021

--

Photo by Wes Hicks on Unsplash

Professional software developers don’t just write code to make it work, they also write code for other people to understand.

In real-world projects, developers spend roughly 60–80% of their time reading code. Therefore, producing readable code is very important in order to save time for everybody in the team as well as avoid bugs.

Top tech companies often have very strict code review processes because they know that bad code will lower development productivity and product quality.

In this article, I will show you 5 common mistakes to avoid when writing code. Believe me, you will no longer appear to be a rookie developer after knowing these mistakes.

1. Repeat Yourself

Suppose we need to validate email for 3 input fields.

Here is the bad code

You could see that we repeat the validation code for each input. This is bad because if we have to change the regex value /\S+@\S+\.\S+/, we will need to update it manually on every place we use it.

--

--

Viet Nguyen
Geek Culture

I love coding, writing about tech, and bringing value to others. https://vietjs.tech/