Coding Guidelines

Coding Guidelines

Sitecore Coding Guidelines

  • Use simple, meaningful and intuitive names for data templates, fields, and sections
  • Implement code in a consistent and simple manner to make site maintenance and troubleshooting easier
  • Follow industry standard best practices for the technologies you implement
  • Use C# rather than VB because all the Sitecore programming examples are in C# and C# is the language understood by Sitecore Support
  • Use App_Config/Include files instead of directly modifying the web.config file so that customizations are not overwritten during a Sitecore version upgrade
  • Use <settings> in a *.config file to hard code information, rather than placing it in the code
  • Use content items to model static text values and metadata instead of hard-coding them in the code
  • Use comments to explain the logic behind the code rather than the code itself
  • Use the FieldRenderer and other Sitecore web controls in order to support the Page Editor
  • Use parameters and properties when creating pipelines/events
  • Reference GUIDs rather than paths because items get moved more often than they get deleted and recreated
  • Always test for null and empty strings before binding the data
  • Use LINQ expressions over foreach because they will be easier to read and maintain
  • Write exceptions to the Sitecore log files
  • Use a distributed source control environment, such as GIT, to manage both code and configuration files separately
  • Use Team Development for Sitecore (TDS) to extend the benefits of source control to Sitecore code definition items
  • Set up a continuous integration system, such as CCNET, to speed up code deployments
  • Use the SecuritySwitcher class over the SecurityDisabler class
  • Define navigation based on the information architecture when it makes sense, such as for page-centric sites.  Define navigation using a separate hierarchy under the metadata (globals) portion of the Content Tree when it makes sense, such as for panel-centric sites that use panels in various combinations to display pages and the hierarchy of the Content Tree has no relation to the organization of the site

Sources