Friday, May 06, 2005

Back with (dot)NET

After working with the .NET framework since beta 1 I recently took a 8 month hiatus from it to do some work with linux and python/perl. Over the last couple days I dug back into it using v2.0 of the framework and Visual C# Express 2005. I have to say WOW. Microsoft really was able to pull off some great things.

Before the hiatus a few upcoming features were interesting to me. Generics and Annonymous methods are two very useful framework features that I never got to see until now.

With generics, something I've been dying to use, we can instantiate a class with specific types. For example let's create a class that holds a reference to a type that we'll define:


public class HoldSomething<anytype>
{
private anytype _data;

public void Store(anytype data)
{
_data = data;
}

public anytype Retrieve()
{
return _data;
}
}

It's an overly simple example but with that class we can instantiate it with the type we're going to use:

// let's work with an int
HoldSomething<int> hold = new HoldSomething<int>();
hold.Store(10);

// let's work with a string
HoldSomething<string> holdastring = new HoldSomething<string>();
hold.Store("Hello World");

I believe Generics makes the C# language a bit more dynamic, kind of like Python or Perl. There were many times in that past where I had to reference and unknown type with System.Object resulting in implicit boxing.

I'm also blown away with all the neat little features tucked in Visual C# 2005: refactoring support, practical debugging enhancements, a light footprint, better ergonomics, and more as I keep using it.

Tuesday, May 03, 2005

TetrisNET



This was one of my first projects with C#. At the time C# was still in Beta 2. I used the tetris idea as a way to learn more about the framework and how the language works.

My first hack is based around 3 objects: CTetrisGame, CTetrisBoard, and CShapeBase.

CTetrisGame controls the game and does the rendering. It also handles game play such as checking for completed lines and game scores. It's a rough sketch of the controller in MVC.

CTetrisBoard simply manages the game board. It remembers where blocks are stored and does boundary checking. CTetrisGame encapsulates an instance of this object.

CShapeBase starts an object hierarchy to represent each shape. CShapeBase encapsulates the basic shape functionality such as movement and rotation. Each concrete shape inherits from the CShapeBase and overrides the layout of itself. CTetrisGame then randomly picks the shape from an array of shape instances to handles the game action.

Future ideas included a remote service to record game scores. That idea was never fully implemented. Another idea was to add sound. I left the hooks in place but they are commented out in the current source.

If I were to redesign the source code I would have implemented a more traditional MVC architecture. Linked here is the "solution" updated with Visual C# 2005 Express Edition. Feel free to download and critique. I love feed back.

[Download Source and Executable]

Interesting Links

I tend to collect links on my desktop for future reading. While cleaning up my desktop today I figured I'd post them before deleting them:

and for fun ...

Monday, May 02, 2005

Glass3d



Glass3d was an experiement with C#/GDI+ and basic 3d rendering. Although I would not normally use GDI+ to render this it was a good exercise in threading and basic Win32 GUI programming.

NOTE: The EXE is compiled against the framework v2.0.50215. The "solution" was setup under Visual C# Express 2005.

[download glass3d]

Sunday, May 01, 2005

Off Shoring ... literally

"In an outrageous affront to U.S. labor laws, a California company plans to anchor a 600-cabin cruise ship just beyond the three-mile limit off the coast of El Segundo, near Los Angeles, and stock it with foreign software programmers."

[newsmax]

Gotta love the effects of capitalism...where audacity is rewarded and the stagnant is left behind.