Resources - ASP.Net Coding StandardsAdopting a common coding standard across your web applicationsNote: These standards assume C# but are just as applicable to VB etc. All these standards stay as close as possible to those recommended by Microsoft. The Microsoft's Design Guidelines for Class Library Developers (MSDN site) is a useful set of guidelines which all ASP.Net developers should take a look at. In particular, those new to C# coding should see the naming conventions section, including capitalisation conventions (Pascal vs camel etc) and when to use nouns, verbs etc for naming of identifiers. It is interesting to note that Microsoft are moving away from the hungarian style of notation in .Net (I think based on the premise that everything is an object anyway in the framework and identifier names should be based on semantics not types). Although Microsoft's guidelines are an excellent guide, I created this standards page, as I could not find a one-stop summary of standards I could follow quickly when building ASP.Net web applications - Microsoft's are not exactly a quick reference guide! Also, they do not target ASP.Net specifics (e.g. Web Control naming). Naming and CapitalisationBelow summarises the naming recommendations for identifiers in .Net. Pascal casing is used mainly (ie capitalise first letter of each word) with camel casing (capitalise each word except for the first one) being used in certain circumstances.
Note that acronym parts of phrases may be all in uppercase (e.g. SMSMessage) where relevant. User interface objects (text boxes, drop down lists etc) are treated as a special case and discussed in the next section. User Interface Objects and ControlsThe Microsoft .Net guidelines do not go into detail on the naming of user interface objects (again probably because they are only objects after all), but one approach that is well adopted is the use of the "control type" prefix convention (similar to hungarian style often used in VB, C++ etc). Although this should not be used for indicating variable types, it is useful for user interface controls as it makes it explicitly clear where user interface elements are in your code. Some samples are below for ASP.Net web form controls:
NamespacesAll namespace should use Pascal casing and be prefixed with your company (and department if you wish). See examples below: Sample "project level" namespaces:
Generic reusable routines, classes etc which will be used across projects, can sit at the 'company' or 'dept' level, for example:
Commenting CodeCode should be commented where necessary and C# XML commenting tags used, to aid VS intellisense, object browsing and on-line documentation generation if needed. Example: some sample C# source is given below for a method in an SMS tool I developed recently:
Full details of more XML tags can be found in the Visual Studio.Net on-line help.
|
|