Dec 31
We had a test that failed randomly with different actual results today. After spending half an hour on it, I finally figured out what was going on. My coworkers had sorted a list of products first and then used them as keys to create a HashMap. Later on they got the key set out of the HashMap and hope to process the products in order. What they forgot is that Set is not sorted therefore won’t return stuff in the same order they are put in. Our progressive rounding calculator happens to be very order dependent.
You should only sort a collection right before you need it to be sorted. This way you won’t miss a sort. It also makes the interface clearer because sorting a collection should be part of your implementation and other people who are using your API shouldn’t have to do the sort for you.
Dec 31
Or should we call it Specification Factory? It all started when James and I were working on a story. We have a Home class that instantiates various classes based on some insane heavy if-else logic. We decided that we’ve had enough of it. James suggested that we could create a Factory and convert the if-else logic to a key of String type instead. I like the Factory idea but not quite happy with having an extra string in our code just for this purpose. Then I remembered the Specification pattern that Ted introduced to us a couple of days ago. What if we use the Specification as the key? You have a map with the Specification as the key and the class you want to instantiate as the value. Then all you need to do is to iterate over the key set of the map and get the value once you find a Specification that is satisfied. A piece of code sample is shown below.
for (Specification spec: classMap.keySet()) {
if (spec.isSatisfiedBy(someObject)) {
return classMap.get(spec);
}
}
Dec 31
Jeff was telling me about the AirPort Express he just bought. It sounds like a really good product. Although from various reviews floating around on the internet and also some comments on Apple’s product page it sounds like it has a short life span. Some technician even found out the cause of it. Hmm… I don’t what to do now. It IS Apple. It DOES look really cool. Apparently it works pretty well when it’s alive. Hope Apple will fix the problem by the time I want to buy it.
Dec 31
This is by far the best variable names I’ve ever seen.
public class ValidationMessage
{
//internal members
string messageId;
string messageText;
string helpLink;
/* ... */
double cheeseburger;
char broiled;
long time;
//helper functions
/* ... */
}
Dec 31
Personally, I think refactoring is one of the best things that ever happened in software development. Everybody who’s ever worked with me will know that I’m a huge fan of refactoring. I don’t like living with broken windows. Refactoring is my tool to fix them. Unfortunately, this tool sometimes becomes an excuse to break windows. People occasionally tend to write bad code because they think they can refactor it later. The idea is good. But a lot of the time the code won’t get refactored at all because project schedule becomes tight or the original author simply forget to do it. Then other people start using and extending it. The next thing you know, it becomes too late or too expensive to refactor. More than 1000 TODOs hanging around in our project is the living proof of that. So please don’t live with broken windows even if you own a glass shop.
Dec 31
I did something nasty that slowed down our test suite by two minutes (out of eight minutes). That’s when Ted started calling me The Two Minutes Guy. The problem is the result of a series of mistakes I made.
* I used a Factory based on HashMap instead of if-else despite the fact that the HashMap contains only two keys.
* I put the Factory in the domain object that’s using it instead of creating a separate class.
* I named the class which the Factory creates Strategy. In fact, it’s not a Strategy at all.
* Because of mistake #2, I created a static block to initialize the HashMap in order to reduce the overhead. But later on I moved the initialization of the HashMap into the constructor.
* Then I successfully slowed down our test suite by 25%.
The worst of all the evils is that I was not pairing with anybody!!! Starting from next Monday, I’m gonna be the pair programming/switching police of our team. The first criminal to catch is myself.
Dec 31
Last week, I bought a Linksys WRT54GL wireless router to replace my crappy SMC7004AWBR. The first thing I did after I got it was replacing the firmware with DD-WRT.v23.SP1. It installed without a clinch. But the connection, especially the wireless connection, would break down after about 15 minutes and I had to reset the router. I tried micro, mini and standard versions of DD-WRT. They all had the same problem. After two days of trying, I decided to switch to HyperWRT since it’s based on the Linksys factory firmware. It turned out to be a lot more stable than DD-WRT. I haven’t reset it for a week. My BitTorrent download used to kill my DSL connection everyday. I always thought it’s the modem’s problem. But it has happened only once in a week with this WRT54GL.
This is currently what I have enabled on this 70$ Linux machine:
* transmit power set to 70mW
* port triggering for BitTorrent
* static DHCP for one of my computers
* QoS
I strongly recommend this router to everybody. Especially with the open source firmware. The only additional feature that SMC router offers is the built-in parallel print server. But I’m converting my 6 years old Asus laptop to do that with Ubuntu and Samba.
Last words, never buy any SMC product.
Dec 31
Whenever you are trying to solve a problem, you should always come up with at least five different ways and pick the best one. This sounds very textbookish but is actually a very good practice in software design. It is a fact that a lot of the time everybody knows that option number x is the correct choice from the very beginning. But this practice often triggers quite a few interesting thoughts. Some make you think about the problem from a totally different angle. An angle from which you will never look at the problem before. It might be inappropriate for the problem you are trying to solve. But it could very possibly be perfect for some others.
Dec 31
Just a very cute picture of our cat. No I didn’t overfeed him.

Dec 31
We went to Elbow Falls on Monday. The amount of people there reminded me of China. So we took a short hike along the river. It was really short but quite scenic comparing to the crowded picnic area. I was also able to take a picture of Elbow Falls in distance.
