The Null Object Pattern

Noticed this interesting article about the Null Object Pattern. Basically, it is the idea that the null/nil object could accept any message and return itself, rather than the more canonical approach of throwing an exception. This seems to lead to simpler, more elegant, code due to the lack of exception handling and null/nil checks. The trade off seems to be, you get generally simpler, more obvious, code at the expense of the occasional hard to track down bug.

I am not sure what I think about this but it does feel a bit like the debate around static vs. dynamic languages and in that debate I am firmly on the dynamic side of the fence because the subtle errors just do not seem to occur very often. Perhaps the subtle errors around null/nil do not occur often enough to warrant the checks we currently have.

[via: RCR 303]

YubNub

YubNub is very cool. It is basically a command line for the web. For example, you can say “define good” and it returns a web page with the definition. Even better you can define new commands. I just defined a new command, lexfn, which finds a set of words that are related to the one you provide. (I find this particularly useful when trying to come up with names for classes and methods.) So go and add some cool commands.

[Via: tecosystems]

Bookmarklets for Zapping Annoyances

Maybe it is just me but I have started to really dislike reading webpages with black text on burn-your-retinas-off white background. (Yea, I know my website is this way. I am going to fix it real soon now…) I found this site with lots of cool bookmarklets for fixing that, and other annoyances on the web.

How I Really Feel About Java

I realized recently that you just read my blog you might get the, incorrect, impression that I really dislike Java. I am, fundamentally, an idealist and that makes it hard for me to ignore the rough edges and inconsistencies in any technology I use (even ones I love).

I just wanted to make it clear that overall I think Java is fine. You can get certainly get stuff done in Java and it is a more productive environment than C/C++. There is no doubt that Java works (and there is a lot to be said for that), but I think it could be quite a bit better than it currently is.

So, Java is not my favorite language, but I don’t really hate it, either.

Why Java is Not My Favorite Language — Reason #16.

UnsupportedOperationException. Why, in the name of all that is good and right, would you have such a dumb exception? Either the operation is important or it is not. If it is not don’t clutter the interface with it. If it is it ought to actually be implemented.

I have known about UnsupportedOperationException for a while now but I had not run into a method that actually threw it until yesterday. That method was ArrayList.remove(). I can just hear the lame argument for having this method throw UnsupportedOperationException now, “Removing an item from the underlying array would inefficient and/or hard to write.” If you feel any of that matters fine, but don’t lie to me and tell you have a bunch of operations, by claiming you implement the List interface, and then blow up in my face when I try to use one of those operation.

If remove() is really not a fundamental operation for lists (which I would debate, but whatever) it should not be part of List. There should be a RemoveList, or some such, interface which implements List and adds remove(). Interfaces are free, you can have as many of them as you need.

If you do not actually implement all methods of an interface you have no right to claim you implement the interface, regardless of what the javadoc comments say.

{Update: Curt Cox pointed out that I was, in fact, not using the normal ArrayList class. The offending class was actual java.util.Arrays$ArrayList which I can only assume, since there are no Javadocs for it, is an intentionally broken version of ArrayList.}