This post was last edited by qi777ji on 2021-8-18 10:02
Today I read the chapters on MCU driver and programming. Although the MCU models involved are a bit old, it can be seen that the author is very attentive. He first explains the principle, then the detailed explanation, followed by the detailed routine, and finally the program description. The program should be written line by line by yourself, and almost every line has comments, and the comments are very detailed. There are also relevant pictures to explain the principle, which is rare in this impetuous era. This is very valuable for beginners.
I noticed a problem, which is the naming of program variables. I think it is necessary to discuss it. If you write some programs yourself and look at them yourself, it doesn't matter. But generally, larger companies will have specifications or SOPs for program writing, which makes it easier to maintain programs. Many people may have this experience. Looking at some people's programs is like reading a book of heaven, with no rules or order. Generally, companies emphasize rules and uniformity. If someone suddenly leaves the program he wrote, the people behind him will have no way to maintain it. An unmaintainable program is unsustainable and becomes garbage. For example, the names of local variables should be meaningful. Don't use x, y, z, etc. (except for For loop variables, you can use i, j, k, l, m, n). Good variable naming rules make it clear at a glance, and with reasonable comments, you can know what the program is doing.
Common variable naming rules are: 1. Hungarian naming method [Hungarian] Add the corresponding lowercase symbol as a prefix to the variable name to identify the scope and type of the variable. It is widely used in environments such as Windows. It is
relatively old and complicated, and it is estimated that not many people use it.
2. Camel case naming (camel case naming) [camelCase] uses a mixture of uppercase and lowercase letters to form the names of variables and functions. Except for the first word, the first letter of other words is capitalized. In recent years, it has become more and more popular in environments such as Windows. It is used more and more properly
. 3. Pascal case naming [PascalCase] is similar to camel case naming. The only difference is that the first letter of camel case naming is lowercase, while the first letter of Pascal case naming is capitalized.
4. Underscore method became popular after the appearance of c. I personally like to use underscore method.
g_iRelayTriggerOff is a Hungarian naming convention.
relayTriggerOff is a CamelCase naming convention.
RelayTriggerOff is a PascalCase naming convention.
relay_trigger_off is an example of an underscore naming convention
. Relay_Trigger_Off Underscore + Pascal --- if necessary! Actually, I prefer this! ! ! (By the way, just because you like it doesn't mean you can use it in your company! Reality is so cruel! Poor workers!)
If you are a great programmer and the company cannot do without you, then you can write some incomprehensible programs to your heart's content, leaving no way for those who come after you!!! It
is difficult to change a person's programming style, but you must choose a style that suits the company, because the company cannot adapt to you, only you can adapt to the company. This process is very painful. You must develop a good programming style. Continue reading next time!