1. Introduction
Machine Computer Science is an applied sciences, its knowledge system is a typical inverted triangular structure, the basic knowledge used is not much, but with the application of the field and the direction of the different, produced a lot of branches, so that programming is not a very difficult thing, a high school student after a specific training can be achieved. However, will be programmed and the process is absolutely different, the same programmer, some people become architects after a few years, some people are still coding, but ctrl-c, ctrl-v used more skillful. In China, programmers end up with no more than two: one is to turn to technology management, the end of which is the CTO, and the second is to continue in depth, its end is the chief architect, the person who becomes CEO is a minority. If you are still a normal programmer, and want to continue on the path of technology, I think you should first add a little bit of software engineering ideas, learn a little about design patterns, only with these capabilities, you can from the overall and macro level to consider problems, analysis and solve problems. I coding for many years, in the middle of a lot of detours, although ultimately there is no big achievement, but finally some experience, very willing to take some of their experiences to share with you, this may be helpful for your development. From programmer to architect, the most inseparable concept is object-oriented (OO). I remember when I was in college, we started a course called "Object-oriented Programming". At that time, we just learned a C language, development environment with or DOS under the Turbo C, the slightest experience of project development has no, pure air-to-air. So, a semester down, I am always in a state of ignorance, neither understand the process and object-oriented exactly what the difference, and do not understand the benefits of object-oriented can bring.
2. Process-oriented (OP) and object-oriented (OO)
2.1 Egg and rice bowls
Some people describe the difference between op and oo: a process-oriented procedure is an egg fried rice, and a program written with an object-oriented approach is a cover-pouring meal. The so-called Rice Bowl, Beijing called, the northeast is called risotto, Guangdong called dish Head rice, is in a bowl of white rice topped with a covered dish, you like what dishes, you will be poured on what vegetables. I think this analogy is still more appropriate.
The details of egg fried rice production, I am not very clear, because I have not been a chef, also can not cook, but the final process must be the rice and eggs mixed together fry evenly. Rice bowls, it is to make a good meal and covered dish, if you want a fried pork bowl, you will be watered a portion of pork, if you want a green pepper potatoes to pour rice, pour a green pepper potato wire.
The advantage of egg fried rice is that it tastes evenly and tastes delicious. If you do not love to eat eggs, only love to eat vegetables, then the only way is to all pour out, re-make a vegetable fried rice. Cover the rice will not be so much trouble, you just need to put the above covered dish, replace a covered dish on it. The disadvantage of pouring rice is tasty, may not have egg fried rice so fragrant.
is egg fried rice good or is it good? In fact, this kind of problem is very difficult to answer, not to be higher and lower than the words, you must set a scene, otherwise it can only be said to have strengths. If everyone is not gourmet, not so much attention, then from the restaurant point of view, do rice bowls is obviously more advantageous than the eggs, he can be combined out any number of combinations, and will not be wasted.
2.2 Software Engineering
The advantage of pouring rice is that the "vegetable" and "rice" are separated, thus improving the flexibility of making bowls. Food is not satisfied with the meal, food is not satisfied with the change of food. The professional term of software engineering is "maintainability" is better, "rice" and "vegetable" coupling degree is relatively low. Egg Fried rice will "egg" "rice" mixed together, want to change "egg" "rice" in any one is very difficult, coupling is very high, so that "maintainability" is relatively poor. One of the goals of software engineering is maintainability, which is mainly manifested in 3 aspects: comprehensible, testability and modifiable. The main benefit of object-oriented is that it significantly improves the maintainability of the software.
is process-oriented (OP) and object-oriented (OO) just two ways of coding? No! You get a user needs, such as someone to ask you to make a software, you need to go through the demand analysis, and then the overall/detailed design, the final code, in order to finally write software, pay the user. This process is in line with the basic human behavior: What to do first, how to do it, and finally to do things. Some students said: "I did not follow the steps you said, I was directly encoded." In fact, you will experience these three stages, but your subconscious is not so clearly divided. For the people who get the demand, may make up, and have to go back to re-pondering, or inevitably these processes,
Oo as an example, corresponding to the process of software development, OO derived 3 concepts: OOA, Ood and OOP. The method of object-oriented analysis is called OOA, and the method of object-oriented design is called Ood, which is called oop by object-oriented encoding. The difference between the process-oriented (OP) and the object-oriented (OO) nature lies in the different ways of analysis, which ultimately leads to different coding methods.
2.3 Process-oriented (OP) and object-oriented (OO)
about process-oriented programming (OPP) and object-oriented programming (OOP), there are a lot of people who give this definition, you can find a professional explanation from any material, but in my experience, speaking relatively dull, not very intuitive. Unless you've accumulated quite a bit, it's still hard to say. I'm an old programmer, and although today's routine is more inclined to manage, it still keeps coding habits, what does that mean? I should have no problem communicating with you. Whether you are repeating the way I have traveled, or have already walked in front of me, we all will have such a part of the same experience, will have an understanding of the ideological level and tacit agreement, so I will try to follow the majority of the conventional thinking of writing down. Process-oriented programming (OPP) is produced before object-oriented programming (OOP), so object-oriented programming (OOP) must inherit some of the advantages of the former, and discard some of the former shortcomings, which is in line with the natural law of human progress. Both in their respective development and evolution process, will certainly be mutual reference, mutual integration, to absorb each other's merits, thus appearing in some aspects of convergence, these are the inevitable result. Even if they have more similarities, they will not change their nature, because their starting point is entirely two different ways of thinking. On the relationship between the two, my point is this: object-oriented Programming (OOP) is necessarily process-oriented (OP), process-oriented programming (OPP) in the whole should draw on the idea of object-oriented (OO). This paragraph is really empty, and there will certainly be controversy, but I urge you to read the following content, then to judge my point of view is correct or not. like C + +, C #, Java, etc. are object-oriented language, c,php (for the time being, because PHP4 support OO) are process-oriented language, then is not I write in C + + program must be object-oriented, The program written in C must be process oriented? This view is obviously not really thoroughly understand the difference between the two. Language is always a tool, and each of the predecessors creates a language that is the weapon you use to realize your ideas. I think a lot of people write code in C#,java, and if you look at it, it's actually a process-oriented (OP) program written in object-oriented (OO) language. So, even if you give Guan Yu a stick, give you a blue Dragon Yan Yue Dao, he can still play you full head is a bag. You are carrying a moon sword, also can not become Guan Yu, because you lack the essence of Guan Yu's most essential thing---the peerless martial Arts. The same truth, if you don't understand Oo thought, how can you write a realOO program? Object-oriented (OO) and process-oriented (OP) are definitely two different ways of thinking. is that a process-oriented thing, or is it not necessary to exist? I have never said that. In fact, process-oriented programming (OPP) has been around for decades, and many people are still using it. Its advantage is that the logic is not complex circumstances are easy to understand, and operating efficiency is much higher than the object-oriented (OO) programming. Therefore, process-oriented programming (OPP) is still used in system-level applications or quasi-real-time systems. Of course, many programmers and master-level characters, because of the overall control of the system is very strong, but also like the use of process-oriented programming (OPP), such as Apache,qmail,postfix,ice and so on these more classic systems are the product of OPP. Such scripting languages as PHP, mainly for web development, for some relatively simple business logic systems, but also often use process-oriented programming (OPP), which is why PHP can not step into enterprise application development, one of the reasons, However, PHP5 has been able to support OO very well now.
2.4 Detailed process-oriented programming (OPP)
Before object-oriented, we adopted the development method of process-oriented programming (OPP). One of the most commonly used analytical methods in process-oriented programming is "functional decomposition". We will break down the requirements of the user into modules, then decompose the modules into large functions, and then break down the large functions into small functions, the whole requirement is in this way, the final decomposition into a single function. This way of solving the problem is called "Top down", the principle is "the whole after the local", "first big after small", also some people like to use "from the bottom Up" analysis method, first solve the local difficulties, gradually expand, and finally combined out the entire program. In fact, these two ways coinage, ultimately can solve the problem, but generally the use of "top-down" approach is more common, because this way is the most easy to see the nature of the problem. Let me give you an example of process-oriented programming: User requirements: The boss asked me to write a general-purpose calculator. The end user is the boss, I as a programmer, the task is to write a calculator program. OK, very simple, the following is done in C language Calculator: Assume that the program's file name is: MAIN.C. int main (int argc, char *argv[]) {//variable initialization
int nnum1,nnum2;
Char COPR;
int nresult;
NNUM1 = nNum2 = 0;
COPR = 0;
Nresult = 0; Input data
printf ("Please input the first number:\r\n");
scanf ("%d", &nnum1);
printf ("Please input the operator:\r\n");
scanf ("%s", &COPR);
printf ("Please input the second number:\r\n");
scanf ("%d", &nnum2); Calculation results
if (COPR = = ' + ') {
Nresult = NNum1 + nNum2;
}else if (cOpr = = '-') {
Nresult = nnum1-nnum2;
}else{
printf ("Unknown operator!");
return-1;
}//Output result
printf ("The result is%d!", nresult);
return 0;
} Throw away the details do not say, I think most people will almost all realize it, very clear, very simple, fully embodies the "simple is the United States" principle, process-oriented programming is so organized in order to gradually realize user needs. Anyone who has done the procedure knows that the user's demand is never stable, at most only can be "relatively stable." Users may be at any time to add a function, reduce the requirements of a function, may also require changes in the process, the most annoying of programmers is the frequent changes in demand, especially the program has been written more than half, but this situation is always unavoidable, and can not be fully blame to the customer or demand analyst. Using the code above, for example, the user might ask a similar request:
First, you implement "addition" and "subtraction" in your program, and I want it to also calculate "multiplication" and "division".
Second, your current HMI is too simple, I also want a Windows Calculator interface or Mac Calculator interface. I have to figure out how to write this code as the user needs start to get more. I added today "multiply" "divide" the operation, tomorrow discouragement again let me add a "square", "cubic" operation, this if all the computation is exhausted, how also must write a Qianbabai line code bar. Also, users require the interface can be replaced, but also to write a lot of interface generated code, and a Qianbabai line. Later, so many code heap together, how to maintain, find a variable to half a day, read the code to be half a day, in case of careless change wrong, still have to adjust half a day. In addition, the interface design I am not good at, have to find a more professional people to do, after the finished and then add in it. This process is the process of "software crisis". With the software widely used in various fields, software development has become more and more large, the complexity is more and more high, and its user needs more and more unstable. According to the user's two requirements, the process-oriented programming how to deal with it? I think we all know how to change it. Very easy, the "compute" and "interface" are divided into two separate functions, encapsulated in different files.
Assume that the program's file name is: MAIN.C. #include "interface.h"
#include "calculate.h"
int main (int argc, char *argv[]) {//variable initialization
int nnum1,nnum2;
Char COPR;
int nresult;
NNUM1 = nNum2 = 0;
COPR = 0;
Nresult = 0; Input data
if (getparameters (&nnum1,&nnum2,&copr) = =-1)
return-1; Calculation results
if (Calcmachine (nnum1,nnum2,copr,&nresult) = =-1)
return-1; Output results
printf ("The result is%d!", nresult); return 0;
} interface.h:
int getparameters (int *nnum1,int * Nnum2,char *copr); interface.c:
int getparameters (int *nnum1,int * Nnum2,char *copr) {
printf ("Please input the first number:\r\n");
scanf ("%d", nNum1);
printf ("Please input the operator:\r\n");
scanf ("%s", COPR);
printf ("Please input the second number:\r\n");
scanf ("%d", nNum2); return 0;
}calculate.h:
int calcmachine (int nnum1,int nnum2,char cOpr, int *nresult); CALCULATE.C:
int calcmachine (int nnum1,int Nnum2,char copr,int *nresult) {
if (COPR = = ' + ') {
*nresult = NNum1 + nNum2;
}else if (cOpr = = '-') {
*nresult = nnum1-nnum2;
}else{
printf ("Unknown operator!");
return-1;
};
return 0;
Process-oriented programming (OPP) is the "functional decomposition" of user requirements. The user needs to be decomposed into modules (. h,.c), then the module (. h,.c) decomposed into large functions (function), and then the large functions (function) decomposed into small functions (function), and so on. Functional decomposition is a very technical content of the work, it needs not only the decomposition of a rich practical experience, but also need scientific theory as a guide. How to decompose, decomposition principle, what is the size of the module appropriate? These are the issues that architects have to consider, and what we want to focus on later. The advantage of process-oriented programming (OPP) is that the program is executed sequentially and the process is clear. Its disadvantage is that the main control program takes on too many tasks, each module needs to control and dispatch the main control program, the main control and the task of the module is not balanced.
Some people define process-oriented as: algorithm + data structure, I think it is also very accurate. In process-oriented programming, the algorithm is the core, the data is subordinate, and the data flows with the algorithm. So use a process-oriented approach to programming, usually before you start, you have to write a flowchart or a flow chart.
. NET Senior Architect 0002 Architect's path (1)---process-oriented and object-oriented