. Net Architecture Design Guide for beginners (1) the era of Hello World

Source: Internet
Author: User

In middle school, the school opened a computer class. At that time, the computer was a relatively rare thing. There were a dozen computers in the school, and they were specially located in a hall. The room was covered with thick carpets and covered with heavy curtains all day. The day before each class, we need to bathe in our clothes and cut our nails. In class, everyone put on shoes and lined up to enter the data center. Then you sat down in your seat and took out a 5 inch-inch soft disk under the teacher's command. the disk was installed with the DOS operating system and inserted into the drive of the computer. Then turn on the monitor and host power in turn. In a burst of buzz, wait for the computer to start and enter a magical world full of fantasies.

At that time, I wrote the first line.Program. At that time, we learned a language called gwbasic, which is a branch of the basic language.

Basic is a very simple interactive programming language. Each line must be encodedCodeCompile a row number. The row number is a natural number. For future debugging purposes, it is usually intentionally left surplus when the row number is originally compiled, not in accordance with 1, 2, 3 ...... To compile the line number, but according to 10, 20, 30 ...... . After the program is entered, run the "run" command. The compiler will explain the execution program in the order of row numbers.

This programming method is too simple. You only need to remember several key words for process control and input and output to write a simple program. During that time, I was thinking every day about writing the things I encountered in my daily life into a program, multiple equations, a number-guessing game, And a trigonometric curve ...... Write down the idea of programming on paper, and write it on the computer every week during class, debugging and running. The debugging method is also very simple, that is, print the value to the screen and run it to view the result. Run the "save" command to save the code to a floppy disk.

The middle school period should be the most flexible period of thinking for a person. In the future, the experience will be gradually enriched, but the ability to learn new knowledge is actually declining. Unless specially trained, many aspects of knowledge will remain at the level of middle school. For example, for a computer professional, his knowledge of history, language, physics, and chemistry is likely to remain at the level of the middle school forever. During that time, I wrote a program frantically. My biggest wish was to have a computer in my house and install the gwbasic compiler. I could keep myself in the room every day and use gwbasic to write super Mary, or a game like a tank war.

Gwbasic uses a very primitive method for process control-Goto. He also has the concept of a function, but it is actually goto to a code segment (using the gosub command). After the execution is complete, Goto is returned (using the return command ). According to the popular concept at the time, there was no improper use of goto in the program, which is a normal way to implement conditional loops. For example, the following code:

50 let I = 0
60 I = I + 2
70 print I
80 if I <100 Then goto 60

The following is a piece of code I wrote at the time. This is a game of guessing numbers. He is in the circle where goto came to goto, like entering a maze. Fortunately, the size of this maze is not big, and it is easy to find out what he is doing. The reason why this code can be saved to the present is that it is not saved in a floppy disk like other codes, but recorded in the blank space of the book.

10 print "guess a number"
20 input
30 if a> 5 Then goto 60
40 if a <5 Then goto 80
50 if a = 5 Then goto 100
60 print "too big"
70 goto 20
80 print "too small"
90 goto 20
100 print "right"
110 end

This programming method is noodle code. This is the simplest encoding method, which can be mastered immediately without long learning or too much experience. However, the problem he can solve is limited. He can only write a quiz game, or draw a function graph of Y = A * sin (x) + B. If you want to use him to write a Super Girl, it will be very, very difficult.

Later, in the era of structured programming, Goto became a sinner who destroyed the structure of the program and was gradually abandoned by everyone, currently, only a few places still play a role (for example, exception handling in VB or C ). However, this goto programming method has affected me for a long time. I still use this programming method when I was studying FORTRAN77 in college. This method is very simple. You don't have to think too much to solve the problem. It also makes me a little rich, so I am too lazy to study other programming methods.

Structured Programming is an improvement of noodle code. He first divided the problems to be solved into several modules, and then divided each module into smaller modules, so that they can be further refined, until the functions of each module can be implemented using a program statement, the program design is completed. When dividing modules, the principle of structured programming is: a module can only have one entry and one exit, and the connection between modules should be completed according to the basic structure. This means that GOTO can only be used with if to form the branch and loop structure. Branch and loop structures in anyProgramming LanguageThere are more simple and clear keywords for implementation, So goto naturally loses its meaning.

Structured Programming is a process-oriented programming method. The so-called "process-oriented programming" is translated from "procedure-Oriented Programming" and should be understood as "process-oriented programming ". According to this programming method, people first need to determine what process to use to implement business requirements, and then break down the process step by step, then break down ...... The process can be implemented with a statement. The following process implements a quiz: Test and calculate the square of 11 to 20, each calculation of a number can get 10 points, and finally output the total score.

