null considered harmful

By incident I stumbled accross the book “Clean Code: A Handbook of Agile Software Craftsmanship” by Robert C. Martin. In this book there is a section on exception handling which is a worthwhile read. It states some obvious things – like handle exceptions there where you know what to do with them — but it is good to be remembered by these best practices once in a while…

One of the more interesting things in that section I found the usage, or better should-not-usage, of null values. Return null is typically a sign of something that doesn’t work. Returning null values clutters op code with all kinds of “if null” checks. Moreover, who hasn’t seen a NullReferenceException lately? Instead of returning null, a number of alternatives can be thought of:

First, if the null is actually the result of an error conditions, throw an exception containing thate error condition. If the error is actually based on a deeper lying exception, simply don’t handle that exception and have it bubble upwards. This way it is clear to the user of our object/method that an error condition has been met. Moreover, the exception should contain the necessary information to aid the programmer in preventing that condition.

Second, if the null value is the result of an expected situation, implement the “Null Object Pattern”, or “Special Case Pattern” instead. Using these patterns you return an object that implements the expected interface, but which implementation is empty. For example, a search for files in an empty directory should return an empty list instead of null. The empty list can be iterated, checked for presence of files, but does not have to be explicitly checked for null.

ImageCloud plugin

During my work I got confronted with Wordle. A colleague used Wordle to show what a specific website was about. I got interested in how these beautiful word clouds were made and if I could add them to my own website.

Regrettably, the Wordle algorithms cannot be shared by the author because of intellectual property reasons (IBM owns his work). Given the popularity of Wordle, I found it strange that no WordPress plugin existed that would generate similar word clouds. Searching the web for similar algorithms didn’t provide me with much answers either. But hey, how hard can it be? I decided to have a go at it myself.

Read more

text2tag plugin

I have been wondering how to keep the tags in a blog to describe its content accurately. As I’m not the most disciplined person, tagging posts correctly and precisely is not what I’m best at. During my work I encountered someone who had made use of Wordle. He used Wordle to quickly analyse the contents of a website. The result was great. Simply counting the words seemed a simply and effective way to accurately describe the contents of a site.

So I ended up creating two plugins: one for creating tag-clouds that have the “Wordle” look and feel, and one for “tagging” posts, simply by enumerating all used words in a post. The first is described on an other post: ImageCloud plugin. The second has become the “text2tag” plugin.

The text2tag plugin can be downloaded from WordPress: Text2Tag.
Read more

New website new content

Hi all,

A fresh start for my new blog. New look and feel, new content. This time I plan to write more on my experiences with different technologies I encounter during work and at home. I’ve noticed that I learn a lot of what people share on the Internet, so this will be my corner where I can contribute…

More content to follow…

Joost

Tags

This page shows an overview of all words used on this blog.

addedallbeencontentcouldcreatecreatingdoduringexamplefeaturesfirstfunctionalityhashaveiifintolikelistlooklotmaymemoremostmuchmynewnotonesetsitesomesupporttherethesetimeuseusedwayWebsiteworkyouyour

Plugins

This site is made using WordPress, the excellent blogging tool. One of the great things about WordPress is that it is so easy to extend. For example the layout of this blog is an theme extension. Furthermore the pictures are managed using the Yet Another Photoblog plugin.

In order to have this blog do exactly what I want, I’ve created a few plugins of my own:

  • text2tag plugin A plugin that collects all used words in posts and pages into a taxonomy (e.g. the post tags). This creates a taxonomy with a pretty accurate overview of what a blog is about.
  • ImageCloud plugin This plugin creates Wordle-like tag-clouds using gif images. An example of such a cloud you can find on my tags page. Actually this cloud is created in combination with the Text2Tag plugin.
  • XP Uploader A plugin that allows images to be uploaded to a YAPB enabled blog using the XP Web Publish Wizard. This makes it possible to upload images to your blog directly from Windows XP Explorer.
  • YAPB Bulk Uploader This plugin adds mass image upload functionality using a Flash Uploader. The benefit of this plugin over the XP uploader is the operatating system independence and the fact that you do not have to configure anything on your desk- or laptop.

Any suggestions to or questions about these plugins are welcome!

Joost

Return top