📄 vcgxb.htm
字号:
<HTML>
<HEAD>
<TITLE>vcgxb.htm </TITLE>
<LINK REL="ToC" HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm">
<LINK REL="Index" HREF="htindex.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/htindex.htm">
<LINK REL="Next" HREF="vcgxc.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcgxc.htm">
<LINK REL="Previous" HREF="vcgxa.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcgxa.htm"></HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<A NAME="I0"></A><P ALIGN=CENTER>
<A HREF="vcgxa.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcgxa.htm" TARGET="_self"><IMG SRC="blanprev.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blanprev.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Previous Page"></A>
<A HREF="index-1.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/index.htm" TARGET="_self"><IMG SRC="blantoc.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blantoc.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="TOC"></A>
<A HREF="vcgxc.htm" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/vcgxc.htm" TARGET="_self"><IMG SRC="blannext.gif" tppabs="http://202.113.16.101/%7eeb%7e/Database%20Developer's%20Guide%20with%20Visual%20C++%204,%20Second%20Edition/blannext.gif" WIDTH = 37 HEIGHT = 37 BORDER = 0 ALT="Next Page"></A>
<HR ALIGN=CENTER>
<P>
<UL>
<UL>
<UL>
<LI>
<A HREF="#E68E143" >Hungarian Notation for Variables and Objects</A>
<LI>
<A HREF="#E68E144" >Formatting Your C/C++ Source Code</A></UL></UL></UL>
<HR ALIGN=CENTER>
<A NAME="E66E63"></A>
<H1 ALIGN=CENTER>
<CENTER>
<FONT SIZE=6 COLOR="#FF0000"><B>- B -</B>
<BR><B>Naming and Formatting Conventions for Visual C++ Objects and Variables</B></FONT></CENTER></H1>
<BR>
<P>This book's Introduction lists the Hungarian Notation prefixes that are most commonly used. This appendix expands on prefixes and covers the formatting of code, which can help you write better applications.
<BR>
<P>These naming conventions use a modified form of Hungarian Notation that commonly is used in C and C++ programming. The term <I>Hungarian</I> comes from the nationality of the conventions' inventor, Charles Simonyi, who at one time worked on the development of Access 1.0 at Microsoft. The prefix sz, which defines a zero-terminated string variable in C, is a common letter combination in the Hungarian language.
<BR>
<P>You might wonder why you should follow these rules when naming your variables. The long and short of it is that when we all follow the same set of rules, it's much easier to interact with each other. Of course, no variable name, no matter how well formed, will make poorly written code good. But well written and well formatted code, with variable names that follow standards, is much easier to debug and maintain.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>It's a good idea to learn and use as many of the established standards as you can. When you're thinking about making a career change, the ability to show well-written code that conforms to standards will generally be a positive influence on prospective employers.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<BR>
<A NAME="E68E143"></A>
<H3 ALIGN=CENTER>
<CENTER>
<FONT SIZE=5 COLOR="#FF0000"><B>Hungarian Notation for Variables and Objects</B></FONT></CENTER></H3>
<BR>
<P>There are a number of simple rules that you should follow when naming your variables and objects. The following is a set of rules that will assist you in making your code as readable as possible.
<BR>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>Microsoft doesn't always follow these guidelines. The file DBDAOERR.H has #defined variables that are mixed case, and other Windows header files demonstrate the same use of mixed case.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<UL>
<LI>For defined identifiers created using the #define directive, use all capital letters. Use underscores to break the name into logical words as necessary. For example, the NULL symbol is defined as follows:
<BR>
<BR>
</UL>
<BR>
<PRE>
<FONT COLOR="#000080">#define NULL ((void *)0)</FONT></PRE>
<UL>
Notice that the name NULL is in capitals. Also notice that NULL is defined as an address, not a scalar variable.
<BR>
<BR>
</UL>
<BLOCKQUOTE>
<BLOCKQUOTE>
<HR ALIGN=CENTER>
<BR>
<NOTE><B>NOTE</B>
<BR>
<BR>Remember that NULL (as used in C/C++) is different from null as used by databases. NULL in C/C++ is used to indicate an address that is undefined. The database null indicates a field that has no value, which is different from a field that contains a string of zero characters. A character field of zero characters isn't a null field.</NOTE>
<BR>
<HR ALIGN=CENTER>
</BLOCKQUOTE></BLOCKQUOTE>
<UL>
<LI>For all other identifiers, use mixed-case names. Don't use underscores as part of a regular name. For example:
<BR>
<BR>
</UL>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Correct</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Incorrect</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
FirstName
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
FIRSTNAME
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><BR></FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
firstname
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><BR></FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
Firstname
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080><BR></FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
first_name</FONT>
</TABLE></CENTER>
<UL>
<LI>For class definitions, use a preceding capital C, as in COurClass. This helps identify the item as a class definition.
<BR>
<BR>
<LI>For member variables in a class, precede the name with an m_. For example, use m_szFirstName as the name of a variable that holds a first name. The m_ prefix tells you (and anyone else reading your code) that this is a member variable.
<BR>
<BR>
<LI>Use Hungarian Notation for all simple variables. For variables that are classes, structures, or unions, don't use a prefix.
<BR>
<BR>
<LI>It's permissible to use single-character variables for short loop counters, but for no other purpose. If a loop is more than a few lines long, use a significant name for the loop counter. Most loop counters are the characters i, j, and k, used in that order.
<BR>
<BR>
</UL>
<P>Table B.1 lists the more commonly used prefixes of Hungarian Notation. Nothing in the concept of using prefixes prevents you from creating your own prefixes for types that don't already have a prefix defined. However, resist the urge to change a prefix of a data type that already has a prefix defined.
<BR>
<BR>
<P ALIGN=CENTER>
<CENTER>
<FONT COLOR="#000080"><B>Table B.1. Hungarian Notation prefixes.</B></FONT></CENTER>
<BR>
<CENTER><TABLE BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 CELLPADDING=3 >
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Prefix</I>
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
<I>Description</I>
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
b
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
BOOL (int)
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
by
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
BYTE (unsigned char)
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
c
</FONT>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
char
</FONT>
<TR>
<TD VALIGN=top BGCOLOR=#80FFFF ><FONT COLOR=#000080>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -