13, naming of functions and variable names

xiaoxiao2021-03-06  82

----------------

I see that many programs are named in the variable name and function name, especially the variable name, what A, B, C, AA, BB, CC, what FLAG1, FLAG2, CNT1, CNT2, which are the same There is no "cultivation" behavior. Even good comments. A good variable name or a function name, I think there should be the following rules:

1) Intuitive and can be spelling, I hope that literally is meaningless, don't "decode".

2) The length of the name should be the shortest length, but also to maximize its meaning.

3) Don't write all over, don't lower your lowercase, you should write, such as: getLocalHostName or useeraccount.

4) You can be short-handed, but you have to understand, such as: ErrorCode -> Errcode, ServerListener -> Servlisner, Useraccount -> USRACCT, etc.

5) In order to avoid the full bureau function and variable name conflict, you can add some prefixes, usually the module is referred to as a prefix.

6) The global variable is unified to add a prefix or a suffix, let people see this variable knows that it is global.

7) Name the function parameters in Hungarian nomenclature, local variables. But still have to adhere to the principle of "Wangwen Business".

8) Maintain consistent with standard libraries (such as: STL) or development libraries (such as: MFC).

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

New Post(0)