"Programming" means "writing programs". Although the name sounds very professional, in fact, programs are everywhere in life, and almost everyone has written programs. It's just that many people don't know what programs are, so they don't realize their existence.
For example, Lao Wang's mobile phone received a message from his wife.
The content of the message is: After get off work, go to the school to pick up the children, then go to the supermarket to buy fifteen eggs and a bag of bread, and finally pick up the express delivery.
For example, the method of stir-fried pork belly with green pepper is:
- First stir-fry the pork belly.
- Take the fried pork belly out of the pan, and then stir-fry the green pepper.
- Finally, pour the pork belly back into the pot, stir-fry with the green pepper, and add salt and other seasonings.
For example, the steps to put an elephant in the refrigerator are: open the refrigerator door, put the elephant in, and close the refrigerator door.
Broadly speaking, the above examples are indeed programs, but they are not computer programs, but "generally speaking, programs".
You can see that they all describe "specific goals" and specific steps in sequence, but you will know later that a program does not necessarily have specific steps.
In a broad sense, the concept of a program can be defined as: expressing relevant information about "specific goals to be achieved".
According to this definition, we can recall many common programs in life.
For example, some people will write a schedule that lists the things to do every day,
When to get up, when to eat, when to go to bed... and complete them on time.
The "schedule" here is a program, and "things to do every day" is the specific goal to be achieved.
For example, the outpatient hall of the hospital generally provides a medical treatment flow chart, telling people to complete the medical treatment in the order of registration, waiting, medical treatment, payment, medication, treatment, reexamination, etc.
The "medical treatment flow chart" here is a program, and "completing the medical treatment" is the specific goal to be achieved.
For example, the math teacher asked a question on the blackboard: calculate the result of 1+1.
The "question" here is also a program. Although the specific steps are not written, it expresses a goal such as "calculating the result of 1+1".
From the above examples, we can find that the meanings of "program" and "plan" are somewhat similar. The English word "program" does have the meaning of "plan". For example, the "Apollo program". In short, the concept of program is so simple. Don't think too complicated. It's okay to equate "program" with "plan".
From the concept of programs, we can know that it is not difficult to write a program. You only need to write what the "specific goal to be achieved" is. The difficulty lies in how to execute the program and accurately achieve the "specific goal" in the program.
Since the program itself is just static information and cannot act on its own, this involves a question - who will actually act?
We can call those things that actually act and try to achieve the program goals "executors of the program", or "executors" for short. It should be noted that the executor of the program can be a person or an animal, a machine or equipment, or even a certain substance.
For example, the math teacher asks a question on the blackboard: calculate the result of 1+1, and asks the student Xiao Ming to answer.
Xiao Ming calculated the correct answer, and Xiao Ming is the "executor" of the program "calculate the result of 1+1".
For example, Lao Wang completed tasks such as picking up his child and buying things according to the information he received. Lao Wang is the "executor" of these programs.
For example, the company's employees work according to the work plan.
Employees are the "executors" of the "work plan" programs.
Even if there is an executor, it is not necessarily guaranteed to achieve the goal of the program, because the executor himself or the objective conditions may have certain limitations, or the executor may misunderstand the details of the goal because the program lacks key information, and ultimately cannot accurately execute the program.
For example, if student Xiao Ming does not know what addition and the plus sign mean, and does not even know numbers, then for the program of "calculating the result of 1+1", there is no guarantee that Xiao Ming can accurately execute it.
For example, Lao Wang found that there were many kinds of bread in the supermarket, but he didn't know which one to buy. At this time, his wife couldn't be contacted for some reason, and his children also didn't know which bread to buy. In the end, he might buy a random bread, which happened to not be the bread that his wife wanted, and the program failed to execute.
For example, if the ivory is not put into the dog's mouth in advance, it is very unlikely that the dog will spit out the ivory, so the program "dog mouth spits out ivory" may fail to execute.
For example, from the principle of physics, it is unlikely that a fireball will appear out of thin air in the palm of the hand, so the program "fireball from the palm" may fail to execute.
Strictly speaking, it is impossible to guarantee the accurate execution of the program 100%, but we can take as many measures as possible before the program is executed to ensure the execution of the program as much as possible. The main measures are as follows:
We can transform and strengthen the ability of the executor so that the program can be executed.
For example, if student Xiao Ming does not know what addition and the plus sign mean, he cannot execute "calculate the result of 1+1". We can first teach Xiao Ming what addition is, and then let Xiao Ming execute this program.
If the principle is feasible, we can write a second program with "specific steps" to assist the execution of the first program.
For example, you can write the specific steps of "stuffing ivory into a dog's mouth": open the dog's mouth, stuff the ivory in, and close the dog's mouth.
Then let Xiao Ming execute "stuffing ivory into the dog's mouth", and then let the dog execute "spit out ivory from the dog's mouth".
Although the program is executed by the executor, in many cases the executor we are talking about is not the real executor in essence, but an intermediary between the program and the real executor. The role of the intermediary is to assist the real executor, which is equivalent to acting as a proxy for part of the work of the real executor. We can call it "executor proxy" or "executor interface". The "real executor" and "executor interface" together constitute the "program execution environment", referred to as "execution environment".
For example, when student Xiao Ming is executing "calculating the result of 1+1", the real executor is actually the "nerve cell group" in a part of Xiao Ming's brain.
The work done by the other parts of Xiao Ming's body is to transmit the program from the blackboard to the brain and transmit the execution result of the program back to the blackboard.
Then "part of Xiao Ming's body" is actually an intermediary, so we can think that part of Xiao Ming's body is an "executor interface" rather than a real executor. Part of Xiao Ming's body and Xiao Ming's brain together constitute the "program execution environment", but part of Xiao Ming's body and brain are closely connected, and they are physically integrated with each other. When it is not necessary to be so rigorous, it is logically OK to call "Xiao Ming" as a whole an "executor".
For example, when we execute a "computer program" on a personal computer, the real executor is actually the "CPU or related processor", but we do not directly hand over the program to the processor, but operate the computer through the keyboard or mouse, and then entrust the operating system to call the program, and finally execute it on the processor.
Then "mouse and keyboard", "part of the computer hardware", and "operating system" are actually intermediaries, and they are all "executor interfaces". It can be seen that "interfaces" can also be connected to "interfaces". They and "CPU or related processors" together constitute the "program execution environment". When formally learning computer programs in the future, the concept of "execution environment" will be used repeatedly.
It should be noted that the "operating system" itself is a program, but the program is just "information" and cannot act on its own. It must rely on the executor. Therefore, strictly speaking, the above operating system is an "operating system in execution". It has been executed by the CPU. Therefore, it can be seen that the "programs in execution" itself can also become part of the execution environment of the program.
The "programs in execution" is a special state of existence of the program. It can change the ability of the executor. We will not discuss it in depth here, maybe later.
Programs written specifically for computers are called computer programs. "Computer" is the "execution environment" of "computer programs", but "computer" is just a common name, and generally refers to personal computers.
From a professional perspective, the scope of computers is very broad, such as laptops, mobile phones, tablets, calculators, servers, car engine controllers, washing machine controllers, etc., and they are collectively referred to as "computer systems" in the professional sense, or "computers" for short. Then the program written specifically for the computer is called "computer program", and the "computer system" is the "execution environment" of the computer program.
Let's take a look at an example of a computer program. Create a new plain text file (such as a .txt file) on the desktop of the operating system, and enter the following content:
<script>
document.write(1+1)
</script>
Then change the file name suffix .txt
to .html
and open the file.
As you can see, the browser is opened and the result is displayed: 2.
We have successfully written a computer program that achieves the goal of "calculating the result of 1+1". Its execution environment is mainly composed of computer hardware, operating system, and browser. However, for the convenience of communication, we can omit computer hardware and operating system and say that the execution environment is the browser.
The application software we commonly use, such as browsers, office software, various mobile apps, professional design software, industrial control software, and video games, are all computer programs at their core, and can achieve specific goals. Their execution environment is the operating system (computer hardware is omitted here).