My Apprenticeship - Friday, July 30, 2004

This summer I'm revisiting my short apprenticeship at Object Mentor. I'll be posting commentary on all my posts from the summer of 2004 exactly 5 years later to the day.

Friday 7-30-04

IntelliJ IDEA 4.5 just came out and there's a been a flurry of emails about how it lets you analyze your code. The Martins (Micah and Bob) are trading barbs about whose code is more redundant. Paul looked some 10 year old code he was working on and it had hundreds of repetitions. I've only just installed 4.5, so I haven't had time to try the new features. Dare I analyze my old projects?

The pawn is killing me. My chess program takes the pretty obvious tact of having a ChessPiece interface from which all the pieces inherit. Bishops, Knights, Rooks, don't really need to know about the ChessBoard. You can just give them their move and they'll tell you if it's legal. The ChessBoard will do a check to see if any pieces are in the way of a move. But the Pawn -- What a jerk! Pawns can move two spaces on their first move but not on their second. That's not too bad -- I'm using a state pattern to take care of that. But they attack on a diagonal if and only if there is an opposing piece for them to take upon that diagonal square. Also they can do this weird en passan thing if another pawn passes them by making a two square move, but only on the next turn. It's crazy insane. So now I'm faced with the possibility of passing in not only a ChessBoard, but a LastMove to all the ChessPieces even though only pawn really needs it. Well, actually, the King also needs to know about the board for castling, but I'm trying to fight one war at a time. I've been thinking about creating a special moves class which would check for pawn diagonal attacking and en passan and other things. But that's pretty ugly too as the pawn logic is going to be in a number of places. Hmm.

Of course all this is a little silly because the rules of chess haven't changed in over 200 years are aren't likely to change any time soon. I could, in theory, couple the code as tightly as I want. But the whole point of this exercise (for me) is to learn something about managing dependencies so I'm going to pretend that the rules may change.

Some sort of program that analyses the quality of your code? Is this the birthplace of metric_fu? Not really, just the beginning of a thought that really didn't mature until much later.

I love that I'm trying to keep knowledge of the board away from the pieces. I really spent a bunch of time drawing UML diagrams and thinking about dependencies before writing any code. If nothing else, it was good practice thinking about design.

Comments

Popular posts from this blog

What's a Good Flog Score?

SICP Wasn’t Written for You

Point Inside a Polygon in Ruby