Peter Bahaa's Blog

Business and Technical Articles

Writing Professional Code Part (2)

November 11
by Peter Bahaa 11. November 2008 19:04

Design Pattern

Following any design pattern is the key of good project development; the website structure must show the business entities and its contents, ex: we are using a mixed design pattern of MVC and N-Tiers , so we need to have each item in place , we didn’t to stuck one specific design pattern , we need to apply what will help developing our project, btw , I was talking to Stephen Forte , “I invented a new design pattern ” , he smile and said back “ Design pattern did get invented it get discovered ” .

Naming Convention

You need to follow any naming convention, but it must be readable and if you run code analysis it will guide you through its rules, ex:

public DataTable SelectCustomerProjects

(

int customerId

, DateTime projectDateFrom

, DateTime projectDateTo

)

{

DataTable myDataTable = new DataTable("myDataTable1");

//......

return myDataTable;

}

Globalization

You need to put all your global functions in Web.Config , also be sure to cast any kind of numbers and dates with Current Culture

Ex: Convert.ToInt32(objectToConvert, CultureInfo.CurrentCulture);

Code analysis will show the write globalization options.

Comments

Write /// up on the function and this will produce the full big comment, ex:

/// <summary>

/// Get Customer's Projects

/// </summary>

/// <param name="customerId"> Cusomter Idenity </param>

/// <param name="projectDateFrom"> Project Starting Date Range From </param>

/// <param name="projectDateTo"> Project Starting Date Range To </param>

/// <returns>Projects of selected customer id or the selected data range in a DataTable</returns>

Resources

Use local and global resources so that your project could be converted to any language easily, (for web development) don’t write anything outside a controls, that won’t get work with resources.

Code Maintainability

Avoid high circular complexity functions , if you run code analysis , any function had circular complexity more than 25 it will produce a warning , so u need to break-down this function into smaller function so it will more maintainable ,

Also avoid writing business logic in presentation layer (UI) because that will make your project hard to get maintained.

Global Error Handling

Avoid writing Try {} catch{} only when u really need them and catch this errors globally by Web.Config “Custom Errors”

<customErrors mode="On" defaultRedirect="~/CustomErrors/Default.aspx" ></customErrors>

Logging

Use Global.asax to Log errors :

void Application_Error(object sender, EventArgs e)

{

// Code that runs when an unhandled error occurs

//Log the Error

}

W3C Standards (For Web Projects)

Check those @ http://www.w3schools.com/w3c/default.asp

Add comment




biuquote
  • Comment
  • Preview
Loading



Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar