Tuesday, January 24, 2006
Saturday, January 21, 2006
Adventures in Test Driven Development
I just finished reading Test Driven Development By Example by Kent Beck.
It looks pretty cool. In the book Test Driven Development: A Practical Guide, author Dave Astels swears that TDD will make programming fun again. I find that particularly appealing, because it's been quite a while since I thought programming was fun. Don't get me wrong, I do like my job. I like programming. It gives me a deep sense of satisfaction when I finish a feature or fix a bug. I just haven't had fun writing code since I played around on my Dad's TI-99/4A.
Anyway, I finished reading Kent's book and was keen to start using TDD, so I did something I haven't done in years.
I started writing code at home.
That's a tough thing for me to admit. Almost every programmer I know writes code at home for fun. I never did. I got enough coding done at work. At home I was all about doing other things, like hanging out with friends and family or working on other hobbies.
I have also been reading about C#. I picked it because I wanted to learn more about Microsoft's .NET platform and learn something that might help at work.
So, I started a project at home with the latest version of Microsoft's Visual C#.
For the curious, I'm using Visual C# 2005 Express for my IDE, Perforce for source control, and NUnit for the unit testing framework. I'm developing a magic item creation tool for Arcana Evolved. I don't intend to release it, at least not with any data. The data belongs to Monte Cook, and I believe one already exists. Regardless, it should be a good learning exercise for me.
Goals
There are several things I'd like to get out of this project.
- Learn more about TDD
- Learn about XML (no, unlike seemingly most other programmers on the planet I haven't yet worked with XML at all)
- Learn the C# language
- Learn how to write windows apps in C#, using windows forms
- Figure out if C# could be used to write games
- Evaluate C# and the .NET platform for use at work
- End up with a good utility for myself should I ever finally get around to running an Arcana Evolved game again
- Figure out if writing code can really be fun again
The Story So Far
So far I'm done with Spell Completion Items, Single Use Items, Charged Items, and Constant Items. Magical Arms and Armor is a beast of a different color, and so is going to take more work. I have written 91 unit tests for about 8 classes, though one class has no tests of its own.
Things I've learned so far:
- Test Driven Development doesn't necessarily mean you start with a blank slate. It's good to think a bit about what you're implementing before you do it. TDD already forces you to do that by making you write tests first. You only write code in response to failing tests.
- Writing a to-do list on paper really helps. It keeps me focused on the test I'm working on and lets me not worry about juggling everything I need to do in my head.
- Starting out is hard. I have to remind myself to test first. See the red bar. Make the test work. Then refactor. My natural impulse is to work on several problems at once, to make changes that I "know" I'll need later. Usually I end up with too much stuff. I really have to fight the impulse to go right to the debugger.
- Fake data works great for tests. I don't have to pour through the AE book looking for a spell with a particular modifier when I can just make one up.
- Writing code is indeed fun again. For me, this is the most important part.
What's Next
I still have several things to do.
- I have to tackle Magical Arms and Armor, which work differently than all of the other items.
- I have to add a UI
- I have to get real data into the system
I think I'm going to start on the UI next. I'm going to use Charles Petzold's book Programming Microsoft Windows Forms, as well as Pro .NET 2.0 Graphics Programming. Between those two books I hope to be able to figure out the basics of windows forms. I'm told that .NET makes windows programming significantly easier. I sure hope so, because writing code with MFC is painful.
I haven't yet looked into learning XML, though I should do that soon. I can only use test data for so long.
Anyway, I've joined the TDD mailing list and found it very useful. I haven't posted there yet but I'm sure I will.
I've also been bitten by the TDD bug, but that will have to wait for another post. For now, things are going very well. Programming is fun again, and like I said above, that is the most important part.
Saturday, January 14, 2006
Back in, um, pain
One Saturday morning I woke up and could hardly move. Getting out bed was painful. I hobbled like an old man over to the bathroom. In the time since the previous night the bathtub wall had somehow grown to nearly thirty feet tall. Or at least, that's what it felt like.
After a hot shower I was better. Not great, but better.
I sort of have a history of back trouble. My father's back has gone out a few times. It went out once when he was playing with us kids at the school playground. He went to pick my sister up and he went down. I believe the paramedics came for that one. I remember he managed to get up on his hands and knees, and then couldn't go anywhere from there. Another time, his back went out when he bent over to pick up his toothbrush.
So anyway, my dad has had back trouble. So does my mother. Me, when I have trouble it's almost always with one shoulder.
This time, however, it was my lower back. Anyone who has had back problems will tell you how painful it is, how tense you get. You spend a lot of time wondering when your back will give out next. All of a sudden, the ground seems really far away. Getting in and out of the car becomes and adventure. You hobble from place to place. People wonder if you're just a young 80, or if you really are 30.
The only things that tends to make backs get better is time and rest. Well, that and moving correctly. Lift with your legs. Don't bend at the waist without bending at the knees. Get out of bed by turning on your stomach and inching backwards onto the floor. Be really careful of where and how you sit down, because if you choose poorly you won't get back up again without help.
Anyway, that Saturday I took it easy. By Sunday things were better. Not 100%, but better. Monday passed without incident.
Tuesday, Frangelica wanted to go to the mall to get makeup for the upcoming party. We went to Sephora.
Frangelica approached an employee to ask about some mythological powder or ungent or some such alchemical concoction. The employee smiled.
Before I knew what was happening, Frangelica was swarmed. At one point, there were three employees working on her. Over the course of our visit, all five store employees helped her with something.
In the meantime, I stood up and tried not to look too out of place. Which was hard, because I was the only male non-employee in the store. And my back was killing me. That's the other thing about back problems. Walking is more or less ok. Standing is bad. I stood for what felt like hours. I would have gone outside to sit on a bench, but I knew Frangelica needed me to pay for what was looking like about one million dollars worth of makeup.
Eventually I couldn't stand it any more. I told Frangelica I was going to hobble out to a bench. The employee chirped, "We're almost done."
Foolishly, I believed her. Looking back on it, they were only halfway through.
I must say that when Frangelica emerged from the flurry of activity, she was stunning. By which I mean, even more stunning than usual.
After some small discussion we decided that the various ungents, creams, powders, tonics, and whatnot would be Frangelica's Christmas present.
By the end my back felt a little better, but only because it had gone numb.
The next day I could hardly move. Getting out of bed was a Herculean effort. Scaling the sheer walls of the bathtub was too. A hot shower didn't help.
So, off I went to the doctor. Naturally, my doctor was on vacation, though I did like the doctor I saw. He hooked me up with industrial strength Ibuprofen and some groovy muscle relaxants, told me about a couple of exercises I should do and then sent me home.
The next day I went back to work, fuzzy from the muscle relaxants.
Normally, you shouldn't take the muscle relaxants and drive. It's a bad idea. But this is Virginia (the "welcome" sign to the state says, "Welcome to Virginia. 2 drink minimum"). Being numb improved the driving experience. Sure the idiots were still there. Sure I nearly died. I just cared less.
Anyway, about a week went by and my back wasn't getting much better. Sure it was a little better, but it wasn't the amazing improvement I was expecting. I was running out of muscle relaxants. So, back to the doctor I went. Naturally, both my doctor and the doctor I had seen previously were unavailable.
The doctor I got was a small Chinese woman. "If you're not better by mid-January, come back and see us."
Right. Clearly, I forgot to mention that with back problems, everything is slow, including the healing.
Now that it is mid January, I am feeling a lot better. My back is still a little tender, but I'm almost back to normal.
New Year, New Plague
Then we came home and got TEH PLAGUE. Again.
Clearly this whole family visit thing just doesn't work in my favor. The Grandma and the Spinster visit over Thanksgiving, and we get TEH PLAGUE. Frangelica and I get better. Then my back decides to give me... trouble. And I get a more mild version of TEH PLAGUE again, just before we drive back to Chicago, which made the drive that much more fun.
Then, just a few short days after we get back from Chi-town, Frangelica and I both get sick. Again.
I'm ready for a new, more healthy year now.
So, what's happened in the last month? I think that calls for a few new entries.