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.
No comments:
Post a Comment