3030 views|3 replies

252

Posts

0

Resources
The OP
 

Reading Notes on the Good Book "Electronic Engineer Self-Study Handbook" 03 Program [Copy link]

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!

This post is from Analog electronics

Latest reply

There are specifications or SOPs for program writing, which makes it easier to maintain the program.  Details Published on 2021-8-21 11:40

2w

Posts

74

Resources
2
 

There are so many naming rules, haha, which one is the mainstream one and the popular one?

This post is from Analog electronics
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle

Comments

Camel case, Pascal case, and underscore case should be more commonly used!  Details Published on 2021-8-20 15:27
 
Personal signature

加油!在电子行业默默贡献自己的力量!:)

 

252

Posts

0

Resources
3
 
soso posted on 2021-8-18 13:54 There are so many naming rules, haha, which one is the mainstream one and which one is the popular one?

Camel case, Pascal case, and underscore case should be more commonly used!

This post is from Analog electronics
 
 
 
 

104

Posts

0

Resources
4
 
There are specifications or SOPs for program writing, which makes it easier to maintain the program.
This post is from Analog electronics
 
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list