Wednesday, February 29, 2012

Coming in to Port, the C# way

So the past couple of days I have been looking in to C# as a programming language. I was amazed at how similar it is to C++, and still how much easier it is to use. I decided that C# would be a better suit for the game engine that I am building right now. It will also help me get to know C# very well, and will be a great learning experience.

So for the past couple of days I have ported my Component-Context code over to C#, with great results. I C++, I had many problems with including headers from other classes. In C++, the order in which the compiler finds the declared classes allows you to use those class in defining others. This was a big problem because many of my engine classes depended on each other. I had to resort to using prototyping, which I think is ugly. In C#, this order does not matter, making cross-dependency much cleaner and easier.

However, C# is much less flexible in terms of templates (or Generics as C# calls them). This made me rethink my structure for managing the components and contexts. This restructuring was good, and made the structure much more powerful. When you attach a component onto an entity, the component itself is responsible for registering itself with the respective Context. This gives it more flexibly, while simple as well.

So far I have been very pleased with C# flexibility and power. Along with Mono, I am able to keep an openness for different platforms. I also find MonoDevelop a very well designed IDE for C#.

No comments:

Post a Comment