Basic elements of the Program (personal feeling)

Source: Internet
Author: User
Tags key string

This article is just my personal thoughts after reading a little bit of information. I have not carefully verified the content, so I hope readers can read it critically. There must be a lot of errors in it, and I hope you will not be enlightened.

 

To make a computer perform computation successfully, operator & operands is generally required. At the beginning, operator only had "+". Later, it developed various addition-based arithmetic operations. The method we used was the "encapsulation" we often encountered.

 

Numbers and characters:

A number is essentially a symbol for a computer. Therefore, a number can naturally represent characters and other symbols. Because the computing capability of the original computer is limited, it can only calculate eight bits, so the amount of information it can process is 0 ~ 256 this range (IBM is 0 ~ 127, which has some relationship with the card machine of IBM ). However, Americans who invented computers do not think this is difficult because there are only 26 English characters. Even if some symbols are added, they will not exceed 256. Therefore, the computer has the ability to operate characters.

Since then, the computer has the ability to operate on numbers and characters, or simply put, it has the ability to operate on symbols.

 

Array (tuple ):

It is easy to define a character, but it is difficult to define a character consecutively. For convenience, people use the Array (tuple) tool to simplify operations. An important reason why an array can be accessed through subscript is that the array is stored continuously in the memory space. Therefore, you only need to move the pointer to a certain distance.

Find the next character.

 

String)

Pointer jump is a very powerful mechanism, and it is an important way to implement map. I guess string is implemented in this way. It is an encapsulation of character arrays. Because it is human encapsulation, many operations can be performed on strings, such as selection and segmentation.

 

Dictionary)

This is a data type in Python. Some of them are similar to map in Java. I think it is similar to JSON format in JavaScript, all implement the ing from one object to another (the object here is a generalized object, not just an object in the object-oriented model in the computer ).

The implementation of ing between strings is as follows: first, perform character-by-character matching. After finding a string, follow the agreed offset, add this offset to the address of the previous string, which is the address of the other string. This method has the advantages of simplicity and high efficiency. The disadvantage is that a fixed storage space is required and the string length must be limited. If this limit is too large, it will lead to a huge waste of space. If it is too small, it is not applicable to most cases. However, for interpreted programs, the problem is not very high. interpreted programs are either relatively small, do not use a large amount of memory, or have a memory reclaim mechanism, not afraid of memory overflow.

Just now I thought, it is really inconvenient to implement this ing method. Alternatively, you can add a pointer to each key string. After finding the key string, you can get the pointer and find another string. The advantage of this method is flexibility, but the disadvantage is that it takes up a little space.

 

Statement

This does not know how to translate, but we often use it in programs, such as def, print, assignment, if, while, etc. I think statement, like operator, is the encapsulation of the operators in the Assembly. They are the basis of various operations and can be used to operate peripherals and memory. How to determine the number of statement, so that it not only meets the ability required by the computer, but also meets the minimum number, the programmer is the easiest to grasp, is a learning.

I think there are at least the following operations to be defined for statement:

Operations within the computer:

  • Move characters in registers
  • Encapsulation of arithmetic operations
  • Allocate, modify, and recycle memory space

Exchange with peripherals

  • Input from peripherals such as the keyboard and mouse)
  • Display (output) on the display device)

Encapsulation

For a computer program, the elements mentioned above, operator, number, string, and statement are enough. using them, we can implement any computer program. In fact, computer programs are composed of these elements. But why do people still invent many other tools? The reason is simple. With the infinite complexity of the program, it is increasingly difficult for people to control the correctness and reliability of the program. To solve this problem, people think of encapsulation.

The most basic encapsulation is the encapsulation of operator and statement. Another important encapsulation is the data type. The data type is meaningless for systems such as computers that can only perform syntax analysis. The data type is a restriction on people. It determines the range of data representation and operations that can be performed on it. This can prevent the destruction of some data and simplify the operations of programmers, the added difficulty lies at the compiler end.

 

Debugging)

Bugs in a program can be divided into three types: syntax errors, semantic errors, and runtime errors.

Syntax error:This type of errors is obvious. Generally, the compiler will find them for us.

Semantic Error:Such errors are generally hard to find and need to be continuously tested. But it is still possible to make mistakes, because computer programs face a complicated world and it is difficult to write a program that can maintain its robustness under complicated circumstances. One way to reduce errors is to restrict input and reduce interaction with the outside world.

Runtime error: These errors are often associated with semantic errors. In some cases, if the specified runtime environment is inconsistent with the actual runtime environment, it may also cause runtime errors, such as insufficient memory.

It can be seen that the main source of bugs in the program is semantic errors, that is, the programmer's logical errors. An effective way to reduce such errors is to constantly encapsulate the program, reduce the complexity of the program through encapsulation, and make it easier for programmers to find bugs. In addition, detailed and clear comments and documents are a good sign of a program, which can minimize semantic errors caused by different understandings of the same thing.

 

Natural Language and formal language

Natural Language:This feature is closely related to the context and requires a lot of content to express an accurate information.

Formal Language:It has nothing to do with context. Each element has a clear information.

It can be seen that there is a gap between the natural language used by people and the formal language used by machines. This is also an important reason why programmers are unwilling to write documents. But also because

For this reason, we need better documentation. In addition, some natural languages are processed to become"Terms", Using them to bridge the gap is also a common method. This

It is a problem faced by many natural sciences. Therefore, we can also use their methods to solve this problem.

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.