Good programming habits

xiaoxiao2021-03-18  178

McConnell said in << Code Complete >>, good habits, because most of the programmers do nothing to do. Bill Gates also said that any outstanding programmers have done very well in the past few years, from that, the programmer's offset will be fixed. The predecessors said this, so, in the initial programming, they should be connected to the side, and cultivate good habits as soon as possible. Good habits refers to the norms of the industry in terms of the program's typography. In the program, the blank line functions as a segmentation program. Dedicated (more but less) will make the procedure layout clearer. Generally, after each class declaration, each function defines the end of the line. In a functional body, the lack of interval between the relevant statements is closely related, and the line should be separated elsewhere. A code is only one thing, such as when defining variables, it is best to occupy a row, and the variable is defined to give initial values. '{' And '}' It is best to separately, and two corresponding curly brackets should be in the same column. If a piece of code should be separated too long to write, such as: if ((very_longer_variable1> = very_longer_variable12) && (very_longer_variable3 <= very_longer_variable14) && (very_longer_variable5 <= very_longer_variable16)) in the definition pointer easily when we encounter this problem, such as INT * i, j; maybe mistake we define two pointer variables i, j, but in fact only i is a pointer variable, J is a plastic variable, in order to prevent such a situation, we generally should put the '*' Close to the variable name to be defined, such as Int * i, J; this will not produce such misunderstandings. Write the data of the public and private types in front of the class, but advocate writing the public type data in front because public general definition is the outward interface and private is usually the data that requires hidden. So don't just let yourself think clearly when designing classes, but also convenient for others to read. After all, the user is most concerned about the interface, who is willing to see a bunch of private data members? ! Be sure to write a comment! The program must be written, only occasionally executing on the machine (Harold Abelson, etc.). The writing program is first for people, followed by a computer (Steve McConnell). Write an comment helps others reading and understand your procedure, it is more likely to help you understand the procedures you write, maybe the maintainer after your program is yourself, when you try to remember what you are thinking about a year ago? . The identifier should be intuitive and can be spent, and it is desirable to know that "decoding" is not required. Its length should comply with the principle of "min-length &&max-information". Generally, the constant is all in uppercase, and the static variable is plus S_, the global variable is added to the first letter, etc., the first letter, etc., the data is in front of the data, and the data in the class is plus M_, don't write only Difference two variable names. The most objective thing is that naming rules should be consistent with the style of the operating system or development tool used.

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

New Post(0)