How can programmers ensure that their programs have no bugs? From: csdn)

Source: Internet
Author: User

There is no doubt that programmers are good at thinking about problems. A program is written through the basic stages of thinking, design, writing, debugging, testing, and running. But most programmers have a problem that they are reluctant to test their own code. After the debugging is completed, they think that the work is over. testing is the work of testers.

Theoretically, if there is a problem with the code, the tester and the end user will certainly be able to find these bugs, and it is really costly to wait for a time to return back and find out where the problem is wrong, the cost is:

1. The impact on the programmer's reputation
2. Affected Product Quality
3. The customer's trust is affected.
4. At this time, debugging becomes much more difficult.
 
If it's big, let's talk about the influence of your own reputation. If your program always has such a bug, you will get less benefits, even if you write a lot of code.

In fact, the last point is also very important. When we are dealing with a piece of code, we can do everything well, but if we prevent this piece of code from being in a huge system, simple problems cannot be found immediately. When saving debugging for your own sake, we should keep our programs as bug-free as possible.

So how can we ensure that our code has no bugs?

Programmers must overcome some of their own fatal shortcomings to fundamentally solve this problem. So what is this problem? As we have mentioned above, programmers are very tolerant of their own code and think it is correct. In fact, this idea is quite normal. The program is written after the programmer thinks and designs it. The programmer will not write what he thinks is incorrect into the code, at this time, we have always assumed that the program is correct. However, if people are not sages, how can they not make mistakes. In fact, programmers have a good attitude towards other programmers, with a very picky attitude and a learning attitude; but once they treat their own code, it is very difficult to do so; this is the most fatal. Programmers must also be picky about and learn their own code. This is based on the assumption that their code is wrong, and then what needs to be done is how to prove that their code is correct. Programmers themselves can do this at every stage of the Program Generation: careful design (it is worthwhile to draw time at this time, we must ensure that we have a clear outline of our programs before we can start to write), code writing, unit testing (unit testing is not important), functional testing.

Careful design: the programmer must have a clear understanding of the entire structure and logical structure of the code before writing the code, you can only write code at this time. I have not mentioned the document here, but I have mentioned the idea that must be clear. But a clear idea is not something that everyone can create directly in their heads. Many people are ordinary people, there is no way to think clearly about all the problems in your mind, so remember, especially for complicated logic.

Code Writing: for uncertain code, such as a newly designed algorithm, it is best to ensure its correctness. You can test this part separately, which makes the code modular and ensures the correctness of the Code. One sentence: It is relatively simple to ensure the quality of a small amount of code.

Unit test: the importance of unit test is not described in detail. Now there are many tools to help programmers and reduce the workload.

Function Testing: the programmer guarantees the final level of code quality. To do this, we may have to write some code for testing or even testing. Use a large number of cases for testing and incorrect cases. This is different from the tester's test: the programmer's attention is still put within the scope of his own code, reducing the difficulty of troubleshooting.

If you fail to find any problems in your program after the above steps, I think your program should be robust enough. In fact, it must be noted that: code review.
 
As mentioned above, the attitude of programmers towards others' code is picky and learning. Therefore, it is a good way to let other programmers review your code and check whether the program has any logic errors. The team should review the Code. This is a practical experience.

As a good programmer, we must have the above habits and treat our code like a child. We must cherish our code and make the code correct.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.