Gareth Lennox

Empty unit tests

I was reviewing some code, and noticed a couple of unit tests that had “TODO” comments in them (and no code). The problem is that when running these tests, they were passing. Someone reading the list of tests would assume that the test was testing what it claimed to be testing, when in actual fact its doing nothing.

The first option to avoid this problem is to not actually create test methods until you’re ready to implement them.

I know I like to sometimes lay out a list of tests I want to implement before actually writing them. If you want to do this, then I suggest you create the methods, but ensure that the test is ignored (in nUnit, put an [Ignore] attribute onto the method), or that it fails (in nUnit, Assert.Fail). This is especially important if you’re going to commit to your source control system your partially complete tests.

Doing it this way will ensure that

  1. You don’t forget that you need to implement the test.
  2. That someone doesn’t think that something is being tested when in actual fact it isn’t.

Using Yahoo Pipes to aggregate feeds

pipe I’ve got a list of links in the sidebar of this blog. What is not obvious is that this list is an aggregated list of links that come from multiple sources. At the moment, I mark links as interesting from two sources:

Ideally, I don’t want to have 2 lists on the side, especially when most items I both bookmark in Delicious and share in Google Reader.

Enter Yahoo Pipes. Its an incredibly easy-to-use and powerful tool. You can see the pipe I’ve created here: http://pipes.yahoo.com/pipes/pipe.info?_id=wAcslJ753RGkTFabBR50VA. If you click the “View” Source” link you can see how its put together.

The general idea is to:

  1. add multiple sources (fetch feed)
  2. union them together into one feed
  3. Ensure they are unique, based on the id
  4. Sort them by the publish date
  5. Output the result

The end result is one rss feed that contains the unique list of links and is sorted properly. I just then point the WordPress RSS widget at that feed, and it works.

You can do a lot more fancy things, but what I’ve described above is the simplest.

Refracted

So I’ve decided to start posting my own photo’s onto a dedicated photo blog, you may have noticed the photos appearing in the sidebar (the wonders of rss!). If you’re interested in photography, you might find it interesting. The blog’s address is http://refracted.co.za/. I’m not going to be posting any more photos on this blog, other than the ones in the sidebar.

On the name

Its tricky coming up with unique, short names that can be turned into domain names. I came up with refracted.co.za the other day, and it seems quite fitting, as when a photograph is created, the light cannot help but be refracted and bent, firstly by the interface between the glass in the lens elements and the air (it’s related to the speed of light in the different mediums – see wikipedia for more information), and by the lens elements themselves.

How to sort rated items

This is a fascinating article:

PROBLEM: You are a web programmer. You have users. Your users rate stuff on your site. You want to put the highest-rated stuff at the top and lowest-rated at the bottom. You need some sort of “score” to sort by.

The article goes into detail about how all the most common sorting algorithms are incorrect. We implemented a system a while back, using wrong solution #2 (from the article), and had all sorts of issues with things getting sorted incorrectly. The proposed algorithm looks rather scary though.

Need to keep this in mind when I next implement a rating-based system.

UPDATE: Another article, now bringing in a time component.

Commented out code

One of my pet peeves is opening a source code file, and seeing half of it commented out, or blocks within it commented out. What’s wrong with this?

Commented out code serves no purpose, other than to confuse.

If you try uncomment it, chances are that the code around it has changed, and the uncommented code now won’t even compile.

Also, when reading the code and trying to understand it, the chunks of commented out code get in the way. “Should I be taking this code into account, or not?”

A lot of the time it is not obvious as to why it is commented out. I’ve seen lots of pieces of code commented out, with no reason given as to why. Maybe the developer was testing something and forgot to uncomment the code before checking in? Or is it old code that was not needed any more (then why is it still here?).

Code is usually commented out when the developer is not sure if the code will be needed in the future, and is leaving it there “just in case”.

Ultimately, you don’t need to keep commented code around. Your source control system can handle it. As long as you comment your commit properly, its a matter of 5 minutes work to find the old code and resurrect it.

SARS Scam

I’ve just noticed a new SARS (South African Revenue Services if you’re not South African!) related scam. The e-mail you receive is worded as follows:

Tax Notification

After the last annual calculations of your fiscal activity we have determined that you are eligible to receive a tax refund of ZAR xxxx.xx.
Please submit the tax refund request and allow us 48 hours in order to process it.

A refund can be delayed for a variety of reasons. For example submitting invalid records or applying after the deadline.
To access the form for your tax refund, click here

Regards,
South African Revenue Service (SARS)

Document Reference: (92054568).

The click here link (which I’ve removed) takes you to a very legit looking SARS site, but, its not hosted on any SARS domain, and is not SSL encrypted. The site asks you for your full name, your credit card details (including the PIN number).

I’m pretty sure SARS doesn’t need your credit card details to refund you!

Looking Up

So, after much thought, I’ve decided to start posting more photos here. Hopefully it will force me to post more often!

This picture was taken on a yacht we went on for Saratoga’s end of year function.

Looking up

Learning Zend Framework

So, I’m playing with Zend Framework. My initial impressions are that it seems very cool. The database stuff especially. One thing, and this is not limited to the Zend Framework, is that it’s such a big system, there is a lot of stuff to get your head around, so documentation is critical. Unfortunately, the documentation is written on a per-component basis, so it gives you next to no useful information on commonly encountered problems.

There is a quick start, but it ignores common issues, such as: How do you create a link to another controller (i.e. another part of the system)?

Now, I just spent 30 minutes trying to find this out. The official documentation is silent on this basic task. After searching all over the place, I finally found this site, that tells you to use “the url helper”. There is nothing (or at least as far as I can see) about this url helper in the documentation.

Shouldn’t the documentation cover this sort of thing? Or at least a FAQ somewhere? (there is one on the wiki, here, but its about frequently encountered problems, not questions, and does not cover the above issue).

Maybe there is something I’m talking about, but if it does exist, its not easy to find on google!