The process-oriented programming method must determine the problem-solving process before programming, which is not flexible. When we solve a problem, it is difficult to set the process reasonably at the beginning. For example, if we develop an email server, the user initially requires this function: when receiving the email, determine whether it is spam or not. If it is spam, it will be moved directly to the spam folder. Later, during the development process, we found that the spam recognition rate is not very high, and some normal emails will inevitably be removed as spam, resulting in users' failure to receive emails in time. So this process must be adjusted to this: the spam cannot be removed, but a warning mark is added to the title. In addition, this process changes will affect other processes: when using the pop client to download emails, only the title and plain text content can be downloaded for spam emails to ensure the security of the client. It can be seen that the business process needs to be constantly fed back and adjusted in the subsequent development process to achieve a better effect. However, according to the process-oriented programming method, we must first determine a process and then start the design, otherwise the demand will be uncertain. If the process is found to be inappropriate in the programming process and the efficiency or accuracy does not meet the requirements, the program will be re-designed. In this way, it is very difficult to write and modify programs, and you have to worry about the impact on other processes.

Later, another programming method was developed: object-oriented programming. Object-Oriented Programming is translated from "object-oriented programming" (OOP). In fact, it should also be understood as "object-oriented programming ". In this way, do not rush to determine what processes are used to meet business needs, but first look at what "things" are included in the requirements and how these things appear, what are the attributes, what can be done, what kind of events will occur, and what kind of relationship between these things. Use a program to create these things, and then let them run to implement the expected functions.

For example, if the problem with the email server is not clear about the process, we can first look at what is in the email server. The most obvious thing is that there should be an email class. Email has three behaviors: Receive, show, and download ). Spam is a special case of mail and can be considered as a sub-class of email, as follows:

Junkmail overwrites the methods for receiving, displaying, and downloading emails. If spam should have some special handling methods, you can only modify the junkmail class-Move it to the spam folder when receiving it, or add a warning sign when displaying it, filter out non-text content during download-no other class code needs change. This will not affect the normal mail processing process.

The difference between process-oriented and object-oriented programming is that they have different requirements. Process-oriented programmers understand their needs as a business process. They like to ask users "What is your business process ?", Then they analyzed these processes, combined these processes, and finally met the requirements. Object-oriented programmers understood the requirements as one object, they like to ask users, "What is this thing, where is it from, and what can it do? ", Then they make these objects so that they can call each other and meet the business needs. The comparison of the two programming methods will be described in the following sections. Here are two simple points:

1. objects are more stable than flows. Business process development requires many restrictions, and even the program efficiency and running mode will in turn affect the business process. Sometimes, users can actively change business processes to better achieve business purposes, and changes in a process often lead to a series of changes. This makes the program designed according to the business process often face changes.

2. objects are more closed than flows. On the surface, a business process has only one entry and one exit. However, each step of the process may change the content of a data, change the status of a device, and have an impact on the outside world. The object is completely connected to the outside world through the interface, and the internal affairs of the interface are irrelevant to the outside world.

According to the object-oriented programming method, we need to use objects to reflect things that appear in the real world. If the requirements are complex, there will be a large number of objects and complex relationships in the program, making it more and more troublesome to modify the program. In fact, some objects always have fixed relationships, some objects are contained relationships, some are dependency relationships, and some are the creators of other objects ...... Experienced programmers will find some rules from these relationships and find some methods to address these relationships, which forms a design pattern. For example, if a communication company sets various packages for its users and selects different packages, different billing policies are adopted for calls. In this case, the Strategy mode can be used; A bicycle company sells parts for bicycles at the same time. Some parts are a combination of multiple parts and can be combined with other parts into a larger part, which can adopt the composite model. Sometimes programmers can get design inspiration from the pattern and have an impact on the overall architecture of the software. I will introduce the design pattern in subsequent chapters.

The idea of software development has undergone decades of development. The earliest noodle-style code was quickly learned by a middle school student and could be used to solve a multi-dimensional equation immediately. Later, structured programming was developed to split the code into multiple modules, this enhances code reusability and facilitates debugging and modification, but the structure is much more complex. The earliest programming method was process-oriented. It was very intuitive for beginners to understand quickly. Later, with the object-oriented method, the solution to the problem did not look so straightforward, you must first develop business objects before implementing business processes. With the development of object-oriented programming, there have been design patterns, MVC, Orm, and countless tools and frameworks. Why is the software increasingly complicated? In fact, this is not the reason for the software itself, but because the requirements to be addressed by the software become more and more complex.

The earliest computers only needed to help people with pure computing tasks. He used plug and switch as the input device, and the signal lamp as the output device. There was no memory or program. At that time, people needed computers to help people take computing tasks in census and weather forecasts. Early computers used to participate in the Manhattan program. Initially, the military hired about 100 computing workers to participate in the calculation of data on nuclear fission, but the progress was far from satisfactory. Later, the development of computers greatly accelerated the development of atomic bombs, which accelerated the end of the Second World War as soon as possible.

