Team Geeks - Beta Code Standards

Team_Geeks 团队账号 2023-12-06 23:03:16
Which course does this assignment belong to230 1-MUSE Community-CSDN Community Cloud
Assignment RequirementTeamwork-beta Sprint-CSDN Community
Team nameGeeks
The goal of this assignmentteam's code standards

目录

  • Code Standards
  • Statement writing
  • Note
  • Identifier naming
  • Readability
  • Variables, structures
  • Functions, procedures
  • Measurability
  • Program efficiency
  • Quality Assurance
  • Code editing, compilation, review
  • Code testing, maintenance

Code Standards

Statement writing

  1. If the parameters in the function or procedure are long, they should be divided appropriately.
  2. Align using only the space bar, not the TAB key.
  3. The code in all files should be indented, and the left and right parentheses should correspond to each other.
  4. In JS, JSON, and wxss files, the left parenthesis (such as "{, [", etc.) Should be placed after the code, and the right parenthesis (such as "},]", etc.) Should be indented with the code.
  5. When more than two keywords, variables, and constants are operated equivalently, spaces should be added before, after, or before and after the operators between them; Non-equivalent operations should not be followed by a space if it is a closely related immediate operator (such as->).

Note

  1. In general, the effective annotation amount of the source program must be more than 20%.
  2. Write comments while writing the code, and modify the corresponding comments while modifying the code to ensure the consistency between the comments and the code. Comments that are no longer useful should be deleted.
  3. The content of the annotation should be clear, clear and accurate, so as to prevent the ambiguity of the annotation.
  4. Avoid using abbreviations in notes, especially very abbreviations.
  5. The comment shall be similar to the code it describes. The comment on the code shall be placed above or to the right (the comment on a single statement). It shall not be placed below. If it is placed above, it shall be separated from the code above by a blank line.
  6. Data structure declarations (including arrays, structures, classes, enumerations, etc.) must be annotated if their names are not sufficiently self-annotated. Comments on a data structure should be placed adjacent to and above it, not below it; comments on each field in the structure are placed to the right of the field.
  7. The global variable shall be annotated in detail, including the description of its function, value range, which functions or procedures access it, and matters needing attention during access.
  8. Annotations are indented as described.
  9. Comments must be written for variable definitions and branch statements (conditional branches, loop statements, etc.). Avoid inserting comments in the middle of a line of code or expression.
  10. Annotate the function and intention level of the code to provide useful and additional information.
  11. The annotation shall consider the readability of the program and the layout of the appearance. If the language used is both Chinese and English, it is recommended to use more Chinese unless it can be expressed in very fluent and accurate English.

Identifier naming

  1. The name of the identifier should be clear, clear and have a clear meaning. At the same time, complete words or abbreviations that can be understood by everyone should be used to avoid misunderstanding.
  2. If special conventions or abbreviations are used in naming, notes shall be provided.
  3. Your own unique naming style should be consistent from beginning to end and should not be changed back and forth.
  4. For variable naming, it is forbidden to take single character (such as I, J, and K..). It is suggested to indicate its variable type and data type in addition to specific meaning, but it is allowed to use I, J, and K as local loop variables.
  5. The naming convention must be consistent with the system style used and be unified in the same project. For example, use the UNIX style of all lowercase and underline or the way of mixed uppercase and lowercase. Do not use the way of mixed uppercase and underline. It is allowed to use m _ and G _ as special identifiers, such as identifying member variables or global variables, followed by the way of mixing uppercase with lowercase.
  6. Don't use numbers or strange characters to define identifiers unless necessary.
  7. Use the correct antonym to name variables with mutually exclusive meanings or functions with opposite actions.
  8. With the exception of special applications such as compilation switches/header files, avoid definitions that begin and end with an underscore, such as _ EXAMPLE _ TEST _.

Readability

  1. Pay attention to the priority of operators, and use parentheses to clarify the operation order of expressions, so as to avoid using the default priority.
  2. Closely related codes in the source program should be adjacent as far as possible.
  3. Don't use difficult and skillful sentences unless it is necessary.

Variables, structures

  1. Remove unnecessary public variables.
  2. Clarify the relationship between a public variable and the function or procedure that operates the public variable, such as access, modification, and creation.
  3. When passing data to public variables, be very careful to prevent the occurrence of unreasonable values or out-of-bounds.
  4. Prevent local variables from having the same name as public variables.
  5. Do not use an uninitialized variable as an rvalue.
  6. Use strictly formalized, portable data types, and try not to use variables that are closely related to specific hardware or software environments.
  7. The function of the structure should be single, which is an abstraction for a transaction.
  8. Don't design a comprehensive and flexible data structure.
  9. The relationship between different structures should not be too complicated.
  10. The number of elements in the structure should be moderate. If the number of elements in the structure is too large, it can be considered to combine the elements into different sub-structures according to a certain principle to reduce the number of elements in the original structure.
  11. Carefully design the layout and order of elements in the structure to make the structure easy to understand, save space and reduce misuse.
  12. The design of the structure should consider forward compatibility and future version upgrade as far as possible, and reserve room for some possible future applications (such as reserving some space).
  13. Name the custom data type appropriately and make it self-descriptive to improve code readability. Pay attention to the unification of naming methods in the same product.

