Tuesday, July 22, 2008

How to Make a Software Developer Pull His Hair Out

If you're writing any sort of software that you expect others to build off of (e.g., some sort of library), and you want to make sure that your users scream in agony and never need the services of a barber again, here's a few ways to do that:

1. Make sure you've got all the important functionality implemented, but then hide the implementation with private methods and package local classes so that developers can't extend or customize the functionality.
Real-Life Example: At work, we're using MyGWT (well, not for much longer). We have a tree table, and when the user hides (or shows) a column, that needs to be saved (duh). Turns out that for some reason, simply marking a column as hidden doesn't actually hide it. Yet, the functionality works when I click on the menu item! Well, in order to make that happen, I needed to programatically make the same method call that happens when you (un)check the box to hide (show) the column. Good news--that method is protected. Bad news: (a) it's in a class that's automagically instantiated by another class. (b) one of the arguments to that method relies on a package local field of another class. Yikes. Well, 5 silly new classes later, I can stand up and say, "Mission Accomplished".


2. Write your code as inefficiently as possible. You know...call a method (say, foo) which returns an array, find out how many elements are in the array. Then:


for ( int i = 0; i < foo().length; i++ ) {
Thing[] things = foo();
Thing thing = things[i];
}
Yeah, nice, until you peek under the hood and realize what foo() does... Whoa. That wasn't pretty...

No comments: