18 years of development experience sharing (ii) Problem Solving (I)

Source: Internet
Author: User

for The Source, intention, and content positioning of the series, refer to the first section. The link address is as follows:
http://blog.csdn.net/binarytreeex/article/details/8174445
http://www.cnblogs.com/WideUnion/archive/2012/11/12/2766397.html
it is no longer repeated here. The previous article is about the learning topics of Program Members. If you are interested, you can access the following connections:
http://blog.csdn.net/binarytreeex/article/details/8174445
http://www.cnblogs.com/WideUnion/archive/2012/11/12/2766397.html

This article mainly discusses the methods and experiences for solving problems in practical work. When I was in college, my teacher once said that the engineer's responsibility is to solve the problem. No matter how powerful a developer is and how good a developer is at work, nothing can be done if the problem cannot be solved. Therefore, solving practical problems is the core value of a software engineer. The content shared in this article is positioned to be the same as that in the first article. I believe this will be different from the content of most or a considerable part of textbooks and training courses. What I want to share with my colleagues is my experience and experience in practice. These contents mainly focus on solving problems and thinking skills. Therefore, this article cannot solve a very specific problem. For example, you cannot find the answer to how to implement paging query in this article, and how to transmit parameters to the thread. In addition, some common so-called solution methods are not discussed in this article, such as Forum posts, questions from Google, Baidu, and QQ groups, and questions from veterans. Of course, these methods are also useful and even the most commonly used. I will not discuss the reasons for positioning, nor I want to deny the functions and values of these methods. Because the content introduced in this article comes from personal practices, the limitations and one-sidedness are inevitable for a broad topic like solving the problem and all developers. Therefore, we recommend that you make your own choice and make appropriate changes based on your own experience in actual application scenarios so that you can better apply the content described in this article. If the shared content can play a positive role for our colleagues to solve problems in their actual work, then my goal will be achieved. Of course, it would be the best if it could be as easy as Ding Jie Niu.

As the first part of the problem solving article, it is mainly for beginners. I would like to discuss several factors that affect new users in solving actual problems. I have observed these factors in my actual work. In general, the problems encountered by new users are relatively simple, because they generally do not give a difficult problem to new users. Therefore, Newbie problems should not be called problems. Of course I don't mean anything to despise new users, but it's just for the problem itself. Based on this premise, the novice pays attention to improving his work methods. In the final result, it can improve or even significantly improve the ability to solve practical problems. These factors are mainly the following:
1.Not clear or do not know what you are doing
2.Feature implementation is not in place
3.Program debugging failed
The three questions will be discussed in sequence below.

I. I don't know or know what I am doing
One manifestation of poor performance is that it took time to solve the problem, but it was not solved. Of course, there are a variety of reasons for this result, some of which are that the novice chooses a completely wrong method or direction to solve the problem. For the method or direction of choice that cannot solve the problem, new users often do not feel anything at all. The first impression is what they are doing, it is often unclear or even completely unclear. The understanding of the problems to be solved is also a reason. If so, the solution is relatively simple, that is, every time you receive a task or prepare to solve the problem, you need to confirm whether you understand it clearly. But more situations are not caused by understanding the problem itself. What should we do at this time?

First, we need to establish a belief that the problems assigned by superiors to new users are generally simple and easy to solve. So don't be confused. You must have the confidence to win. Next, let's first think about how I plan to solve this problem. Of course, due to the lack of experience and the difference in individual abilities, this kind of thinking may not work very well under considerable circumstances, but I suggest you stick to it, when the number of times exceeds the limit, the capability will gradually increase. The third point is to confirm that all the information needed to solve the problem is clear. New users have never been familiar with things before. This is especially true for project-specific content. Solving a real problem cannot be an isolated problem. The problem to be solved is often related to other existing content. These related content is often not understood by new users. Therefore, new users need to confirm that they have understood the content. Otherwise, they need to ask questions by hand. This is a reasonable question.

