Anti-patterns in SharePoint development

There are many anti-patterns in SharePoint development, but since I seem to be doing more and more code reviews at the moment, I thought I’d list out some key ones I keep coming across.

  1. People write way too much C# code. Developers tend to fall back to C# far too quickly, without using out of the box components. A common example is when 300 lines of code is used to do a simple query operation against a list. In almost all circumstances, a Content Query Web Part, a Data View Web Part or even a simple SPDataSource is enough, and can be built in declarative code. Each line of code introduces potential performance problems, and each line of code has to be maintained and tested going forward.
  2. Developers often fail to deal with how their solution is going to be deployed. I’ve seen developers use stsadm -o export/import as a deployment mechanism. That’s fine for an initial deployment but really fails to deal with ALM scenarios – even in the short term. They also rely on manual steps and configuration to deploy – which is fine, but is prone to human error and isn’t a good strategy for platform hygiene.  
  3. Exception handling is almost universally poor. You need to work through how you are going to trap, record and report error conditions in your code. Defensive coding practices are key here, as is proper use of the ULS. The Microsoft Patterns and Practices Group have released good guidance on this.
  4. Scalability is often overlooked. I’ve seen code examples where entire DataTables are pushed into Viewstate. This is clearly not going to be good for performance – a complex object like that will have to be serialised (and then deserialised), which will put a load on server resources, and add significantly to the page weight (it could add MBs to it depending on the size of the data set).
  5. General .NET best practice often goes out of the window – so I’ve seen really bad patterns in XSLT and XML development.

There is good guidance, both officially from Microsoft and unofficially from the community, so there is really no excuse any more. Happy coding!

Advertisements

ReBlog: SharePoint 2010 Beta Release Known Issues

There have been a number of issues in the SharePoint 2010 Beta Release that have been written down and shared by the documentation team:

http://blogs.msdn.com/sharepointdeveloperdocs/archive/2009/11/20/sharepoint-2010-beta-release-known-issues.aspx

Essential reading for anyone playing with the beta…