9 programming habits of successful software developers (4)

zhaozj2021-02-17  51

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.

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

New Post(0)