Monday, January 14, 2013

.Net & SharePoint Coding Standards and Best Practices document

What are your .Net / SharePoint Coding Standards? Where is your SharePoint Best Practice document?

Many customers have posed this question at some point of time or other. And organizations spend lot of time and effort to create the documents (often only to impress customers). A senior resource in the team, an Architect or a Tech Lead, is usually allocated the task of creating the document. However, Coding standards need to be updated with every new release of the product, .Net or SharePoint. Keeping the document updated with the new release of products is an ongoing task. And we have seen SharePoint guidelines (for when to Dispose, and when not to Dispose) change for few scenarios in past.

I often come across Coding standard documents that are for .Net 2.0 or .Net 3.5 being used in today’s projects on .Net 4.0 and SharePoint 2010/2013. They have not been updated for recent versions of .Net and SharePoint due to various reasons. The document owners are (and most likely will always be) playing catch up with Microsoft releases.

Sometimes, the standards document is created and updated, but team members are not aware and educated about the same. The standards remain only on paper if not enforced in reality.

In my opinion, unless there is required expertise, long term commitment and budgets, Enterprises should stop maintaining coding standards for .Net and SharePoint.  

No, No…I didn’t say that there is no need to define them.

Microsoft is maintaining the standards and best practices for us. So why reinvent the wheel?

The time originally spent on documenting the standards can be more effectively utilized on educating the team members about the standards, and enforcing compliance towards the same in the organizational projects.

There is a possibility that your organization standards may differ from MS Standards (mostly related to naming conventions). In such cases, only the differences need to be captured instead of recreating entire standards.

Below are few links that might be useful:

·        C# / VB.Net Standards

Choose the version of .Net in above link for your project (Choose .Net 3.5 for SharePoint 2010 and .Net  4.0 for SharePoint 2013)

·        SharePoint 2010 Standards

All the links under “Customization Best Practices” at above link.

Update [11 Sep 2014]: Above link now redirects to a different page in MSDN. Copying relevant links below for reference.

Customization Best Practices

Best Practices with SharePoint Foundation 2010
Learn the latest best practices and guidance that can help you create efficient custom applications in Microsoft SharePoint Foundation 2010 and help avoid common development problems.

Best Practices with SharePoint Server 2010
Learn the latest best practices and guidance that can help you create efficient custom applications in Microsoft SharePoint Server 2010 and help avoid common development problems.

SharePoint Guidance from the Microsoft patterns & practices Group
Learn how to make the right decisions, take advantage of new capabilities, and follow proven practices when building applications for SharePoint 2010.

Disposing Objects
Learn best practices to follow when using SharePoint objects, to avoid retaining objects in memory in the Microsoft .NET Framework.

Handling Large Folders and Lists
Design custom code that works with large folders and lists to optimize performance.

Object Caching Techniques
Learn how to weigh the benefits of caching against the need for thread safety, because some SharePoint objects are not thread safe and caching causes them to perform in unexpected ways.

Writing Efficient Code in SharePoint Server
Troubleshoot and improve the performance of existing and new SharePoint Server applications


Best Practices:
·        SharePoint 2010 Best Practices
Update [04 Mar 2013]: Adding another useful link from Microsoft on SharePoint 2010 Best Practices

It’s also important to develop an understanding of why something is a best practice, what are the implications if you don’t follow it. Read the available documentation, discuss with a peer, follow a Master’s blogs, Watch Channel 9 Training Videos, these are some ways to build the depth and breadth.

Update [18 Sep 2013]: Adding SharePoint 2013 Best Practices link
·        SharePoint 2013 Best Practices


You can use code review tools for your ensuring the standards compliance in your projects.

MSOCAF = SPDisposeCheck + Important FxCop Rules + SharePoint 2010 Specific Rules

MSOCAF is an important tool for SharePoint Development. Though it’s created and mandated for SharePoint Online team, it can be used for On Premise projects also.

Update [18 Sep 2013]: Adding SPCAF
·        SharePoint Code Analysis Framework (SPCAF)
SPCAF is another useful tool for SharePoint Developers and available here.
SPCAF has the following advantages over MSOCAF:
1.     SPCAF has 400+ rules that it analyses compared to 120+ rules of MSOCAF
2.     It is easy to integrate SPCAF with Visual Studio 2010/2012 (not yet available for VS 2013).  I don’t think its possible to integrate MSOCAF with Visual Studio.
3.     You don’t need to have SharePoint 2010 installed on a machine to run  SPCAF, which is a limitation of MSOCAF. However, it needs .Net Framework 4.5.
At the time of updating this blogpost, SPCAF is in beta and available as a free download. The authors of SPCAF plan to make it a paid utility in near future.

Update [11 Sep 2014]:
SPCAF is now paid tool.  SPCopCE, SPCop Community Edition, is the free version of  SPCAF and  available here: 
For .Net, you can leverage FxCop or Visual Studio Code Analysis or a 3rd Party tool of your choice.



Thanks for the links Vinay !!

Rajdeep Chakraborty said...

Thank you Vinay.

Anonymous said...

The SharePoint 2013 links also pointing to 2010 link. Please check once. Probably you can refer to