Current location - Recipe Complete Network - Complete cookbook of home-style dishes - This book tells you why computers can understand human language and programming thinking makes you smarter
This book tells you why computers can understand human language and programming thinking makes you smarter

In this Internet age, when we go shopping, take photos, make phone calls, and browse information, we only need to bring a smartphone. If you wanted to implement these functions 20 years ago, you would need to bring a lot of things. The computers in our pockets today are more powerful and smaller than the computers that sent astronauts to the moon 50 years ago.

Why are computers so powerful that they can understand human language? It wasn't until I read the book "Programming Thinking for Everyone" that I answered my doubts and understood the working principle of computers. All these functions are inseparable from the programming design of programmers. When it comes to programming, people always think of programmers sitting in front of the computer and typing a long list of mysterious codes. In fact, programming embodies human wisdom.

In the book "Programming Thinking for Everyone", the history of computers and the working principle of binary are explained, as well as how to create programming thinking. Programming a computer requires logic, reasoning and mathematics. Programming thinking can improve thinking skills and solve problems creatively.

Learning programming thinking is not about mastering coding skills, but learning a way of thinking to solve problems. This book has four chapters: learn to think about programming; solve problems; learn programming languages; and keep working hard.

The author of this book, Jim Christian, is a famous British technology education expert and programming geek. He has won Dr. Dobb’s Programming Excellence Award.

Let’s take a look at how computers understand human language and how we use programming thinking to solve problems.

Characteristics of computers.

A computer refers to an electronic device that can receive, convert, store information, and then output the information in a set form.

Computers come in many forms: cell phones, tablets, desktop computers, laptops. Although they have different shapes, their internal structures are similar: motherboard, network, input and output devices, external memory, random access memory, and microprocessor.

The microprocessor is what people often call the central processing unit or CPU. It is the brain of the computer and is responsible for processing "thinking" work.

Inside the microprocessor, there are thousands of switches waiting for the arrival of electrical signals. The electrical signals pass through the switches of channels and gates and are generated in the form of binary numbers. The more cores a microprocessor has, the more instructions it can run per second.

Programming is to translate human thoughts and thinking into binary digital language that a computer can understand, and then convert it into actions to be executed by the computer.

The language of computers--binary.

All input and output in the computer are realized by encoding and decoding binary numbers composed of countless 0s and 1s, and converting them into codes that the computer can recognize.

Binary was developed in 1679 by the German genius Leibniz. Binary is a counting method that uses only two numbers, 0 and 1, because computers can only recognize codes composed of 0 and 1.

The two numbers 0 and 1 control the switches of the transistors inside the computer. 1 means on and 0 means off. When people operate a counting machine, they control the switches of the transistors inside the computer to guide the current into the correct direction and implement the program.

The arithmetic commonly used in our work and life is the decimal system, which means adding 1 to every 10. The binary rule of computers is that every 2 is entered into 1. 1 and 0 are the language that computers can understand, representing on and off, yes and no, true and false.

In the binary system, the number 1 is represented by 1; the number 2 is represented by 10; the number 3 is represented by 11; the number 4 is represented by 100; the number 8 is represented by 1000.

If you use the decimal system, you can only count to 10 with two hands, but if you use the binary system, you can count to 31 with one hand.

If you use two hands, you can count to 1023, because in binary, the value of the next finger is twice that of the previous finger. The little finger of the first hand represents 16, the thumb of the other hand represents 32, the index finger represents 64, the middle finger represents 128, the ring finger represents 256, and the little finger represents 512.

This game is very fun and can exercise innovative thinking and logical thinking.

Binary values ??can also be used to represent the 26 letters of the English alphabet. A uses the number 1; B uses 10; C uses 11;...

If this set of information: 1000 101 1100 1100 1111 is spelled out as "Hello", thus converting human language into language that computers can understand.

Computer language pays attention to grammar and context. A comma or a letter can change the meaning of the entire sentence. It can be said that a slight difference can lead to a huge difference.

Computer programming languages ??have gone through three stages: machine language, assembly language, and high-level language. There are more than 100 programming languages ??in the world, but only 10-15 are commonly used. Here are a few programming languages .

Algorithm

An algorithm is a series of clear instructions executed in a set order in order to complete a certain task. The more specific and clear the instructions in the algorithm, the smaller the probability of errors when the instructions are run.

For example, we let a robot named Xiaozhi make the bed.

Because Xiaozhi does not understand the method of "making the bed", our tidying requirements are: put away the duvet, blanket, and pillows, so the instructions we give must be specific and clear.

1. Lay the duvet flat on the bed.

2. Lay the blanket flat on top of the duvet.

3. Place the pillow on top of the blanket.

Algorithms are like recipes used for cooking. They are commands to be executed by the computer. Let’s take a look at giving instructions to the robot Xiaozhi to make a sandwich with cheese.

You see, in the above steps, the description is very specific. It talks about how to hold the knife and the direction of the knife edge. In fact, it can also be specific about the angle of the knife and the speed of spreading butter.

In steps 7-10, the instructions include the time to apply butter. Because Xiaozhi does not know how much butter is enough, the programmer estimates that it takes about three seconds.

Loop

The design of a programming language must be convenient and efficient. When writing an algorithm, a lot of specific instructions are required, which is not only cumbersome, but also repetitive. In order to avoid repeated instructions, loops can be used to process some basic instructions in programming to make the program simpler.

For example, if we ask the robot Xiaozhi to walk over 10 steps, we have to say "take 1 step toward me" 10 times. The instructions given in this way are not only cumbersome, but also easy to make mistakes in the number of times. The solution is to use Loop: "Take 10 steps toward me."

A loop is a structure that executes repeated instructions until the end of the process. There are two types of loops: counting loops and conditional loops.

