Following are the standard coding guidlines. Architecture
1. Always use multi layer (N-Tier) architecture. 2. Never access database from the UI pages. Always have a data layer class which performs all the database related tasks. This will help you support or migrate to another database back end easily. 3. Use try-catch in your data layer to catch all database exceptions. This exception handler should record all exceptions from the database. The details recorded should include the name of the command being executed, stored proc name, parameters, connection string used etc. After recording the exception, it could be re thrown so that another layer in the application can catch it and take appropriate action. 4. Separate your application into multiple assemblies. Group all independent utility classes into a separate class library. All your database related files can be in another class library.
ASP.NET
1. Do not use session variables throughout the code. Use session variables only within the classes and expose methods to access the value stored in the session variables. A class can access the session using System.Web.HttpCOntext.Current.Session 2. Do not store large objects in session. Storing large objects in session may consume lot of server memory depending on the number of users. 3. Always use style sheet to control the look and feel of the pages. Never specify font name and font size in any of the pages. Use appropriate style class. This will help you to change the UI of your application easily in future.
Comments
Good and meaningful comments make code more maintainable. However, 1. Do not write comments for every line of code and every variable declared. 2. Use // or /// for comments. Avoid using /* … */ 3. Write comments wherever required. But good readable code will require very less comments. If all variables and method names are meaningful, that would make the code very readable and will not need many comments. 4. Do not write comments if the code is easily understandable without comment. The drawback of having lot of comments is, if you change the code and forget to change the comment, it will lead to more confusion. 5. Fewer lines of comments will make the code more elegant. But if the code is not clean/readable and there are less comments, that is worse. 6. If you have to use some complex or weird logic for any reason, document it very well with sufficient comments. 7. If you initialize a numeric variable to a special number other than 0, -1 etc, document the reason for choosing that value. 8. The bottom line is, write clean, readable code such a way that it doesn't need any comments to understand. 9. Perform spelling check on comments and also make sure proper grammar and punctuation is used.
|
No responses found. Be the first to respond and make money from revenue sharing program.
|