Naming is the core of program planning. The ancients believed that knowing a person's true name would grant them incredible power over that person. As long as you think of the right names for things, it will give you and those who come after you more power than code. Don't laugh!
The name is a long-term and far-reaching result of something in the ecological environment in which it is located. In general, only programmers who understand the system can come up with the most appropriate name for the system. If all names are naturally appropriate, the relationship is clear, the meaning can be deduced, and ordinary people's inferences can be expected.
If you find that only a few of your names match their corresponding objects, it’s best to take a good look at your design again.
Class named
in for class (0;
}
----------------------------- -------------------------------------------------- -
Function naming
Function names follow the C GNU convention, all letters are lowercase, and '_' is used to separate words.
Reason
This makes it easier to distinguish related class names. 🎜>For example
function some_bloody_function()
{
}
----------------------------- -------------------------------------------------- -
Error return detection rules
Check all system call error messages, unless you want to ignore the error.
Define the system error text for each system error message to include
----. -------------------------------------------------- --------------------------
Braces {} Rules
Of the three main brace placement rules, there are two are acceptable, the first of the following is the best:
Place the curly braces in the same column below the keyword:
if ($condition) while ($condition)
{ {
... ...
} }
The traditional UNIX bracket rule is that the first bracket is in the same column as the keyword, and the last bracket is in the same column as the keyword:
if ($condition) { while ($ condition) {
... ...
} }
Reasons
Non-principled issues that have caused intense debate can be resolved through compromise, and either method is acceptable. , however, for most people, the first one is preferred. The reason is in the field of psychological research.
There are more reasons for preferring the first one if the character editor you use supports bracket matching. For functions (such as vi), the most important thing is to have a good style. Why? We say that when you have a large program and want to know where this large program ends, you first move to the beginning bracket. Press the button and the editor will find the corresponding closing bracket, for example:
if ($very_long_condition && $second_very_long_condition)
{
...
}
else if (.. .)
{
...
}
To move from one block to another just use the cursor to match your bracket keys, no need to move back and forth to the end of the line Find matching parentheses.