Project code experience, programming specifications

1. Clear
code is first shown to humans, then the compiler, and then executed by the machine.
For example, multiple for, if statements, using the following style will be clear

if ()//多重会比较清晰
{
    
    
}


if (){
    
    
}

2. Concise,
try to write code that is easy to understand and easy to implement. It's quite satisfactory. Don't think about show. Write according to the specifications . You may not remember some uncommon usages of the function in the future.

3. Adhere to the appropriate code style. The
code style includes code and comments . Sticking to a certain style from scratch will make the code look more comfortable.

4. Don’t try to design a comprehensive data structure.
First, it can be realized, and then think about other things.

Programming naming convention

  1. Add g_ before global variables, add s_ before static variables, and pointer p_
  2. Proper nouns are written together-gBest (the optimal position of the group), cycle_gBest (the value corresponding to several cycles)
  3. Choose a good name-variables like temp, a, b, etc. have no meaning. You can remember what the meaning is when you look at the name

5. Think first before writing the code. The first step
to get a requirement is to analyze the requirement, disassemble the problem, and disassemble the big problem into smaller problems . The code can be written quickly when the idea is clear.

6, version management
Git

Guess you like

Origin blog.csdn.net/qq_43641765/article/details/111339062