A counting loop is a loop controlled by the number of times, called a for loop. The for loop will repeat the instruction regardless of the result.

Conditional loops use conditions to control the number of loops, which is the While loop.

By using loops in the algorithm, you can double the programming work by modifying a single statement, achieving twice the result with half the effort.

For example, we can use loops to improve efficiency in the sandwich program instructions. After step 10, add one more instruction: Repeat steps 1-10 above. In this way, the robot will work repeatedly, but this will cause an infinite loop. The robot will work according to the instructions and keep spreading butter on the slices of bread until the slices of bread are used up, and finally the program crashes.

In order to avoid this defect, we need to repair the program and modify step 11 to: Repeat the above steps 1-10 until the two slices of bread have been buttered. This adds a specific condition to make the robot's operation more perfect.

Variables

Variables are often encountered in programming. A variable is like a labeled box containing variable names and variable values.

Variables are often encountered in electronic games. For example, how many lives a game character has left, the number of lives is a variable.

Our human body also has variables, such as: hair length, changes in height and weight, and age.

Let’s play an age guessing game.

In this game, the age in the program applies to people of any age. The person’s age is the variable name, and the numerical value of the age is the variable value. You can write: ((age×2+1)× 5+5) magic.

Conditional Statement

A conditional statement is a statement in which the computer makes a choice based on given information.

In life, we have to make choices based on conditions every day. For example: If the sidewalk signal light is red, then we have to wait for the green light to turn on, otherwise we may be hit by a car.

Let’s do a question related to conditional statements: Suppose you go to your friend John to pay back the money, and it turns out that John, James, and William are identical triplets. Someone tells you that John, James He always tells lies, but only William tells the truth. You can only ask one question to confirm whether this person is John. What would you ask?

The correct answer is: "Are you James?" Because William told the truth: "No." James lied: "No." Only John lied and was the only one who answered "Yes" .

Debugging

The term debugging originated in the 1940s and was proposed by U.S. Navy Rear Admiral Grace Heber.

When she was writing a program for a computer at Harvard University, she discovered that a real bug had gotten into the computer and prevented the computer from running normally. Debugging (debugging to remove the bug) came from this.

Debugging is to carefully examine the writing process, algorithms, and flow charts to eliminate and repair problems or errors that prevent the program from running properly.

In the process of writing a program, the computer only executes the instructions it receives and does not think like a human being. Therefore, after the program is written, a lot of time is spent on debugging the code.

Commonly used methods for debugging are: looking for bugs (program errors); adding comments to the code; and the little yellow duck debugging method.

The little yellow duck debugging method seems stupid, but it is very effective. It is to put a little yellow duck next to the computer, and then explain all the details of the program to the little yellow duck who knows nothing about it.

The secret of this method is that when programmers explain how the code runs to people who don’t understand programming, they must explain the details of how the code runs in great detail. The programmers will find errors in the program and solve them themselves. question.

Programming thinking includes rational reasoning, logical thinking and mathematical operations. Learning programming thinking can creatively solve problems and express ideas.

Programming thinking has four parts: problem decomposition; pattern recognition; abstract thinking; algorithm design.

Problem decomposition

Pattern recognition

For example, if we want to log in on some websites, we will be asked to enter a verification code. This is pattern recognition, and the purpose is to Prevent others from pretending to be users to enable other functions.

Abstract Thinking

When using abstract thinking, set aside information that is not relevant to the problem.

For example, you are going to play ball at two o'clock on Sunday afternoon, and your home is 5.2 kilometers away from the stadium. You have to water the flowers and mop the floor in the morning, and go to your mother's house for dinner at noon. You can probably finish it at one o'clock. My mother’s house is 3.5 kilometers away from the stadium, so how far do I have to walk between one and two o’clock?

In all the information, watering the flowers and mopping the floor have nothing to do with going to the stadium, because my mother’s house is closer to the stadium. There is only one relevant information: my mother’s house is 3.5 kilometers away from the stadium.

Algorithm Design

You must have heard the story of the mathematical genius Gauss. In 1785, Gauss's teacher gave his students a question to add up all the numbers from 1 to 100. The teacher originally wanted to take up more class time, but to the teacher's surprise, the 8-year-old Gauss quickly gave the answer. Answer: 5050.

There were no computers in that era, and Gauss did not add numbers one by one from beginning to end.

Let’s see how Gauss uses programming thinking to solve problems.

The first is problem decomposition. He decomposes a big problem into small problems and finds out the regularity of each group of numbers, that is, adding the first and last numbers of each pair will result in the same number.

The second step is to form your own pattern recognition. You can disrupt the order. Just add all the numbers. 1+100=101, 2+99=101... There are 50 groups of numbers that are equal to the sum of the first and last numbers. The number 101.

Again, abstract thinking is used, unnecessary arithmetic steps are omitted. There is no need to add the first and last numbers to the last group.

The last step is algorithm design, which uses multiplication. Do the calculation: 50×101=5050.

No matter how powerful the computer function is, it is also given by humans. The real power is the human brain.

With the development of the Internet, people’s lives have become inseparable from computers, such as: using mobile phones to make calls, listening to music, and taking photos; using computers to send emails and browse financial information; when shopping in supermarkets to check out, just You need to scan the QR code for the product, and the computer will automatically settle the amount and check the bill.

The book "Programming Thinking for Everyone" tells us that programming is the bridge between humans and computers, and humans create a better world through programming. We don’t need to learn programming, but we must learn programming thinking.

Programming thinking is our meta-skill for solving problems and is closely related to our lives. Work, study, and even housework are inseparable from the logical ability and creativity of programming thinking. Learning programming thinking is learning to think. .