<?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>Kevin Grad &#187; Programming</title>
	<atom:link href="http://couchware.ca/www/kev/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://couchware.ca/www/kev</link>
	<description>Designer, Programmer and Co-Founder</description>
	<lastBuildDate>Fri, 30 Apr 2010 20:33:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Comment from today&#8217;s code.</title>
		<link>http://couchware.ca/www/kev/2009/09/24/comment-from-todays-code/</link>
		<comments>http://couchware.ca/www/kev/2009/09/24/comment-from-todays-code/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 01:39:53 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wezzle]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[lwjgl]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=165</guid>
		<description><![CDATA[

// WARNING: the ctrl mask randomly subtracts 96 from the ascii
// of any character returned from getEventCharacter(). This is because
// LWJGL is fucked. We had a 30 min convo about this and decided
// to fuck the ctrl key. Alt is better.

]]></description>
			<content:encoded><![CDATA[<pre>

// WARNING: the ctrl mask randomly subtracts 96 from the ascii
// of any character returned from getEventCharacter(). This is because
// LWJGL is fucked. We had a 30 min convo about this and decided
// to fuck the ctrl key. Alt is better.
</pre>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/09/24/comment-from-todays-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Wezzle Collision Generator</title>
		<link>http://couchware.ca/www/kev/2009/03/13/wezzle-collision-generator/</link>
		<comments>http://couchware.ca/www/kev/2009/03/13/wezzle-collision-generator/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 04:10:25 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Wezzle]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=124</guid>
		<description><![CDATA[I have a fascination with programming languages. I have been reading up on many different ones trying to get a feel for them all. I enjoy learning about the different syntaxes and what the advantages are of the different paradigms. I find most of the languages offer really interesting concepts and benefits.

Last night I was [...]]]></description>
			<content:encoded><![CDATA[<p>I have a fascination with programming languages. I have been reading up on many different ones trying to get a feel for them all. I enjoy learning about the different syntaxes and what the advantages are of the different paradigms. I find most of the languages offer really interesting concepts and benefits.<br />
<span id="more-124"></span></p>
<p>Last night I was hacking around with <a href="http://www.ruby-lang.org/en/">Ruby</a> and decided that to teach myself how to program better I would do something interesting for Wezzle. I had the idea of taking the <a href="http://couchware.ca/blogs/kev/2009/01/27/wezzle-xml/">XML markup for our achievements</a> and making some sort of generator using our achievement pseudo-language.</p>
<p>Our achievement language basically amounts to what is known in computing as a <a href="http://en.wikipedia.org/wiki/Domain-specific_language">Domain Specific Language (DSL).</a> Luckily for me Ruby is a pretty good language for writing DSL&#8217;s. </p>
<p>I decided to start with the achievements that I find to be the hardest to write, COLLISION. A COLLISION occurs between 1 or many items. There are two seperate types of collisions which can be defined as either an AND or an INTO relationship. These can be seen in the following two examples:</p>
<p>Example 1:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;achievement</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;A Tale of Two Rockets&quot;</span> <span style="color: #000066;">difficulty</span>=<span style="color: #ff0000;">&quot;SILVER&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fire a rocket into another rocket.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;COLLISION&quot;</span> <span style="color: #000066;">operation</span>=<span style="color: #ff0000;">&quot;BETWEEN&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/achievement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Example 2:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;achievement</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;A Tale of Two Rockets&quot;</span> <span style="color: #000066;">difficulty</span>=<span style="color: #ff0000;">&quot;SILVER&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Fire a rocket into another rocket.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;rule</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;COLLISION&quot;</span> <span style="color: #000066;">operation</span>=<span style="color: #ff0000;">&quot;BETWEEN&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;ROCKET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/rule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/achievement<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>While these two examples may look the same, they mean two different things. The first one can be written as COLLISION BETWEEN ROCKET AND ROCKET simply means that two rockets will be activated in a single turn. The second one however would be written like COLLISION BETWEEN ROCKET INTO ROCKET and means a rocket will be fired and activate another rocket by hitting it.</p>
<p>I have written a generator in ruby that takes an achievement (currently only collisions) in the following form:</p>
<p>BEGIN COLLISION<br />
achievement:Rocketeer:BRONZE<br />
description:Fire a rocket into a rocket and fire a rocket and a rocket.<br />
rule:COLLISION BETWEEN ROCKET INTO ROCKET<br />
rule:COLLISION BETWEEN ROCKET AND ROCKET<br />
END</p>
<p>This is currently defined within the program and will output the properly formatted and tabbed XML which you can then paste into your achievements.xml file. The goal is to have it work for all achievements, and I will keep you updated as to the progress should I choose to continue. As it stands, you can find the current version <a href="http://couchware.ca/blogs/WezzleCollisionGen.rb">here </a>although it&#8217;s a little bit ugly. Please note, you must have ruby 1.9+ in order to run it.</p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/03/13/wezzle-collision-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Performance still matters.</title>
		<link>http://couchware.ca/www/kev/2009/03/10/performance-still-matters/</link>
		<comments>http://couchware.ca/www/kev/2009/03/10/performance-still-matters/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 16:08:35 +0000</pubDate>
		<dc:creator>kev</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Big O]]></category>
		<category><![CDATA[Java2D]]></category>
		<category><![CDATA[OpenGL]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[SVG]]></category>
		<category><![CDATA[Wezzle]]></category>

		<guid isPermaLink="false">http://couchware.ca/blogs/kev/?p=112</guid>
		<description><![CDATA[With the abundance of computing power in processors today it is easy to fall into the trap of implementation without thought of performance. It is something I think all programmers do, myself especially.

Computers today have tons of processing power.  Who really cares about algorithm design when the computer can perform millions of calculations per [...]]]></description>
			<content:encoded><![CDATA[<p>With the abundance of computing power in processors today it is easy to fall into the trap of implementation without thought of performance. It is something I think all programmers do, myself especially.</p>
<p><span id="more-112"></span></p>
<p>Computers today have tons of processing power.  Who really cares about algorithm design when the computer can perform millions of calculations per second? This was a common thought of mine until recently. </p>
<p>When I learned big O notation and performance estimation in university I often thought to myself that I would never need to remember it, and it was not really useful for programming today. I was way off. Big O is something I have recently started using again and encourage every programmer to use as a way of estimating algorithm performance.</p>
<p>When we started making Wezzle we initially began designing without real thought of efficiency. Our initial implementation was all about design. However, we were very inexperienced when it came to actually designing good quality code. We quickly ran into some severe performance issues, and the Wezzle design still has some major flaws that really aren&#8217;t worth fixing at this point. One thing I can say with certainty is that my understanding of good design has improved by a drastic amount from this experience.</p>
<p>Our initial game design included the use of <a href="http://www.w3.org/Graphics/SVG/">Scalable Vector Graphics (SVG)</a>. We chose to use SVG because we liked the way they looked and the fact that window resizing was a non-issue. However, we failed to take into account how performance critical games truly are, and how incredibly slow SVG graphics are. </p>
<p>Our initial game was extremely choppy and virtually unplayable on old machines. We spent a lot of time trying to figure out why that was and how to boost performance. Eventually we decided to bitmap our graphics and noticed a SUBSTANTIAL increase in playability and performance. </p>
<p>I was pretty shocked by this entire scenario. First, I had always assumed that performance today was a non-issue, and second, I never thought that the type of graphics we used would make such a huge difference in terms of performance. </p>
<p>SVG wasn&#8217;t even close to all of our performance issues with early versions of Wezzle. We had a bunch of calls that were needlessly being made every game tick (we still find this problem with some of our code) as well as various other design flaws that affected overall performance. We had an inefficient algorithm to refactor the board and just in general a lot of areas that could be streamlined. We also had a bunch of performance issues with label generation (which we fixed with a cacheing scheme) and some troubles with <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ref/PhantomReference.html">phantom references</a> (yuck!). We made extensive use of the built in <a href="http://en.wikipedia.org/wiki/Profiler_(computer_science)">profiler</a> in <a href="http://www.netbeans.org/">netbeans</a> during our first refactoring phase.</p>
<p>Since then Wezzle has gone through countless refactorings and countless optimizations. Another huge increase in performance came when we switched from <a href="http://java.sun.com/products/java-media/2D/index.jsp/">Java2D</a> to <a href="http://www.lwjgl.org/">OpenGL (lwjgl)</a>. Perhaps in a later post I will talk about some of the various optimizations we have employed in Wezzle, but that is beyond the scope of this article.</p>
<p>Even with all the performance issues in Wezzle, I thought to myself that games are kind of a unique situation that is very performance critical and lots of calculations are happening, maybe performance is only relevant to gaming.</p>
<p>Again I was wrong. As anyone who does any web development can attest to, large database operations can be TERRIBLY inefficient. I am currently under contract developing some code that loads a large number of records into a grid structure. I am limited by the fact that this grid is only usable to us by passing it XML on the client side, as well as various restrictions about look and feel that were dictated by my client. Perhaps in a future post I talk about the multitude problems with the grid I am using, and there are many, but that would take way too much space to type in this post. </p>
<p>Anyway, my first implementation which contained some optimizations took around 15 minutes to update 500 records from the grid. The records were huge and data validation was being done on every individual cell and since the grid had to be submit as a whole (as an XML string) I was parsing and updating the entire grid. </p>
<p>This was not acceptable and also mildly surprising. Going through my code I have optimized even more. I implemented a dirty cell scheme, marking cells which have been edited as dirty so that on the submit I can only validate cells which have been marked as dirty. This assumes that all data already in the database is valid (not always the case!). I validate pasted in values at paste-time and that&#8217;s it (once they pass validation, they are considered good from the client side). Finally, I mark records which have been modified as dirty and even though I still have to submit the entire grid, I now only parse the records that have been marked and skip the rest. This has vastly improved update performance on the average case. It has improved updates in the worst case as well, but not by quite so much, a full submit still takes some time.</p>
<p>I&#8217;m going to end this by saying that while yes, performance is an issue, it is also sometimes a non-issue. First and foremost you should code something for clarity. A clear design that is slightly less efficient is always better than a streamlined but cryptic design. It is a mistake to optimize something that doesn&#8217;t actually need optimization and a big time waster. A popular saying is &#8220;design for clarity first and foremost and use a profiler to determine which areas need to be optimized.&#8221; This idiom does make sense and makes a valid point, but I would instead say to design for clarity and performance in conjunction as performance can often be a surprising bottleneck. </p>
]]></content:encoded>
			<wfw:commentRss>http://couchware.ca/www/kev/2009/03/10/performance-still-matters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
