JSEDLAK » Best Practices

Posts Tagged ‘Best Practices’

Lessons In Bad Code Design

I run into these so much these days…

  1. Order Dependent Coding – Often I find code that is entirely dependent on the order of the content tree. If you are trying to render a specific item in the tree you have to go based on some unique feature of that item, not its order. The best choice here is not to depend on the specific item at all but rather that it exists and is of a certain type. Try to abstract your code to depend on the item being passed in to your code.
  2. Hard Coded Values – Hard coding has its time and place; it is especially great for quick and dirty tests. However you shouldn’t rely on a hard coded value for mission critical applications. All too often I find that developers write in a hard coded value that is possible the end-user will want to change. While this might provide you with a faux hour of work later on, it is just unethical and bad design. Rely on configuration files or databases instead to drive the settings of your code.
  3. Error Checking and Response – It is important that as a developer you attempt to catch errors. It is understandable that you will not be able to develop a 100% bug free application, but simple errors are simple to catch and handle. This is even more important in the web sphere where a single error can bring down an entire page in an ugly manner. While an unhandled exception in a (.NET) WinForms application presents the user with a nice “continue or quit” box, an unhandled exception on a site can easily cause a messy error page to show with no options for the user. One of the most common problems with the web is checking for a null value!
  4. Templating – Templates, Themes, et cetera all exist for a reason. They provide us with a way to treat all content of a certain type in a single manner. This greatly reduces the code we have to manage and reduces the dependency on us (by the end user) to create new content. This is a good thing, so use templates the way they were meant. Do not create a single template for a single instance of a content item.