10 Good Coding Habits

Tony
6 min readJun 3, 2024

Every good habit is a treasure. In this article I will compile 16 good habits for writing code, each of which is very classic. Developing these habits can help avoid most non-business-related bugs and I hope it’s helpful to you.

1. Testing after Modification

Testing your changes after modifying the code is a fundamental skill for every programmer. Especially, don’t hold onto the mentality of luck: “I just changed a variable or I only modified one line of configuration code, no need to test it myself.” After making changes to the code, it’s essential to test it yourself as much as possible. This can help avoid many unnecessary bugs.

2. Validate Method Parameters

Parameter validation is also a fundamental skill for every programmer. When handling methods, “parameter validation is a must.” For example, check if parameters are allowed to be empty or if their lengths meet your expected criteria. It’s essential to develop this habit, as many “low-level bugs” are caused by “not validating parameters.”

For example, if your database field is set to varchar(16), and someone passes a 32-character string, without validating parameters, you’ll encounter a direct exception when inserting into the database.

3. Consider the Compatibility of…

--

--