Unit Testing and Design Patterns
I've spent quite a lot of time lately poring over various books on unit testing and design patterns. These are two topics which I find very appealing, for a number of reasons...
Over the course of the past four years I've been working with a number of fairly large Java, ASP.NET, and ColdFusion websites. Usually they're pretty gruesome on the inside, and they are all inevitably as gruesome to maintain.
As the company I work for is a small one, we don't have a devoted testing staff. And while unit testing is only part of the testing equation, our lack of said staff makes unit testing all the more sexy. There's a definite air of zen about unit testing, regardless.
I took a whack at unit testing several months ago while working on my FORCE backbone library, but I wasn't quite sure how to write tests. Everything I wrote seemed either trivial, contrived, or both. Information on the topic being fairly scarce at the time, I lost some of the drive to keep at it on my own, and no lasting habit was formed.
I've taken it up again after reading through a great book on Ruby, which I'm finding a like quite a lot. Even more than Python, I think. It's been a genuinely entertaining experience to tinker around with. I wrote a little VERGE 2 .VPK unpacker in it as an exercise. I'll put it up somewhere tomorrow for anyone interesting in having a look-see.
The book I'm referring to is Programming Ruby: The Pragmatic Programmer's Guide. It has a section devoted to unit testing, and I think that's pretty cool that they felt it was a worthy enough topic to be included in what is effectively the language's definitive text. And while I won't say I'm now a unit testing master, I slowly begin to see more what I should be aiming for in my tests. I'm not generally an excitable person, but I've got to admit that unit testing gets me pretty excited!
I've also recently come across a very cool book on design patterns which agrees with my... unique sense of humor. The book is Head First Design Patterns, and it's one of the better books I've read on any programming topic. Even subject matter that I was already fairly familiar with kept my attention. The overall style of the book is very engaging, and I never found myself skipping ahead due to loss of interest or stale dialogue.
The best thing about this book though is the way the examples evolve. They are far more practical than your average programming text, and while they may still be very watered down implementations of their real-world counterparts, they do a great job of associating the examples with the real world in such a way that you find yourself nodding your head a lot and experiencing numerous "Ah-ha!" and "Oh-ho!" moments.
Coverage of foreign topics didn't leave me scratching my head, and things I thought I knew were given a richer definition. My growing understanding of design patterns is another one of those things that gets me really pumped to pull all-night coding sessions. That, and also quilting.
These things weighing on my mind, I've been tinkering around with a more highly interface driven design for my FORCE backbone, and a more conscious utilization of a few design pattern techniques.
I've also spent a lot of time pondering how item such as bitmaps, sprites, and animations will be represented in my backbone library. Code reuse has been one of my foremost preoccupations. There is a lot of potential for heavy code reuse across these fundamental components.
For example, bitmaps and game map layers are structurally identical — they are both grids. That being the case, I see no reason why I can't design my backbone in such a way that I can perform geometric plotting operations, and algorithms such as flood-fill, etc. with the same code. It brings to mind Allegro and its methods for geometric plotting with callbacks.
At any rate, many goodnesses abound! More on this tomorrow.