Tuesday, February 20, 2007

C# and Partial Classes

As I was perusing the Spacewar code-base I ran across an interesting class declaration:

partial class SpacewarGame : Microsoft.Xna.Framework.Game
{

Interestingly, I had apparently found part of a class. Being the diligent person that I am, I immediately set out to find the rest of it. Unfortunately, my search was in vain because this was the only declaration of the SpacewarGame class. I immediately wondered what benefit was bestowed by the partial keyword. A quick wikipedia search reveals the following:

A partial class, or partial type, is a feature of some object oriented computer programming languages in which the declaration of a class may be split across multiple source-code files, or multiple places within a single file.

My first thought is why is this actually needed? Apparently partial classes come in handy when dealing with generated code. The classic example is when dealing with windows form code. The generated code is hidden from the developer and she can easily add to the class without worry of losing those changes if and when the class is re-generated. Hmm... that sounds fair.

However, it apparently does not stop there! Another valuable benefit includes multiple developers working on the same class without stepping all over each other since they will be working on different files. This would seem to work especially well where locking strategies are implemented with version control software. Or, how about facilitating the modification of big classes? Ok, now I am starting to feel uncomfortable. In my view, both of those situations are a smell of bigger issues.

But I am told that I should not be concerned. The compiler collects all the class pieces and stitches them together, ensuring that a valid type can be constructed. In terms of maintenance, if I were ever unfortunate enough to work on a project that over utilized partial classes, I could rely on the Visual Studio Class view for easily accessible, complete class definitions.

Well, I am not convinced. Even though partial classes may have a use, in my view it is somewhat limited. I do see, however, that the ability to abuse them is quite large. I feel that I encountered the beginnings of that in the Spacewar code-base. In the end, I see this as another example of a well-intended feature making developers lives harder rather than easier.

On a side note, Ruby's mixins have been compared to partial classes, however I think they are fairly different animals.

If you want to learn more about partial classes check out the following links: msdn magazine , msdn reference

Saturday, February 17, 2007

The plan...

My goal will be to develop Space Ball, a competitive, multi-player game focused around the possession of the Game Orb. The player who holds the orb for the longest time within the game time limit wins. That's it... Nothing too fancy. Since I am no artist, I am not planning on incorporating any new art work. It's all about the game play for me!

In support of this goal, I have come up with a prioritized list of stories for my Feb. 28th deliverable:
  1. As a player, I can see the Game Orb when the game begins.
  2. As the Game Orb, I can bump into other objects.
  3. As a player, I can pick up the Game Orb.
  4. As a player, I gain points while holding the Game Orb.
  5. As a player, I can shoot the Game Orb out of the possession of another player.
  6. As a player, I can release the Game Orb.
  7. As the game orb, I appear in random locations at the beginning of the game.
  8. As a player, I gain health while carrying the Game Orb.
Most of the current features implemented in the base project will be maintained. However, I may drop the Orb of Death in the center of the field of play. I dislike being sucked into it's fiery clutches and I feel this will detract from game play.

Until next time...

Friday, February 16, 2007

And so the journey begins...

Since I own an Xbox 360 and thoroughly enjoy the content on Xbox Live, I was intrigued by the recent release of Microsoft's XNA framework. Even though I currently make a living cutting code in Java and my last experience with a Microsoft development product was with VB 6 (I honestly do not miss that at all) , I couldn't resist diving in and checking it out. To make it even more interesting, I figured I would submit an entry to the Dream, Build, Play: Warmup Challenge.

My goal is to put in some entertaining enhancements into the SpaceWar game in the next couple of weeks while learning C# and the intricacies of XNA. This should lead to an entertaining series of posts!

In preparation, I have installed VS C# Express Addition, installed XNA Game Studio Express, generated the Space War project, set up my subversion repository and installed Nunit. Now I just need to tear myself off my 360 long enough to get to work!!