Friday, February 06, 2009

Why I'm So Slow

The computer science homework has now grown to about 80 lines (including blank lines, comments, all that).

I know why it takes me so long to get started. For one, most of the assignments are big enough that I can't plan out the entire thing in detail in my brain before starting, so I know that I can't come up with an optimal design before I begin. This means that I know that there is going to be writing and rewriting and changing of plans. Since I'd like to keep that to a minimum, I want to try to at least have my major decisions be right.

And then when I'm in the midst of doing it, I get to points where I need to make decisions, and sometimes it takes me far too long. I know that one way is the "right way" to do it, but I'm not sure how to tell the compiler what I mean. The other way is the wrong way, but I know how to do it. I'm at one of those branch points right now. I'm writing a function that opens a file, reads data into a struct that's defined in a library that someone else wrote, and then is supposed to do something with the information that's read in.

Now, at this point the "deal with the information" should probably be outsourced to another function. It would be much, much, much easier for me to include the "deal with" in the same function as the "read in," but this is not what is expected. So now I need to figure out how to tell a new function everything that it needs to know so that it can do the dealing with. If I just pass it the struct full of data, will it be able to get the data that it needs? When it's done with the struct, will the struct be in a state where the next function can get what it's expecting? Where should it store the dealt with data? So many questions that I don't immediately know the answers to. Breaks my train of thought as I try to track down how to do things the right way.

And when I'm writing this new function, I wonder what I should give it and what it should give back. I think that I go about this entirely the wrong way. We've been told in class that we should write the function header before writing the function. I can't do that. Too many choices. Unless a function is obviously calculating something, I tend to start by having it be void and passing it a pointer to whatever it's supposed to fuck with. Then I start writing it. When I discover that it needs new things to do its job (or has something interesting to return), I adjust.

With my bad memory, I now find that I work most effectively on my office computer with its four million pixels of screen real estate. I put the assignment web page and an xterm window on the "small" (1680 x 1050) monitor (together with iTunes, email, Twitter, iChat, etc.) and I use C-x 3 to fill my main monitor with as much code as I can fit on the screen. It's a damn good thing that I didn't take cs when I was an undergraduate and I had a 640 x 480 screen. (No, I wouldn't have had to use a vt100, as I would have telnetted in using DarTerminal.) So I'll be in my office most of the rest of the day, making slow progress on this assignment. I maybe back over the weekend, too.