Hi everyone, I have been into software testing for nearly 5 years and been a Project manager for 1.5 years so far. Over this period, I have come across some common mistakes that a software programmer does, mostly freshers (and even some experienced ones at times!)

Below I have listed these common mistakes, which if taken care off at the initial stage of coding itself, can save you a great amount of productive time which goes in fixing issues and then re-testing it at later stages.

1)  Analyze your task

Being a developer, our instinct is to start implementing of the solution as soon as possible. But its equally important to analyze it first. Identify various scenarios which are associated with it, Try to think for a users perspective so as to identify the negative scenarios which you need to cover. If you plan your approach for a task well, there is more possibility of you covering most of the test scenarios associated with the task and thus reducing testing time.

2) Importance of unit testing

As a programmer, we usually have a tendency not to check the small bits of code that we write initially. Mostly we assume that as per our logic the code would work as intended and continue. Once a big chunk of code is written we run the code to check the output. Rarely we get the output as expected in the first go, Mostly we end up getting some sort of an error.

When we debug the code (again taking nearly the same time it took for coding initially!) to figure out what caused the error, it might be some minor blunder that could have been avoided if checked initially. A minor code update may then turn out to require a full code verification if its some variable that is being used in the entire code!..so First best practice is to check your code after few lines.

3) Pay attention to ‘Warnings’

This is the most common thing that any programmer does. Ignoring the warnings the compiler shows. Reason being that warnings do not stop the code from running so why waste time over it, right?.

Here we should note that some warnings that are coming up now may turn into error in future as the code expands and gets more complex.
To avoid headaches in future, try as much possible to reduce the warnings to as minimum as possible or best to completely remove them.

4) Clean the code

We write a piece of code and after sometime realize its not required. What we do next? it might be required ahead so lets just comment and keep it.

Remember that if the code is not required currently it might as well not be required ahead (if required one can always code in future). This will help you to keep the overall code less, more readable and most importantly only what is required will be present. Also, the next time you see the code you won’t be distracted by that extra commented piece of code.

5) Commenting the code

As it might be you or someone working on the code that you are currently implementing, always comment what the code is doing. It is not required that each and every line of code needs to have a comment. But one can comment what a certain function is doing or why it has been called at a certain place.

When you come back to the code after a long time you won’t be lost looking at it 😉 or if some other person is working over it, she/he will be seeing you as a good coder ( You are getting benefitted either way, isn’t it?)

6) Using online code wisely

Thanks to the internet we can easily get any code. But before you use a piece of code, understand it thoroughly. Do not ignore the internal working of it because you are getting the required output currently. Definitely, it won’t be a straightforward task later for you to change it as it is dependent on understanding the code.

Multiple solutions may be shared by different people for a problem. Analyse them and pick the best one (one that suits your needs better). Do not directly go with the very first one that you come across.

7) Code review by a colleague

Its never harms to take a second opinion from a colleague regarding a piece of code written by you.

In this way, you get a different perspective of your code which might help you to optimize it in a better way. If you feel any suggested change is not currently required, the suggestion may still be useful in the future for some other scenario where your colleague’s approach suits better.

8) Keep code simple and structured

While coding try to keep the code as simple as possible. This is an important aspect when it comes to readability of code.

Also keeping the code structured as per the user’s flow. Eg Implementing the called function being right above the calling function so that in future you don’t have to use Ctrl+F frequently to locate where the function is.

To implement the above points it will take time while coding but this what you invest now which can save you a lot of productive time ahead. It will reduce the cycle of ‘fixing issue’ -> ‘re testing’ -> ‘fixing issue’. (Those of you who are into the s/w field will know at times how vicious this cycle can be).

I hope this article will help you’ll to minimize bugs.

Happy coding!!

Feel Free to get in touch with us at www.AstraSys.in