Running trough items, the don’t forgets

As engineer I guess everybody likes to debug some stuff. Including me. What I actually dislike are the ‘already expected’ bugs.
Today I found three big bugs in some code of myself and some of my collegues. So it’s time to write down muy first SC5 development rules.
My today’s rules are about: walking trough items in the Sitecore tree.

    When need items for a list, overview, archive, news, etc, create a template for there self. After you can always check if the item has at least the right template(item.Template.Name/item.Template.ID).
    Everytime you resolve an item using (for example: Sitecore.Context.Database.GetItem(“/sitecore/content/home/”)) check if the received item-objects aren’t null. Nullpointers are so easily created. But always hard to find in more complex code.
    Never forget that Sitecore paths start with a ‘/’.
    Never add full Item-objects to DataTable, DataSets, etc. When you are going to bind then to a repeater for example, it will cause lots of preformence. Validate the data in your code by filling only the properties you need. It much easier and your code becomes more clear. With some good validation you should also be able to protect yourself against nullpointers. And when the API changes for some reason, your IDE will notify you while compiling.
    Last but not least, don’t forget the rules of recursion. Recursion is very powerfull but can also let your application crash by out-of-memory-exceptions, etc. You definitelly need to know what you’re doing!

Hope this wise lesson 😉 will protect others from making mistakes during Sitecore development. Ofcourse it isn’t all just Sitecore stuff. Some is also general programming :).

Bye for now,
– Alex

2 thoughts on “Running trough items, the don’t forgets”

  1. Let’s try again, – this time HTML encoding the tags manually.

    Another one, easily forgotten (relating to XSLT) when comparing nodes:

    <xsl:if test=”$sc_item=.”>

    as this will cause full node (with children)comparison. Instead:
    <xsl:if test=”$sc_item/@id=@id”>

    – Lars

  2. Hey Alex,

    Waarom krijg ik een lelijke popup van een gekke kikker op jouw site?

Comments are closed.