Let me give you a simple example. I was asked to directly modify a function on the interface during an interview, which was modified in a real project. When solution is enabled, it finds that there are many projects and N-plus forms, so the first problem to be faced is where to change the location? New users I have seen may do the following:
1.You can find it in the entire solution, and you don't doubt whether you can find it after finding it for N hours.
2.Execute the program, find the main form (which is a progress), and modify it in the main form. It is not considered if it should be changed in the main form. If the content to be modified is not found in the main form, add it and implement this function.
3.If you have not done anything, you may be in a daze. You may want to wait for a while and then wait for a while.
4.The first line you seeCodeStart to read the code and try to understand the logic. The idea is not to understand how to modify the code?
5....

The first point is that the method selection is incorrect. The error is not about finding the form, but about looking for the form after N hours. Suppose you have a letter without an address, but you only need to tell you the content and then ask you to give it to someone who matches the letter content. Then, will you traverse the whole city from the first street badge in the first street of a city in turn? Another problem is that you do not get feedback from your own practice activities to modify your behavior or decision-making. The impression is that you don't know what it means to do what you do, and you don't feel like you can complete the task. The second point is that it is a non-brain-free approach, requiring that you change the program rather than implementing a new function. Whether the position of the Code is correct is not considered. This is completely unaware of what you have done. The third point is relatively bad and should be changed as soon as possible. The fourth point is that there are problems with methods and ideas. A newbie may wish to evaluate his or her reading capability. If he or she thinks that he is strong enough, he or she may try again. Otherwise, he or she should not do so. It can be said that such newcomers have problems with their own abilities. In fact, people with enough reading capability generally do not start reading the process blindly. Basically, what you dare to do this is that the reading capability is poor.

Let me talk about my practice. Of course, I am not saying that this is the standard answer. I just want to introduce an alternative method for your reference. The first step of the modification function is to know which form to modify. The best choice for so many forms is to ask questions. please familiarize yourself with the project and tell me where the form is. The reason is as follows:
1.I don't know about projects. I started to ask questions without knowing anything. Of course, I have roughly read those forms, but I find it difficult to find them.
2.At that time, I was in the hands-on test, and I could not spend a limited amount of time looking for a form.

the second reason is that my example is stronger. Of course, the actual work may be different, so you need to choose different methods based on your specific situation. However, one principle is to use the main energy and time to solve the main contradictions, so as not to be distracted by secondary or tributary issues. I obtained the information required to solve the problem through inquiry, which is the basis for solving the problem. Step 2 is to open the correct form and modify the code as required. Then there is another question: where is the code to be modified, or where should I change the code? Then, can I use the above two reasons to ask another question? In my case, I can no longer ask questions. The reasons are as follows:
the code in the form is not complex and can be solved independently. This fact is only known after reading the code. Therefore, new users can try to solve the problem. The key is to modify their methods in a timely manner based on the feedback from the practice and take the best way to solve the problem. If I did not read the code for the above two reasons and asked another question, the interviewer will know the complexity of the Code, therefore, he may think that my abilities are faulty. Therefore, you must pay attention to the measurement and degree when asking questions. Newcomers can take this example as a reference. Of course, they may encounter different situations, so they should make judgments based on their specific situations. It is unwise to remind new users not to modify the code written by others in real projects without understanding it. If you really want to change it, call a method in the change, write the code you want to write in that method, and write comments and dates for that method and the place where the method is called. The logic is not very complex for the problem I encountered, so I can check the code to confirm the location. At that time, I was a programmer with work experience, but as a computer test question, I still gave a very difficult question. This shows that it will not be too difficult for new users, therefore, we should be confident. Then I modify the code in the relevant location to implement the required functions.

Next comes a new question. How can we execute programs in the face of so many projects? How can I execute the code to be debugged? This is also the information required to solve the problem. Without this information, the program cannot be debugged, and the problem cannot be solved. After the code is changed, the problem can be solved only after the code is debugged. As mentioned above, we can add another Quantitative Scale for implementation in practice. It takes 30 minutes to modify the code. In principle, the time for solving the secondary problem should be less than or far less than this time. In my example, if it takes 30 minutes to execute the program, the method is incorrect. Therefore, do not spend too much time on secondary conflicts, and do not waste time. It may take one hour for you to find the target instance. The person you know tells you that it takes only a few seconds. In addition, you should be aware that new users should be accustomed to asking questions and dare to ask questions in similar cases. However, you must remember to ask questions of the same or similar type. My solution to this issue is as follows: I checked the project where the form is located and found that the project was not started by default. Therefore, set this project to start by default. Note that the solution settings are modified at this time. It is best to remember which of the original startup projects are to be changed back. Then execute the project. The result is that the program throws an exception and cannot be executed, indicating that the initialization failed.

