GST Billing Software

header image

Coding Guidelines

Erachana Line

The coding guidelines that need to be followed during application development are described below:

Indentation:

1. Use TAB for indentation. Do not use SPACES. Define the Tab size as 4.

2. Comments should be on the same level as the code (use the same level of indentation).

Good:

// Format a message and display string

message = "Hello ";

MessageBox.Show( message );

Not Good:

// Format a message and display string

message = "Hello ";

MessageBox.Show( message );

3. Always place curly braces ({ and }) in a new line.

4. Use one blank line to separate logical groups of code.

Good:

If(val1>val2)

{

decimal Val3=val1+val2;

decimal Val4=Val3/2;

message = "Value is " + Val4;

MessageBox.Show( message );

If(…)

{

// Do something

// ...

}

}

Not Good:

If(val1>val2)

{

decimal Val3=val1+val2;

decimal Val4=Val3/2;

message = "Value is " + Val4;

MessageBox.Show( message );

If(…)

{

// Do somethin

}

}

5. There should be one and only one blank line between each method in the class.

6. The curly braces should be in a separate line and not in the same line as if, for etc.

Good:

if ( ... )

{

// Do something

}

Not Good:

if ( ... ) {

// Do something

}

7. Use a single space before and after each operator and brackets.

8. Keep private member variables, properties and methods at the top of the class file and public members after private member variable definition.

9. Place all namespaces ("using" statements) together at the top of the class file.

10. Use #region to group related pieces of code together. If you use proper grouping using #region, the page should look like this when all definitions are collapsed.

Naming Conventions:

1. Use Pascal casing for Class names

public class HelloWorld

{

...

}

2. Use Pascal casing for Method names or Expressions

void SayHello(string name)

{

...

}

3. Method names or Expressions Name should be Meaningful, descriptive and which should have not had any special characters.

4. Use Camel casing for variables and method parameters

int totalCount = 0;

void SayHello(string name)

{

string fullMessage = "Hello " + name;

...

}

5. Use the prefix "I" with Camel Casing for interfaces (Example: IEntity )

6. Use 'g' as prefix for the form level variables if get and set specifiers are used separately, then prefix 'g' and 's' respectively

Example: gBillNo, gId;

7. Use Meaningful, descriptive words to name variables. Do not use abbreviations.

Good : string address;

decimal salary;

Not Good: string nam;

string addr;

decimal sal;

8. Do not use single character variable names like i, n, s etc. Use names like index, temp One exception in this case would be variables used for iterations in loops:

for ( inti = 0; i< count; i++ )

{

...

}

If the variable is used only as a counter for iteration and is not used anywhere else in the loop.

9. Do not start variable with underscores (_) and should not use other special character

10. Do not use variable names that resemble keywords.

Example: string string=""; stringgoto=""; string class="";

For more info regarding key words refer below link

http://www.tutorialsteacher.com/csharp/csharp-keywords

11. Prefix Boolean variables, properties and methods with "is" or similar prefixes

Example: bool IsDuplicate;

Exception:

1. Do not use try/catch blocks for flow-control.

2. Never declare an empty catch block.

3. Avoid nesting a try/catch within a catch block.

4. Do not write try-catch in all your methods. Use it only if there is a possibility that a specific exception may occur and it cannot be prevented by any other means.

5. Use validation to avoid exceptions (Pre Save Validations, Pre Delete Validation, Post Save Validation Expression)

6. Exception message should not be technical it should understandable to end user.

7. When application throws an exception, use the throw statement without specifying the original exception. This way, the original call stack is preserved.

Good:

catch

{

// do whatever you want to handle the exception

throw;

}

Not Good:

catch (Exception ex)

{

// do whatever you want to handle the exception

throw ex;

}

8. Write your own custom exception classes if required in your application. Do not derive your custom exceptions from the base class SystemException. Instead, inherit from ApplicationException.

9. Avoid nesting a try/catch within a catch block.

10. Only use the finally block to release resources from a try statement.

General Classes:

1. Use the TypeConverter class to convert the values of the variable from one datatype to another datatype.

2. Use AggregateFunctionEvaluator class to get the Aggregate Values of the given GridColumn.

3. Use ExcelImport class to Import the specific data from Excel sheet to Data Base.

4. Use ExcelSheet and ExcelExport classes to Export data from Database to Existing Excel Template or Generated and Designed Excel.

5. Use SqlInterpreter Or DataAdapter class to execute the SQL queries.

6. Use GlobalVariables class to set and get values for the defined Global Variable.

Best Coding Practices:

1. Convert strings to lowercase or upper case before comparing. This will ensure the string will match even if the string being compared has a different case.

Example :

if ( name.ToLower() == "john" )

{

//…

}

2. Use String.Empty instead of ""

Good:

If ( name == String.Empty )

{

// do something

}

Not Good:

If ( name == "" )

{

// do something

}

3. Avoid writing very long methods. A method should typically have 1 to 25 lines of code. If a method has more than 25 lines of code, you must consider re factoring into separate methods.

4. Try to avoid hardcode the values and get it from Database or from Config file.

5. Write the sql queries in the formatted way not a horizontal way

string sql= "select 0 as chk, trantdsdetails.id, " +
"bill.billnumfull," +

"trantdsdetails.deductiondate, " +

"coalesce(trantdsdetails.taxrate, 0) as TaxRate, " +

"coalesce(trantdsdetails.TaxAmount, 0) as TaxAmount, " +

"coalesce(trantdsdetails.surchargerate, 0) as SurchargeRate, " +

"coalesce(trantdsdetails.surchargeamount, 0) as SurchrgAmt, " +

"coalesce(trantdsdetails.cessrate, 0) as CessRate, " +

"coalesce(trantdsdetails.cess, 0) as CessAmount, " +

from trantdsdetails" +

" left join LinkTDSChallan on TranTDSDetails.Id = LinkTDSChallan.DeductionID " +

"inner join bill on bill.billid = trantdsdetails.tranid " +

"inner join partymaster on partymaster.partyid = bill.partyid" +

"where trantdsdetails.tdsmasterid =" +TypeConverter.ConvertToInt(this.gSection) +" +

"and partymaster.deducteetype =" + this.gCompanyType + "" +

"and coalesce(TranTDSdetails.TDSAmount,0) <> 0 " ;

6. Try to avoid the single line with multiple conditions and make them in multiple lines

This needs to be done wherever a line of code is crossing the visible area in Visual Studio

Good :

If(dt.rows.count>0

&&txtVal.Text!=String.Empty

&&cmbPlcae.selectedIndex>0

&& val1>0)

{

//Do Something

}

Not Good :

If(dt.rows.count>0 &&txtVal.Text!=String.Empty&&cmbPlcae.selectedIndex>0 && Val1>0)

{

//Do Something

}

7. Use enum to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.

Usually it is best to define an enum directly within a namespace, so that all classes in the namespace can access it with equal convenience. However, an enum can also be nested within a class or struct.

Example :

EnumItemCategory

{

Taxable,

NonGST,

Exempted,

NilRated

}

8. Do not hardcode numbers. Use constants instead. Declare constant in the top of the class file and use it in your code. However, using constants are also not recommended. You should use the constants in the config file or database so that you can change it later. Declare them as constants only if you are sure this value will never need to be changed.

Example :

const double pi=3.142;

const int filesize=2048;

9. Any repeated code, which can be generalized with parameter, needs to be put it into function and called with arguments.

Variable Declaration Standard to be included