Sunteți pe pagina 1din 9

Programming Standards

Coding Style

Code Style
Source Code files One Namespace per file and one class per file.
Curly Braces On new line. Always use braces when optional.
e.g.

Bad Good

if (bIsEventNo) if (bIsEventNo)
doEvenCalculation() {
Else doEvenCalculation()
CallOddCalculation() }
Else
{
CallOddCalculation()
}

Indention Use tab with size 2. (with Insert spaces option set)
Comments Use // or ///. Avoid /* */
Do not put after code in same line.
Bad Good

if (bIsEventNo) // Check for even no // Check for even no.

Variables One variable per declaration. Initialize it wherever required.

Language Usage

Code Style
Native Data Types Use built-in C# native data types vs. .NET CTS types.
E.g. int vs. Int32
Enums Avoid changing default type.
Properties Never prefix with get or set.
Method Parameters Use a maximum of 7 parameters.
base and this Use only in constructors or within an override.
Trinary conditions Avoid.
for and foreach Prefer using for over foreach.
Conditionals Do not evaluate against true or false
No embedded assignment.
Avoid embedded method invocation.
Try/Catch/Finally Do not use exceptions for flow control.
Use throw; not throw e; for re-throwing.
Only catch what you can handle.
Events Always check for null before invoking.
Dispose() & Close() Always invoke them if offered.
Finalizes Avoid implementing one.
Never define a method named Finalize().
AssemblyVersion Increment manually.
ComVisibleAttribute Set to false for all assemblies.

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

Naming Conventions for Identifiers

Terminologies & Definitions:

Pascal Casing convention capitalizes the first character of each word (including acronyms over
two letters in length) as in the following examples.
PropertyDescriptor
HtmlTag
Camel Casing convention capitalizes the first character of each word except the
first word, as in the following examples.
propertyDescriptor
ioStream
htmlTag

Identifier Casing Prefix Suffix Example


Namespace Pascal namespace System.Security {…}
Interface Pascal I public interface IEnumerable {…}
Class Pascal C public class CDimension {…}
Method Camel public virtual string toString();
Property Pascal public int Length { get; }

Event Pascal Handler public class Process {


Public event EventHandler Exited;
}
Fields(static) Camel public MessageQueue {
Public static readonly TimeSpan infiniteTimeout;
}
Enum value Pascal FileMode {
Append,

}
Parameter Camel public static int ToInt32(string inputValue)

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

Windows Controls:

Control Prefix Example


Text Box txt txtFirstName
Combo Box cbo cboEmployeeID
Label lbl lblFirstName
Command Button btn btnOk
Option Button opt optAdd
Check Box chk chkApplyDate
List Box lst lstItems
Check List Box chklst chklstConditions
C1 Flex Grid grd grdItems
Group Box gb gbItemInfo
Panel pnl PnlPersonalInfo
Form F FStudent
User Controls uc ucFooter
Menu mnu mnuAdministration
Menu Item mni mniStudentDetail
Status Bar sts stsMain
TreeView tvw tvwBOMHierarchy
Control ctl ctlExceptionHandler
Table tbl tblItems
Progress Bar pgb pgbWorkProgress
CToolTip tip tipItemDescription
Frame fra fraAddressInfo
Image img imgEmployee
Toolbar tbr tbrMain
Dialog dlg dlgOpenFile
Data dat datParent
File Chooser fil filAttachedDocuments
Hor. Scroll Bar hsb hsbShowDetail
Ver. Scroll Bar vsb vsbShowDetail
Communications com com
Color Chooser clr clrFillColor

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

Variables:

Type Prefix Example


boolean b bSucceed
byte by byInnerLoopCntr
int (primitive) i iCtr
long l lRowID
decimal (primitive) d dAmount
double (primitive) dbl dblAmount
float (primitive) f fPercentage
string s sName
Enums enm enmColor
Array a asItems[N]
Arraylist al alParameters
Hashtable ht htNameValuePair
Object o oStudent
Database db dbTescor
DB Connection dbcon dbconOracle
Dataset ds dsStudentPersonal
Data Reader dr drStudentPersonal
Collection col Col
URL url urlYahoo
URLConnection urlcon urlconWorldWeb
Font fnt fntArial
Double (object) odbl odblCalculateResults
Integer (object) oi oiSelectedIndexes
Long (object) ol olSelectedRowIDs
Decimal (object) od odCalculatedValues
Float (object) of ofTaxPercentages
Dimension dim dimBox
Color clr clrBack
CDimensions dclr dclrBox

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

User Defined Types:

Type Prefix Example


Class C CStudentPersonnalInfo
Interface I IEntryScreen

Scope Prefixes:

Type Prefix Example


Member (Module Level m_ m_bDataSaved
variable)
Member static mst_ mst_iInstances
Argument a_ a_iStudentId
Local Variable No Prefix Local Variable

Database Field Naming Conventions:

Field Data Type Prefix Example


VARCHAR S S_EMPLOYEE_NAME
DATE/DATETIME DT DT_JOINING_DATE
CHAR C C_FLAG
NUMERIC N N_ID
NVARCHAR NS NS_EMPLOYEE_NAME

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

Form Standards
1. All forms should be centered (property 'StartPosition' set to 'CenterScreen').

2. All MDI child forms should be centered to MDI Main and smaller than MDI Main.

3. Minimize and Maximize buttons of all MDI child forms should be off (property 'MinimizeBox'
and 'MaximizeBox' set to 'False').

4. Form shouldn't be resizable (property 'FormBorderStyle' set to 'FixedSingle').

5. Appropriate spaces in the top, bottom, left and right corners of all the forms (Two pixels on top,
two on right and left corners and one on bottom).

6. Appropriate icon used throughout the application.

7. Tabs should be set.

8. Focus should be set on the right fields at the time of form load and after clearing the controls.

9. All controls should be properly aligned with appropriate spacing between them.

10. Font of form header label should be bold and color should be 'DarkBlue'.

11. Form header label should be followed by a group box with 'Height' set to 2 and 'Text' property
blank.

12. All label captions should be followed by a colon except the form header label.

13. Label captions of required fields should be followed by an asterisk (' * ') and the color of the
font should be 'Blue'.

14. Property 'MaxLength' of all text boxes should be set to the field value in the database.

15. Text fields which will remain disabled forever should be made 'Bold'.

16. The height of text boxes should be '20' and the width can be changeable.

17. The size of buttons should be '80, 22’ (with the exception that if the caption of a button isn't
getting accommodated then its width can be increased with all the other buttons of the same size
as that one).

18. Property ‘DropDownStyle’ of combo box should be set to ‘DropDownList’ (Unless there is an
exceptional case).

19. Label messages should be informative with Fonts 'Bold' and color 'Blue' for informative
messages and 'Red' for error messages.
20. Shortcut keys specified for the menu items and the buttons shouldn't be same.

21. Check verbiage (proper values are getting inserted and retrieved from the database).

22. Perform validations. Eg: - Numeric field should accept only integer values etc.

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

Checklist for Source Code Review

1. General
a. Followed file naming conventions for Form/Class/Modules?
b. Is the objective of Form/Class/Module defined?
c. Code indented properly?

2. Variables & Constants


a. Followed variable naming conventions?
i. Variable type prefix is appropriate.
ii. Scope prefix is appropriate.
b. Meaningful and Self explanatory?
c. Used constants instead of value for constant values?

3. User Defined Methods


a. Followed method naming conventions.
b. Method name is meaningful and self explanatory.
c. Followed naming conventions for parameters
d. Is parameter passing type appropriate? (By Val or By Ref)
e. Specified scope properly?
f. Does only one task? (Should do only one task, multiple task should be
divided.)
g. Is it very lengthy? (Should not be too lengthy , if it is try to break it in
parts)
h. Should have only one exit point.

4. User Defined Functions


a. Followed method naming conventions.
b. Method name is meaningful and self explanatory.
c. Followed naming conventions for parameters
d. Is parameter passing type appropriate? (By Val or By Ref)
e. Specified scope properly?
f. Is return type specified?
g. Does only one task? (Should do only one task, multiple task should be
divided.)
h. Is it very lengthy? (Should not be too lengthy , if it is try to break it in
parts)
i. Should have only one exit point.
j. Is value returned?
k. Should have single return statement.
l. Return value should be compatible to return type.

5. Exceptional Handling (In Procedure and Functions)


a. Handled exception using Try catch block?
b. Avoided use of On Error.
c. Is finally used to do cleanup?

6. Condition
a. Ignored case while comparing strings?
b. Used brackets for the query combined with “OR” logical operator?
c. Avoided multiple negations in the query?

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

7. IF-Else Construct
a. Avoided multiple If-else?
b. Does every condition meet?
c. Is condition readable and easily understandable?

8. Looping
a. Is loop definite?
b. Is condition readable and easily understandable?
c. Avoid repetitive calculative inside the loop?

9. SQL Query and interaction with Database through code


a. Is SQL generation standard followed?

10. Approach
a. Is business logic encapsulated in Class?
b. Is design modular?

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com
Programming Standards

Tips for Coding

1. Break complex task into sub task.


2. A Procedure/Function/Property should perform only one task.
3. Procedure/Function should not be too big. (Not more than 20 lines
approximately). In such cases break the task into some more sub tasks.
4. Events should not contain the implementation. It should call the required
Functions/Procedures.
5. Use centralized function/procedure to enable/disable action performing controls
as well as security related things. Events should call this function accordingly.
6. Encapsulate global flag variables in properties. It will help in debugging.
7. Do not provide single event handler for the more than one control where control’s
status is important. Ex. Checkbox, Option button, combo box etc.
8. Write function/procedure for common task even though it’s very small (1 to 2
lines). This will help in debugging.
9. Forms should contain only presentation logic & data validations.
10. All the business logic and interaction with database should be encapsulated in
the Classes/Modules.
11. Use StringBuilder class to handle string operations.
12. Explicitly specify access modifiers.
13. Always avoid hard coded value. Use constants or enum in such cases.
14. Group class implementation using #region.
15. Group interface Implementations using #region.

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022


Tel: 9960276669
Website: http://www.zeonsolutions.com

S-ar putea să vă placă și