This is the fourth problem. Should I try to solve this problem or directly ask a question? In my example, I directly ask a question for the following reasons:
1.Resolving initialization failure is beyond the scope of the exam
2.I don't know about that project, but the logic in Initialization is complicated and uncertain, so can it be within the time specified by the test? (in fact, the time is not clearly specified, but generally, there is an acceptable scope subjectively.) The completion is uncertain.
3.Let's take a look at the cause of initialization failure. Let's take a look at the problem that I still have the ability and time to solve the initialization and throwing exceptions. Can I fix the bug? My answer is: no. Because I am not an employee of the company, I should not modify the code that does not require me to change.

The third reason is the strongest in this case. New users can flexibly determine their decisions based on their specific circumstances in the company. So I changed the default startup project back, and asked me to tell me how to execute the modified Code. After obtaining the information related to solving the problem, the debugging will soon be completed, and the computer pen questions will be successfully completed. Because it was modified in a real project, a detail is the location of the code I modified and the new method when I leave.

A newbie can understand when to ask questions and how to solve the problems and how to solve them. I believe that there will be more or less developers who have years of work. If this problem is extended, its application can be expanded to identify the main contradiction of the problem, and then it can be applied to solve more complex problems.

2. function implementation is not in place
Lack of experience and lack of business knowledge is the main reason why I have observed that the functions of new users are not in place. Of course, this kind of problem is also normal, and it is not a serious problem or fault. Simply put it up and avoid it at work. The following lists the following situations:

A. If the user registration function is required and no specific requirements are provided, it is required that the user enter the password again. The current usage habits do not clearly inform or do not do, and the programmer can be understood as the function implementation is not in place without actually doing it.
B. Whether the size, color, and font of the controls on the form interface are consistent with those of existing controls. For example, if the size of the existing button controls on the form is the same, you should pay attention to the fact that the newly added button is a little larger or smaller.
C. Whether the operation habits are consistent. For example, whether the widget content is filled together, whether the mouse is moved to the control, whether there is a selected effect, and the error information display position.
D. Encoding style, whether the annotation writing format is consistent, and so on.

Here is another example I encountered in my actual work. A newbie completes a user logon interface and its logic. However, if you fail to log on successfully due to your password or other reasons, the logon interface cannot be closed and you cannot perform other operations, such as exiting the software. This is a real case, and the new employee refused to modify it after I proposed something imperfect. In the end, I used the example of a dark logon to the war network that I played together to help him understand the functional defects. The logon function is implemented on the subject and the test is passed. This is no problem. However, there is a problem that the login cannot be exited. This means that the function implementation is not in place or is incomplete. In actual development, this is basically equivalent to the incomplete function.

Another reason for inadequate functionality is lack of quality awareness and product awareness. I have made this mistake. This problem occurs when I work in an outsourcing company. It was the first time that a user could directly operate on a software product. Previous ideas always focus on the implementation of functions, while ignoring the Notes mentioned above, so the modules I developed did not pass the test. Note: At that time, I had six years of development experience and elevation certificate, and I was definitely not a newbie. I would like to emphasize that new users should pay attention to it.

3. program debugging failure
As a whole, the program is a hurdle for new users. Smooth program debugging is an important indicator that developers can work independently. When I think back to my learning C language, I still had a hard time. First, let's talk about compilation errors, mainly including syntax errors and Link errors.

