Generic Tips:
1. Try to minimize the development efforts using some tools for creating business objects and data access libraries
2. Try to use existing readymade libraries such as Microsoft.Practices.EnterpriseLibrary which has almost all the functions to access the database. On top of this you can create the DAL which contains the code for inserting, updating, deleting, selecting data for business objects.
3. For C#.NET install the StyleCop plug in for VS.NET which will be useful for coding standards. This is the tool Microsoft uses for their internal application development.
Find the similar plug-ins for other development platforms and use them.
Coding Tips:
1. Do not hard code strings, integer values everywhere. Keep the constants class and access the constant variables from that class
2. Try to use resource files for static controls, labels, text, messages. This would be useful if we have support multilingual in future. application.
3. Write the clean code so that anyone can understand quickly. Use the commenting style of each language such as
In C#.NET you can use /// and add summary and signature definition of function.
4. Try to use regular expression where ever possible in the code. Use the readymade controls for validations controls
5. Before writing each function try to see if you make sure of same function elsewhere so you can minimize the code by adding few more lines of code and parameters. Try to club all the utility functions together such as DateTime functions in one Utility class.
6. The sample function block in C#
///
/// Parses alert XML and returns the alerts object
///
/// Get the Alerts XML string
///
private alerts ParseAlertsXML(string alertsXML)
{
//// [Variable Declaration section] – This section you declare all the variables
//// XML serialize
XmlSerializer serializer = null;
//// Text Reader
TextReader reader = null;
//// Alerts Object to return
alerts objAlerts = null;
try
{
//// [Validation section]
//// Validate the inputs here and return error in inputs data is not valid
//// Object Cration and function logic
//// Create the objects necessary for function logic
//// Create new objAlerts
objAlerts = new alerts();
//// Create new XML Serializer object
serializer = new XmlSerializer(objAlerts.GetType());
//// Create new stringreader object
reader = new StringReader(alertsXML);
//// Fill the objAlerts from AlertsXML string
objAlerts = (alerts)serializer.Deserialize(reader);
//// [Returning the to caller if return type is not void]
//// Return objAlerts Object
return objAlerts;
}
catch (Exception)
{
[Raising Exceptions or returning the required value based on function use]
//// Return null since we are getting error in parsing the file
return null;
}
finally
{
//// [Very Important Section: Cleaning the objects created locally]
//// IMP Note:If you are using any IO (file) opreations such accesing the file, //// stream, it is very you should close them before exiting the application.
if (reader != null)
{
////Close the object
reader.Close();
}
//// Clear the objects here
serializer = null;
reader = null;
objAlerts = null;
}
}
Please see the above code architecture which you can implemented for any project. This architecture is N-tier architecture. It is shown as web application architecture but you can use this architecture for any other application development such as Windows application, Windows Mobile application, Java applications etc…
Finally one important point that by following coding standards you are making your own life easier. If you are following the coding standards you will reduce the number of bugs in the application also fixings the bugs / issues would be easier for yourself since the code written by you is clean and easier to understand.
Follow the standard coding practices and see the difference. Also spread knowledge / awareness of following coding standards among other colleagues so that they can also follow it.
I hope this will help everyone.
No comments:
Post a Comment