Code Naming Conventions Used in "ASP.NET Unleashed"

xiaoxiao2021-03-06  21

Code Naming Conventions Used in this book

......................... ..

Nevertheless, having a common convention is valuable when code must be read by multiple people in an organization (think code reviews). Having a common convention also makes it easier to read your own code if you return to it at a later date.

The most popular variable naming convention is called Hungarian Notation. It was originally developed by Charles Simonyi at Microsoft and has been used internally at Microsoft for a number of years. According to this convention, you should name all variables starting with a standard three or four Letter Prefix That Repesents The Variable's Data Type. for Example, An Integer Variable Used To Repesent A Customer's Age Should Be named IntCustomerage.

Microsoft recommends that you do not follow this convention in the case of the .NET Framework and ASP.NET. The motivation for this recommendation is that they expect you to use an advanced editor, such as Microsoft Visual Studio, to write your code. Visual Studio Automatically Provides you with information about a variable's type.

However, in this book, I will not assume that you are using Visual Studio to write your ASP.NET pages. In practice, developers use a wide variety of editors-such as Web Matrix, TextPad, UltraEdit, and Notepad-to write code Since I am NOT Assuming That You Are Using Visual Studio, a variable naming convention is necessary.

Furthermore, in my experience, many companies require their programmers to follow a strict naming convention that is typically some variation on the Hungarian Notation. I'll be using a variation of Hungarian Notation for the naming conventions used in this book. I've created a set of prefixes and naming conventions for the basic variable data types, ASP.NET Web Controls, ADO.NET classes, and event-handling subroutines. These conventions are listed in the following tables.My goal is not to provide a standard prefix for Each and Every Class in The .NET Framework. That Would Require Over 3,400 Standard Prefixes! The goal is to provide standard prefixes for the Most Common Types That You Would Use in Asp.net.

Table. Variable Naming Conventions

Type Prefix Example Array arr arrShoppingList Boolean bln blnIsPostBack Byte byt bytPixelValue Char chr chrDelimiter DateTime dtm dtmStartDate Decimal dec decAverageHeight Double dbl dblSizeOfUniverse Integer int intRowCounter Long lng lngBillGatesIncome Object obj objReturnValue Short shr shrAverage Single sng sngMaximum String str strFirstName

Table. WebControls

Type Prefix Example AdRotator adrt adrtTopAd Button btn btnSubmit Calendar cal calMeetingDates CheckBox chk chkBlue CheckBoxList chkl chklFavColors CompareValidator valc valcValidAge CustomValidator valx valxDBCheck DataGrid dgrd dgrdTitles DataList dlst dlstTitles DropDownList drop dropCountries HyperLink lnk lnkDetails Image img imgAuntBetty ImageButton ibtn ibtnSubmit Label lbl lblResults LinkButton lbtn lbtnSubmit ListBox lst lstCountries Panel pnl pnlForm2 PlaceHolder plh plhFormContents RadioButton rad radFemale RadioButtonList radl radlGender RangeValidator valg valgAge RegularExpression vale valeEmail_Validator Repeater rpt rptQueryResults RequiredFieldValidator valr valrFirstName Table tbl tblCountryCodes TableCell tblc tblcGermany TableRow tblr tblrCountry TextBox txt txtFirstName ValidationSummary vals valsFormErrors XML xmlc xmlcTransformResultsTable. ADO.NET

Type Prefix Example Connection con conNorthwind Commmand cmd cmdReturnProducts Parameter parm parmProductID DataAdapter dad dadProducts DataReader dtr dtrProducts DataSet dst dstNorthwind DataTable dtbl dtblProduct DataRow drow drowRow98 DataColumn dcol dcolProductID DataRelation drel drelMasterDetail DataView dvw dvwFilteredProducts

Event-handling subs

The name of an event-handling subroutine will consist of the ID of the control that raised the event followed by the type of event being handled. For example, a subroutine named btnSubmit_Click handles the Click event of a Button control named btnSubmit.

When a control that raises an event is not assigned an ID, the type of the control is used instead of the ID. For example, the subroutine named Button_Click handles the Click event of a Button control without an ID.

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

New Post(0)