For detailed information on best practices related to writing custom code using the SharePoint Object model refer to the following article.
http://msdn2.microsoft.com/en-us/library/ms778813.aspx