9 programming habits of successful software developers 5

zhaozj2021-02-08  205

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

A = 0;

Else

a = 1;

What do you know what the above program means? If you don't know what the variables x, y, and a refer to what is, it is difficult to understand. Let us give it a marked comment again:

/ *

* Programs detection profit or loss

* /

INT x = 100;

/ * X is the total amount of the sale * /

INT Y = 1000

/ * Y is the cost of doing books * /

Int a;

/ * Confirm that there is a profit * /

/ * Comparison X and Y: * /

IF (x

/ * 1 means losses * /

a = 1;

Else

/ * 0 Refers to the profit * /

A = 0;

This note, people who don't understand C language will also understand what the statements mean, what each variable refers to. Write a comment is a good habit, but don't comment. The comment is for a so-understanding, not for writing a long-editing article.

INT profit = 1;

/ * Profit equal to 1 ?? * /

INT LOSS = 0;

/ * Loss is equal to 0 ?? * /

/ * If the profit is equal to 1 * /

IF (Profit == 1)

/ * Print "win profit" ?? * /

Printf ("We Made a Profit! / N");

/* if not */

Else

/ * Print "We lose" * /

Printf ("We Made a Loss! / N");

This comment is a waste of time. Generally, a quarry is required, and the comment is required, and the purpose of the program, the use of a function, Procedule, etc. also needs.

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

New Post(0)