Program debugging capability and recommendation books

Source: Internet
Author: User
In the software industry, I personally think that every Coder and leader (except for those who do not need code after leader) should have good coding capabilities, the most important thing is that the debug capability should be solid. Do not tell me that debugging is a task of tester and QA. First of all, you must realize that debugging is not simple. It can help you improve your development capabilities and speed up development, it saves development costs. Second, you should know that the debug capabilities and technologies you have mastered are not likely to compete for Tester or QA jobs. They are more careful and comprehensive in their work, more creative. Because vc6 has been used for the past few years, the following points of view and related descriptions are based on VC, which must be biased and incorrect. I hope you will not hesitate to point out that, I agree to accept, discuss, learn, and make progress together. I personally think the debug capability includes the following three aspects:
1. Good coding habits, good logic structure capabilities, and the ability to predict bugs. A mature programmer should have a good programming habit, not only need to have a good coding format specification, but also need a good structure for the logic implementation in the program. Programming is actually a collection of data and logic. Data Processing is relatively simple, or requires less logical thinking capabilities. When algorithm logic is implemented on data, the same logic is used, different programmers may have different implementation structures. From this perspective, the "good coding habits" mentioned here should refer to the good programming structure used for logic implementation. A good programming structure should be able to prevent errors, make good arrangements for handling errors and handling exceptions after they are foreseen and reported. Maybe someone says this is not easy? Is it okay to add condition judgment or exception handling to each logical judgment? I personally think this is not the case. Too many if, assert, assert, and other statements or macros, especially the parallel if statements, require a lot of time for judgment and execution, for a sub-Program (function), especially a subprogram (function) that is frequently called, a little time is wasted at a time. When multiple and frequent calls are wasted, it is quite impressive, therefore, if statements are not used much, and the possibility of program errors is small! If you really need to use multiple if statements for conditional judgment, it is best to use nested if statements to gradually narrow the judgment scope, which consumes less time than the parallel if statement, it should also be noted that the condition judgment of the IF statement is not omnipotent, and the judgment of macros such as assert and assert is not omnipotent, it may cause differences between the response speed and the final compilation result of the debug and release versions. The impact on some programs that focus on performance and response speed cannot be ignored. However, in the debugging phase of the development process, we advocate the use of these macros to identify algorithm errors and deficiencies. In addition, for the use of exception handling segments, do not use exception handling wherever possible, an exception is used only when the program cannot be executed or crashed after an error occurs. Sometimes, you can use exception handling to continue executing the program with an error, however, the possible final results are not what the customer needs or expects, so that it is easy for the customer to question: Are you doing anything in the program? This also causes you to lose the prerequisite information for a bug and thus the chance to modify the bug. So sometimes, when a program error occurs, only a MessageBox pops up to prompt some information, closing the program is also a good way.
2. debugging tracking and error locating capabilities during coding. This capability is mainly used in the development process. When you build a program and run it, a bug or a memory leak occurs. At this time, you need to use various tools for debugging and tracking. First of all, you need to believe that VC is not only a good ide, but also a good debug tool. Its call stack, conditional breakpoint, data breakpoint, disassembly and other tools are powerful enough, enough to deal with common bugs, but now many programmers, including those who claim to be old programmers, may not be able to use these tools well, in particular, conditional breakpoints and data breakpoints (detailed instructions are provided in the second book described below ). When VC cannot meet your requirements, you need to use other tools, such as smartchecker, boundchecker, purify, SoftICE and so on. From this perspective, the "debugging tracking capability" here is not only the programmer's ability to locate bugs, but also the ability to master and use debugging tools. "Never cut firewood by mistake". Before development or development, you should study some development and debugging tools as a good way to improve this ability. It is better to calm down and think about the working principles of these tools. This will not only help you predict bugs during programming, it will also help you improve your programming skills. For example, why can an array access out of bounds be found in a program in VC in debug mode? This is because in debug mode, when allocating the memory occupied by the array, the compiler adds a byte of out-of-bounds memory at both ends of the Array Memory. This is why many MFC programs have no errors in debug mode while using custom messages, but errors in release mode. Here I also want to talk about the two debugging methods I like most: When a bug occurs, first determine the location of the bug, and then: A. comment out the paragraphs that may cause the bug, provide a reasonable value directly where the data value needs to be obtained, and then check whether the program can run correctly. In this way, we gradually narrow down the scope and finally find out the bug; b. If the bug is located in a small function, subroutine, or function, you can create a test project in a completely "clean" environment, this function, subroutine, or function is tested to locate the bug. What I want to talk about at the end of this section is to use your network. When a bug occurs, you may feel confused or confused. At this time, you can use your network resources and use powerful search engines (such as Google and Baidu ), enter the relevant error message. You may find a webpage with a similar problem. Maybe someone else has encountered the same or similar problem. The answer provided by others is what you need, or, it can give you tips and inspiration!
3. Good awareness of post-event bugs. When a bug occurs, a good programmer can follow the premise of the bug and the time point when the bug occurs, and the position in the program, it is good to know which function or function of which the bug may occur, what causes the bug, and can quickly locate the error and fix it. This capability is often used when the program has been release and used by the customer. A bug occurs during use and the customer "Talks" to you. So how can we have such capabilities? Maybe a lot of such capabilities are accumulated after you have been down for n times by the manager, therefore, this is also a kind of ability to get happiness after suffering, it requires you to have a good understanding and understanding of the structure, operating conditions, operating principles, and related components of your software products. Sometimes you can gain some benefits by looking at others' experiences on the website.
Among the above three abilities, the first is attitude and thinking, while the last two tend to be learning and experience accumulation. I think the first is the most important, the so-called attitude determines everything.
Finally, I recommend several books about debugging:
1. Writing clean code -- Microsoft techniques for developing bug-free C Programs -- This is a book that has been published for a long time and may not be seen in the bookstore now, but you have to trust Steve Maguire, author of this book (formerly a senior Microsoft programmer, participated in the Development and porting of Excel on multiple platforms. Many error prevention, troubleshooting, and testing principles provided by Excel can still benefit from this. The author combines the main points of each chapter with his actual work experience and provides detailed examples and related code. The language used is even more humorous, which makes it hard to read and understand, in particular, the exercises and questions provided at the end of each chapter are more practical and thought-provoking. That is why this book has always been widely discussed and loved by a wide range of programs. So far, we have not seen any books comparable to this. The "High Quality C ++ programming guide" and "software engineering ideas" by Dr. Lin Rui circulated on the Internet are inferior in depth and breadth!
2. debugging Windows programs (Chinese Version translated as windows program debugging, published by China Power Publishing House)-a popular book in bookstores. The language used in this book is relatively simple and easy to understand. It may be the result of the translator's careful handling. The narration habits are more in line with Chinese tastes. This book consists of three parts: Debugging strategy, debugging tool, and debugging technology. This book mainly introduces some of the technologies necessary to develop programs under the IDE and compiler of VC. After reading this book, you will certainly have a better understanding of MFC, the differences and connections between structured exceptions and C ++ exceptions, how to debug multi-threaded programs, how to debug com programs, and how to debug memory, how to debug the drawing program. Whether you are a developer who thinks you have many years of development experience or a beginner, I believe that as long as you read this book patiently, you will feel the same deep sigh as me: the original VC debugging function is so powerful! It would be nice to see this book early!
3. debugging applications (I have not yet seen the Chinese version)-This book mainly introduces debugging of VC and VB, of which VC debugging accounts for about 70%-80%. This book is also divided into three parts: the form of debug, powerful debugging, debugging tools and technology. Some of the content is the same as what was mentioned in the previous book. However, this book provides many new things: it introduces remote debugging, provides some examples of new tools, and introduces more underlying things, it even involves reading and understanding compilation-related information. After reading the previous book, if you want to improve it, this book is a good choice for you.
The first book is mainly to cultivate the first debug capability. The last two books are to cultivate the second debug capability, and the third is to rely on experience accumulation.
On the premise that these books will be helpful to your development process, what I want to say is that even if you read these books, you won't write programs with no bugs, after all, there are many objective and subjective factors in the types and situations of bugs that cannot be completely eliminated. Program Design is a very practical job. Only by summing up lessons in the work and practice processes and summing up experience can we continuously improve. I wish you all the best in your knowledge and experience !!!

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: 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.