Jun 11

This was on digg today: Top Ten of Programming Advice NOT to follow. I’d like to share my take on them one by one.

10) “Use error codes instead of exceptions”

Agree. I don’t know why you want to use error codes unless you are dealing with legacy system.

9) “Use unsigned integers for values that can only be positive”

Well, I don’t really care.

8 ) “Design classes parallel to their physical counterparts”

Agree. It would be nice if you can do it. But you don’t have to. Especially if it’s gonna take a lot of effort.

7) “Make sure your team shares a common coding standard”

Disagree. I don’t care what coding style each team member uses. But with all the concurrent development, version control and merging going on, can we at lease use the same code format please?

6) “Write lots of comments”

Agree. Good programmers don’t need and don’t write comments.

5) “Use accessors or properties rather than public fields”

Disagree. I don’t see what’s the big deal with using accessors.

4) “Use the singleton pattern for variables that you KNOW you should have only one instance of”

Kind of agree. But I think singleton is appropriate for looking up stuff like factories or strategies.

3) “Be tolerant with input and strict with output”

Agree. Actually I don’t recall hearing this advice from anybody.

2) “Code all the corner cases immediately, cause otherwise you’ll never go back and fix things”

Agree. If you follow this advice, it means you are not doing Test Driven Development.

1) “Design first, then code”

Agree. That’s sooooo waterfall.

Jun 11

I bought a latest MacBook Pro the day they released it. It seems that I’ve formed a habit of buying new Apple products on the release day. Of course once I placed the order, I can’t help but checking the order status and following the shipment’s grand journey from Shanghai to Alaska to Memphis and finally to Calgary. I did that for about a dozen times on Friday. It was during one of those times that Chris said to me, “Are you macterbating again?” I paused for a second then burst into laughter. Really, I was not offended at all. Although I still don’t admit that I’m a Mac fanboy, no other word will be more appropriate to describe the state of my mind at the time. I think I’m gonna make a Lolcat picture about it (if my cat can ever cooperate).

May 29

Remote desktop and file sharing between OS X and Linux (Ubuntu is the one I’m using). They should just work, right? Well, sort of. I tried various implementations of VNC for remote desktop. They are all slow. Keyboard doesn’t quite work because Gnome’s keyboard mapping is currently broken in Ubuntu Feisty Fawn. As for file sharing, I tried both Samba and NFS. The former requires quite some set up and is not very stable between OS X and Ubuntu. The latter requires the UID on both systems to be the same. I was not happy with any of these solutions. So I didn’t a little more research and ultimately settled down on the following two pieces of software:

  • FreeNX for remote desktop. It’s free and easy to install. You can get the OS X client from NoMachine. The speed of it just blows any VNC implementation and even Windows Remote Desktop away. I’m using it with a 54M connection and 1920 by 1200 resolution. It feels as if I’m using a local machine.
  • Netatalk for file sharing. It’s just a open source implementation of the AppleTalk Protocol Suite. Because of that, OS X can connect to a Netatalk server very naturally. The speed is also very fast.

Both of these two servers can be installed from the Ubuntu repository. You just use the afp protocol to connect to Netatalk. As I mentioned above, the NX client can be downloaded from NoMachine.

May 09

Recently there has been a heated discussion about the comparison between Ron Jeffries’s way of solving Sudoku with TDD and Peter Norvig’s solution. After reading all the comments, I have to say that it’s a stupid discussion. I have at least two reasons.

First, Sudoku is not the appropriate topic to base the comparison on. It’s the kind of problem that requires relatively complex algorithm but has well defined requirement. In this case, the requirement is: Solve the Sudoku. But if you ask the majority of business application developers what kind of requirement they get, the answer will most likely be something like “Make it work”, “I can tell you. But don’t expect the same answer six months from now.” or “Requirement? We are not sure”. That’s the challenge the main audiences of TDD are facing. Whoever says you don’t need TDD in this kind of situation must be either a genius or insane. No, let me rephrase that. They are just insane.

Second, Ron Jeffries’s example is terrible. He seems like the perfect guy to reference if you want to badmouth Agile and TDD. He made it sound as if TDD eliminates the need for upfront design. That’s not what we do! Brainstorm/design sessions happen a lot more often in an Agile team than in a traditional development team. TDD is there to insure that we don’t write unnecessary code and all the code we write are covered by tests. These tests are usually white box tests. We already know how we want to implement it. We just want to make sure it works and continues to work over time. There are, however, times when we have to write black box tests. That’s when we were given a chunk of legacy code that nobody knows how it’s supposed to work. We have no choice but to gather the up-to-date requirements, write test to demonstrate them and refactor/rewrite the legacy code to be readable and working.

That’s my take on this debate. Ron Jeffries is not a good representative of Agile. There are better guys out there.

May 01

I purchased a license of ecto a while ago. It’s a very nice blogging tool. Maybe even one of the best. But I haven’t been able to use it since I moved to WordPress. It just hangs when trying to retrieve the categories for the posts. After a couple of months, I actually found a fix for it yesterday. I though I can start using ecto again but my happiness didn’t last too long. Ecto doesn’t let me pick any formatting. It totally kills me because I use Markdown and need formatting to preview my posts. This problem seems to be caused by WordPress not sending any formatting options to blog clients. I guess I’m out of luck with ecto here. Luckily I still have the one editor that rules them all – TextMate (Sorry, Emacs). It can post, retrieve and preview MarkDown or Textile. I do have to manually create the header but that just further proves my geek status. This is the first post I wrote with TextMate. We’ll see how it goes.

Apr 22

When I first heard of WATIR, it was an eye opener for me. It kicked HttpUnit/JWebUnit’s ass. Why use something that pretends to be a browser while you can simply interact with a real browser, right? After I introduced Ted to Paul Rogers, we started using WATIR extensively in our project. We created hundreds or maybe even thousands of WATIR tests in just a few months. Everything seems to be going well.

But when we object-oriented developers meet a good OO language, we tend to create a thing called object hierarchy. The more object-oriented we are, the deeper the hierarchy we create. This is not a good thing when you are working with a language with close to zero IDE support. Ruby is one of those languages. It’s a nightmare to figure out whether a constant or method has been defined and where it is if it has. There is also a lot of duplications and therefore chances for error because we cannot reuse the Java code in Ruby. Not too many developers are willing to write and maintain them except those who have to.

Here is where Ruby’s impact on Java comes into play. We’ve already seen it in stuff like GWT, Groovy and Grails. Now there is Watij. My coworker Chris found out about it when he’s working on a side project. It’s pretty much a WATIR clone in Java. But it’s easier to use than WATIR because you can reference your Java code, write your tests as JUnit tests and run them in your favourite IDE. It’s also very easy to set up. I can’t post any screen shots here because Watij currently only support IE and I’m a Mac guy. So you have to give it a try yourself. I’m sure you won’t be disappointed.

Mar 21

Currently I’m reading the book Extreme Programming Explained: Embrace Change (2nd Edition). If you think it’s just the first edition with a little extra, you are as wrong as a failed unit test. Kent Beck pretty much rewrote the book. Some of the new ideas and practices are very close to what I observed through my own experience. Some of them are brand new to me. I’ll talk about one of them here and others later.

Shrinking Team

The idea is that you don’t keep everyone in the team 100% busy. Leave about 70% of one person’s time free. Then let the team work on improving its process until it doesn’t need that one person any more. The team keeps shrinking this way. Later on, if the team has more work than it can handle, merge two small teams together to form a new team.

Now, even Kent Beck himself admits that he’s never tried this in a real project. He just borrowed it from the Toyota Production System. I don’t see it working the exact way he described either. At least I don’t want to be the “extra” person on the team. No, I’m just kidding. That’s not what the practice is about. Keeping a team running full load is definitely a good thing. That’s exactly what happened for the last six months in our project. We are so busy implementing stories and fixing bugs that we don’t have time to think what we can do better. Sometimes we don’t even think about what we are doing. The end result is a lot of duplicate code. Code that hasn’t been thought through. But now it’s too late to change it and I’m not the person that could have made the change either. Let’s just hope things will get better after the first release.

Mar 16

Have you ever used TreeSet in Java? Let’s say we have a class called AClass. It only inherits from Object and doesn’t implement any interface. Now I want to use the following code snippet to add a collection of AClass to a TreeSet:

TreeSet treeSet = new TreeSet();
treeSet.addAll(listOfAClass)

What happens when you run this piece of code? You get a ClassCastException! Why? Because if you don’t supply a Comparator to the TreeSet, it by default thinks that the element you are adding implements Comparable. It just blindly tries to cast whatever you put in it to Comparable. This is not very nice, is it? Shouldn’t it prevent me from adding element that’s not Comparable in the first place? Exception should be part of the interface. Yes, there is the API and source code I can look at. But in the world of code completion, people rarely do that. An appropriate exception would have been a lot better.

Mar 09

This guy from ThoughtWorks has some great insights and techniques about unit testing in Rails. Read this article to find out how to divorce Rails unit tests from database and use mock instead. I’m glad to know I’m not the only one who thinks that Rails by default is way too database centric.

Mar 08

About a month ago, the Spanish company, FON, was giving away 2000 free wireless routers across Canada. In case you don’t know, FON is the company that claims to have the largest WiFi community in the world. To get the free router all you need to do is joining their community and sharing a little bit of your bandwith with other people. I signed up for one just for fun (it’s a free router, right?). Got the router this Monday. It turned to be a very cute little thing (that’s not my hand by the way).

fon.gif

Small as it is, it has a very unique feature: two SSIDs. One unsecured for public access and one secured with WPA for private access. Very thoughtful. You can also specify how much bandwidth you want to share. If you go to their website, you can see where all the registered routers are including yourself. The following screen cap shows where I am. Well, it’s about a couple of blocks off but close enough. The big green circle is supposed to show the coverage and last activity and the little orange dot is where I live.

fon.jpg

preload preload preload