Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Draft naming convention
Message
De
14/02/2010 12:32:25
 
 
À
14/02/2010 11:16:50
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01449087
Message ID:
01449094
Vues:
62
Hungarian notation is not recommended in .NET. In fact, it's downright discouraged.

http://msdn.microsoft.com/en-us/library/ms229045.aspx

>Naming Convention including Hungarian Prefixes for use with SQL and C#
>Rodes Design
>
>Created: 2010-02-13 15:46
>Updated: 2010-02-14 03:27
>
>
>SQL Data Types
>
>Pre	Size	SQL Data Types	Description  
>
>bt 	1	bit			Integer data with either a 1 or 0 value  
>
>bf	1-510	binary		Fixed-length binary data with a max length of 8,000 bytes  
>bv	1-510	varbinary		Variable-length binary data with a max length of 8,000 bytes  
>
>in 	4	int         	Integer data from -2^31 to 2^31 - 1  
>ib 	8	bigint      	Integer data from -2^63 to 2^63-1  
>id	1-8   identity          Integer data used as primary key
>is 	2	smallint    	Integer data from -2^15 to 2^15 - 1  
>it 	1	tinyint		Integer data from 0 to 255  
>
>nm	5-17	numeric		Fixed precision and scale numeric data from -10^38 +1 to 10^38 -1  
>nd	5-17	decimal		Fixed precision and scale numeric data from -10^38 +1 to 10^38 -1  
>
>my 	8	money			Monetary data values from -2^63 to 2^63 - 1  
>ms 	4	smallmoney		Monetary data values from -214,748.3648 to +214,748.3647  
>
>rl	4	real			Floating precision number data from -3.40E + 38 to 3.40E + 38  
>rb	8	float			Floating precision number data from -1.79E + 308 to 1.79E + 308  
>
>dt 	8	datetime		Date-time data from 1/1/1753 to 12/31/9999, 3.33 milliseconds  
>ds 	4	smalldatetime	Date-time data from 1/1/1900 to 6/6/2079, one minute  
>
>cf 	1x	char			Fixed-length character data with a max length of 8,000 chars  
>cv 	1x	varchar		Variable-length data with a max of 8,000 chars  
>ct 	**	text			Variable-length data with a max length of 2^31 - 1 chars  
>
>uf 	2x	nchar			Fixed-length Unicode data with a max length of 4,000 chars  
>uv 	2x	nvarchar		Variable-length Unicode data with a max length of 4,000 chars  
>ut 	**	ntext			Variable-length Unicode data with a max length of 2^30 - 1 chars  
>
>mg 	**	image			Variable-length binary data with a max length of 2^31 - 1 bytes  
>
>cr	**	cursor		A reference to a cursor  
>
>sv	**	sql_variant		A data type that stores values of various data types
>
>xm	**	xml
>
>tb	**	table			A special data type used to store a result set for later processing  
>
>gt	8  	timestamp		A database-wide unique number updated every time a row gets updated  
>gu	16	uniqueidentifier	A globally unique identifier  
>
>	**    Very large size limit
>
>
>Notes:
>
>* Keywords should be all lower case.
>
>* Use camel case where the first letter is lowercase for variables, parameters, fields, and properties. Note that this varies from some conventions because it includes public variables.
>
>* Use Pascal case where the first letter is uppercase for all other identifiers such as class names, method names, event names, namespaces, enums, etc. Examples: Main, MyClass, ConvertCurrency, Console.Writeline.
>
>* Do not use underscore characters in identifiers but see exception below.
>
>* Use two-character lower-case 'Hungarian' prefixes for all SQL columns as listed above. This is what MS used to call 'System Hungarian' and Joel Spolsky calls 'light Hungarian'. Changes to SQL column data types should be rare. When that must happen, it is worth considering every reference.
>
>* Most common meaning of letter in the first position : 'b' binary or bit, 'i' integer, 'n' number, 'm' money, 'r' real number, 'd' date-time, 'c' character, 'u' unicode character, 'g' global. Exceptions: mg (image), cr (cursor). Use 'u' instead of 'n' to identify Unicode fields. The 'n' in nchar and nvarchar means 'national' but looks like 'n' for numeric.
>
>* Most common meaning of letter in the second position : 's' small, 'b' big, 't' tiny, 'f' fixed, 'v' variable. Exceptions: dt (datetime), tb (table), gt (global timestamp)
>
>* There is no difference between 'numeric' and 'decimal' but use nm for fields that contain natural numbers, nd for fields with decimal values.
>
>* Use one-character lower-case prefixes for local working variables: b (bool), i (int), l(long), f (float), d (double), m (decimal), c (char), s (string). These letters follow the C# 'numeric suffix' letters. Examples: bOK, i1, i2, iPtr, fX, dBig, mCalc, c1, cFlag, sVowels.
>
>* Use lower-case prefixes of three characters or more for public variables, parameters, fields, properties, etc. in C# code. These should reflect the usage of the data and would not directly correspond with SQL or internal data types. This is what MS used to call 'Apps Hungarian'. For instance 'dol' for dollar amounts and 'cent' for cents. A property such as 'dolPrice' or 'euroPrice' could have a C# data type of decimal. A property such as 'centBalance' which has no fractional part could be stored in a decimal or integer data type. More examples: heightWindow, widthWindow, heightForm, strLastName, rowPosition, colPosition, unsafeUserName, strFile, intFile, rstFile. When picking a prefix, go for the most important aspect of the variable. Do not combine aspects.
>
>* TABLE names have no prefix but are typed in all upper-case. The primary key of table TABLE is idTABLE. When a table name appears as part of an identifier name, separate it with an underscore. Examples: CUSTOMER_Browse, ADDRESS_Lookup.
>
>* Note that there is no letter to indicate scope as sometimes seen: m_ClassMember, g_nWheels. Instead the scope is roughly indicated by the length of the prefix: 1 letter = local variable, 2 letters = table column, 3+ letters = class member, etc.
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform