Programming Standards For Dot Net

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Programming Standards For Dot Net as PDF for free.

More details

  • Words: 1,715
  • Pages: 9
Programming Standards

Coding Style Code Source Code files Curly Braces

Indention Comments

Style One Namespace per file and one class per file. On new line. Always use braces when optional. e.g. Bad

Good

if (bIsEventNo) doEvenCalculation() Else CallOddCalculation()

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

Use tab with size 2. (with Insert spaces option set) Use // or ///. Avoid /* */ Do not put after code in same line. Bad Good if (bIsEventNo) // Check for even no

Variables

// Check for even no.

One variable per declaration. Initialize it wherever required.

Language Usage Code Native Data Types Enums Properties Method Parameters base and this Trinary conditions for and foreach Conditionals Try/Catch/Finally Events Dispose() & Close() Finalizes AssemblyVersion ComVisibleAttribute

Style Use built-in C# native data types vs. .NET CTS types. E.g. int vs. Int32 Avoid changing default type. Never prefix with get or set. Use a maximum of 7 parameters. Use only in constructors or within an override. Avoid. Prefer using for over foreach. Do not evaluate against true or false No embedded assignment. Avoid embedded method invocation. Do not use exceptions for flow control. Use throw; not throw e; for re-throwing. Only catch what you can handle. Always check for null before invoking. Always invoke them if offered. Avoid implementing one. Never define a method named Finalize(). Increment manually. 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 Namespace Interface Class Method Property

Casing Pascal Pascal Pascal Camel Pascal

Event

Pascal

Fields(static)

Camel

Enum value

Pascal

Parameter

Camel

Prefix

Suffix

I C

Handler

Example namespace System.Security {…} public interface IEnumerable {…} public class CDimension {…} public virtual string toString(); public int Length { get; } public class Process { Public event EventHandler Exited; } public MessageQueue { Public static readonly TimeSpan infiniteTimeout; } FileMode { Append, … } 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 Text Box Combo Box Label Command Button Option Button Check Box List Box Check List Box C1 Flex Grid Group Box Panel Form User Controls Menu Menu Item Status Bar TreeView Control Table Progress Bar CToolTip Frame Image Toolbar Dialog Data File Chooser Hor. Scroll Bar Ver. Scroll Bar Communications Color Chooser

Prefix txt cbo lbl btn opt chk lst chklst grd gb pnl F uc mnu mni sts tvw ctl tbl pgb tip fra img tbr dlg dat fil hsb vsb com clr

Example txtFirstName cboEmployeeID lblFirstName btnOk optAdd chkApplyDate lstItems chklstConditions grdItems gbItemInfo PnlPersonalInfo FStudent ucFooter mnuAdministration mniStudentDetail stsMain tvwBOMHierarchy ctlExceptionHandler tblItems pgbWorkProgress tipItemDescription fraAddressInfo imgEmployee tbrMain dlgOpenFile datParent filAttachedDocuments hsbShowDetail vsbShowDetail com clrFillColor

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022 Tel: 9960276669 Website: http://www.zeonsolutions.com

Programming Standards

Variables: Type boolean byte int (primitive) long decimal (primitive) double (primitive) float (primitive) string Enums Array Arraylist Hashtable Object Database DB Connection Dataset Data Reader Collection URL URLConnection Font Double (object) Integer (object) Long (object) Decimal (object) Float (object) Dimension Color CDimensions

Prefix b by i l d dbl f s enm a al ht o db dbcon ds dr col url urlcon fnt odbl oi ol od of dim clr dclr

Example bSucceed byInnerLoopCntr iCtr lRowID dAmount dblAmount fPercentage sName enmColor asItems[N] alParameters htNameValuePair oStudent dbTescor dbconOracle dsStudentPersonal drStudentPersonal Col urlYahoo urlconWorldWeb fntArial odblCalculateResults oiSelectedIndexes olSelectedRowIDs odCalculatedValues ofTaxPercentages dimBox clrBack dclrBox

IT Park, Near to VRCE Telephone Exchange, Nagpur – 444 022 Tel: 9960276669 Website: http://www.zeonsolutions.com

Programming Standards

User Defined Types: Type Class Interface

Prefix C I

Example CStudentPersonnalInfo IEntryScreen

Prefix m_

Example

Scope Prefixes: Type Member (Module Level variable) Member static Argument Local Variable

mst_ a_ No Prefix

m_bDataSaved mst_iInstances a_iStudentId Local Variable

Database Field Naming Conventions: Field Data Type VARCHAR DATE/DATETIME CHAR NUMERIC NVARCHAR

Prefix S DT C N NS

Example S_EMPLOYEE_NAME DT_JOINING_DATE C_FLAG N_ID 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

Related Documents

Vb Dot Net Coding Standards
November 2019 3
Dot Net
December 2019 31
Dot Net
November 2019 27
Dot Net
May 2020 23
Dot Net
August 2019 35