vijay

welcome Netizen

Share Your Knowledge.It is a way to achieve immortality

Wednesday, February 22, 2012

VB.NET Golden Rules


The purpose of this article is to provide coding style standards for the development source code written in VB.NET. These is the best practice to follow the below standard forever in your vb.net.

The following guidelines are applicable to all aspects VB.NET development:

o  Make code as simple and readable as possible. Assume that someone else will be reading your code.
o  Prefer small cohesive classes and methods to large monolithic ones.
o  Use a separate file for each class, struct, interface, enumeration, and delegate with the exception of those nested within another class.
o  Turn Option Explicit and Option Strict on for every project under Project | Properties | Common Properties | Build. These can be made the default options for all new projects by going to Tools | Options | Projects | VB Defaults.
o  Don’t use the On Error Goto or  On Error Next statements. Use structured exception handling via Try/Catch blocks instead. They are the preferred method of performing error handling in .NET.
o  Write the comments first. When writing a new method, write the comments for each step the method will perform before coding a single statement. These comments will become the headings for each block of code that gets implemented.
o  Use liberal, meaningful comments within each class, method, and block of code to document the purpose of the code.
o  Mark incomplete code with ‘ TODO: comments. When working with many classes at once, it can be very easy to lose a train of thought.
o  Never hard code “magic” values into code (strings or numbers). Instead, define constants, static read-only variables, and enumerations or read the values from configuration or resource files.
o  Use the StringBuilder class and it’s Append(), AppendFormat(), and ToString() methods instead of the string concatenation operator (+=) for large strings. It is much more memory efficient.
o  Be sure Dispose() gets called on IDisposable objects that you create locally within a method. This is most commonly done in the Finally clause of a Try block. It’s done automatically when a Using statement[1] is used.
o  Never present debug information to yourself or the end user via the UI (e.g. MessageBox). Use tracing and logging facilities to output debug information.
I hope you like this article..Also please share your thought about rules must follow in .net


0 comments:

Post a Comment