<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
 
 <title>poita.org</title>
 
 <link href="http://poita.org/" />
 <updated>2012-02-01T22:31:43+00:00</updated>
 <id>http://poita.org/</id>
 <author>
   <name>Peter Alexander</name>
   <email>peter.alexander.au@gmail.com</email>
 </author>

 
 <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/poita" /><feedburner:info uri="poita" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
   <title>Scoped Imports in D</title>
   <link href="http://feedproxy.google.com/~r/poita/~3/Aq7iPx5tHNQ/scoped-imports-in-d.html" />
   <updated>2012-01-26T00:00:00+00:00</updated>
   <id>http://poita.org/2012/01/26/scoped-imports-in-d</id>
   <content type="html">&lt;p&gt;One of the nice things about the &lt;a href='http://dlang.org'&gt;D programming language&lt;/a&gt; is that it has very convenient syntax for conditional compilation. For example, suppose you want to print out some useful info in debug builds. You just use:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='d'&gt;&lt;span class='k'&gt;debug&lt;/span&gt; &lt;span class='n'&gt;writeln&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;Value of x is &amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;One problem that I constantly run into in cases like this is that I haven&amp;#8217;t &lt;code&gt;import&lt;/code&gt;ed &lt;code&gt;std.stdio&lt;/code&gt;, so I have to go right up to the top of the file, add &lt;code&gt;debug import std.stdio;&lt;/code&gt;, back down again, and continue. &lt;em&gt;Sigh&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Not so fast! D has scoped imports, so you can put the &lt;code&gt;import
std.stdio;&lt;/code&gt; right where you need it.&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='d'&gt;&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;main&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nb'&gt;string&lt;/span&gt;&lt;span class='p'&gt;[]&lt;/span&gt; &lt;span class='n'&gt;args&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='k'&gt;debug&lt;/span&gt; &lt;span class='k'&gt;import&lt;/span&gt; &lt;span class='n'&gt;std&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='n'&gt;stdio&lt;/span&gt;&lt;span class='p'&gt;;&lt;/span&gt;
  &lt;span class='k'&gt;debug&lt;/span&gt; &lt;span class='n'&gt;writeln&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;args&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
  &lt;span class='c1'&gt;// ...&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;#8217;s the little things like this that make D so pleasant to use.&lt;/p&gt;</content>
 <feedburner:origLink>http://poita.org/2012/01/26/scoped-imports-in-d.html</feedburner:origLink></entry>
 
 <entry>
   <title>API Performance</title>
   <link href="http://feedproxy.google.com/~r/poita/~3/IJGAJym7cWQ/api-performance.html" />
   <updated>2012-01-25T00:00:00+00:00</updated>
   <id>http://poita.org/2012/01/25/api-performance</id>
   <content type="html">&lt;p&gt;One thing that I&amp;#8217;ve never given much thought about until recently is the performance of APIs. I don&amp;#8217;t mean things like avoiding &lt;code&gt;virtual&lt;/code&gt; function calls in your interfaces. I mean designing an API so that it promotes usage that is optimal for the hardware you are running on.&lt;/p&gt;

&lt;p&gt;A good example of this was explored in Noel Llopis&amp;#8217; post &lt;a href='http://gamesfromwithin.com/data-oriented-design-now-and-in-the-future'&gt;&lt;em&gt;Data-Oriented Design Now And In The Future&lt;/em&gt;&lt;/a&gt;. Imagine you are designing the API for a physics system. One key operation of a physics system is to perform ray casts. The obvious API for this would be:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='d'&gt;&lt;span class='n'&gt;RayHitInfo&lt;/span&gt; &lt;span class='n'&gt;rayCast&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;PhysicsWorld&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;Ray&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Many physics systems use an API like this. For example, it&amp;#8217;s very similar to &lt;a href='http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html'&gt;the API&lt;/a&gt; provided by Unity3D.&lt;/p&gt;

