Week 1, Wednesday

March 25, 2009 at 8:03 pm (Java, Week 1) (, , , , , )

We worked from a client site today, where Jim and Eric S. generally work. They had an iteration meeting this morning, so I was there to observe. I’m told this one was really abnormal, as the new feature demo was only a few minutes long and it was around one computer rather than a conference room: one of the customers was on a tight schedule and had actually already signed off on some other stories from the iteration.

Each time Micah sits down with me and I try to explain my way through something, I realize how differently I need to approach my coding. Here’s the conversation that ends up happening (perhaps a bit paraphrased and exaggerated for my point):

Me: So, one of my tests is failing but the others are all passing. Here’s the code…
Micah: OK, so walk me through it.
Me: Well, this thing depends on that one and needs to call on it for later on when it updates the other thing. And before, when I was working on that first thing, I had a weird problem with the other thing so I changed the implementation of that first thing to be the new thing’s gobbledygookandtrailingoff… [you get the idea]
Micah: Wait. Go back to the beginning. Let’s think through each step.

I must slow down and be more methodical, especially when I’m having a problem. And even more especially when I’m having a problem understanding why I’m having the problem. The whiteboard was VERY helpful in solidifying my understanding of the minimax algorithm itself, especially as I applied terms from the implementation to it. Recursion can be really difficult for me to understand when I don’t go step by step (or call by call).

My ComputerPlayer is getting better: it wins when it can win immediately, but it gets much dumber after the first move. I actually thought it was finished at one point, but alas, my tests weren’t extensive enough and I was able to beat it easily. I banged my head against the wall (figuratively, of course) for awhile today trying to get it working – I think I needed to step away for awhile. Jim suggested 25 minutes of continuous coding/debugging, and then a 5-minute break (the Pomodoro technique). I’ll give that a shot tomorrow.

There was a lot of refactoring today. Some of it was to sanitize some nasty stuff I’d written, but some was out of necessity. For instance, I had the Board responsible for deciding the next move possibilities, but it should have been the Player, since the move itself depends on the player’s mark (X or O). This meant I had to bring a method or two up out of my Board class into the Player before I could move on with the algorithm. I also learned a couple more refactorings in IntelliJ that will save a lot of time: Introduce Variable and Extract Method. I had to spend a little time verifying for myself that the Extract Method change wasn’t going to break anything, so I need to crack the cover of the Martin Fowler Refactoring book sometime soon. It’s in my reading queue piling up from Amazon, but there are several others as well.

I spent a little time with Java generics and Lists in the morning – I’m used to Ruby where an array resizes for you automatically, so I figured that a new Java array, even one with space for 9 allocated, would have length 0, as it does in Ruby. But of course int[] possibleMoves = new int[9] is just an array of nine ZEROS. At any rate, I’m certain this is a much better way to learn a language than trying to learn all the syntax cold before hopping into the code, but it’s frustrating sometimes. I have a good friend living in Berlin who knew only a few phrases in German like “Where is the bathroom?” when he moved there a few years back, but of course he was fluent within a year or so. I imagine it’s similar here, except that I don’t have to speak in Java to buy a sandwich. Yet…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: