<?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; Game Coding</title>
	<atom:link href="http://www.doolwind.com/blog/tag/game-coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.doolwind.com/blog</link>
	<description>Pragmatic Thoughts On Game Development</description>
	<lastBuildDate>Wed, 28 Jul 2010 22:53:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Fluent Game Design With Fluent Interfaces</title>
		<link>http://www.doolwind.com/blog/fluent-game-design-with-fluent-interfaces/</link>
		<comments>http://www.doolwind.com/blog/fluent-game-design-with-fluent-interfaces/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 08:00:08 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Game Coding]]></category>
		<category><![CDATA[Game Designer]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Scripting Language]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=419</guid>
		<description><![CDATA[Game designers often find themselves writing code in modern games.  Often, they have little to no programming experience and therefore must be taught the basics of programming (sequence, conditionals and loops).  I propose utilizing a technique that simplifies the code written by game designers in their games.  This technique is known as “Fluent Interfaces”. What [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/fluentinterfaces.jpg"><img class="alignright" title="Fluent Interfaces" src="http://www.doolwind.com/images/blog/fluentinterfacessm.jpg" alt="" width="200" height="125" /></a>Game designers often find themselves writing code in modern games.  Often, they have little to no programming experience and therefore must be taught the basics of programming (sequence, conditionals and loops).  I propose utilizing a technique that simplifies the code written by game designers in their games.  This technique is known as “<a href="http://en.wikipedia.org/wiki/Fluent_interface">Fluent Interfaces</a>”.</p>
<p><span id="more-419"></span></p>
<p><strong>What is Fluent?</strong></p>
<p>Fluent interfaces allow game designers to <span class="pullquote pqRight">write more fluid and readable code</span>.  Through the use of method chaining, English like sentences can be written to express game functionality.  Fluent interfaces can be implemented in any object oriented programming language.  Below is an example of a line in the game design document, a standard implementation example and a fluent example:</p>
<p><span style="text-decoration: underline;">Game Design Document:</span></p>
<p>&#8220;Do 5 damage to all enemy tanks within range 2 of an entity&#8221;</p>
<p><span style="text-decoration: underline;">Standard Example:</span></p>
<pre class="csharpcode"><span class="csharp05">foreach</span><span class="csharp10">(</span><span class="csharp00"> </span>var<span class="csharp00"> </span>unit<span class="csharp00"> </span><span class="csharp05">in</span><span class="csharp00"> </span>player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">)</span><span class="csharp00"> </span><span class="csharp10">)</span><span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">if</span><span class="csharp10">(!</span>unit<span class="csharp10">.</span>IsType<span class="csharp10">(</span>Enemy<span class="csharp10">)</span><span class="csharp00"> </span><span class="csharp10">||</span><span class="csharp00"> </span><span class="csharp10">!</span>unit<span class="csharp10">.</span>IsType<span class="csharp10">(</span>Tank<span class="csharp10">))</span><span class="csharp00">
        </span><span class="csharp05">continue</span><span class="csharp10">;</span><span class="csharp00">

    </span>unit<span class="csharp10">.</span>Damage<span class="csharp10">(</span>5<span class="csharp10">);</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p><span style="text-decoration: underline;">Fluent Example:</span></p>
<pre class="csharpcode">player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Enemy<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Tank<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>DoDamage<span class="csharp10">(</span><span class="csharp04">5</span><span class="csharp10">);</span></pre>
<p>This fluent example closely matches the design document and is easier to read.  It also uses less language constructs like loops and conditions.  With Intellisense, designers are given a context sensitive list of operations they can perform.  Designers simply build up the expression that describes the original line in the game design document they are implementing.</p>
<p><strong>How to implement Fluent Interfaces </strong></p>
<p>Fluent interfaces are actually quite easy to implement.  Objects expose methods that return a reference to the object itself allowing method chaining.  The best way to describe this is by showing the implementation required for the examples above.</p>
<p>First, we create the object we will be working on (I’ve called it UnitsList in my examples).  This gives us the first part of the fluent call (Get.UnitsWithinRange(2)).</p>
<pre class="csharpcode"><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">class</span><span class="csharp00"> </span>ScriptObject<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span>UnitsList<span class="csharp00"> </span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp05">int</span><span class="csharp00"> </span>range<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">new</span><span class="csharp00"> </span>UnitsList<span class="csharp10">(</span>range<span class="csharp10">);</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p>The UnitsList object must have a set of methods that return references to the object itself allowing method chanining:</p>
<pre class="csharpcode"><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">class</span><span class="csharp00"> </span>UnitsList<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">public</span><span class="csharp00"> </span>UnitsList<span class="csharp00"> </span>Where<span class="csharp10">(</span>UnitIs<span class="csharp00"> </span>condition<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">this</span><span class="csharp10">.</span>conditions<span class="csharp10">.</span>Add<span class="csharp10">(</span>condition<span class="csharp10">);</span><span class="csharp00">
        </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">this</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp10">}</span></pre>
<p>The fluent expressions are terminated by returning void from a function.  This lets the designer know they have no more options and often that the actual operation will be performed.</p>
<pre class="csharpcode"><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">class</span><span class="csharp00"> </span>UnitsList<span class="csharp00">
</span><span class="csharp10">{</span><span class="csharp00">
    </span><span class="csharp05">public</span><span class="csharp00"> </span><span class="csharp05">void</span><span class="csharp00"> </span>DoDamage<span class="csharp10">(</span><span class="csharp05">int</span><span class="csharp00"> </span>damage<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">foreach</span><span class="csharp10">(</span><span class="csharp00"> </span>var<span class="csharp00"> </span>unit<span class="csharp00"> </span><span class="csharp05">in</span><span class="csharp00"> </span><span class="csharp05">this</span><span class="csharp10">.</span>mainUnit<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span>range<span class="csharp10">)</span><span class="csharp00"> </span><span class="csharp10">)</span><span class="csharp00">
        </span><span class="csharp10">{</span><span class="csharp00">
            </span><span class="csharp05">if</span><span class="csharp10">(!</span>PassesConditions<span class="csharp10">(</span>unit<span class="csharp10">))</span><span class="csharp00">
                </span><span class="csharp05">continue</span><span class="csharp10">;</span><span class="csharp00">

            </span>unit<span class="csharp10">.</span>Damage<span class="csharp10">(</span>damage<span class="csharp10">);</span><span class="csharp00">
        </span><span class="csharp10">}</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">

    </span><span class="csharp05">private</span><span class="csharp00"> </span><span class="csharp05">bool</span><span class="csharp00"> </span>PassesConditions<span class="csharp10">(</span>Unit<span class="csharp00"> </span>unit<span class="csharp10">)</span><span class="csharp00">
    </span><span class="csharp10">{</span><span class="csharp00">
        </span><span class="csharp05">foreach</span><span class="csharp10">(</span><span class="csharp00"> </span>var<span class="csharp00"> </span>condition<span class="csharp00"> </span><span class="csharp05">in</span><span class="csharp00"> </span>conditions<span class="csharp10">)</span><span class="csharp00">
        </span><span class="csharp10">{</span><span class="csharp00">
            </span><span class="csharp05">if</span><span class="csharp10">(!</span>unit<span class="csharp10">.</span>IsType<span class="csharp10">(</span>condition<span class="csharp10">))</span><span class="csharp00">
                </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">false</span><span class="csharp10">;</span><span class="csharp00">
        </span><span class="csharp10">}</span><span class="csharp00">
        </span><span class="csharp05">return</span><span class="csharp00"> </span><span class="csharp05">true</span><span class="csharp10">;</span><span class="csharp00">
    </span><span class="csharp10">}</span><span class="csharp00">
</span><span class="csharp10">}</span><span class="csharp00">
</span></pre>
<p>There are a couple of key things to notice:</p>
<ol>
<li>This last code example      looks a lot like the original standard example</li>
<li>A lot more “engine” code      is required to setup a fluent interface than a standard interface</li>
</ol>
<p>So, in effect, an extra layer of abstraction is being placed over the original code.  Rather than designers working on loops and conditions, they are calling (well named) methods.  This makes their life a lot easier and simplifies maintenance of their gameplay code.  It pushes the burden of maintenance down from the gameplay to the engine level and therefore on programmers, who are better suited to maintaining code.  If there is a change in the engine or game, this extra level of abstraction serves to buffer the designers and reduce the amount of code that needs to be written.</p>
<p><strong>Good Interface Design</strong></p>
<p>Care needs to be taken when designing the interfaces and exposing methods to the designers.  Rather than exposing all functions off a single object my recommendation is to define different objects for different situations.  The example provided starts with the player and retrieves a list of units around it.  Filters are then added before the final operation is performed on the resulting list.  By limiting the methods available to the designer to simple filters there is little risk of them making a mistake.  Also, the fact that the &#8220;DoDamage&#8221; function returns void stops them from chaining anything further.</p>
<p><strong>Other Syntaxes</strong></p>
<p>One small point is that designers can structure their fluent “sentences” in any way they please:</p>
<pre class="csharpcode">player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">).</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Enemy<span class="csharp10">).</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Tank<span class="csharp10">).</span>DoDamage<span class="csharp10">(</span><span class="csharp04">5</span><span class="csharp10">);</span></pre>
<pre class="csharpcode">player<span class="csharp10">.</span>UnitsWithinRange<span class="csharp10">(</span><span class="csharp04">2</span><span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Enemy<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>Where<span class="csharp10">(</span>UnitIs<span class="csharp10">.</span>Tank<span class="csharp10">)</span><span class="csharp00">
  </span><span class="csharp10">.</span>DoDamage<span class="csharp10">(</span><span class="csharp04">5</span><span class="csharp10">);</span></pre>
<p>There is no difference between the above two examples.  It’s simply a matter of coding style preferred by the writer.</p>
<p><strong>Conclusion</strong></p>
<p>What do you think of Fluent Interfaces?  Have you used a similar technique before?  Do you think the extra engine code and maintenance is too much hassle for the gain in clarity to designers?</p>
<p>As an experiment, try exposing a small set of functionality through a fluent interface and see whether your designers like working with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/fluent-game-design-with-fluent-interfaces/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<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>
		<item>
		<title>How To Write Perfect Code</title>
		<link>http://www.doolwind.com/blog/how-to-write-perfect-code/</link>
		<comments>http://www.doolwind.com/blog/how-to-write-perfect-code/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 22:05:25 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Game Coding]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=98</guid>
		<description><![CDATA[Have you ever written perfect code?  If so, how often does this happen?  If not, why not, and do you think it&#8217;s possible?  Perfect code is something that many developers strive for but few, if any, achieve.  In this entry, I will discuss the set of requirements that must be met for a developer to [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever written perfect code?  If so, how often does this happen?  If not, why not, and do you think it&#8217;s possible?  Perfect code is something that many developers strive for but few, if any, achieve.  In this entry, I will discuss the set of requirements that must be met for a developer to be in a position to write perfect code.</p>
<p><span id="more-98"></span></p>
<p><strong>What is Perfect Code?</strong></p>
<p>My definition for perfect code is &#8220;Code that solves a problem, without bugs, in an optimal way&#8221;.  This has slight ambiguities, so I&#8217;ll break it down.</p>
<p>1.  Solves a problem</p>
<p>The whole idea of writing the code is to solve some non-trivial problem.  To do this perfectly, the solution must be solved for all possible cases.</p>
<p>2.  Without bugs</p>
<p>The code needs to perform the required task correctly in all situations.  This includes valid and invalid input and situations.</p>
<p>3. In an optimal way</p>
<p>I come from a game development background and therefore performance is important.  Depending on the situation, optimal will take on a different meaning.  For games, this might mean that the entire game loop must run at a minimum of 30 frames per second.  For a banking program this might mean that a transaction takes less than 10 second to complete.</p>
<p><strong>Is Perfect Code Possible?</strong></p>
<p>The simple answer is, yes.  Code can be written that perfectly solves a problem, without bugs and can therefore be classed as perfect.  Unlike many professions, what we create is never fully &#8220;set in stone&#8221;.  Code can change at any level, from fixing a broken statement to re-architecting an entire application.  When the three requirements below are met, developers are in the best possible position to write perfect code.</p>
<p><strong>The Requirements (aka What&#8217;s Needed To Write Perfect Code)</strong></p>
<p>To expect perfect code from developers, the following 3 requirements must be met:</p>
<p>1. Thorough Domain Knowledge<br />
2. Enough Time<br />
3. Great Developers</p>
<p>Just think about each of these for a minute before continuing.  If you&#8217;re a developer, do you meet all three requirements in your current position?  If not, which ones don&#8217;t you meet, and why?  Feel free to post a comment.</p>
<p>Below I&#8217;ll break down these requirements and show two graphs.  One for the amount of return gained for levels of input into each requirement.  The second graph shows the cost of achieving a set level of quality.</p>
<p>Each requirement also has a limiting factor.  This is the top reasons why developers often write imperfect code.</p>
<p><strong>1. Thorough</strong> <strong>Domain Knowledge</strong></p>
<p>Developers must have a good grasp on the subject matter they are to be working on.  If you&#8217;re making a driving game, you need to know the way cars handle, what torque is and why a blowoff valve sounds so cool.  If you&#8217;re writing an accounting program then you need to be boring, and therefore understand accounting (or is it the other way around).  You also need to know about debits and credits and the difference between cash flow and capital.</p>
<p>Moving from no domain knowledge to a simple understanding helps a lot when striving for perfect code.  After this point, learning more about the domain helps, however the next big leap in code quality comes from having an intimate understanding of the domain (the small mark on the x-axis in the graph below).</p>
<p>The following graphs show the level of quality gained by increasing domain knowledge and the cost required to achieve this.</p>
<p><img src="http://www.doolwind.com/images/blog/perfect/perfectDomain.jpg" alt="" /></p>
<p>Limiting Factor:</p>
<p>It&#8217;s difficult to find someone with expert domain knowledge and takes time for people to learn.  Also, many developers simply won&#8217;t want gain an intimate understanding of the domain.  This can be solved by having domain experts work closely with developers.  See <a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Domain Driven Design</a> by Eric Evans for an in depth discussion on this topic.</p>
<p><strong>2. Enough Time</strong></p>
<p>Most projects I&#8217;ve seen rarely have enough time.  Time is critical for writing perfect code as it unlocks the following factors:</p>
<ol type="1">
<li>Hacks/quick fixes won&#8217;t be      written</li>
<li>There will be little to no      overtime</li>
<li>Peer reviews and pair      programming become possible</li>
<li>Work can be designed      rather than simply hacked together</li>
<li>Work can be thoroughly      tested</li>
</ol>
<p>The mark on this graph shows where &#8220;enough time&#8221; is given for a project.  If enough time is given, the quality in code jumps substantially.  After this time though, there is a point of diminishing return as having developers continue to work on the project won&#8217;t return great gains.</p>
<p><img src="http://www.doolwind.com/images/blog/perfect/perfectTime.jpg" alt="" /></p>
<p>One point to note is that if the amount of time given to developers changes mid project, all bets are off.</p>
<p>Limiting Factor:</p>
<p>Money is the major limiting factor with giving developers more time.  However it isn&#8217;t the only one.  Competitors can bring products out before yours or customers may have strict deadlines that you must meet.  Also, developers don&#8217;t live forever, and rarely life in the same job forever.  The longer a project runs, the more likely you are to lose developers and therefore have to retrain and rehire more, at great cost.</p>
<p><strong>3. Great Developers</strong></p>
<p>I agree with the concept that good developers are 10 times more efficient than average developers.  Joel Spolsky put this perfectly when he said <a href="http://www.joelonsoftware.com/articles/HighNotes.html">&#8220;Five Antonio Salieris won&#8217;t produce Mozart&#8217;s Requiem.&#8221;</a> For those that haven&#8217;t seen Amadeus, he&#8217;s saying that the order of magnitude difference between good and great developers is staggering.  Unfortunately, you just can&#8217;t get the quality you need unless you have great developers; it&#8217;s as simple as that.</p>
<p>The mark on this graph show&#8217;s the level of developer skills required to write perfect code.  About the top 5-10% of developers fit into this bracket.  The good news is that the difference in cost between an average developer and a great isn&#8217;t the same order of magnitude higher.</p>
<p><img src="http://www.doolwind.com/images/blog/perfect/perfectDeveloper.jpg" alt="" /></p>
<p>Limiting Factor:</p>
<p>Great developers are hard to find!  With companies like Microsoft and Google paying crazy amounts of money, the top tier will often work for them.  However the good news is that great developers can be trained and in the right environment, so long as you have smart people you can often turn them into great developers if they (and you) care enough about software development.</p>
<p><strong>Do We Want Perfect Code?</strong></p>
<p>That may seem like a simple question, however in reality it isn&#8217;t.  In a vacuum, for most developers that question is rhetorical.  Of course we want to write perfect code, we take pride in our work and we strive for excellence.  However, when you look at the cost involved in achieving perfect code it is not always a requirement.</p>
<p>This is something we must take seriously when writing software as the realities of business mean that more often than not, imperfect code is exactly what the business needs.  It&#8217;s better to ship code with issues than to not ship code at all.</p>
<p><strong>Conclusion</strong></p>
<p>I&#8217;m sure I&#8217;ve said at least a few controversial things, so please comment and/or email me to continue the discussion.  I continue to strive for perfect code in my life, and whether I&#8217;ll ever reach it is irrelevant.  I&#8217;ll leave you with a quote from one of my favourite movies:</p>
<p><strong> </strong></p>
<p>&#8220;There are no perfect men in this world, only perfect intentions.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/how-to-write-perfect-code/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Qualities of a Good Game Programmer</title>
		<link>http://www.doolwind.com/blog/qualities-of-a-good-game-programmer/</link>
		<comments>http://www.doolwind.com/blog/qualities-of-a-good-game-programmer/#comments</comments>
		<pubDate>Tue, 05 Sep 2006 08:23:23 +0000</pubDate>
		<dc:creator>Doolwind</dc:creator>
				<category><![CDATA[Game Development]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Game Coding]]></category>
		<category><![CDATA[Game Programming]]></category>

		<guid isPermaLink="false">http://www.doolwind.com/blog/?p=60</guid>
		<description><![CDATA[After the excellent response to the programmer’s personality test I wrote I thought I’d look a little more into the beast that is a games programmer. Rather than giving a list of questions to be answered I thought I’d give a list of the qualities I’ve seen in good game programmers over the years. Some [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doolwind.com/images/blog/c&amp;c.jpg"><img src="http://www.doolwind.com/images/blog/c&amp;c.jpg" alt="" width="239" height="133" align="right" /></a>After the excellent response to the <a href="http://www.doolwind.com/blog/?p=54">programmer’s personality test</a> I wrote I thought I’d look a little more into the beast that is a games programmer. Rather than giving a list of questions to be answered I thought I’d give a list of the qualities I’ve seen in good game programmers over the years. Some of these qualities extend to general software development and others to people in general. As usual feel free to leave comments or email me <a href="mailto:alistair@doolwind.com">here </a>with any thoughts.</p>
<p><span id="more-60"></span></p>
<p><strong>1. Make many mistakes, but only once</strong></p>
<p>I thought I’d start with the controversial one. On the surface it would seem better to say that good programmers shouldn’t make mistakes at all, however I believe this is not the case. I first heard this idea used at flight school with the Australian Air Force where my instructor told me that fighter pilots could make as many mistakes as they liked so long as they didn’t make the same one twice. He used the analogy of a large bag which holds all the mistakes you’ll make in your life. He said to make sure every time you make a mistake you take it out of the bag, sloppy people then just put it back in and wait till they make it again. Successful people take it out, analyse it, and make sure they completely understand where it came from and what they can do to stop it in the future. This is some of the best advice I’ve received over the years, and those that follow it often turn out to be better programmers. Everyone’s deleted a file from the build machine by mistake or incorrectly integrated a file before checking it in removing previous work done to it. The important thing is that we stop and realise what we’ve done wrong and make sure we understand the problem, discuss it with others if need be, and file it away to make sure we remember it in the future. This is particularly important for game programmers as we have short schedules, complex work and an unforgiving customer base. In a business app a mistake may simply mean a debit or credit isn’t bolded correctly, but for us it may mean <a href="http://www.fatal1ty.com/">Fatal1ty</a> (Johnatahn Wendel) may not go quite high enough with a rocket jump and lose a match. Or more likely, 40% of your gamers will encounter the problem tell all their friends your game sucks because rocket jumps are inconsistent and you’ll lose a lot of sales. Either way we’re only human, so making mistakes is fine, so long as we learn and only make them once.</p>
<p><strong>2. Actually Play games</strong></p>
<p>I was both disgusted and disturbed when I finally made it into the industry and found out just how many game developers just don’t play games. They may play the game their actually making but once work’s over they’ll all shuffle off home, watch TV or do some other inane activity that doesn’t involve gaming. I often find the best game developers are those that go by the motto ‘We makes games we’d want to play’. Even if your game development house doesn’t believe in something like this, perhaps you do, and I implore you to do so. How can people that don’t even play games come close to this level of devotion? I don’t believe they can. Also fitting in with this quality is playing a wide range of games. Part of my dislike for World of Warcraft is the fact it’s stagnating the gaming-life of a lot of players. I’m all for people being passionate about a game, but I think gamers, and especially game programmers need to keep an eye on all the different games that are out to make sure they don’t get too focused on a particular game or style, homogenising the games they make.</p>
<p><strong>3. Be fluent in the language they’re using</strong></p>
<p>This is kind of a no-brainer, but notice I used the word ‘fluent’. I believe there are a number of levels of skill a programmer can have in a particular language and with software development practices in general. To paraphrase, being fluent means you can think about any concept that’s in general use in games today and given enough time you can create a program that will perform that task. The created program should naturally be maintainable, robust, correct and optimized. When I began game programming I wasn’t fluent in C++ and this showed. It took me a number of years of coding in my spare time and then full-time for a while before I reached that level and it has completely changed the way I work. Reaching this goal doesn’t take countless years, but it does take dedication and passion (but that’s for point 5).</p>
<p><strong>4. Ready to learns from others</strong></p>
<p><img src="http://www.doolwind.com/images/blog/carmack.gif" alt="" align="right" />Being fluent in a language doesn’t mean you’re a perfect programmer, in fact I think there are quite a few levels above ‘fluent’. These levels are for another article; however the important point is that chances are you don’t know everything there is about game development, nor about software development in general. I’ll be the first to admit there’s far more I don’t know than I do, so the important thing here is that you are willing to learn from others. Even if you are the technical director of a company, or John Carmack himself, I believe that you will be able to learn something from nearly any other competent programmer out there. The great thing about being human is that we are all shaped by our own lives, so no two people are the same. Even if you’re the greatest AI programmer known to man and you could make <a href="http://en.wikipedia.org/wiki/Skynet">Skynet</a> if you just quit work and put your mind to it, a student fresh out of school will have a different experience with programming and may show you a technique that he’s just come up with for making sure your robots don’t turn on mankind and destroy the world. I said at the beginning of this article that some of these qualities apply to life in general, and this is one of them. I believe that if you go through life listening to people and learning from them, and their mistakes, you’ll come out a better person at the other end.</p>
<p><strong><br />
5. Passionate about software development</strong></p>
<p>I touched on this in #3 as I think it’s the most important of the qualities. You really have to be passionate if you want to be able to become fluent in both the language your games are written in and in general game and software development practices. If you take game programming as just a job then you’re not going to be able to stick it out for the long term and make awesome games. I’ve seen people who are excellent C coders who want to make games as it’s a bit of a challenge to them. They write some awesome code, but it just seems to be missing something, that intangible ‘it’ that makes certain games awesome and others just boring. From what I’ve seen, for most people this passion is born out of a passion for playing games. As I was growing up I lived and breathed games, reading every magazine I could and visiting the hyperactive website every day to find out any news or secrets I could. As I became older I started having ideas for how to make the games I was playing better and ideas for entirely new games. I think passion is the single biggest factor that helps me to move forward and try and become the best games developer I can. This isn’t something you can learn or read books to attain, it’s just something that you either have, or you don’t. So whether you’re in the games industry or hoping to make it one day, please remember that passion for the games you play and make is your strongest quality. Make sure you nurture it by continuing to play and love games and never shut out the little part of your brain that is constantly coming up with ways to better the industry and drive it forward into the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doolwind.com/blog/qualities-of-a-good-game-programmer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