&lt;p&gt;Most game engines also have some sort of game object system, whose main task usually involves looping through each game object, calling an update function. Many of those update functions will need to perform ray casts; perhaps something like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='d'&gt;&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='n'&gt;update&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;
&lt;span class='p'&gt;{&lt;/span&gt;
  &lt;span class='c1'&gt;// ...&lt;/span&gt;
  &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;rayCast&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;world&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='n'&gt;forwardRay&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt;
    &lt;span class='n'&gt;doSomething&lt;/span&gt;&lt;span class='p'&gt;();&lt;/span&gt;
  &lt;span class='c1'&gt;// ...&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If you have many objects doing this then you are going to run into performance problems. The ray cast is going to touch lots of data (and code) to perform the query, causing multiple cache misses as it traverses through space partitioning data structures, mesh data, etc. Then, once the ray cast is complete, you will continue processing update functions, likely pushing most or all that ray cast data and code out of the cache. When the next ray cast comes up, you have to pull it all back in again.&lt;/p&gt;

&lt;p&gt;In addition to the poor memory performance, you also can&amp;#8217;t parallelize the ray casts. The call is blocking, so no other object updates can happen until the ray cast completes, meaning that no other ray casts are available for parallelization.&lt;/p&gt;

&lt;p&gt;From a performance point of view, the ideal use case would be to&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Gather all the queries up front from each game object.&lt;/li&gt;

&lt;li&gt;Batch process those queries.&lt;/li&gt;

&lt;li&gt;Feed the results back to game objects to continue updating.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The key thing to note here is that &lt;strong&gt;this ideal is impossible to achieve with the current API&lt;/strong&gt;. In order to make this change, you will have to go through and re-shuffle the logic for each raycasting update function.&lt;/p&gt;

&lt;p&gt;If you want a performant API then it is something that should be considered beforehand, as it may not be easy to fix later on. In general, APIs that encourage asynchronicity and batched execution tend to have higher potential for good performance than synchronous, one-at-a-time functions.&lt;/p&gt;</content>
 <feedburner:origLink>http://poita.org/2012/01/25/api-performance.html</feedburner:origLink></entry>
 
 <entry>
   <title>Simplicity in Everything</title>
   <link href="http://feedproxy.google.com/~r/poita/~3/oQ9u0Yw6K7g/simplicity-in-everything.html" />
   <updated>2012-01-22T00:00:00+00:00</updated>
   <id>http://poita.org/2012/01/22/simplicity-in-everything</id>
   <content type="html">&lt;p&gt;This website is now created using Jekyll. Originally, I had used Joomla, a big, industrial-strength content management system.&lt;/p&gt;

&lt;p&gt;Joomla worked well for a while, but I quickly reached a point where I found myself unable to do, what should have been, simple things. For example, I couldn&amp;#8217;t see any obvious way of extracting all the text from my posts &amp;#8211; it was stored in a database somewhere. There was no simple way to test changes to my site locally because I couldn&amp;#8217;t see how everything pieced together. It was just too complex for something that should have been very simple.&lt;/p&gt;

&lt;p&gt;So I got thinking about what would be the simplest way to generate my website.&lt;/p&gt;

&lt;p&gt;Well, what is my website? It&amp;#8217;s just a collection of pages with the same layout, but with different blobs of text inserted in the middle for each post. I&amp;#8217;d also like to generate some lists: recent posts, related posts, that kind of thing.&lt;/p&gt;

&lt;p&gt;Ideally, what I want is something that transforms this&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='nt'&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
&lt;span class='nt'&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;{{ page.title }}&lt;span class='nt'&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
{{ page.content }}
&lt;span class='nt'&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;into this&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='html'&gt;&lt;span class='nt'&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
&lt;span class='nt'&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Simplicity in Everything&lt;span class='nt'&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class='nt'&gt;&amp;lt;p&amp;gt;&lt;/span&gt;This website is now created using Jekyll...&lt;span class='nt'&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
...
&lt;span class='nt'&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;#8217;s &lt;em&gt;exactly&lt;/em&gt; what Jekyll does. It just goes through all your pages and uses &lt;a href='http://liquidmarkup.org/'&gt;Liquid&lt;/a&gt; to transform them into a static site. Don&amp;#8217;t believe me? The entire source for this site is &lt;a href='https://github.com/Poita/poita.org'&gt;on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;To test my website locally, I just run &lt;code&gt;jekyll --server&lt;/code&gt; and head on over to &lt;code&gt;http://0.0.0.0:4000&lt;/code&gt;. To deploy, I just run &lt;code&gt;jekyll &amp;amp;&amp;amp; rsync
...&lt;/code&gt;, which generates the site and copies it over to my remote server. That&amp;#8217;s it.&lt;/p&gt;

&lt;p&gt;Why can&amp;#8217;t everything be this simple?&lt;/p&gt;</content>
 <feedburner:origLink>http://poita.org/2012/01/22/simplicity-in-everything.html</feedburner:origLink></entry>
 
 <entry>
   <title>Homepage 2.0</title>
   <link href="http://feedproxy.google.com/~r/poita/~3/b-zrta40WpE/homepage-2.0.html" />
   <updated>2012-01-22T00:00:00+00:00</updated>
   <id>http://poita.org/2012/01/22/homepage-2.0</id>
   <content type="html">&lt;p&gt;Well, I&amp;#8217;ve done it again. New website from scratch.&lt;/p&gt;

&lt;p&gt;This time, I&amp;#8217;ve gone for simplicity. I got sick of the incredible bloat of Joomla and all its features that were unnecessary for what I wanted to achieve: an essentially static website that I can easily configure.&lt;/p&gt;

&lt;p&gt;This time, I&amp;#8217;ve gone with &lt;a href='https://github.com/mojombo'&gt;Tom Preston-Werner&lt;/a&gt;&amp;#8217;s excellent &lt;a href='https://github.com/mojombo/jekyll'&gt;Jekyll&lt;/a&gt; static site generator. I just write my posts in Markdown, run jekyll, and it generates all the HTML for me. I have full control over the layout of the site, and everything is there in plain text.&lt;/p&gt;

&lt;p&gt;The source for this site is &lt;a href='https://github.com/Poita/poita.org'&gt;hosted on GitHub&lt;/a&gt;.&lt;/p&gt;</content>
 <feedburner:origLink>http://poita.org/2012/01/22/homepage-2.0.html</feedburner:origLink></entry>
 
 
</feed>

