There are multiple bad coding practices which I learn with the passage of time and I also learn how to avoid those.
1. Typos in Your Code.
Using of wrong spelling, local languages for function names, variables, class names and others this is not related to a programming skill but it has an impact on maintaining code. I avoid it by using a better performing IDE’s. The latest IDE’s have auto correct spelling feature which helps a lot. I also used to keep meaningful names. So if someone read my code, he/she instantly understand at least 80% scope of the code. For example
int age; // this is a variable which tell that it will keep the age respectively.
2. Failing to Indent or Format Your Code
Using bad indentation and bad formatting is also an other bad programming practice. It creates complexity. A bad formatted code will be
– hard to read
– hard to maintain
– hard to point the errors
Badly formatted code
Nicely formatted and indented code
<pre><html> <head> <title> </title> </head> <body> </body> </html></pre>
You can see which code is easy to read and understand. I use the latest IDE’s which usually format the code automatically by keeping indentation and different colors. You can also set your own preferences.
3. Failing to Modularize Your Code
It’s good coding practice to write functions that do one thing and one thing only. That helps keep them short and, therefore, easy to understand and maintain. Long functions have many possible paths through them, making them much harder to test. A good rule of thumb: One function should occupy no more space than a single screen. Another one: If it has 10 or more “if” statements or loops, then it’s too complicated and should be rewritten.
4. Hard-Coding Passwords
An other bad programming practice is to use hard coded password and it can be other sensitive information. I avoid keep those information under a secure layer for example Configuration table in database.
5. Optimizing Code Prematurely
A badly optimize code can be very difficult to maintain. I am using a rule of thumb
b. check functionaliy
c. check performance
d. get to work in any parts that really need optimizing in order to improve performance.