For syntax errors during compilation, you can choose to solve the preceding errors first. This is because the compiler may check the syntax errors of the Code, which may lead to subsequent errors. At this time, it is unwise to try to solve the subsequent syntax errors, and the difficulty is relatively higher. Therefore, we recommend that you start from the first or first when resolving syntax errors. Another policy is to solve easy syntax errors first. Sometimes there are many syntax errors, which are annoying to look at. In this case, you can first solve simple and obvious errors. For example, if you see a piece of code in the book and want to give it a try, you can knock the code in and compile it. At this time, there are many syntax errors, so you can solve the errors such as undefined Identifiers (the cause of this error may be a mistake in the Code. In this way, we can gradually reduce the number of errors, so that our attention can be better focused on difficult errors. In general, it is easier to troubleshoot syntax errors. Currently, popular development tools provide more and more support for syntax error troubleshooting. Therefore, it is recommended that you use your own capabilities to completely troubleshoot syntax errors.

Compared with syntax errors, it is more difficult to troubleshoot Link errors during compilation. In C or C ++ compilers, the frequent cause of Link errors is that the necessary library files are not referenced in the project. When a link error occurs, make sure that,Source codeNo problem. Because the code is compiled and generated only through lexical and syntax checks, it is unlikely that a link error occurs in the Code itself. This clue tells us that we should not find the source code to solve the problem. Note that for errors during compilation, you must check the error information, clarify what the error message is, and then troubleshoot the error. Remember. In many cases, the error message directly gives the answer. I encountered a problem when developing entitymodelstudio. I referenced the DLL of another project in one project, but due to operation problems, the actually referenced DLL is a different version of the same name DLL file in another location. The consequence is that there are no problems with the DLL project debugging, but it is always wrong in debugging after reference. A newbie can understand that the actual problem is not playing according to the rules.

In addition to compilation errors, the other type is the so-called logical errors. This is the focus of developers to debug programs. In fact, on many occasions, hundreds of errors are excluded within three hours. Therefore, it is the core issue to exclude logical errors that cannot implement specified functions. The specific manifestation of a logical error is that the execution result of the program fails to meet the expected results, or it only partially meets the requirements rather than fully meets the requirements. Of course, there are various reasons for this result, which may be the choice.AlgorithmIf there is a problem, the called method is incorrect, and so on. For this question, I suggest you master the basic skills of the debugging program, that is, to view the breakpoint settings and variable values.

Breakpoint settings can be set from the beginning of the Method for Finding the error location, or a place that must be before the error location. When the program stops at the breakpoint, press F10 (step over) track code step by step. When you find that the result is incorrect after executing a line of code, you need to check this line of code. If it is a single code, modify the code according to the error result. If it is a method call, it will enter the internal content of this method (according to F11, step ), use the same method to continue tracking. This method can gradually approach the wrong position. Sometimes, in order to improve the efficiency of tracking code, you can set breakpoints at some key points to view program execution conditions when you are familiar with errors and code. It sounds simple, but some new users make such a mistake. The F11 and F10 functions are clear, but when the result is incorrect after the method is called, you do not know that you want to enter the method to continue tracking the code. This reminds new users that F11 and F10 are used in turn until they locate the final error. If you only use this method to locate and eliminate errors, such errors are easier and the most likely case. The following describes a little difficult information.

Sometimes we may need to write a little bit of code (this code is not a test code) to help set the debugging method with breakpoints. For example, the error location is in a circular body. If we simply set a breakpoint in the loop body, the first time the cyclic execution is stopped at the breakpoint, and then start the single-step tracking. At this time, there will be a problem. How many times does this loop need to be tracked before it can wait until there is an error loop? If it was the first time, or the last few times, it would be okay. If it was 100 times, 200 times, or more times, it would be troublesome. In this case, you need to write some code to assist debugging. If the loop is a for loop, write the code similar to the following in the proper position of the loop body:

For (INT I = 0;...; I ++)
{
// The code to be debugged already exists. Assume there are several lines.
...
// This If statement is the debugging code to be added
If (I = 100)
{
Int A = 10; // the breakpoint is set in this line of code.
}
// The code to be debugged already exists. Assume there are several lines.
...
}
The result of code debugging is that the program stops at the breakpoint when the cycle reaches 101st. This can significantly improve the debugging efficiency. In other cases, the program we debug is related to Windows messages. In this case, it is troublesome to set the position and timing of the breakpoint. For example, when you need to set the breakpoint to a mouse event or an onpaint event, this will happen. If this parameter is set directly, the program stops every time the mouse event or onpaint event is triggered. At this time, it is far from the time when the error occurs. In this case, you can choose not to set the breakpoint, and then set the breakpoint before the last step. For example, you need to display user input data in the customer zone in the onpaint event. You can execute a line of code to refresh the customer zone at the right position (for the C # form, invalidate, or MFC, you can also consider sending messages ), the breakpoint is first set on the refreshed code. When the execution of the program stops at that line of code, set the breakpoint in the onpaint method, and then press F5, so that the breakpoint in onpaint can directly stop at the time we need. Another alternative solution is to take out the code in onpaint and put it in the Click Event of the button if possible, so that debugging can avoid the original troubles. The general idea is to add the debugging code to the program, which is generally an if statement. The condition of this statement indicates the time when you want the program to stop and track in a single step, and then set the breakpoint to the code inside the if statement.

In some cases, you can consider using the console to output information. Of course, you can also choose to write files for the same purpose, but for the Visual Studio development environment, the console output is more convenient for debugging programs. Write some code that outputs information to the console at a specific position of the program. in C #, I use the writeline method of the console class or the same name method of the debug class. In this way, the execution of the program will not be interrupted, and the necessary information can be seen at the same time. This is a good advantage. When debugging, if you find it difficult and the error location cannot be determined, I suggest you adopt a step-by-step solution. First, implement the simplest situation, then debug and pass, and then implement the next situation, and then debug and pass. If possible, I would like to emphasize that it is best to achieve independence step by step. For example, the code can be separated by an obvious if else statement or switch statement branch, or the code can be placed in different methods. In this way, when debugging a program, we can focus on only one situation at a time, and the code that handles different situations does not interfere with each other visually at least, which is helpful for us to solve the problem. This method is very effective in many cases. If you use it well, you can simplify the problem. This method is used when developing the Sequence Graph of entitymodelstudio. what is different is that the classification counting of various operation behaviors of the sequence graph is a bit difficult for beginners.

4. Two useful techniques
I will introduce two more techniques that I think are useful, that is, the comparison method and key point search. This is my experience in the first year of my work in the maintenance of Home Appliances. I found that it is also useful in software development. The comparison method is to have a piece of code (or example) in hand to implement the required functions, and now we need to implement the same functions, then we can compare the example to implement the required functions. It sounds very simple. In fact, the expression of this method is indeed very simple. Maybe some people think this is different from Google or Baidu's copy/paste? It should be said that copy/paste will be used. This is the same, but the idea is different. This is the difference. I used a post I saw on csdn a few days ago as an example.

The post contains the following code (not the original text, but the meaning is the same ):
Public class myclass
{
Int age {Get; set ;}
}

The question in the post is: assign a value to the age attribute of the myclass object and an error is prompted. This is of course a beginner's problem. Simply add the public modifier to solve the problem. Next, we will use the comparison method to solve the problem.

The problem is that the attribute cannot be accessed through the object, but the fact is that it should be accessible, so we should try to find an example, which can access the attribute through the object. In this example, it is easy to find the internet, and then compare the difference, it should soon be found that the difference is a public, add it. And copy/paste
Still close. But sometimes this example cannot be found. What should I do? Then we can try to solve the problem by comparing other content. For example, the problem is that the attribute cannot be accessed through an object. Can the attribute be accessed through an object? If you find an example of a method that can be accessed through an object, you can consider modifying attributes by calling the method example. This is the difference in thinking skills and requires flexible application of methods. What should I do if I cannot access the Internet because it is more difficult? You can use the existing code in the current project as an example. This problem is difficult to say, but the steps for thinking should be a bit challenging for new users. From the perspective of problem solving skills, if a newbie can have such ideas, then I think this newbie is talented. Hope new users can understand it. Different techniques use the comparison method to solve more difficult problems in more complex situations. This part is discussed in the next article.

In my personal experience, when a newbie learns to develop or start a new development direction for a developer, it is typical to use a new language, you may encounter problems that cannot be explained by common sense. For example, my first Windows program. I used a short time to knock 30 lines of code into the computer, but it took almost eight days for the debugging to pass. The reason for this Hello World Program is that the project name is incorrect. I use ABC and change it to AAA. This type of problem has also been encountered in subsequent development experiences, but the overall problem is getting fewer and fewer, and the time required to solve the problem is getting shorter and shorter. But their common feature is that they cannot be explained by common sense or disappear without any reason. When encountering such problems, first make sure that the current project is simple enough. If there is not enough simple project, consider creating a new one. Then you can try to gradually comment out the code to find out the cause of the problem. Alternatively, you can construct a program that is simple enough to debug, and then modify the program step by step to approach the target. If any problem occurs during this process, the problem lies in that step. Of course, it is best to back up each step. In general, this method also belongs to the scope of the comparative method.

The so-called key point search means that the program execution is sequential in time, and the actual code is also sequential in general. Once a program encounters a problem, we can divide the program into two parts: the one before the problem and the one after the problem. If the result we see is correct, the problem point should be in the Code executed after the current time point. Note that I am talking about the order of time points, it is not a sequence in the physical location of the source code. So we should look for the code and set the breakpoint at the right position. The F10 and F11 mentioned above are also specific manifestations of this meaning. I want to emphasize this idea again. I hope that this thinking technique can help beginners straighten out their ideas when they encounter problems and are confused, rather than simply viewing the role of F10 and F11 as the function corresponding to the two buttons.

4. suggestions for new users
Well, this blog is roughly written here. It seems that there may be a lot of content for new users. I believe these methods and techniques will be helpful for beginners. However, the application of any method requires a step-by-step process, just like human growth. Therefore, new users cannot stick to the mentality of stuttering into a fat man. It is the right way to improve and make progress in practice. In addition, you must have confidence in yourself. In fact, new users still have many advantages, such as fast learning, strong adaptability, enthusiasm for doing everything or willingness to do anything, and an impact on difficulties. Therefore, in the face of lack of experience and poor abilities (poor words may be difficult to use), you do not need to worry or affect your mood. In short, we can do our best. Today is better than yesterday, and this is better than last time.

5. Question and Answer
Finally, I will explain a question in the study. I mentioned in this article that it is best to read a book in 20 to 40 minutes. If it is difficult to ask a question, Let's explain it here. First, I know two quick reading skills. The first is the Orthodox fast reading method. It is said that Stalin can use this method to read a five hundred-page book within four hours. The usual reading method is to read a word at the point with the most clear vision. The quick reading method requires the reader to read a word at a time with the eyes, for example, three or seven. This is three or seven times faster than the common reading method. This method requires practice. The second method is actually a technique. That is, to read only the first and last sentences of each paragraph, this method is said to be able to get 10% of the information in 50% of the time. I have not tried this technique, so it is unclear how it works. Second, when reading a computer book, you can scan text in sight. This is not a quick reading, which is much faster than quick reading. Then, use the line of sight to filter out sensitive words and find the key words. If you are interested or do not understand the words, stop and take a look. In addition, existing development experience is also crucial. For example, when I read the ADO database development book, I directly used the example code in the line-of-sight scanning book, and read the initialization of ADO. Then I followed the steps and method names. The reason is that before that, I used the development experience of C ++ using ODBC. In addition, it should be noted that this method may not be suitable for new users, because the novice has little experience and the ability to debug the program is limited. A newbie cannot understand the code, so it is necessary for a newbie to try the code on the machine. However, the veteran does not need to use it. With sufficient development experience, this type of entry-level examples can be easily tuned. Therefore, development experience is also useful in reading books. Another issue that needs to be clarified is that the text in this series has nothing to do with any training institution. If you have other questions or want to communicate, join our group: 231233168.

The next article is about solving the problem, but the difficulty will increase a lot. The question should be about solving the problem (below ). This is intended for developers with certain development 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: 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.