Posts Tagged ‘programming’

On the Subjects of object == null and collection.size() == 0

Tuesday, July 28th, 2009

Let’s just get one thing straight here people, an object that is null does not mean the same thing as a collection/array of length zero. I’m sort of seeing this more and more as I continue my existence on this planet and I say we put a stop to this now. Take this example method declaration (written in Java):

public Collection<searchresult> getSearchResults(String searchTerm);</searchresult>

Straight forward enough, I would hope. This method takes in a searchTerm String, magic happens (ah abstraction), and a Collection of type SearchResult is returned. Now here is the kicker: what happens if the search query resulted in no results? What should be returned? And why?

(more…)

Bug Finding Program

Tuesday, November 25th, 2008

Typically, I am against reading comments in any sort of social-anything site but there are very few times where I am linked a fantastic comment that deserves its own post. This is one of those comments. From Reddit.com, the bug finding program comment by user G_Morgan:

I have a bug finding program. You pass in the name of a code file and it returns a truth value if there is a bug in that file or not.

The current prototype is:

bool hasBug(String &progFile) {
    return TRUE;
}

G_Morgan’s function could not be any more true.

(more…)