16/12/2013: 10 Best Practices of programming from CodeSpread
We love programming and having a knowledge of best practices always helps in writing beautiful code. Here, we have few best practices shared by professionals.
Best Practice#1, Use foreach loop instead of for loop wherever required.*
Best Practice#2, To make your file compact, right click on namespaces and select remove unused strings. It will remove all the unused namespaces, which are not used in your code anytime.
Best Practice#3, Create a separate config for connection strings and include it in web.config.
Best Practice#4 , Dispose unmanaged objects explicitly for ex: COM Objects
Best Practice #5, Create automatic properties and use either get or set, try to avoid both get and set together, if not required.*
Best Practice #6, Never append your stored procedure with ‘sp_’ as it might be treated as a system stored procedure and will lose its scope.
Best Practice #7, Please write each SQL verb on a new line as shown in the image.
Best Practice #8, During Exception Handling, Always use finally block to clear the objects while using try catch blocks.
Best Practice #9, Streaming interfaces, like XmlTextReader, give better performance and scalability, compared to loading large XML documents into the XmlDocument or XPathDocument classes and then using DOM manipulation
Best Practice #10, Keep EnableViewState Property as false for the page and enable it only for the required controls. It will minimize the page size.