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,