Functions, procedures

  1. Handle the error return code of the called function carefully and comprehensively.
  2. In the same project team, it should be clearly specified whether the function caller or the interface function itself should be responsible for checking the validity of the interface function parameters. By default, the function caller is responsible for checking the validity of the interface function parameters.
  3. Avoid designing multi-parameter functions, and remove unused parameters from the interface.
  4. Try not to write functions that depend on the internal implementation of other functions.
  5. The function should be predictable, that is, it should produce the same output as long as the input data is the same.
  6. Check the validity of all parameter inputs of the function.
  7. Check the validity of all non-parameter inputs of the function, such as data files, public variables, etc.
  8. The function name should accurately describe the function.
  9. The return value of the function should be clear and clear, so that the user can not easily ignore the error situation.
  10. When calling a function to fill in parameters, unnecessary default data type conversion or mandatory data type conversion should be minimized.
  11. Avoid unnecessary statements in functions and prevent junk code in programs.
  12. Prevent unrelated statements from being placed in a function.
  13. Reduce recursive calls within or between functions.
  14. For a function that provides a return value, it is better to use its return value when referring to it.

Measurability

  1. In the same project group or product group, the format of the information string printed by debugging shall be unified. At least the module name (or source file name) and line number must be included in the information string.
  2. While programming, select appropriate test points for unit testing, carefully construct test codes and test cases, and give clear comments. The test code part shall be a sub-module (in the module) to facilitate the installation and removal of the test code in the module (through the commissioning switch).
  3. Use assertions to find software problems and improve code testability.
  4. Use assertions to check for illegal situations that should not occur when the program is running normally but may occur during debugging.
  5. Assertions cannot be used to check for error situations that are certain to occur in the final product and must be handled.
  6. Add explicit comments to more complex assertions.
  7. Confirm the parameters of the function with the assertion.
  8. Use assertions to ensure that undefined features or functions are not used.
  9. Assertions and other debugging codes shall be removed from the formal software product (that is, relevant debugging switches shall be turned off).
  10. Write an error-proofing program, and then declare the error with an assertion after handling the error.

Program efficiency

  1. Always pay attention to the efficiency of the code when programming.
  2. Improve the code efficiency on the premise of ensuring the correctness, stability, readability and testability of the software system.
  3. Local efficiency should serve the global efficiency, and the improvement of local efficiency should not affect the global efficiency.
  4. Improve the space efficiency by improving the division and organization of the system data structure and optimizing the program algorithm.
  5. Carefully analyze and optimize the relevant algorithms.
  6. Analyze and optimize the division and organization of the functions in the module, improve the organizational structure of the functions in the module, and improve the efficiency of the program.
  7. Don't spend too much time trying to improve the efficiency of function code that is not called very frequently.
  8. On the premise of ensuring the quality of the program, the space efficiency is improved by compressing the amount of code, removing unnecessary code and reducing unnecessary local and global variables.
  9. In multiple loops, the busiest loop should be placed in the innermost layer.
  10. Avoid containing judgment statements in the loop body. The loop statement should be placed in the code block of the judgment statement.
  11. Try to replace division with multiplication or other methods, especially division in floating-point operations.
  12. Don't go for tight code.

Quality Assurance

  1. Build software quality in the process of software design.
  2. Priority principle of code quality assurance.
  3. Prevent references to memory space that has been freed.
  4. Prevent memory operation from crossing the boundary.
  5. Carefully deal with all kinds of errors that the program can encounter.
  6. At the beginning of system operation, check the consistency of the data loaded into the system.
  7. It is strictly prohibited to change the relevant settings and configurations of other modules or systems at will.
  8. Fully understand the interface of the system before using the functions provided by the system.
  9. Do not change the interface with other modules at will.
  10. Always be aware of confusing operators. When you have finished writing a program, you should check these operators from beginning to end to prevent spelling errors.
  11. When using variables, pay attention to their boundary values.

Code editing, compilation, review

  1. Turn on all alarm switches of the compiler to compile the program.
  2. Check the code by means of code walk-through and review.
  3. Before testing the product, the testing department shall conduct spot check and review on the code.
  4. When writing the code, pay attention to saving it at any time and backup it regularly to prevent the loss of the code due to power failure, hard disk damage and other reasons.
  5. In the same product software (project group), it is better to use the same editor and use the same setting options.
  6. Reasonably design the software system directory to facilitate the use of developers.
  7. Some statements generate an alarm after compilation, but if you think it is correct, you should remove the alarm information by some means.

Code testing, maintenance

  1. Unit testing requires at least statement coverage.
  2. At the beginning of the unit test, track each statement and observe the changes of data flow and variables.
  3. The cleaned, tidied, or optimized code should be reviewed and tested.
  4. Correct errors immediately and record them.
  5. Any modification of the official version of the software shall be documented in detail.
  6. Analyze the errors that disappear automatically and find out how the errors disappear.
  7. The problem should not be solved by "trying", but the root cause of the problem should be found.
  8. Insist on thoroughly unit testing the code at the coding stage, and don't wait for later testing to find problems.
  9. Remove the randomness of code operation (such as removing useless data and code and preventing and paying attention to the "internal registers" in the function as much as possible), so that the results of function operation can be predicted and the errors can be reproduced.
...全文
114 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

176

社区成员

发帖
与我相关
我的任务
社区描述
梅努斯软件工程
软件工程 高校 福建省·福州市
社区管理员
  • LinQF39
  • Jcandc
  • chjinhuu
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