naming standards and basic rules in .net coding

Post on 29-Nov-2014

1.389 Views

Category:

Education

5 Downloads

Preview:

Click to see full reader

DESCRIPTION

This presentation about Naming standards and basic rules while coding in C#.net, this is best of my knowledge. If any mistakes please let me know .. Thanks for share!

TRANSCRIPT

…For Better Development

exception

class for

switch

interface

catch

while

if

elsenam

espaceint

string

do

public

Naga Harish Movvame.shareourideas@gmail.com

Naming convention is a set of rules. Those rules applied in our computer programming.

Naming is an important step to improving the clearness, readability, and maintainability of code when many developers are working on same application development.

For Well-organized code. To make easier to understand for

everybody in the team. To reduce time to understand source

code by new users. For better appearance. One important thing, you can

improve you value in development.

• Avoid using identifiers that conflict with keywords (for e.g.:- int, char, string and ….).

• Don’t use single character for Variable names.– Avoid using words like i, j, n, x, t and so on.– Give meaningful name like index, count, temp, flag …

• Don’t use long and meaningless names for variables, to understand in better way. It must short and smart.

• Don’t create variable with same name like Index and index using different case.

• Follow the standard while creating namespace or package– [CompanyName].[TechnologyName].[Feature]– For example:– Microsoft.Office.Word

• Write comments.• Don’t write more line code in same

method, try to separate into small methods. It may useful in feature.

• Use Tab then more white spaces.• Avoid hardcode numbers, use constants• User a single space before and after for

each operator and brackets.– if ( isTrue == true )Note:- Sorry!, I focused on DOTNET

• Avoid hardcode for strings, try to use resource files. So it will be easy to implement multi-language.

• Do not use a type prefix, such as C for class, on a class name. For example, use the class name FileStream rather than CFileStream.

• Do not use an Enum suffix on Enum type names.

• Is best to avoid using _ in class and interface names mainly.

• For better understand use Collection word at end of Collection class. For example :- MediaCollection

• Pascal case:-– The first letter in the identifier and the first letter of

each subsequent concatenated word are capitalized.– For Example GetName or SetName

• Camel case:-– The first letter of an identifier is lowercase and the

first letter of each subsequent concatenated word is capitalized.

– For Example getName or setName• Uppercase:-

– All letters in the identifier are capitalized. Use this convention only for identifiers that consist of two or fewer letters.

– For Example System.IO or System.Web.UI

Identifier Case Example

Class Pascal MyClass

Enum type Pascal Day

Enum value Pascal Sunday

Event Pascal OnClick

Exception class Pascal FileNotFoundExceptionNote:- Always ends with the suffix Exception IOException here IO is in upper case

Read-only Static field Pascal CheckValue

Interface Pascal IMyInterfaceNote:- Always begins with I.

Method Pascal GetName

Namespace Pascal System.Data

Parameter Camel userName

Property Pascal CurrentUserName

Protected instance field Camel getName

Public instance field Pascal GetName

Class-Level Private Variables Camel(with Leading Underscore)

_recordId

• It is better to follow those naming style in coding in .NET.

• So it will become easy to understand yourself and other developers, when any logic errors came.

• Don’t leave exception catch empty, write code for entry to event logo.– For e.g.:- try{ /*…..*/} catch { /*Event logo

*/}

Enjoy while coding…!

http://msdn.microsoft.com/en-us/library/czefa0ke%28v=vs.71%29.aspx

http://www.asp.net/ajaxlibrary/act_contribute_codingStandards_Naming.ashx for Ajax tool

Naga Harish Movva

top related