Programmers do not practice it in a day, but following some programming ideas can reduce us from detours.
Today, I read "Linux Device Drivers" and mentioned programming ideas in Chapter 1. I have done many development projects. Because I am not a company developed by a large team, such as Huawei or some foreign companies, many projects have very few employees and basically need to be independently responsible. In retrospect, I have made great progress in the system design structure. However, there has been no serious conclusion. At that time, I read Thinking in JAVA, and the preface was well written, that is, it involves programming ideas. What can I talk about in detail, but I cannot think of it now. So I want to record what I see or think.
I remember that there was a large project in the past year, and the applications provided by JAVA had never been able to break through in terms of performance. I tried and tested more than N, and it was useless to split threads, finally, I think it is the limitation of JAVA VM and can only be bypassed. I used the multi-process method. Of course, there are no threads in the process. I simulated the working mode of multiple boards and the process can run on the local machine or other machines, although java vm has restrictions on a single process, the efficiency of multiple processes can increase linearly. I used the module method to modify my system. At first, I felt that the workload would be huge but it was really good to organize it. Because the functional modules are completely and independent, you just need to change the architecture and the vest.
I think testing is very important for developers. Although sometimes the company may have dedicated testers, it is very important for developers to control themselves and write test tools. Although the test tool is only auxiliary, for example, a SIP process applet I wrote may set the process method according to the script and add the parameter header of the SIP message, at first, it was just a lack of debugging and compilation. Later, this program became an important debugging tool to simulate various environments, including abnormal processes. There was also a small program for Performance Testing I wrote myself. Later, a project was very urgent and the cooperation team had been working on it for a long time. The larger the capacity, the more urgent the problem was, A problem is found. Later, there was no way. After a few days of the night, I took the test Applet as the main body and finally became a large program.
Return to the topic. Today's topic: whether to provide "mechanic" or "policy ".
This is the key to system design, including OS. The problem solved by "Mechanics" is: what functions are provided, and "policy" solves the problem of how these functions are used. These two parts should be placed at least in different places of the program, or in different program modules. In this way, the software package is easy to develop and can meet specific needs. We can also separate the function provision from the actual (specific) applications. Policy-free is required for the function.
In another case, our program needs to use macro definition # ifdef xxxx to shield OS differences. This difference includes the common code for linux and windows, as well as the differences between different OS versions. The Code related to this can be regarded as low-level in the program, while the Code of the high-level part calls the low-level function without considering the differences between versions or platforms. When writing code, we should differentiate them so that the program is not only easy to understand, easy to maintain, but also better scalability and adaptability.
Related links:
My articles related to programming ideas