Guide to High quality C++/C programming-3rd-naming rules (2)

Source: Internet
Author: User

L "Rule 3-1-8" uses the correct set of antonyms to name a variable with a mutually exclusive meaning or a function of the opposite action.

For example:

int minvalue;

int maxValue;


int SetValue (...);

int GetValue (...);

2 "recommendation 3-1-1" to avoid the number of names, such as Value1,value2, unless the logic does need to number. This is to prevent programmers from being lazy and refusing to name their brains to cause meaningless names (because it's the easiest to use numbers).

3.2 Simple Windows Application naming rules
The author makes a reasonable simplification of the "Hungarian" naming rules, the following naming rules are easy to use and more suitable for the development of Windows application software.

L The "rule 3-2-1" class name and function name are grouped by words that begin with uppercase letters.

For example:

Class Node; Class name

Class Leafnode; Class name

void Draw (void); The name of the function

void SetValue (int value); The name of the function

L "rule 3-2-2" variables and arguments are grouped by words that begin with a lowercase letter.

For example:

BOOL Flag;

int DrawMode;

L "rule 3-2-3" constants are all in uppercase letters, with underscores separating the words.

For example:

const int MAX = 100;

const int max_length = 100;

L "rule 3-2-4" static variable prefix s_ (for static).

For example:

void Init (...)

{

static int s_initvalue; static variables

...

}

L "Rule 3-2-5" if a global variable is required, prefix the global variable with g_ (representing global).

For example:

int g_howmanypeople; Global variables

int G_howmuchmoney; Global variables


The data members of the "rule 3-2-6" class are prefixed with m_ (representing member), which prevents the data members from having the same name as the parameters of the members function.

For example:

void Object::setvalue (int width, int height)

{

M_width = width;

M_height = height;

}

L "rule 3-2-7" to prevent conflicts in some identifiers and other software libraries in a software library, you can add prefixes that reflect the nature of the software for various identifiers. For example, all library functions for the three-dimensional graphics standard OpenGL begin with GL, and all constants (or macro definitions) begin with GL.

3.3 Simple UNIX Application naming rules
< note: The original text here is missing >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.