Occasionally, when I go to an IT website, I find that there are many things that seek novelty, novelty, specialization, and bias! It can be said that there is everything in the world! But in the face of the current situation of Chinese software, on the one hand we find that there are many, many practical softwares in the process of being compiled, and many people are working overtime and are very busy; there are still many, many practical softwares that no one has developed and is waiting for. Someone developed it. On the other hand, we also found that there are a lot of idle programmers who don't know what they want to develop! I don’t know what programming skills I need to master, so I spend a lot of time learning this and that online. Apart from learning, I still learn, but I just don’t do it. The good time is lost in vain, which is heartbreaking. Many programmers don't know that what these practical software currently lack most is not new, strange, specialized, or biased things, but practical technology, and the quality and skills in the application of practical technology.
Since programming is "all roads lead to Rome", programmers have great autonomy and can use any method to implement functions, resulting in uneven programming levels. I think programmers should master practical programming skills. To master these skills, they must master the essence of these skills. Only by thoroughly understanding these essences can they summarize their application scope and points of attention: and those programmers who only know how to write programs but do not know why they are written in this way are It may not be possible to use the best statements, the simplest statements, and the most appropriate statements to write programs, let alone use higher skills to combine these statements to achieve high-quality programs.
In long-term programming practice, I believe that the following programming skills are the foundation and must be mastered. Other higher-level programming skills must be used to learn them.
1. Assignment
Assignment is an indispensable basic statement in programming, and it is the most basic statement. Mastering this statement seems very simple, but the simpler it is, the more attention you need to pay attention to. The simplest assignment is to assign a value to a variable. For example x=1.
The essence of assignment is the transfer between things. Moreover, assignment itself is an intermediate process, and the meaning reflected at the code level is to assign a value or memory pointer in memory to a memory pointer.
There are two aspects to assignment: one is: what value or variable or object is taken, and the other is: what variable or object is assigned to. When programmers are programming, they are often confused in two aspects: what values, variables, and objects I get, how to find these values, variables, and objects, and who do I assign them to after I get them. This is what we often encounter.
When we assign values we should pay attention to:
1) The data types on both sides of the equation must be equal.
2) Assignment statements are faster than other statements. This should be noted when focusing on efficiency.
Assignment statements are faster than function calls and faster than loop statements.
For example: a loop statement is written in a huge loop:
for(i=0;i<3;i++)
A[i]=i+1;
Might as well turn it into an assignment statement:
A[0]=1;
A[1]=2;
A[2]=3;
3) When there are multiple assignment statements, the assignment processing may be sequential.
4) There are too many assignment statements (more than 20, which are very rigid to read and have no technical content). Circular assignment may need to be considered.
2. Conditional processing
Conditional processing is second only to assignment processing in programming content, and program changes are basically caused by conditional processing. Different processing will be carried out when different conditions are met. Therefore, the essence of conditional processing is that changes in things bring corresponding changes.
In programming practice, we are often confused about: What conditions? What to do? And also consider when to start considering conditions.
Assignment processing is a sequential processing. The condition increases the possibility of assignment processing. When the condition is met, the A assignment may be executed. When the condition is not met, the B assignment may be executed.
When processing conditions, we must pay attention to:
1) How do we choose my terms? That is our conditional expression.
In fact, this issue is very complicated.
Generally speaking, we will take the most important condition as the first condition. However, we will also consider the condition of the largest result set that satisfies the condition as the first condition. Such final conditions often cannot be met, or even after they are met, they do not require much processing.
From the design of conditional expressions, we can use a single variable to represent the condition, or multiple variable operations to represent the condition. A single variable can be represented by numeric, character, or logical types. Among them, it is also very particular.
For example. flag==1;flag=='1';flag==True
Both can allow program conditions to be transferred, but there are many factors to consider in how to choose.
2) Let’s not leave out exceptions
For example, when we consider i=1 and i=2, we do not consider i<1 and i>2.
The omission of conditions often indicates that our programmers lack the overall concept and the concept of exceptions. This is one of the reasons why many programs are poorly written.
3) There cannot be any intersection between conditions
For example:
If(i>1 &&i<=5)
x=1;
If(i>4&&i<10)
x=2;
When i=5,
x is equal to 1 first, and then equals 2. This must be avoided. Many program errors are related to such problems.
4) Pay special attention to the coverage of conditional processing.
For example: if (flag==1)
X=1;
If(flag==2)
X=2;
X=5;
No matter what the conditions, x is always equal to 5.
5) Be aware of the respective adaptations of if and case. Know when to use if and when to use case.
3. Cycle
Loop is a simple expression of repeated operations. As long as there are repeated operations, loop statements can be used. The essence of cycles is repetition.
When processing loops, we must pay attention to:
1) Circular processing is an important aspect that affects efficiency
When there is an efficiency problem in the program, you must first look for it in the loop statement.
2) Prerequisites for loop processing
Generally speaking, loop statements can be used for repeated executions more than three times. For less than three times, it is best not to use loop statements.
For example:
For(i=0;i<3;i++)
B[i]=i;
It is better to write:
B[0]=0;
B[1]=1;
B[2]=2;
Of course, in terms of readability and scalability, loop statements can also be used.
3) Different loop conditions use different loop statements
Programmers need to know when to use for, when to use do while, and when to use foreach.
Although the above statements can achieve the same purpose, programmers still need to know their scope of application so that they can be most appropriate.
4) Make full use of the statements in the loop, such as interrupt loop, continue loop, function return, program exit, etc., to make the loop more colorful.
4. String operations
Strings are an important representation of information. String manipulation is one of the most commonly used operations in programming. The essence of string operation is the processing of information. Since there are no standards for much information, programmers manipulate it to conform to their own standard requirements.
For example: some strings contain a variety of information, then the strings must be split; some strings are missing information, then the strings must be merged.
Mainly pay attention to the following aspects when operating strings:
1) Empty string processing
Since the original string will have several spaces at the beginning and end of the string due to operational reasons and system reasons, the spaces must be removed before the string is processed.
2) Garbled code processing
There are various garbled characters in some strings, causing incomprehensible characters to appear in the string display. These situations are mainly caused by the presence of control character codes in strings and character mismatches in Chinese characters.
3) Delimiter processing
Delimiters often appear in a record or parameter to separate information, and information can be taken out through delimiters. In practice, it may happen that the information content itself contains delimiters, or delimiters are generated during garbled code generation. In these cases, the delimiters need to be changed or special processing must be performed.
4) Conversion between characters and other data types
In actual programming, the consistency of the objects we operate on often requires the operation of converting strings to other data types, or converting other data types to strings. Generally speaking, it is easier to convert other data types into strings, but when converting strings into other data types, you must consider whether the string format before conversion meets the requirements.
For example: to convert "1,000,000" into a numerical value, remove "," before conversion.
5) Substring processing
Substring processing is often used in queries. There are three types of substring matching: front, middle and last. Substring matching often takes more time. The shorter the substring and the longer the query string, the longer it takes. When querying in the indexed field, only the first match can use the index to achieve the purpose of fast query. However, if the middle and later matches are used, the index will be invalid, and each record needs to be matched one by one, which takes the longest time. Programmers must understand the above content and take advantage of the situation in order to correctly process substrings to achieve fast query purposes.
5. Arithmetic operations
Arithmetic operations are second only to string operations in programming. Among them, adding 1 has many operations and is widely used. Addition, subtraction, multiplication and division are most commonly used in general application software. The essence of arithmetic operations is the processing of numerical information. Arithmetic operations are algorithmic requirements for practical applications on the one hand, and programming algorithms on the other.
For example, the application system needs to calculate the area of a rectangle. Then the S=L*D statement will be written.
If you want to program and calculate the area of 100 rectangles, you need a pointer to calculate the area of the next rectangle through the pointer + 1. The pointer is incremented by 1. This operation is required by the algorithm.
Arithmetic operations are used in applications where formula calculations are relatively simple. However, the techniques and implementation of arithmetic operations used in algorithms are not that simple. The key points to note are: define some intermediate variables, and make them into loop operations through the addition and subtraction of intermediate variables.
6. Array
An array is a collection that stores data. Array operations are also commonly encountered in programming: the essence of an array is a collection of things. However, it should be noted that the number of collection objects is limited, and its array is stored in memory, so array operations are very fast. A large part of the use of arrays is the use of loop statements. The combination of arrays and loops greatly improves the quality of programs.
For arrays we should pay attention to:
1. Issues related to the number of arrays
2. Representation method and storage form of multi-dimensional arrays
3. Array out-of-bounds problem
4. Empty array
5. The use of arrays in loop statements.
Attachment: I thought this topic could be solved in one article, but the more I wrote, the more it became. I had no choice but to simplify it and then simplify it, so let’s write it in parts.
Next article "Practical Programming Skills Programmers Should Master 2"
Main content:
7. Call
8. File operations
9. Logical operations
10. Array
11. Database
12. Controls
13. Class
14. Parameterization