Well, this is a great old saying. But I still hope that more programmers can understand the influence of some details and habits on program reading. This largely determines the portability of the program.
1. Note that spaces are reserved between variable values. Some programmers often do not pay attention to it.
Bad:
Body.txt Version. Text = ib. Version. ToString ();
Body. oriDate. Value = ib. CreatedDate;
Body. revDate. Value = ib. UpdatedDate;
Okay:
Body.txt Version. Text = ib. Version. ToString ();
Body. oriDate. Value = ib. CreatedDate;
Body. revDate. Value = ib. UpdatedDate;
Comments:
A single sentence does not mean that when dozens of rows are together, it is enough for you to have a headache.
2. For or if statements, keep braces.
Bad:
If (I! = ArrHidBrand. Count-1)
Hidbrand + = ",";
Okay:
If (I! = ArrHidBrand. Count-1)
{
Hidbrand + = ",";
}
Second:
If (I! = ArrHidBrand. Count-1) hidbrand + = ",";
Comments:
When many statements of the same type are nested, the first method is easy to confuse and make mistakes, the second method is clear and understandable, and the third method is relatively easy to understand.
3. Avoid complex sentence structures and syntaxes, such as ternary operators. The following is an example.
Bad:
Body.txt HidBrand. Text = hidbrand = ","? "": Hidbrand;
Okay:
If (hidbrand = ",")
{
Body.txt HidBrand. Text = "";
}
Else
{
Body.txt HidBrand. Text = hidbrand;
}
Comments:
I believe that you can understand the first writing method only when you think about it. Good code should be pleasing to the eye, and many of us do not pay attention to it.
4. Duplicate code extraction to reduce repeated code. This is a high requirement. I hope everyone can review their code and try to streamline their code.