<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Doolwind&#039;s Game Coding Blog &#187; Unit Testing</title>
	<atom:link href="http://www.doolwind.com/blog/tag/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.doolwind.com/blog</link>
	<description>Pragmatic Thoughts On Game Development</description>
	<lastBuildDate>Mon, 16 Aug 2010 23:19:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using C# For a Commercial Game</title>
		<link>http://www.doolwind.com/blog/using-csharp-for-a-commercial-game/</link>
		<comments>http://www.doolwind.com/blog/using-csharp-for-a-commercial-game/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 03:27:13 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Game Coding]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Scripting Language]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=260</guid>
		<description><![CDATA[Does the title of this article make you cringe?  People have mixed feelings when it comes to C# and the .NET framework.  Just like many hardcore game developers 10 years ago swore that games should only be made in straight C, many developers today say that C++ is the only way to go.  This article [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/csharpcommercial.jpg"><img class="alignright" title="C# Commercial" src="http://www.doolwind.com/images/blog/csharpcommercial.jpg" alt="" width="109" height="82" /></a>Does the title of this article make you cringe?  People have mixed feelings when it comes to C# and the .NET framework.  Just like many hardcore game developers 10 years ago swore that games should only be made in straight C, many developers today say that C++ is the only way to go.  This article outlines my reasoning for using C# for a commercial game on PC.</p>
<p><span id="more-260"></span></p>
<p><strong>Rapid Application Development</strong></p>
<p>The primary reason for using C# is because coding in it is more productive than any other language I&#8217;ve used.  Language features like interfaces, generics and delegates make it a cleaner language than C++.  Development practices such as unit testing and dependency injection are also easier to use in C#.  This clarity translates to more readable code and less bugs, particularly when working with a larger or younger team of developers.</p>
<p>The second productivity gain comes from having access to the .NET framework.  From its XML handling for configuration, to built-in math libraries, many of the core functions you can think of are taken care of.  This saves you writing the code yourself and lets a reliable, tested framework do the heavy lifting in areas you don&#8217;t want to spend your time.</p>
<p>C# lets you focus on making a game rather than writing an engine, or learning someone else&#8217;s engine.</p>
<p><strong>Unified Code &#8211; Client, Server, Tools, Scripting</strong></p>
<ul>
<li><strong>Server</strong> &#8211; I&#8217;m writing the server      architecture (matchmaking, leaderboard, etc) in ASP.NET and C#.  This lets me share libraries between the      client and server and makes calling web services from the client a breeze.</li>
<li><strong>Tools</strong> &#8211; All our tools are also      written in C#.  This means that our      tools can have rendering within them, can reuse libraries and simplifies      the creation of in-game tools.</li>
<li><strong>Scripting &#8211; </strong>As I&#8217;ve mentioned in a <a href="http://www.doolwind.com/blog/why-you-should-use-csharp-for-your-scripting-language/">previous article</a>, I&#8217;m using C# for the scripting      language in our game.</li>
</ul>
<p><strong>Better Software Development</strong></p>
<p>C# supports better software development practices in a number of key ways:</p>
<ul>
<li><strong>Refactoring      Tools</strong> &#8211;      Visual Studio has great refactoring support such as renaming identifiers      and extracting methods &amp; interfaces.</li>
<li><strong>Separation of      Concerns</strong> &#8211;      Splitting a project into separate .dll&#8217;s is trivial in C#.  This helps with maintainability and encapsulation      of code and encourages good separation of concerns.</li>
<li><strong>Unit Testing</strong> &#8211; C# has great support for      unit testing through NUnit or MSTest.       As I&#8217;ve <a href="http://www.doolwind.com/blog/test-driven-game-development/">previously discussed</a>, unit      testing fits perfectly in certain areas of game development.  The easier unit testing is to achieve,      the more people are likely to adopt it.</li>
</ul>
<p><strong>In-Game Web Browser</strong></p>
<p>As part of the game engine we are developing we decided all interaction with the server for matchmaking would be through http/html.  This reduces the need for creating such a complex in-game UI system and simplifies communication with the server.  The .NET web browser control is extremely easy to use and communication between the browser and host application (the game) is a simple.</p>
<p><strong>Run-time isn&#8217;t too large</strong></p>
<p>I&#8217;m currently targeting the .NET 2 framework.  This put&#8217;s the footprint at around 20MB.  The latest .NET frameworks (3.5 and 4) both have a &#8220;client profile&#8221;.  This is a subset of the .NET framework that comes in at about 30MB.  My plan is to use the .NET 4 client profile once it is released as it gives me access to all the latest language features (Linq, lambda expressions, dynamic objects, etc).  MS is <a href="http://blogs.msdn.com/jgoldb/">currently planning</a> to make .NET 4 client profile a windows update meaning the .NET framework will finally become (almost) ubiquitous among PC&#8217;s running windows.</p>
<p><strong>Negatives</strong></p>
<p>There are obvious drawbacks to using C# for a commercial game engine which we took into consideration when making our decisions.</p>
<ul>
<li><strong>Not Cross      Platform</strong> &#8211;      While engines like Unity have proven that C# can run on multiple      platforms, this does not occur out of the box.  As we&#8217;re targeting PC&#8217;s exclusively for      our first release this was not a problem.</li>
<li><strong>Xbox run-time      not great</strong> &#8211;      C# can run on the Xbox as part of XNA game studio, however the run-time      performance isn&#8217;t great.  Garbage      collection is a particular problem which requires refactoring code to      achieve acceptable frame rates.<strong></strong></li>
<li><strong>Harder to use      C++ libraries</strong> &#8211; Linking to straight C++ (non-COM) libraries is not trivial like it is      connecting to other .NET libraries.       Extra time is required if there is a requirement to use existing      libraries such as RakNet.<strong></strong></li>
<li><strong>Some performance      concerns</strong> &#8211; C#      does have some performance concerns with garbage collection and certain      double math operations.  However the      algorithmic gains received from working with such a great language outweigh      the small performance issues in certain areas.  As with any language, bad code will run      slow.<strong></strong></li>
</ul>
<p><strong>Conclusion</strong></p>
<p>C# is a great language.  I thoroughly enjoy coding for it and I find it makes me more productive when creating games.  I plan to release my MVC engine in the future as an open source project.  Until then, I&#8217;m continuing to develop our engine and I&#8217;ll keep you up to date with the progress.</p>
<p>For reference, here are a couple of commercial games using C#:</p>
<p><strong>Arena Wars</strong> -<a href=" http://www.arenawars.net"> http://www.arenawars.net</a><strong></strong></p>
<p><strong>AI War Fleet Command</strong> &#8211; <a href="http://www.arcengames.com/aiwar_features.php">http://www.arcengames.com/aiwar_features.php</a></p>
<p><strong>Sacraboar</strong> &#8211; <a href="http://www.sacraboar.com">http://www.sacraboar.com</a></p>
<p>Have you used C# for game development?  Are you sick of chasing memory leaks and crashes in your C++ applications?  Do you think game developers will move on from C++ now or in the future?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/using-csharp-for-a-commercial-game/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
