9 programming habits of successful software developers

zhaozj2021-02-08  212

Some people who have a good original program will think: As long as the program runs well, there is no matter what the original program is. But absolutely not the case. The software is not finished in one time, it is necessary to make changes, expansion and other management. Therefore, the original procedure should be as easy as possible to understand, and the management is convenient. In doing so, the first is for software developers, followed by the software performance. Managing inconvenient programs will not make good software. I hope to learn good program habits through this article. To understand the content of this article, you should know at least 1 development tool language. It is a C language for example, but you don't worry about the C language. The principle described here is not a specific language. 1. The statement should be completed --- (colon;) one of the frequent mistakes often has a colon after the end of the statement. Such problems are not easy to discover, and the programmer is not known when it is. When programming, pay attention to whether each statement ends with a colon, although not all languages ​​ends with a colon. The following is an example of forgetting a colon. INT main (void) {/ * has no colon, resulting in problems * / printf ("Hello World! / N") Return (0);} Many people make such errors. Less than a few procedures are not difficult to find such problems, but more than 1,000 procedures? Find that the statement that I forgot to write a colon will not be very easy. Remember, end a statement, must write a colon, just like the end of the general article. There is also a wrong mist of colon not to write a colon. Experienced programmers see that the following example will feel funny, but the author does have seen a lot of such mistakes. / * Main () does not write a colon * / int main (int Argc, char * argv []); {Printf ("Hello World"); return (0);} Function or method is not written .

2. To properly use spaces and TAB keys C language, it is not distinguished, so the program can also write it all the time, but such a program will not understand "very difficult" program, please see The following example: if (x == 0) {a = b = c = D = max; x ;} This is written, may save space, but not only others, the programming it will be difficult to understand. The program is easy to understand! IF (x == 0) {a = b = c = D = max; x ;} Is this written, do you look clear? The program has to be exact spaces to understand. 3. Uniform use of braces and cut-off mode Each programmer has its own habits using braces ({}) and modified ways, so that when handing over the program to others, there will be confusion. For example, INT MAIN () {int x = 1; int y = 10; While (x

4. Some people who do not mess with the IF statement like to use the "if" statement, as follows: if (a == 0) {A ; return (a);} if (a == 1) {a = 5; return (A );} if (a == 2) {a = 10; return (a);} if (a == 3) {a = 20; return (a);} if (a == 4) EXIT ( 1) Is there any better way than this? ELSE IF statement? Not. A good way is to write a simple program with the "switch-case" statement: Switch (a) {case 0: A ; return (a); case 1: a = 5; return (a); case 2: a = 10; Return (a); case 3: a = 20; return (a); default: exit (1);} If the value is not consistent with A, the job defined in Default is executed, the above example is to Perform the end. 5. Many people who do not mess with the procedure (Block) often use the program to cut off. It is a program that is more difficult to understand using more than three cut off. Please see the following example: int a = 10; int b = 20; int C = 30; int D = 40; if (a == 10) {a = A D; if (b == 20) {b = B a; if (c! = b) {c = c 1; if (D> (A B)) Printf ("Made it all the way to the bottom! / n");}}} This may be Exaggerated, but there are still many people really do this. How do you write better? One method is to use a function to partition: Void next (int A, int b, int C, int D) {if (c! = B) {c = C 1; if (D> (A B)) Printf ("Made It All the Way To the Bottom! / N");}} int Main () {INT A = 10; INT B = 20; INT C = 30; INT D = 40; if (a == 10 ) {A = a D; if (b == 20) {b = b a; Next (A, B, C, D);}} return (0);} To write this, maybe increase workload But the program is structured, it is easy to understand, and if the function is better, it can be used in other places.

6. Write a note to develop a habit of writing a comment. Especially the procedures or variables that others are difficult to understand must be annotated. After a month, maybe you also need to see the comment. INT x = 100; int y = 1000; if (x

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

New Post(0)