Programmer must see ★ Programming Principles (Chinese English Comparison) ★ - "Enough Rope to Shoot yourself in the foot

zhaozj2021-02-16  49

Name and Identifies 44 Names SHOULD BE Common English Words, Descriptive of What The Function, Argument, ORVARIABLE DOES

44 names should be ordinary English words, used to describe this function, parameter or variable

44.1.do Not CLUTTER NAMES with GIBBERISH

44.1 Don't let the name (meaningless, deeper, not appropriate)

45 macro names shop be entirely_capitalized

45 macro names should be shaped like: entirely_capitalized

45.1 Do Not Capitalize MEMBERS OF An ENUM

45.1 Do not write enumerated type members to 45.2 DO NOT CAPITALIZE TY NAMES CREATED with a TYPEDEF

45.2 Do not write types defined by TypeDef

46 Avoid The Ansi C Name Space

46 Avoid ANSI C Name Space 47 Avoid The Microsoft Name Space

47 Avoid Microsoft Name Space 48 Avoid Unnecessary Symbols

48 Avoid unnecessary symbols 49 Symbolic Constants for Boolean Values ​​Are Rarely Necessary

49 Boolean symbol constant basically useless

General Programming Principle 50 Don't Confuse Familiarity with Readability

50 Be familiar with code and code is good, two things 51 A Function SHOULD Do IONE Thing

51 A function should only complete one thing 52 Too Many Levels of Abstract Or Encapsulation Are As Bad as Too Few

52 Excessive or too little abstract or package hierarchy 53 a Function SHOULD BE CALED More Tan Once, But? Br>

53 A function should be called multiple

53.1 Code Used More Than Once Should Be Put Into A Function

53.1 The code used in more than one place should become a function

54 a Function Should Have ONLY One Exit Point

54 A function should only have one exit point

54.1 Always Put A Return At The Outer Level

54.1 Always put a Return in the outer layer

55 Avoid Duplication of Effort

55 Avoiding Two Courses 56 Don't Corrupt The Global Name Space

56 Do not pollute the global name space

56.1 Avoid Global Symbols

56.1 Avoid global symbols 56.2 Never Require Initialization of A Global Variable To Call A Function

56.2 The call to the function should not depend on whether global variable is initialized

56.2.1 Make Locals Static in Recursive Functions If The Value Doesn't Span A Recursive Call

56.2.1 In the final return function, if a variable is independent of the timing, it should be a local static variable.

56.3 Use Instance Counts in Place of Initization functions

56.3 Using an example in the initialization function 56.4 if an esturn, don't use else

56.4 If there is Return in the IF statement, don't write else57 put The Shortest Clause of An IF / Else On TOP

57 shortest IF / Else clause in the top 58 try to move ire ire time Time Time

58 Try to make an error in the run to compile time 59 USE C Function Pointers As SELECTORS

59 Using C Function Pointer as a selector 60 Avoid Do / While LOOPS

60 Avoid Do / While Cycle

60.1 Never USE A Do / While for a Forever Loop

60.1 Do not use DO / While to achieve an infinite loop

61 Counting Loops Should Count Down if Possible

61 Cycling counts should be from big to small 62 don't do the same thing in Two Ways at the Same Time

62 Don't use different methods at the same time 63 Use for if any two of an initialization, test, or increment ispent

63 If ​​you initialize, test, the increment is two, you should use for statement 64 if it doesn't Appear in the test, IT Shouldn't Appear in Other Parts of for Statement

64 There is no variable that appears in the test portion of the for statement, nor should it appear in other two parts 65 Assume That Things Will Go Wrong

65 Always assume things to have an error 66 Computers Do Not Know Mathematics

66 computer does not understand mathematics

66.1 EXPECT The IMPOSSIBLE

66.1 Always impossible 66.2 Always Check Error-Return Codes

66.2 Checking the error Returns code

67 Avoid Explicit Temporary Variables

67 Avoid explicit temporary variables 68 NO MAGIC NUMBERS

68 Do not appear pure numbers 69 make no assumptions about sizes

69 Don't make a assumption 70 BEWARE of CASTS (C Issues)

70 pairs of type conversion to be careful (C language problem) 71 Handle Special Cases Directly

71 Treatment of special circumstances 72 don't try to make lint happy

72 Don't try to make Lint Do not report a problem 73 Put Memory Allocation and DEACATION CODE IN THE SAME PLACE

73 Allocate memory and release memory should be together 74 Heap Memory IS Expensive

74 Pile of memory is expensive 75 Test Routines SHOULD NOT BE Intective

75 Test Process should not be interactive 76 An Error Message SHOULD TELL TELL TELL TELL TELL TELL TELL TELL TELL

76 Error message should tell the user what is the correct 77 Don't Print Error Messages if An error is Recoverable

77 If a mistake is recoverable, do not print an error message 78 don't use system-dependent functions for error messages

78 Do not use system-related functions in error messages

转载请注明原文地址:https://www.9cbs.com/read-19044.html

New Post(0)