Generally people go back to basics when something bombs , till then best practices are kept only in books. Anyways i have been thinking of writing about it from long time and here it goes today . just follow some of best practices and webparts maintenace becomes much easier and no more "Webpart maintenance page ".
- Error Handling : This is the most important part of webpart development . Always defined a try , catch , finally block in your webpart .E.g http://www.codeproject.com/KB/sharepoint/Errorhandling_in_Webparts.aspx
- Validate all user inputs
- Register the Client Side script to improve performance
- Always dispose the sharepoint Objects e.g. SPSite, SPWeb e.g. http://www.sharepoint-tips.com/2006/06/best-practices-writing-webparts-for.html
- Refrain using loops with list objects . use CAML query as much as possible to retrieve desired data