The idea of programming (structured programming)

The idea of ​​programming

Recently, I read the classic book "C Programming (Fourth Edition)" by Tan Haoqiang. I discovered that there are a lot of deeper thoughts in it, which I didn't feel at all during the first study. Once again I feel that a good book is worth reading over and over again. The following are the points I have seen that I think are more essential:

1. The formula proposed by the famous computer scientist Voss: algorithm + data structure = program. Algorithm: the description of the operation, that is, the steps that require the computer to operate; data structure: what data to use in the program and the type of data and the organization of the data.

2. Four aspects of knowledge that programmers should possess: algorithms, data structures, programming methods and language tools. Among the four aspects, the algorithm is the soul, the data structure is the processing object, the language is the tool, and programming requires appropriate methods.

3. The basic idea of ​​the structured program design method: the process of solving a complex problem is carried out in stages, and the problems dealt with in each stage are controlled within the scope that people can easily understand and deal with. The method is: top-down, gradual refinement, modular design, structured coding. Top-down means that, before proceeding with the program design, the overall planning of the program is carried out. The program can be divided into several parts to write, and gradually analyze what functions each part achieves and how the several parts are connected. stand up. To make an unsuitable analogy, just like the seven-layer architecture of a computer network, each layer only implements its own function, and then passes the ball to the next layer. In each layer, there are some specific designs. The idea of ​​modular design tells us that a very complex function may be difficult to program, but if this complex function is divided into multiple simple functions, then it is very easy to program only this simple function. And later, we only need to splice multiple simple functions together. Structured coding is to write programs using three basic structures: sequence, selection, and loop.

4. Specifically, if the program has more functions and a larger scale, writing all program codes in a main function (main function) will make the main function complicated. Therefore, when designing a larger program, it is often divided into several program modules, each module contains one or more functions, and each function implements a specific function. A C program can be composed of a main function and several other functions. In other words, a C program is composed of one or more program modules, and each program module serves as a source program file. For larger programs, you generally don't want to put all the content in one file, but put them in several source files, and several source program files form a C program. This makes it easy to write and compile separately and improve debugging efficiency. A source program file can be shared by multiple C programs.

5. When a C program is composed of multiple source files, if one file wants to reference an external variable defined in another file, then extern should be used as an external variable declaration in the file.

There is another paragraph, I also feel that it is very good: the purpose of learning programming is not only to learn a specific language, but to learn the general method of programming. To master the algorithm is to master the soul of programming, and then to learn the knowledge of the relevant computer language, you can write programs in any language sequentially. It is difficult to learn programming without a specific language. However, language learning is only for designing programs, it is never an end in itself. There are many high-level languages, and each language is constantly developing, so you must not stick to a specific language, but should be able to draw inferences from one another. The key is to design the algorithm. With the correct algorithm, coding in any language is not difficult.

Guess you like

Origin blog.csdn.net/qq_39529052/article/details/105735760