A bit later, the computer uses the card perforation method as the control method. The programmer records the operations to be run on the card in binary mode. The perforation represents 1, and the non-perforation represents 0. When a card is inserted into a computer's input device, the computer runs as scheduled. This is the earliest machine language. As computers get faster and faster, it is found that many times the computer is waiting for the input device, and a lot of time is wasted. So people designed a computer that can process multiple cards at a time. Multiple cards can be placed in the computer at the same time. The computer schedules the cards according to certain rules and executes them in a certain order of priority. This is the concept of interruption and task scheduling, the earliest operating system appeared like this. A company like a bank or an accounting firm puts the cards written every week in a computer to process a large amount of data. At this time, the computer is still a very complex equipment, and maintenance and use are very difficult. At that time, the computer production company must provide a full set of installation, maintenance, and operation solutions.

At this time, computer programming is to punch in the card, and the language used is completely machine code. Machine code is hard to remember and hard to understand. So people invented the assembly language. The assembly language is actually the mnemonic code of the machine language and can be translated into machine code cards by the compiler. In terms of morphology and syntax, he is closer to natural language, but in terms of process, he is still the machine language.

At this time, computer software has become a costly project. At that time, computer hardware was a very high-end expensive equipment, so that some large companies did not have the courage to buy independently. Instead, they rented machines and invested millions of machines. Software development costs a lot more than renting a machine. The most typical project is the ibm360 operating system. At that time, IBM developed a new computer, ibm360, whose plan was to develop an operating system for such machines. The software development cost is huge, and the construction period is delayed. The operating system will not be released until one year after the entire machine is listed. Later, an engineer involved in operating system development wrote a book describing an important experience he gained in the project: blindly adding manpower to a slow software project, the progress can only be slowed down. Software development requires a great deal of interpersonal communication costs, which makes the scale of the project not measured simply by the number of months.

Assembly language solves the hard-to-write problem of machine code. However, the assembly instruction sets of machines and models produced by different companies are different, programs written on one machine cannot be transplanted to another machine for execution. So someone wanted to solve this problem. He designed a new programming language called FORTRAN. The syntax of FORTRAN is closer to the natural language, and it has designed a compiler suitable for multiple models. It can compile the source code of FORTRAN into machine code that can be executed on multiple machines. Feng nuiman, one of the founders of computer science, thought that this advanced language was of little significance and that computer development should not focus on this place. Feng nuoman must be a compilation expert. He is also very skillful in writing machine code. Naturally, he thinks that there is not much need for advanced languages, and the compilation is quite good. This kind of feeling should be similar to the feeling of some C language experts in today's face of Java and C.

The significance of FORTRAN is that it makes computers no longer a tool that computer professionals can manipulate. Mathematicians, engineers, accountants, and students all have the opportunity to use computers to solve problems encountered in their work. The birth of advanced languages has led to the rapid development of the software industry. At that time, Fortran was still not a structured programming language, and all variables in FORTRAN were global variables. It used similar methods to assembly for process control.

Over the next few years, a number of advanced languages, such as LISP, Algol, and COBOL, have emerged. These languages all have one thing in common: they all come up with the concept of local variables, which are structured programming languages. Local variables have a clearer scope and life cycle. Programs are divided into several sub-processes. variables defined in a sub-process cannot be accessed in other sub-processes. With this mechanism, programmers no longer have to worry about unexpected modifications to their Defined variables, which facilitates more programmers to work together to write large-scale programs.

Over the next few years, more and more advanced languages have emerged, playing an important role in fields such as word processing, scientific computing, and data tabulation. The basic language (basic is not a structured language) emerged in this period. Its full name is the general Symbolic Instruction Code for beginners. The basic syntax is simple, easy to learn, and easy to use. Ordinary people can program with basic after a little training.

From this history, we can see that computer software technology continues to develop, and its purpose is to make it easier for people to use computers to solve problems. People need to use computers to solve more and more complex demands. From the initial scientific computing, we gradually develop into Table processing, accounting computing, and management of the business activities of a large enterprise, this forces the continuous development of software development technologies and ideas. To create a new technical platform, designers do not need to consider too many basic technical issues on this platform; To create new analysis methods, designers can ignore the complexity of details, it is easier to grasp the software architecture as a whole.

The development of software technology is still in this direction. The architecture of software is becoming more and more huge. from single-layer and simple process-oriented code to multi-layer and object-oriented code, on the surface, it becomes complicated, in fact, the logic structure of the software is clearer, so as to continuously meet the increasingly complex business needs. Programmers can free up their power from technical details to solve more complex business problems.

We should also pay attention to this point when learning and using various advanced technologies: The development of technologies aims to solve business problems more easily and reduce development costs-which is also the purpose of using them. This article will introduce some programming ideas and technologies in later sections, and follow this idea to see how these things help programmers solve business needs more quickly and accurately. In order to illustrate how these ideas and technologies make it easier to solve the problem, this article will try to use examples that are close to the actual situation. Simple examples of the form of toys, such as the use of cat, dog and animal to describe the rules of polymorphism, looks very good and interesting, but the thing itself is too simple. Using this method makes it easy to clarify the technical principles, but makes it difficult to understand their use scenarios, and even mistakenly thinks that they have complicated the original simple things. Some examples in this article involve some knowledge in specific business fields, which may seem obscure and boring. I hope you can tolerate it.

To be continue

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.