<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>tl;dr</title>
	<atom:link href="http://didntread.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://didntread.wordpress.com</link>
	<description>Building a multi-dimensional spatially configured feed forward nodal compute network.</description>
	<lastBuildDate>Fri, 06 Aug 2010 06:53:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='didntread.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>tl;dr</title>
		<link>http://didntread.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://didntread.wordpress.com/osd.xml" title="tl;dr" />
	<atom:link rel='hub' href='http://didntread.wordpress.com/?pushpress=hub'/>
		<item>
		<title>A &#8220;free&#8221; benefit to using entity systems</title>
		<link>http://didntread.wordpress.com/2010/06/27/a-free-benefit-to-using-entity-systems/</link>
		<comments>http://didntread.wordpress.com/2010/06/27/a-free-benefit-to-using-entity-systems/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 00:26:45 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[entities]]></category>
		<category><![CDATA[entity systems]]></category>
		<category><![CDATA[OOP alternative]]></category>
		<category><![CDATA[paradigm]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=341</guid>
		<description><![CDATA[In previous posts, I talked about entity systems (though incomplete), but theres one big beneficial side-effect of using entity systems which I hadn&#8217;t considered until now. Recently, I&#8217;ve been spending a lot of time building a production-quality component system, using Intel&#8217;s Threading Building Blocks to efficiently parallelize message handling across available processor cores and I&#8217;ve [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=341&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In previous posts, I talked about <a href="http://didntread.wordpress.com/2009/07/14/building-a-stackless-hierarchy/">entity systems</a> (though incomplete), but theres one big beneficial side-effect of using entity systems which I hadn&#8217;t considered until now. Recently, I&#8217;ve been spending a lot of time building a production-quality <a href="http://didntread.wordpress.com/2010/02/17/flat-hierarchies-in-c-part-1/">component system</a>, using Intel&#8217;s <a href="http://www.threadingbuildingblocks.org/">Threading Building Blocks</a> to efficiently parallelize message handling across available processor cores and I&#8217;ve spent a lot of time on trying to make efficient use of the processor cache (minimizing cache misses, reducing false sharing, etc). In single threaded applications, the processor cache works in the background, transparently reducing memory latency of your code by storing frequently accessed data in fast memory inside the processor, but in multithreaded programs, this works against you because each core&#8217;s cache must be kept synchronized. That means that when a thread executing on one core modifies memory, the changes must be reflected in the caches of the other cores, which takes time and increases processor interconnect traffic. Too much traffic and the bus gets saturated, decreasing the performance of all threads, even ones which do not access this shared data. So, efficient use of the cache is pretty important and it must be done (more or less) manually.</p>
<p>In short, the <a href="http://en.wikipedia.org/wiki/Cache">processor cache</a> works by keeping a copy of values accessed from RAM locally in the processor core. If read memory location A, it will store A and the N following bytes in the cache (the size of A + N is a <em>cache line</em>). I simplified this by assuming that A is aligned to the beginning of a cache line &#8211; in real life, it could be in the middle, or even the end of a cache line. That means that if you store a number of related items next to each other, eg in an array, an iterate through them, you only need to access RAM once &#8211; the other items will already be loaded into the cache (assuming the total size is no larger than the cache line). This is based on the principle of <a href="http://en.wikipedia.org/wiki/Locality_of_reference">locality of reference</a>, that is, it is likely that memory which is near other memory which is being accessed will also be accessed.</p>
<p>Recently, I came across some slides which talk about the <a href="http://research.scee.net/files/presentations/gcapaustralia09/Pitfalls_of_Object_Oriented_Programming_GCAP_09.pdf">pitfalls of object oriented programming</a> and it points out how classes and objects are actually pretty cache-unfriendly. This is because objects encapsulate different properties which fragment the cache. For example, in a game, you might have an Actor class, which encapsulates the idea of a player or computer controlled character. Actors may have the following properties:</p>
<ul>
<li>position</li>
<li>health</li>
<li>inventory</li>
<li>geometry</li>
</ul>
<p>One common operation of Actors may be to update its position in some way. Something like the following pseudocode:</p>
<pre class="brush: cpp;">
class Actor
{
    Position position;
    Health health;
    Inventory inventory;
    Geometry geometry;
};
...
Actor[] global_actors;
...
function update_positions ()
{
    for_each (Actor a in global_actors)
    {
        a.position = update(a.position);
    }
}
</pre>
<p>This seems like a reasonable approach, right?</p>
<p>Except it has a serious flaw. Step by step, what actually happens is something like this: the first Actor is loaded &#8211; a cache miss, so its loaded from RAM, into the cache. The position is read and updated and written to the cache (the processor will flush the change to RAM in the background). Then the second Actor is loaded, but this is also a cache miss, so its loaded from RAM.. and so on for each Actor. This is because the cache line is taken up by other unrelated properties of the Actor class.</p>
<p>If, instead, the positions of all Actors was stored together (and the health for all Actors is stored together, and the inventories and geometry and so forth), lets say as four arrays of structures &#8211; something like the following:</p>
<pre class="brush: cpp;">
Position[] actor_positions;
Health[] actor_health;
Inventory[] actor_inventories;
Geometry[] actor_geometry;
...
function update_positions ()
{
    for_each (Position p in actor_positions)
    {
        p.position = update(p.position);
    }
}
</pre>
<p>the update function would be much more cache friendly. This is because the position objects are adjacent in memory. By accessing the first one, the second and third and so on are loaded into the cache (how many are loaded depends on the size of the Position structure and the size of a cache line).  So instead of having to access RAM for every Actor, it now only needs to do so once for however many Position structures fit in a cache line. Less cache misses equals higher performance.</p>
<p>So back to entity systems. In an entity system, an <em>entity</em> (like the Actor entity) is a collection of <em>traits</em> (like Position). Since the traits are separated from the entities which posses these traits, they can be stored together, such as in an array. Since the traits can be stored together, processing them iteratively, for example, within a <em>system</em> which updates or handles them, conforms to the principle of locality of reference, and is therefore cache friendly.</p>
<p>Entity systems have a number of benefits as a software paradigm, architectural pattern and abstraction, including:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Separation_of_concerns">Separation of concerns</a> &#8211; features and functionality is split into distinct <em>traits</em> (the properties/data) and <em>systems </em>(the code implementing the features)</li>
<li><a href="http://en.wikipedia.org/wiki/Encapsulation_%28object-oriented_programming%29">Encapsulation</a> &#8211; entity systems promote well-defined, potentially restricted interfaces for external systems to change traits (such as, through message passing), essentially a form of encapsulation and data-hiding. Similarly since traits can be considered independently, they offer an <a href="http://en.wikipedia.org/wiki/Data_abstraction">abstraction</a> over specific entities</li>
<li><a href="http://en.wikipedia.org/wiki/Concurrency_%28computer_science%29">Concurrency</a> &#8211; as systems are independent, operating on their traits should be an independent procedure, allowing systems to be executed concurrently</li>
<li><a href="http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming">Polymorphism</a> &#8211; entities can be treated as objects which are a union of their traits, that is, entities essentially function as a <a href="http://en.wikipedia.org/wiki/Duck_typing">duck-typed</a> object system</li>
<li><a href="http://en.wikipedia.org/wiki/Inheritance_%28computer_science%29">Inheritance</a> &#8211; the concept of an entity system doesn&#8217;t give inheritance in itself, however an implementation could by, for example, allowing entities to be used as templates for new entities (create a new entity with the same traits as an existing entity &#8211; <a href="http://en.wikipedia.org/wiki/Prototype-based_programming">prototype based OO</a> &#8211; which can then be extended by adding other traits, if required)</li>
<li><a href="http://en.wikipedia.org/wiki/Code_reuse">Code reuse</a> &#8211; traits and systems offer an appealing method of code reuse</li>
<li>Cache friendliness &#8211; a described above, the nature of entity systems provides opportunities for cache friendly implementations</li>
</ul>
<p>I&#8217;m sure I missed more. As can be seen from the list above, an entity system shares most, if not all, of the desirable traits of object oriented programming, as well as some which are dificult in object oriented software such as concurrency. One can easily see that entity systems are an appealing paradigm for many kinds of software development.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/341/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/341/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/341/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=341&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2010/06/27/a-free-benefit-to-using-entity-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>ANI: implicit, safe, guaranteed deadlock-free parallelism</title>
		<link>http://didntread.wordpress.com/2010/03/04/ani-implicit-safe-guaranteed-deadlock-free-parallelism/</link>
		<comments>http://didntread.wordpress.com/2010/03/04/ani-implicit-safe-guaranteed-deadlock-free-parallelism/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 21:28:07 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Concurrent Programming]]></category>
		<category><![CDATA[Dataflow]]></category>
		<category><![CDATA[fast]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[programming language]]></category>
		<category><![CDATA[safe]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=236</guid>
		<description><![CDATA[I&#8217;ve been involved in the ANI community lately and I&#8217;ve wanted to blog about it, but couldn&#8217;t bring myself to come up with some code samples, since its such an early work-in-progress. I finally managed to muster up enough motivation to talk about some of the existing sample code instead, so here we are. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=236&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been involved in the <a href="http://code.google.com/p/anic/">ANI</a> community lately and I&#8217;ve wanted to blog about it, but couldn&#8217;t bring myself to come up with some code samples, since its such an early work-in-progress. I finally managed to muster up enough motivation to talk about some of the existing sample code instead, so here we are.</p>
<p>The most important question is &#8220;<em>What is ANI and why is it interesting?</em>&#8221; and this is exactly what I hope to answer.</p>
<p>ANI is a (very early) work-in-progress parallel programming language based on the dataflow paradigm. Currently, anic (the ANI compiler) can parse the source code, but cannot yet generate any runtime code. Hopefully I will be able to give a real, live demonstration soon.<br />
What makes ANI interesting is that it aims to be <strong>fast</strong>, <strong>safe</strong> and <strong>easy to use</strong> and it achieves this by building on a solid dataflow-based core language. The compiler and runtime are to ensure that an ANI program will make use of available processing cores, in parallel, and that <strong>this implicit parallelism will never deadlock.</strong> That is, ANI is <em>parallel</em> and <em>safe</em>.<br />
ANI programs also manage memory in such a way that the programmer will not have to manually handle allocation and freeing of memory, but the runtime also does not need a complex or slow garbage collector. This is achieved by the way that ANI manages the dataflow core &#8211; it always knows what data is in use and when it can be freed.<br />
Because of these features, ANI is a very different language to the imperative languages we are used to and, therefore, may seem quite complex and difficult, but once the core concepts are understood, <strong>the language becomes surprisingly easy</strong>. So, lets take a look at these core concepts.</p>
<p>The ANI language is built around a handful of base concepts, namely <em>latches</em>, <em>streams</em>, <em>filters</em> and <em>pipes</em>. I will introduce each in turn.</p>
<ul>
<li>A <span style="text-decoration:underline;"><strong>pipe</strong></span> is a sequence of instructions through which data flows and the core construct through which ANI moves data from operation to operation. A pipe is executed sequentially and multiple pipes will execute in parallel, side by side. When a pipe requires data from a latch or a stream, it may block while waiting for the latch or stream to produce data &#8211; that is, become non-empty.</li>
</ul>
<ul>
<li>A <span style="text-decoration:underline;"><strong>latch</strong></span> is a placeholder for a value, not unlike a variable in imperative languages. Latches may be empty &#8211; containing no value at all &#8211; or they may be initialized. You can, of course, put a value into a latch later and you can take the value out again, making the latch be empty once again. The important part, however, is that when a latch contains a value, any pipes which are blocking to receive its value become runnable and are scheduled to be executed.</li>
</ul>
<ul>
<li>A <span style="text-decoration:underline;"><strong>stream</strong></span> is a queue of latches. Values can be fed into a stream and into a pipe, where it can be processed.</li>
</ul>
<ul>
<li>A <span style="text-decoration:underline;"><strong>filter</strong></span> is a piece of code through which values may flow, as part of a pipe. Filters may alter or consume values from the pipe. For example, a filter could take in a pair of numbers and add them.</li>
</ul>
<p>So, what does ANI look like? The following sample program demonstrates the major constructs which make up the ANI language. This program, taken from the ANI test code, runs a combination of a realtime clock and a simple textual calculator, running in parallel. The user is prompted to enter a number, followed by one of <em>+</em>, <em>-</em>, <em>*</em> or <em>/</em> and then another number. The calculation is performed and the result is output on the next clock tick. The three parts &#8211; input, calculation and clock tick/output &#8211; can all execute in parallel.</p>
<pre class="brush: cpp;">
@std.in;

a  = [[int\]]  &lt;- 0;
op = [[char\]] &lt;- ' ';
b  = [[int\]]  &lt;- 0;
r  = [[int\]]  &lt;- 0;

0 {
    clock =&gt; [[int ms]] {
        (&quot;\r&quot; + ms/1000.0 + &quot;: &quot; + a + op + b + &quot;=&quot; + r) -&gt;std.out;
        1 std.delay
        (ms+1) clock
    }
};

inLoop =&gt; {
    \in -&gt;a
    \in -&gt;op
    \in -&gt;b
    inLoop
};

\\op ?? {
    '+': (\a + \b)
    '-': (\a - \b)
    '*': (\a * \b)
    '/': (\a / \b)
       : 0
} -&gt;r;
</pre>
<p>I will now disect the program and explain each part in turn.</p>
<pre class="brush: cpp;">
@std.in;

a  = [[int\]]  &lt;- 0;
op = [[char\]] &lt;- ' ';
b  = [[int\]]  &lt;- 0;
r  = [[int\]]  &lt;- 0;
</pre>
<p>The <em>@std.in;</em> adds the <em>in</em> latch from the std package to the current namespace. The rest of this code snippets defines and initializes latches for the programs internal use. <em>int\</em> means a latch to hold an integer, <em>char\</em> means a latch to hold a single character. <em>[[datatype]]</em> is how objects are constructed in ANI. So, for example, <em>[[int\]]</em> constructs a latch which can hold an integer. The <em>&lt;- value</em> assigns the specified value to the newly constructed object and the <em>=</em> binds it to an identifier so it can be referred to later. So, the first line creates an integer latch, initializes it to zero and binds the name <em>a</em> to it.</p>
<p>The next code block is a little more involved.</p>
<pre class="brush: cpp;">
0 {
    clock =&gt; [[int ms]] {
        (&quot;\r&quot; + ms/1000.0 + &quot;: &quot; + a + op + b + &quot;=&quot; + r) -&gt;std.out;
        1 std.delay
        (ms+1) clock
    }
};
</pre>
<p>The easiest way to understand this code snippet is by starting with <em>clock =&gt; [[int ms]] {</em>. What this line does is creates a pipe named <em>clock</em>, which takes an integer value (bound to the name <em>ms</em>). The <em>=&gt;</em> means that any values to the left of the name (in this case 0) will flow into the pipe &#8211; that is, it is defined and used in place. If <em>=</em> had been used instead, then 0 would have had to have been sent to <em>clock </em>with <em>0 clock</em>, somewhere outside of its definition. The code inside <em>{ &#8230; }</em> is the body of the <em>clock</em> pipe.</p>
<p>The first line in the clock pipe first concatenates a bunch of strings (implicitly converting the values of <em>a</em>, <em>op</em>, <em>b</em> and <em>r</em> to strings).  <em>ms</em> is divided by 1000.0 before being converted to a string. For example, if <em>ms</em> contains <em>2345</em>, <em>a</em> contains <em>2</em>, <em>b</em> contains <em>5</em>, <em>r</em> contains <em>7</em> and <em>op</em> contains &#8216;<em>+</em>&#8216;, then the expression inside the parentheses would evaluate to &#8220;<em>\r2.345: 2+5=7</em>&#8221; (and \r is a carriage return). The final part of this line, <em>-&gt;std.out</em>, sends this string to <em>std.out</em> which causes it to be output to the screen. The semicolon at the end of the line means that this is the end of the pipe and a new pipe is started (but both are sub-pipes of the clock pipe, which continues until the } is reached. Basically, clock forks into two parallel pipes). This pipe and the next may be executed concurrently, every time clock is sent a value.</p>
<p>The second pipe sends <em>1</em> to<em> std.delay</em>, causing this pipe to be delayed (or paused) for (at least) 1 millisecond and then the pipe continues. The final part of this pipe adds <em>1</em> to the value of <em>ms</em> and passes it to <em>clock</em> &#8211; this causes these two pipes to be executed again, but this time <em>ms</em> has been incremented by one. Essentially, this defines a feedback loop, which causes <em>clock</em> (and therefore its two sub-pipes) to be executed in 1 millisecond increments, printing the current state of the calculator (a, b, op and r) each time.</p>
<p>The next code block prompts the user for input to the calculator:</p>
<pre class="brush: cpp;">
inLoop =&gt; {
    \in -&gt;a
    \in -&gt;op
    \in -&gt;b
    inLoop
};
</pre>
<p>Just like with clock, this defines a named pipe, but this time it doesn&#8217;t take in any values. Instead it executes three input commands before recursively calling itself, causing the program to loop endlessly, asking for input on each iteration. <em>\in</em> unlatches the <em>in</em> latch, which causes the program to wait for user input, which it returns when the user presses the return key. The <em>-&gt;a</em> sends this value to the latch, <em>a</em>. This is repeated for <em>op</em> and <em>b</em>. Note that the in latch is a <em>node\ </em>and its values are implicitly converted to <em>int</em> and <em>char</em>, as appropriate.</p>
<pre class="brush: cpp;">
\\op ?? {
    '+': (\a + \b)
    '-': (\a - \b)
    '*': (\a * \b)
    '/': (\a / \b)
       : 0
} -&gt;r;
</pre>
<p>This final code block executes every time <em>op</em> has received a new value. This is done by destreaming the <em>op</em> latch. Simply unlatching it would have removed the value once, but it would not trigger the following pipe again the next time it receives a value.</p>
<p>The <em>??</em> initializes a pattern matching construct &#8211; essentially, the value on the pipe (the value destreamed from <em>op</em>) is matched against each of the values specified before the <em>:</em> on each line in the following block and the code on the right is executed for whichever value is matched &#8211; or the last one, where the value is omitted, is executed if none match. The code that is executed on a match simply unlatches <em>a</em> and <em>b</em> and applies the appropriate operator to them, depending on what the value of <em>op</em> was. The result of this calculation is then sent into<em> r</em>.</p>
<p>So, we can see how the calculator has received its values, performed its calculations and put the result into <em>r</em>. On its next iteration, the clock would pick up these values and they would be output. At the same time as all of this is happening, the user may be typing the next set of inputs for the calculator. In fact, the input, output/clock and the calculations may all be ocurring in parallel, at the same time.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/236/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/236/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/236/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=236&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2010/03/04/ani-implicit-safe-guaranteed-deadlock-free-parallelism/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>Language concept: elastic scopes</title>
		<link>http://didntread.wordpress.com/2010/02/24/language-concept-elastic-scopes/</link>
		<comments>http://didntread.wordpress.com/2010/02/24/language-concept-elastic-scopes/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 18:30:11 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Language Concept]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[elastic scopes]]></category>
		<category><![CDATA[langauge concept]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scoped locals]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=300</guid>
		<description><![CDATA[I was playing around with the idea of having global variables.. With nested scopes.. In a threaded environment. Yes, I&#8217;m aware that a global variable with scope isn&#8217;t a global variable &#8211; but.. it works.. though doesn&#8217;t really make sense. Actually, it does make sense, but the terminology is off. Basically, its a global variable [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=300&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I was playing around with the idea of having global variables.. With nested scopes.. In a threaded environment. Yes, I&#8217;m aware that a global variable with scope isn&#8217;t a global variable &#8211; but.. it works.. though doesn&#8217;t really make sense. Actually, it does make sense, but the terminology is off. Basically, its a global variable whose value depends on the scope in which its used. Quick code example?</p>
<pre class="brush: cpp;">
ScopedGlobal&lt;int&gt; global = 5; // Global scoped global.

void foo () {
    ScopedGlobal&lt;int&gt; global  = 4; // Local scoped global.
    output(&quot;Value in foo: &quot;, global); // Print 4
}

void bar () {
    output(&quot;Value in bar: &quot;, global); // Print 5
}
</pre>
<p>Ok, that code clearly won&#8217;t compile in C++, but its just an example. Also, it proves nothing &#8211; the local variant simply aliases the global. What I had in mind is a little more complex than this &#8211; what if the local version can be passed to a different scope and still be valid? Perhaps to another thread? Like how a closure captures its enclosing environment &#8211; a local variable could capture its environment and carry it along with it, to another scope or another thread. Capturing the entire environment could be a bit of effort, but a simple variable doesn&#8217;t need to &#8211; its not a function which references its environment, its just a value which needs to retain its state in various scopes. This can actually be implemented in C++ with a little effort and even made thread safe so it can be passed between threads. You can take a <a href="http://gist.github.com/313570">look at my test code here</a>. Of course, my little test only allows the creation of one of these, since the global access is handled through static variables &#8211; but you could keep a table that can be accessed to store a number of variables, so it can actually be implemented in plain C++.</p>
<p>But, thats besides the point of this article. It is, however, the background information for my newest and craziest language concept. I&#8217;m unsure if I should add an &#8220;esoteric language&#8221; tag to this post or not <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>What if scopes were <em>elastic</em>? They could change and move around, altering the state of your variables and program transparently to its execution. Perhaps elastic scopes could even be seen as a computation paradigm? Then again, I&#8217;m not going to go to the effort of figuring out how to turn elastic scopes into a turing complete execution model &#8211; but I am going to theorize how they could be used as part of an execution <em>environment</em> in a highly parallel system.</p>
<p>Instead of functions, I am going to use named scopes, which can be called asynchronously and whose environments can be read from or sent to by other scopes. Heres some possible sample code:</p>
<pre class="brush: cpp;">
scope1 = {
    var val = &quot;in scope1&quot;
    print &quot;scope1 &quot; val

    async {
        scope2 = {
            val = &quot;in scope2&quot;
            print &quot;scope2 &quot; val
            sleep 500
            print &quot;scope2 &quot; val
        }
        scope3 = {
            print &quot;scope3 &quot; val
            sleep 100
            print &quot;scope3 &quot; val
            val = &quot;in scope3&quot;
            print &quot;scope3 &quot; val
            send scope3 to scope2
        }
    }
    print &quot;scope1 &quot; val
}
</pre>
<p>And the output would be something like the following:</p>
<pre class="brush: cpp;">
scope1 in scope1
scope3 in scope1
scope2 in scope2
scope3 in scope1
scope3 in scope3
scope2 in scope3
scope1 in scope1
</pre>
<p>Spaghetti code, of course, but overall, simple enough so far.</p>
<p>So far, its nothing too special, besides perhaps sending the value of val from scope3 to scope2. But imagine, for a moment, what would happen if the value was passed, as an argument, to a function which is executed in its own thread. What if it was passed in such a way that its scope was retained? Lets see an example:</p>
<pre class="brush: cpp;">
function f1 (var v) {
    print v
    sleep 500
    print v
}
scope1 = {
    var val = 5
    threat t = f1
    f1.start(val)
    sleep 100
}
</pre>
<p>What does the second print output? In a normal language, it would be 5, but if val retains its scope &#8211; scope1 &#8211; then it will have went out of scope before reacng this print. Imagine that.. scopes changing in other threads could affect your variables! Of course, I&#8217;m assuming that accessing a variable is always atomic. This would be extremely important in such a language.</p>
<p>Am I going to design a lnaguage around this idea? No, of course not and I shudder to think of all the changing state! Shared state is evil and makes concurrency hard. Yet here I take shared state and make it even more unpredictable than before. But, the idea is still interesting. Could it be used to do wonderful things? Can it be used with immutable data structures? What is an immutable data structure in a mutable, elastic scope? Is it, essentially, mutable? Can this be used as part of a dataflow language to do weird and wonderful things? Or was this a pointless exercise? These are all open questions and I invite people to play with them and see what happens. I will ammend this post after toying with the concept some more.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/300/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/300/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/300/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=300&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2010/02/24/language-concept-elastic-scopes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>Flat hierarchies in C++: Part 2</title>
		<link>http://didntread.wordpress.com/2010/02/23/flat-hierarchies-in-c-part-2/</link>
		<comments>http://didntread.wordpress.com/2010/02/23/flat-hierarchies-in-c-part-2/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 02:15:32 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Concurrent Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[flat hierarchy]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=282</guid>
		<description><![CDATA[This post expands on the previous post in the series by decoupling the components and event handlers and allowing the execution environment to be easily redefined by replacing small sections of the code, without having to change anything else. It also lays the groundwork for a thread safe parallel execution environment. First, we include the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=282&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post expands on the <a href="http://didntread.wordpress.com/2010/02/17/flat-hierarchies-in-c-part-1/">previous post</a> in the series by decoupling the components and event handlers and allowing the execution environment to be easily redefined by replacing small sections of the code, without having to change anything else. It also lays the groundwork for a thread safe parallel execution environment.</p>
<p>First, we include the standard C++ library classes which we will be suing.</p>
<pre class="brush: cpp;">
#include &lt;map&gt;
#include &lt;vector&gt;
#include &lt;deque&gt;
#include &lt;iostream&gt;
</pre>
<p>This next block of code defines a typedef for a mutex and a class for creating atomic blocks of code through RAII. This isn&#8217;t yet used, but in the next post, when we introduce threads and parallel execution, this will be modified to actually refer to a mutex and actually lock and unlock the mutex, allowing the rest of the code to be made threadsafe without any other changes (besides implementing the threads).</p>
<pre class="brush: cpp;">
// Replace this with a Mutex or lock datatype.
typedef int Lock;

// Use RAII to lock and unlock a mutex.
class Atomic {
private:
    Lock lock;
public:
    Atomic (Lock&amp; l)
        : lock(l) {
        // Lock the lock.
    }
    ~Atomic () {
        // Unlock the lock.
    }
};
</pre>
<p>The event base class is unchanged from the previous version.</p>
<pre class="brush: cpp;">
// Base class for event data type.
class Event {
public:
    Event (unsigned int t) : type(t) {}
    virtual ~Event () {}

    const unsigned int type;
};
</pre>
<p>The component base class is almost the same as in the previous version. In fact, its simpler, as it no longer stores a map of event ids to components. It does still contain the methods for registering to receive events and to send events, but these are merely convenience functions which delegate the actual work to the execution manager.</p>
<pre class="brush: cpp;">
// Base class for a component.
class Component {
protected:
    // Register for all events of type &quot;type&quot;.
    void registerForEvent (const unsigned type);
    // Send an event.
     void send (const Event* const event);

public:
     // Event handler, called when an event, which is being listened for, is received.
     virtual void eventReceived(const Event* const event)=0;
};
</pre>
<p>The following is an abstract class defining the execution manager. The job of the execution manager is to map events to the desired components and schedule the event handlers. This is an abstract class so that the actual execution model can be defined in a subclass. This lets us swap in different execution models later without having to change much code.</p>
<pre class="brush: cpp;">
// Abstract class used to manage execution of components.
class Manager {
private:
    static Manager* manager;

public:
    // Provide access to the stored manager.
    static void set (Manager* man) {manager = man;}
    static Manager* const get () {return manager;}

    virtual ~Manager () {}

    // Register for all events of type &quot;type&quot;.
    virtual void registerForEvent (Component* component, const unsigned type)=0;
    // Send an event.
    virtual void send (const Event* const event)=0;
    // Execute component system.
    virtual void exec ()=0;
};

Manager* Manager::manager = 0;
</pre>
<p>We now implement the component methods by delegaing the work to the execution manager.</p>
<pre class="brush: cpp;">
void Component::registerForEvent (const unsigned int type) {
    // Delegate to manager.
    Manager::get()-&gt;registerForEvent(this, type);
}
void Component::send (const Event* const event) {
    // Delegate to manager.
    Manager::get()-&gt;send(event);
}
</pre>
<p>The following code defines a sample event and component and remains largely unchanged from the previous version. It does, however, add another event type, to demonstrate how events may be sent from inside the event handler and it removes the quit event, which is not needed.</p>
<pre class="brush: cpp;">
// Keep a list of event types.
enum EventIdentifiers {
    PRINT_HELLO = 0,
    PRINT_MESSAGE,
    SEND_MESSAGE
};

// A sample event.
class MessageEvent : public Event {
public:
    MessageEvent () : Event(PRINT_MESSAGE) {}
    virtual ~MessageEvent () {}

    std::string message;
};

// A sample component.
class HelloPrinter : public Component {
public:
    HelloPrinter () {
        registerForEvent(PRINT_HELLO);
        registerForEvent(PRINT_MESSAGE);
        registerForEvent(SEND_MESSAGE);
    }
    virtual ~HelloPrinter () {}

    // Sample event handler.
    void eventReceived(const Event* const event) {
        if (event-&gt;type == PRINT_HELLO) {
            std::cout &lt;&lt; &quot;Hello!\n&quot;;
        }
        else if (event-&gt;type == PRINT_MESSAGE) {
            std::cout &lt;&lt; &quot;Message: &quot; &lt;&lt; static_cast&lt;const MessageEvent*&gt;(event)-&gt;message &lt;&lt; &quot;\n&quot;;
        }
        else if (event-&gt;type == SEND_MESSAGE) {
            // Demonstrate sending events from inside the event handler.
            sendMessage(&quot;Send message event sent a message&quot;);
        }
    }

    // Convenience functions for sending events.
    void sendHello () {
        Event* event = new Event(PRINT_HELLO);
        send(event);
    }
    void sendMessage (const std::string&amp; message) {
        MessageEvent* event = new MessageEvent;
        event-&gt;message = message;
        send(event);
    }
    void sendEvent(unsigned int id) {
        Event* event = new Event(id);
        send(event);
    }
};
</pre>
<p>The reference counting class is a utility class which we use to allow us to reference count events, so that if an event is sent to multiple components, we do not delete it until all components have had a chance to process the event. This means that an event can be allocated, sent and forgotton about, as the reference counter will take care of notifying the manager of when the event should be deleted.</p>
<pre class="brush: cpp;">
// Class to keep a thread safe reference count for a pointer.
template &lt;class T&gt;
class ReferenceCounter {
private:
    const T* const item;
    unsigned int count;
    Lock lock;

public:
    ReferenceCounter (const T* const pointer)
        : item(pointer), count(0)
    {
    }
    // Delete the pointer when the reference counter is destroyed.
    ~ReferenceCounter () {
        delete item;
    }
    // Provide access to the internal lock, in case access to addRef() needs to be synchronised.
    Lock&amp; getLock () {return lock;}

    // Provide access to the stored pointer - addRef() must have been called once for each time this is used and release() should be called once after each call - if release() returns true, then this pointer is now invalid and the ReferenceCounter should be destroyed.
    const T* const get () {return item;}

    // Increase the reference count.
    ReferenceCounter&lt;T&gt;* addRef () {
        ++count;
        return this;
    }

    // Decrease the reference count and return true is the reference counter is ready to be destroyed.
    bool release () {
        Atomic atom(lock);
        return --count &lt;= 0;
    }
};
</pre>
<p>We now implement the execution manager. This execution manager will process the events sequentially, inthe order that they were sent and the components will process them in the order that they registered for the events. The execution manager stores a queue of pair &#8211; an event and component to process this event &#8211; which ill be processed in turn. Events are added to the back and taken from the front for FIFO processing. Also, a map of event types and components is stored, so that we can keep track of which component is itnerested in which event.</p>
<pre class="brush: cpp;">
// Sample execution manager used to execute components in a synchronous fashion.
class SynchronousExecutionManager : public Manager {
private:
    Lock queueLock;
    // Queue of events needing to be processed.
    std::deque&lt;std::pair&lt;Component*, ReferenceCounter&lt;Event&gt;* &gt; &gt; eventQueue;

    Lock mapLock;
    // Map of event types to components registered for those events.
    std::map&lt;unsigned int, std::vector&lt;Component*&gt; &gt; eventMap;

public:
    SynchronousExecutionManager () {}
    virtual ~SynchronousExecutionManager () {}

    // Register for all events of type &quot;type&quot;.
    void registerForEvent (Component* component, const unsigned type);
    // Send an event.
    void send (const Event* const event);
    // Execute component system.
    void exec ();
};
</pre>
<p>Registering for an event is a simple matter of adding the component to the list of components registered for a given event type. This is done in an atomic block, so that the event map cannot be modified concurrently.</p>
<pre class="brush: cpp;">
void SynchronousExecutionManager::registerForEvent (Component* component, const unsigned type) {
    Atomic atom(mapLock);
    eventMap[type].push_back(component);
}
</pre>
<p>The send method simply ensures the event is reference counted and then adds itself to the queue for each component that is registered to receive that event. Again, this method locks the shared mutexes so that the queue and map cannot be in an inconsistent state.</p>
<pre class="brush: cpp;">
void SynchronousExecutionManager::send (const Event* const event) {
    Atomic atom1(queueLock);
    Atomic atom2(mapLock);

    // Create a new reference counter for the event.
    ReferenceCounter&lt;Event&gt;* ref = new ReferenceCounter&lt;Event&gt;(event);

    // Get list of components which should receive this event.
    std::vector&lt;Component*&gt;&amp; components = eventMap[event-&gt;type];

    // Add the event to the queue, once for each component - add to the reference count for each one.
    for (std::vector&lt;Component*&gt;::iterator i = components.begin(); i != components.end(); i++) {
        eventQueue.push_back(std::pair&lt;Component*, ReferenceCounter&lt;Event&gt;* &gt;(*i, ref-&gt;addRef()));
    }
}
</pre>
<p>This method handles actually calling the event handler for each event. It does this by taking the next event off the queue, in a thread safe manner, and then calling the event handler. Finally, the reference count for the event is decremented and if needs be, the event is deleted. This ensures that events do not leak memory.</p>
<pre class="brush: cpp;">
void SynchronousExecutionManager::exec () {
    ReferenceCounter&lt;Event&gt;* ref;
    Component* component;
    // As long as there are events to be processed, keep processing.
    while (!eventQueue.empty()) {
        {
            Atomic atom(queueLock);
            // Get the next event/component pair from the queue.
            std::pair&lt;Component*, ReferenceCounter&lt;Event&gt;* &gt; next = eventQueue.front();
            eventQueue.pop_front();
            ref = next.second;
            component = next.first;
        }
        // Handle the event.
        component-&gt;eventReceived(ref-&gt;get());
        // Release reference count for the event just processed.
        if (ref-&gt;release()) {
            // Nobody else is holding any more references to this or will be touching this in any way
            delete ref;
        }
    }
}
</pre>
<p>Finally, a test program to test the event system.</p>
<pre class="brush: cpp;">
// Sample run
int main (int argc, char** argv) {
    // Create the execution manager.
    Manager::set(new SynchronousExecutionManager());

    // Seed the system with some events.
    HelloPrinter a, b, c;
    a.sendHello();
    b.sendMessage(&quot;Hi from b&quot;);
    c.sendEvent(SEND_MESSAGE); // Sent to all 3, which each send another event to all 3, causing 9 string messages to be sent.

    // Run the event system.
    Manager* manager = Manager::get();
    manager-&gt;exec();

    // Clean up.
    delete manager;
}
</pre>
<p>Hopefully this helped you understand how the components from the previous system can be decoupled in a way that the execution environment can be easily controlled without requiring code modification. In the next part, we will implement a new execution manager, which changes the exec() method to actually process the event handlers in a thread pool, for parallel execution.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=282&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2010/02/23/flat-hierarchies-in-c-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>Flat hierarchies in C++: Part 1</title>
		<link>http://didntread.wordpress.com/2010/02/17/flat-hierarchies-in-c-part-1/</link>
		<comments>http://didntread.wordpress.com/2010/02/17/flat-hierarchies-in-c-part-1/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 22:58:14 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Concurrent Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[c++ hierarchies components concurrency]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=229</guid>
		<description><![CDATA[I have decided that the time has come to finish the mini series on flat hierarchies in C++. This part, Part 1 of the new and improved series, is simply a reiteration of my earlier post on the subject, with a full, compilable, code listing. For an explanation, please read the other post. The next [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=229&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have decided that the time has come to finish the mini series on flat hierarchies in C++. This part, Part 1 of the new and improved series, is simply a reiteration of <a href="http://didntread.wordpress.com/2009/07/23/some-thoughts-on-flat-hierarchies-in-c/">my earlier post on the subject</a>, with a full, compilable, code listing. For an explanation, please read the other post. The <a href="http://didntread.wordpress.com/2010/02/23/flat-hierarchies-in-c-part-2/">next part of the series</a> will decouple the components in preparation of adding concurrency.</p>
<pre class="brush: cpp;">
#include &lt;map&gt;
#include &lt;vector&gt;
#include &lt;iostream&gt;
#include &lt;cstdlib&gt;

class Event {
public:
    Event (unsigned int t) : type(t) {}
    virtual ~Event () {}

    const unsigned int type;
};

class Component {
private:
     static std::map &gt; eventMap;
protected:
     // Register for all events of type &quot;type&quot;.
     void registerForEvent (const unsigned type);
     // Send an event.
     void send (const Event* const event);

public:
     // Event handler, called when an event, which is being listened for, is received.
     virtual void eventReceived(const Event* const event)=0;
};

std::map&lt;unsigned int, std::vector&lt;Component*&gt; &gt; Component::eventMap;

void Component::registerForEvent (const unsigned int type) {
    eventMap[type].push_back(this);
}
void Component::send (const Event* const event) {
    std::vector&amp; components = eventMap[event-&gt;type];
    for (std::vector::iterator i = components.begin(); i != components.end(); i++) {
        (*i)-&gt;eventReceived(event);
    }
}

enum EventIdentifiers {
    QUIT_EVENT=0,
    PRINT_HELLO,
    PRINT_MESSAGE
};

class MessageEvent : public Event {
public:
    MessageEvent () : Event(PRINT_MESSAGE) {}
    virtual ~MessageEvent () {}

    std::string message;
};

class HelloPrinter : public Component {
public:
    HelloPrinter () {
        registerForEvent(QUIT_EVENT);
        registerForEvent(PRINT_HELLO);
        registerForEvent(PRINT_MESSAGE);
    }
    virtual ~HelloPrinter () {}

    void eventReceived(const Event* const event) {
        if (event-&gt;type == QUIT_EVENT) {
            std::exit(0);
        }
        else if (event-&gt;type == PRINT_HELLO) {
            std::cout &lt;&lt; &quot;Hello!\n&quot;;
        }
        else if (event-&gt;type == PRINT_MESSAGE) {
            std::cout &lt;&lt; &quot;Message: &quot; &lt;&lt; static_cast&lt;const MessageEvent*&gt;(event)-&gt;message &lt;&lt; &quot;\n&quot;;
        }
    }

    void sendQuit () {
        Event event(QUIT_EVENT);
        send(&amp;event);
    }
    void sendHello () {
        Event event(PRINT_HELLO);
        send(&amp;event);
    }
     void sendHelloMessage (const std::string&amp; message) {
        MessageEvent event;
        event.message = message;
        send(&amp;event);
    }
};

int main (int argc, char** argv) {
    HelloPrinter a, b, c;
    a.sendHello();
    b.sendHelloMessage(&quot;Hi from b&quot;);
    c.sendQuit();
}
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/229/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=229&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2010/02/17/flat-hierarchies-in-c-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>Language concept: mixing functional, imperative and dataflow</title>
		<link>http://didntread.wordpress.com/2010/02/16/language-concept-mixing-functional-imperative-and-dataflow/</link>
		<comments>http://didntread.wordpress.com/2010/02/16/language-concept-mixing-functional-imperative-and-dataflow/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 16:36:37 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Concurrent Programming]]></category>
		<category><![CDATA[Dataflow]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[concept programming ideas]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=216</guid>
		<description><![CDATA[See formatted code here. fun do-op a b op { match op with '+: a + b with '-: a - b with '*: a * b with '/: a / b with _: error } flow gen a b ops -&#62; res { (do-op a&#62;&#62; b&#62;&#62; ops&#62;&#62;) -&#62; &#62;&#62;res } do main { commit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=216&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>See formatted code <a href="http://gist.github.com/raw/305609/275668d9d2d89907052698374f70bb54218d7321/language%20concept">here</a>.</p>
<pre class="brush: cpp;">
fun do-op a b op {
    match op
    with '+: a + b
    with '-: a - b
    with '*: a * b
    with '/: a / b
    with  _: error
}

flow gen a b ops -&gt; res {
    (do-op a&gt;&gt; b&gt;&gt; ops&gt;&gt;) -&gt; &gt;&gt;res
}

do main {
    commit (reduce print
                   (gen [1 2 3]
                        [3 2 1]
                        ['+ '- '*]))
}
</pre>
<p>As I&#8217;ve stated before, I feel that a truely long lasting and useful langauge will have to merge imperative and dataflow programming styles, since both have their own set of advantages and disadvantages and locking programmers into one or the other only limits their expressive ability. This language concept is a largely incomplete idea I had for a textual programming language that does just that by providing a cohesive hybrid between imperative, pure functional and dataflow.</p>
<p>This language consists of three types of code blocks:</p>
<ol>
<li><strong>do</strong> &#8211; these are imperative blocks with standard imperative features: mutable data, I/O interface and manual synchronization. They can call other do blocks as well as flow and fun blocks.</li>
<li><strong>flow</strong> &#8211; these are dataflow blocks and feature dataflow semantics: streams, pipelined processing, automatic memory management and automatic parallelization. They cannot mutate external data and can call only other flow blocks and fun blocks.</li>
<li><strong>fun</strong> &#8211; these are pure functional blocks and they cannot produce side-effects, so may only operate on immutable data and data structures. They can only call other fun blocks.</li>
</ol>
<p>This enforced split between the different paradgms ensures that they do not get inappropraitely polluted by conflicting features. It is perfectly safe for pure functions to be called in a dataflow pipeline, for example, as they cannot affect any concurrently running code, but calling impure functions from within a fun block would taint that blocks purity, so this cannot be allowed.</p>
<p>It may make sense to allow calling do blocks from within flow blocks, but this could lead to synchronisation issues, race conditions and undefined behaviour, so disallowing this would solve a lot of issues. With these restrictions we can make assumptions which simplify compilation, runtime and optimisation as well as development.</p>
<p>Back to the code. Besides the three basic blocks, this code demonstrates a number of different features:</p>
<ul>
<li>support for symbols. The code references &#8216;+, &#8216;-, &#8216;* and &#8216;/. This demonstrates support for a symbolic data type.</li>
<li>pattern matching. The match &#8230; with &#8230; construct demonstrates a Haskell/ML-like pattern matching construct. To make full use of this, a proper parametric type system would be desirable.</li>
<li>streams. Dataflow blocks naturally work well with lists and streams of data and this demonstrates a possible means of taking values from and putting values onto streams, as well as directing flow of data.</li>
<li>functional building blocks &#8211; <em>reduce</em>, in this case.</li>
<li>pure functional I/O handling. In this case, <em>print</em> is passed to <em>reduce</em>, which, since fun blocks can only call other fun blocks (and calling reduce inside of fun blocks is soemthing I&#8217;d expect people to do often), <em>reduce</em> must also be a fun block. This means that any function or closure passed into <em>reduce</em> must also be a fun block &#8211; this means that <em>print</em> must be a fun block. Since <em>print</em> produces output (a side-effect), it cannot be a fun block &#8211; so instead it doesn&#8217;t actually produce side effects, but generates an immutable <em>thunk</em>. The <em>commit</em> function (which is a do block) basically commits the recorded state of the <em>thunk</em> &#8211; producing the side effects dictated by <em>print</em>.</li>
</ul>
<p>That last feature is my answer to Haskells I/O monads. By allowing restricted state (through do blocks) and providing a mechanism of recording state in immutable data structures, through thunks and other mechanisms, most code can be kept side-effect free and pure, meaning it can be safely used in parallel environments, auto-parallelised and also simplifies memory management and allows for more aggressive optimisation.</p>
<p>Since this is a very early concept, thats about as far as I got. I will post more as I think of it and will update the blog if I take any steps towards developing this concept. I would also be interested in hearing thoughts and opinions on this language concept.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=216&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2010/02/16/language-concept-mixing-functional-imperative-and-dataflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>Building a flat hierarchial component system in Clojure</title>
		<link>http://didntread.wordpress.com/2009/12/01/building-a-flat-hierarchial-component-system-in-clojure/</link>
		<comments>http://didntread.wordpress.com/2009/12/01/building-a-flat-hierarchial-component-system-in-clojure/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 12:05:23 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Concurrent Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[hierarchy]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=182</guid>
		<description><![CDATA[I&#8217;ve been playing around with Clojure a lot lately and, just for fun, I implemented a simple system for constructing a component based software architecture where each component runs completely independently and asynchronously. Components communicate by sending events to each other, achieving a flat software hierarchy. &#160; ; Define a function to send events (defn [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=182&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div>I&#8217;ve been playing around with Clojure a lot lately and, just for fun, I implemented a simple system for constructing a component based software architecture where each component runs completely independently and asynchronously. Components communicate by sending events to each other, achieving a flat software hierarchy.
<p>&nbsp;</p>
</div>
<pre class="brush: cpp;">
; Define a function to send events
(defn event [k v] nil)

; Define the data structure used to model a component
(defstruct component-s :name :handlers :state)

; Create a component by creating an instance of the data structure
(defn make-component [name handlers]

(struct component-s name handlers {}))

; Run a collection of components, start by sending an :init event to each component
(defn run-components [&amp; comps]
   (loop [components comps
          events     (atom [])
          key        :init
          value      nil]
      (if (= key nil)
         ; Component processing has completed - no new events have been generated
         'Done
         ; Components have not completed processing - events are still left to be processed
         (let [updated ; Updated list of components
            ; Bind the event function to a closure which can update the vector of events
            (binding [event (fn [k v] (swap! events concat (vector (list k v))))]
               ; Map the update function accross each component in parallel
               (doall (pmap #(conj % (if ((:handlers %) key)
                                                      {:state (conj (:state %)
                                                                    (((:handlers %) key) value (:state %)))}
                                                      {}))
                                    components)))]
            ; Recursively process components
            (recur updated                        ; Updated list of components
                   (atom (rest @events))          ; Remaining events
                   (ffirst @events)               ; Next event type
                   (second (first @events)))))))  ; Next event message
</pre>
<p>We can test this by creating and running some test components:</p>
<pre class="brush: cpp;">
(run-components
   (make-component &quot;Comp1&quot;
      {:init (fn [v s]
            (event :set-msg &quot;Ho&quot;)
            (event :print nil)
            {:msg &quot;Hi&quot;})
       :print (fn [v s]
          (println (:msg s)))
       :set-msg (fn [v s]
          {:msg v})})
   (make-component &quot;Comp2&quot;
      {:init (fn [v s]
         {:msg &quot;Hello&quot;})
       :print (fn [v s]
         (println (:msg s)))}))
</pre>
<p>Comp1 contains three event handlers &#8211; :init, :print and :set-msg. Comp2 only contains two event handlers &#8211; :init and :print.<br />
:init is called to setup the components state and trigger any initial events. :print will print the contents of the states :msg slot to the terminal and :set-msg will change the :msg slot to the value of the events message.</p>
<p>Running this sample will output the following:</p>
<pre class="brush: cpp;">
Ho
Hello
Done
</pre>
<p>It becomes more interesting if the components do a little more, for example:</p>
<pre class="brush: cpp;">
(run-components
   (make-component &quot;Comp1&quot;
      {:init (fn [v s]
            (event :print nil) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
            (event :set-msg &quot;Ho&quot;)
            (event :print nil)
            {:msg &quot;Hi&quot;})
       :print (fn [v s]
          (println (:msg s)))
       :set-msg (fn [v s]
          {:msg v})})
   (make-component &quot;Comp2&quot;
      {:init (fn [v s]
         {:msg &quot;Hello&quot;})
       :print (fn [v s]
         (println (:msg s)))}))
</pre>
<p>Running this will output:</p>
<pre class="brush: cpp;">
Hi
Hello
Ho
Hello
Done
</pre>
<p>Note how the first event gets processed before the second one &#8211; ie, Comp1&#8242;s :msg has not yet been modified.</p>
<p>Of course, you can set up all sorts of crazy chains of events with many event types, complex logic and so on.</p>
<p>What would be really nice is a <a href="http://en.wikipedia.org/wiki/Domain-specific_language" target="_blank">DSL</a> designed for writing these component-based programs, since calling run-components and make-components manually is a little messy. Something like the following would be nice:</p>
<pre class="brush: cpp;">
(program
    (component &quot;Comp1&quot;
        (on :init [v s]
               (event :print nil)
               (event :set-msg &quot;Ho&quot;)
               (event :print nil)
               {:msg &quot;Hi&quot;})

        (on :print [v s]
            (println (:msg s)))

        (on :set-msg [v s]
            {:msg v}))

    (component &quot;Comp2&quot;
        (on :init [v s]
            {:msg &quot;Hello&quot;})

        (on :print [v s]
            (println (:msg s))))))
</pre>
<p>Luckily, this is the kind of thing Lisp is good at and Clojure, being a Lisp dialect, has everything we need to make it happen:</p>
<pre class="brush: cpp;">
(defmacro program [&amp; components]
    `(run-components ~@components))

(defmacro component [name &amp; handlers]
    `(make-component ~name (conj {} ~@handlers)))

(defmacro on [handler args &amp; body]
    {handler `(fn ~args ~@body)})
</pre>
<p>These macros transform our convenient little DSL into a set of calls to run-components and make-components. Success! We can now write fun little component-based programs, arranged in a flat hierarchy, using an anonymous (sender never knows who receives the events; receiver never knows where the events come from) event-based messaging system.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=182&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2009/12/01/building-a-flat-hierarchial-component-system-in-clojure/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>Brainstorming the dataflow language &#8220;syntax&#8221; (Part 1)</title>
		<link>http://didntread.wordpress.com/2009/08/09/brainstorming-the-dataflow-language-syntax-part-1/</link>
		<comments>http://didntread.wordpress.com/2009/08/09/brainstorming-the-dataflow-language-syntax-part-1/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 23:20:39 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Dataflow]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[programming language]]></category>
		<category><![CDATA[syntax]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=148</guid>
		<description><![CDATA[I&#8217;ve spent quite a lot of time, during the past few weeks, working on the representation of my dataflow language. In this post I will attempt to outline my current thoughts and hopefully generate some feedback on what I got right and wrong, what I could improve, how the language could be made more intuitive, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=148&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent quite a lot of time, during the past few weeks, working on the representation of my dataflow language. In this post I will attempt to outline my current thoughts and hopefully generate some feedback on what I got right and wrong, what I could improve, how the language could be made more intuitive, easier (and faster) to develop in and less bug-prone.</p>
<p>For this post, I will define some basic temrinology. This will help me in explaining my ideas in a consistent way, but may not match up with existing terminology. If there is such a mismatch, please feel free to let me know and I&#8217;ll update the post. Later, I will probably make a list of terminology specific to my language, using existing temrinology where possible, as a reference to help people who are viewing my language for the first time. For now, however, I&#8217;ll simply use these:</p>
<ul>
<li><strong>operation</strong> &#8211; a fundamental instruction or external block of code, which acts as a single node in the dataflow network</li>
<li><strong>component</strong> &#8211; either an operation or a collection of operations, or a collection of collections of.. That is, a componecan refer to a single operation, or collection of components (which themselves refer to either a single operation or a collection of components).</li>
<li><strong>expression</strong> &#8211; a deterministic calculation whos output is a function of its inputs, calculated using the substitution model of computation. Expressions consist of a limited set of predefined (usually mathematical or logical) operators.</li>
<li><strong>pre-condition</strong> &#8211; a logical expression which evaluates to either True or False and must be evaluated as True for a component to be considered executable. May optionally triggeran an arror state if this expression evaluates to False.</li>
<li><strong>post-condition</strong> &#8211; a logical expression which evaluates to either True or False and must be evaluated as True for a component to propogate its output to connected nodes. May optionally trigger an arror state if this expression evaluates to False.</li>
</ul>
<p>For now, I have defined a set of data types for use in the language, though what the final set of supported data types will be is, so far, undeicded as I need to do more real-world tests to see what is useful and what is not. The data types I have currently defined are:</p>
<ul>
<li><strong>integer</strong> &#8211; a signed whole number whos range is defined by the host systems native sized integers (ie 32bit on a 32bit machine).</li>
<li><strong>real</strong> &#8211; a signed floating point number, whos range is defined by the host systems native floating point support.</li>
<li><strong>byte</strong> &#8211; an unsigned 8bit value used to store binary data.</li>
<li><strong>character</strong> &#8211; a single unicode character.</li>
<li><strong>pair</strong> &#8211; a container of two values, where each value may be of a different data type.</li>
<li><strong>array</strong> &#8211; a container of a fixed number of values, where each value is of the same data type.</li>
<li><strong>record</strong> &#8211; a container of a predetermined set of named fields, where each field may be of a different data type.</li>
</ul>
<p>Additional, theres a special data type: the sequence. A sequence is a stream of values of the same data type and is the connection between components &#8211; that is, I am naming the flow of data between nodes a sequence.</p>
<p>I am also contemplating whether a variant data type should also be provided as this could be useful, together with a <a href="http://en.wikipedia.org/wiki/Guard_(computing)">guard</a> or <a href="http://en.wikipedia.org/wiki/Pattern_matching">pattern matching</a> mechanism, for receiving data from external sources.</p>
<p>To demonstrate the language syntax, I will construct a network to perform the following sample pseudocode:</p>
<pre class="brush: cpp;">
input a, b and c
value d = (a * b) - 1
if d &gt; 10 then
    value e = c - 1
</pre>
<p>This simple piece of code would be represented in my dataflow language as:</p>
<p><a href="http://didntread.files.wordpress.com/2009/08/syntax-11.png"><img class="alignleft size-medium wp-image-163" title="Sample Code" src="http://didntread.files.wordpress.com/2009/08/syntax-11.png?w=300&#038;h=57" alt="Sample Code" width="300" height="57" /></a></p>
<p>This simple dataflow network shows two &#8220;merge&#8221; components connected together. Before explaining how this network works, I will briefly introduce the merge components.</p>
<p>A basic merge component takes one of the following two forms:</p>
<p><a href="http://didntread.files.wordpress.com/2009/08/syntax-2.png"><img class="alignleft size-medium wp-image-162" title="Merge Component" src="http://didntread.files.wordpress.com/2009/08/syntax-2.png?w=300&#038;h=156" alt="Merge Component" width="300" height="156" /></a></p>
<p>A merge component has two or three inputs and a single output. It also has an accosiated expression. The output is the result of applying the expression to the inputs.</p>
<p>There also exist additional variants of most operations &#8211; those with optional pre- and/or post-conditions attached. Pre-conditions are marked as a green block on the left and post-conditions are marked as a red block on the right. In the sample code, presented above, the second merge node has a pre-condition assigned to it.</p>
<p>In the code editor, it would be possible to <em>collapse</em>, and therefore view, the pre-conditions, expressions and post-conditions. The diagram used the <em>hidden</em> view to demonstrate that a more compact view of code, which does not display all available information, would be available in an editor. The collapsed view would look as follows:</p>
<p><a href="http://didntread.files.wordpress.com/2009/08/syntax-31.png"><img class="alignleft size-medium wp-image-168" title="Sample code (full)" src="http://didntread.files.wordpress.com/2009/08/syntax-31.png?w=300&#038;h=73" alt="Sample code (full)" width="300" height="73" /></a></p>
<p>Note the use of coloured markers where the inputs are used. This is done because forcing inputs to be named, when it may not make sense to name them, programmers, being as lazy as we are, tend to give them meaningless names. This only adds to the noise and makes the program more dificult to read and understand. Using coloured markers makes it immediately obvious which inputs are used where without polluting the code with meaningless identifiers. It should, however, be possible to optionally label the markers, if it makes sense to do so. Perhaps the labels are displayed as a tooltip when hovering the mouse over the marker. It may also be useful to highlight each occurance of an input within the component when hovering the mouse over it.</p>
<p>This code shows that, in the first merge component, the expression <em>(a * b) &#8211; 1</em> is computed. The result of this expression is passed to the next node, which contains the pre-condition that its first input (d in the pseudocode) must be greater than 10. If it is not, then that input (and the input to d) are discarded and no furether action is taken. If the pre-condition passes, however, then the expression is evaluated, subtracting 2 from input c.</p>
<p>The example below is a bit more complex and introduces variants of the &#8220;merge&#8221; component (multiple expressions, single input, etc) and a new node: the &#8220;route&#8221; component. The route component evaluates a condition and then routes the inputs to one of two possible sets of outputs. Route components may have a pre-condition, but cannot have any post-conditions, as the inputs are never modified by this node &#8211; the same effect may be achieved through pre-conditions.</p>
<p>This example deserves a more in-depth explanation than I hae time for, so I will edit this post over the next week or so to add in additional detail and explain my ideas better.</p>
<div id="attachment_174" class="wp-caption alignleft" style="width: 310px"><a href="http://didntread.files.wordpress.com/2009/08/fibonacci.png"><img class="size-medium wp-image-174" title="fibonacci" src="http://didntread.files.wordpress.com/2009/08/fibonacci.png?w=300&#038;h=137" alt="Fibonacci Sequence sample code" width="300" height="137" /></a><p class="wp-caption-text">Fibonacci Sequence sample code</p></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/148/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/148/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/148/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=148&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2009/08/09/brainstorming-the-dataflow-language-syntax-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>

		<media:content url="http://didntread.files.wordpress.com/2009/08/syntax-11.png?w=300" medium="image">
			<media:title type="html">Sample Code</media:title>
		</media:content>

		<media:content url="http://didntread.files.wordpress.com/2009/08/syntax-2.png?w=300" medium="image">
			<media:title type="html">Merge Component</media:title>
		</media:content>

		<media:content url="http://didntread.files.wordpress.com/2009/08/syntax-31.png?w=300" medium="image">
			<media:title type="html">Sample code (full)</media:title>
		</media:content>

		<media:content url="http://didntread.files.wordpress.com/2009/08/fibonacci.png?w=300" medium="image">
			<media:title type="html">fibonacci</media:title>
		</media:content>
	</item>
		<item>
		<title>The dataflow virtual machine, first look</title>
		<link>http://didntread.wordpress.com/2009/08/09/the-dataflow-virtual-machine-first-look/</link>
		<comments>http://didntread.wordpress.com/2009/08/09/the-dataflow-virtual-machine-first-look/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 21:47:22 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Dataflow]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[implementation]]></category>
		<category><![CDATA[virtual machine]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=140</guid>
		<description><![CDATA[Since my last post, I&#8217;ve been mainly working on two things regarding this blog: a simple dataflow virtual machine and the graphical &#8220;syntax&#8221; or representation for a dataflow language. I&#8217;ll briefly write about the virtual machine in this post and then talk about the language &#8220;syntax&#8221; in the next. The virtual machine is a very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=140&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since my last post, I&#8217;ve been mainly working on two things regarding this blog: a simple dataflow virtual machine and the graphical &#8220;syntax&#8221; or representation for a dataflow language.</p>
<p>I&#8217;ll briefly write about the virtual machine in this post and then talk about the language &#8220;syntax&#8221; in the next.</p>
<p>The virtual machine is a very simple system of connected operations/nodes with zero or more inputs and outputs. An output can be connected to an input and then data is sent to the output by the node; this data is forwarded along to the connected inputs. Inputs and outputs are statically typed and, during network construction, the types are checked for compatibility ensuring that type mismatches do not occur at runtime. A node is processed when all of its inputs are met and processing is decoupled from the rest of the logic in such a way that it can be performed in a dedicated thread or even pool of threads. Currently no threads are used, so everything occurs sequentially, although later this will be changed.</p>
<p>Nodes can be set up to receive a constant stream of inputs, without actually running the code to do this. For example, if a nodes input is attached to a constant data source, like a static number, this would not actually have to keep generating the values, instead it is implied that it happens and the input simply retains the value after using it, instead of clearing it.</p>
<p>Though it has yet to be implemented, I&#8217;m thinking a copy-on-write system should be used for data, so that if data is duplicated and sent to multiple nodes, a single copy is shared until a node tries to modify its value, at which point a new copy of the data is created. This makes duplicating/copying data cheaper.</p>
<p>I have also been thinking about dynamic runtime switching between a synchronous and asynchronous operation evaluation systems, where the executing program can choose to switch between these. In the synchronous model, concurrency is synchronised into cycles and any new operations which become executable during a cycle must wait until the next cycle to be run. In an asynchronous model, the new operations are queued and everything essentally runs in a single (although large) cycle. The asynchronous mode potentially tields better utilisation of processing resources, while the synchronous model may be useful to provide runtime guarantees for realtime systems. I&#8217;ve also been thinking about how a profiler could generate utilisation graphs for both &#8211; hopefully further aiding in coming up with runtime guarantees. I definitely need to work on this more, however.</p>
<p>As an aside, I found this great <a href="http://dancinghacker.com/code/dataflow/index.html">C++ library for dataflow</a>, which I might be able to use for my own implementation! I&#8217;ll see. For now, I&#8217;ll continue with my own, since its almost done and allows me to do things how I want. Could speed up work, though, by using existing code.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/140/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/140/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/140/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=140&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2009/08/09/the-dataflow-virtual-machine-first-look/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>
	</item>
		<item>
		<title>Some thoughts on flat hierarchies in C++</title>
		<link>http://didntread.wordpress.com/2009/07/23/some-thoughts-on-flat-hierarchies-in-c/</link>
		<comments>http://didntread.wordpress.com/2009/07/23/some-thoughts-on-flat-hierarchies-in-c/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 16:27:48 +0000</pubDate>
		<dc:creator>dublindan</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[flat]]></category>
		<category><![CDATA[hierarchy]]></category>
		<category><![CDATA[ideas]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://didntread.wordpress.com/?p=113</guid>
		<description><![CDATA[The top search terms for this blog seem to be &#8220;flat hierarchy C++&#8221;, so this is something I should address. I had originally intended on writing a crude implementation in Python, to demonstrate the consept, leaving an actual efficient implementation as an exercise for the reader (possibly implementing it myself for a future post), but [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=113&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The top search terms for this blog seem to be &#8220;<em>flat hierarchy C++&#8221;</em>, so this is something I should address.</p>
<p>I had originally intended on writing a crude implementation in Python, to demonstrate the consept, leaving an actual efficient implementation as an exercise for the reader (possibly implementing it myself for a future post), but perhaps it would be more useful to think about it sooner. In this post, I will write a few short sentences to outline my thoughts on implementing a flat hierarchy in C++, which will hopefully provide readers with some ideas to implement this themselves.</p>
<p>There are two ways of implementing flat hierarchies which I am currently interested in exploring, though I&#8217;m sure theres more. I will briefly explain these here:</p>
<ol>
<li>Independent components which communicate over an anonymous shared-nothing messaging system. This works because the messaging is transparent &#8211; a component never knows which other components will receive its messages, if any. A receiving component likewise never knows which components sent the messages which it is receviing. This anonymous message sending means that components may be added or removed at will and other components will never know. Obviously it may not logically make sense to do this &#8211; if a component relies on certain messages to work and you remove the component which generates the messages, then obviously the first component cannot fnction &#8211; but it will not fail either, it will wait around until you add a component which does generate those messages back into the system. Each component is a node in a flat hierarchy.</li>
<li>An entity system. In this context, an entity system is an alternative to object oriented systems where an <em>object</em> is simply a collection of traits and is a technique borrowed from the game development community. How this object behaves is determined by the traits it has associated with it. Traits may be added or removed at runtime. Each object is independent and can only communicate through its traits. Since traits can be added and removed dynamically, the system maintains a flat hierarchy. Objects can be processed independently and concurrently. The building of entity systems is the subject of my &#8220;<a href="http://didntread.wordpress.com/2009/07/14/building-a-stackless-hierarchy/">Building a Flat Hierarchy</a>&#8221; series of posts, so be sure to check those out, if interested.</li>
</ol>
<p>Since entity systems are reasonably complex and are being covered in their own series of blog posts, I will not talk about them here. Instead I will briefly talk about the independent component method of building a flat software hierarchy.</p>
<div id="attachment_115" class="wp-caption alignnone" style="width: 264px"><a href="http://didntread.files.wordpress.com/2009/07/components.png"><img class="size-medium wp-image-115" title="Component System" src="http://didntread.files.wordpress.com/2009/07/components.png?w=254&#038;h=300" alt="Depicts how components communicate with each other" width="254" height="300" /></a><p class="wp-caption-text">Depicts how components communicate with each other</p></div>
<p>Ok, so hopefully at this stage you have a reasonably good idea of why this system works. If theres still confusion, please leave a comment and I&#8217;ll try and clear things up. Time to move on to implementation details.</p>
<p>I&#8217;m not going to implement the entire thing and just give out the code for people to use because that would take more time than I have to write this post. Also, different projects have different requirements and a system I build now may not be ideal for whatever you have in mind. Best to leave it up to you to fine tune the details to your needs. The version presented here whould give you ideas, but it won&#8217;t be terribly good or efficient.</p>
<p>Lets start with a component:</p>
<pre class="brush: cpp;">
class Component {
private:
     static std::map&lt;unsigned int, std::vector&lt;Component*&gt; &gt; eventMap;
protected:
     // Register for all events of type &quot;type&quot;.
     void registerForEvent (const unsigned type);
     // Send an event.
     void send (const Event* const event);

public:
     // Event handler, called when an event, which is being listened for, is received.
     virtual void eventReceived(const Event* const event)=0;
};
</pre>
<p>And the implementation:</p>
<pre class="brush: cpp;">
std::map&lt;unsigned int, std::vector&lt;Component*&gt; &gt; Component::eventMap;

void Component::registerForEvent (const unsigned int type) {
    eventMap[type].push_back(this);
}
void Component::send (const Event* const event) {
    std::vector&lt;Component*&gt;&amp; components = eventMap[event-&gt;type];
    for (std::vector&lt;Component*&gt;::iterator i = components.begin(); i != components.end(); i++) {
        (*i)-&gt;eventReceived(event);
    }
}
</pre>
<p>All events are derived from the Event base type:</p>
<pre class="brush: cpp;">
class Event {
public:
    Event (unsigned int t) : type(t) {}
    virtual ~Event () {}

    const unsigned int type;
};
</pre>
<p>Lets test this with some stupid events:</p>
<pre class="brush: cpp;">
enum EventIdentifiers {
    QUIT_EVENT=0,
    PRINT_HELLO,
    PRINT_MESSAGE
};

class MessageEvent : public Event {
public:
    MessageEvent () : Event(PRINT_MESSAGE) {}
    virtual ~MessageEvent () {}

    std::string message;
};
</pre>
<p>Now I&#8217;ll implement some very simple and crude components, just to have something that can be run:</p>
<pre class="brush: cpp;">
class HelloPrinter : public Component {
public:
    HelloPrinter () {
        registerForEvent(QUIT_EVENT);
        registerForEvent(PRINT_HELLO);
        registerForEvent(PRINT_MESSAGE);
    }
    virtual ~HelloPrinter () {}

    void eventReceived(const Event* const event) {
        if (event-&gt;type == QUIT_EVENT) {
            std::exit(0);
        }
        else if (event-&gt;type == PRINT_HELLO) {
            std::cout &lt;&lt; &quot;Hello!\n&quot;;
        }
        else if (event-&gt;type == PRINT_MESSAGE) {
            std::cout &lt;&lt; &quot;Message: &quot; &lt;&lt; static_cast&lt;const MessageEvent*&gt;(event)-&gt;message &lt;&lt; &quot;\n&quot;;
        }
    }

    void sendQuit () {
        Event event(QUIT_EVENT);
        send(&amp;event);
    }
    void sendHello () {
        Event event(PRINT_HELLO);
        send(&amp;event);
    }
     void sendHelloMessage (const std::string&amp;amp; message) {
        MessageEvent event;
        event.message = message;
        send(&amp;event);
    }
};
</pre>
<p>Ok, almost done. Lets tie it all together:</p>
<pre class="brush: cpp;">
int main (int argc, char** argv) {
    HelloPrinter a, b, c;
    a.sendHello();
    b.sendHelloMessage(&quot;Hi from b&quot;);
    c.sendQuit();
}
</pre>
<p>This should print &#8220;Hello&#8221; three times followed by &#8220;Hi from b&#8221; three times and then it should quit.</p>
<p>Ok, I&#8217;ll be the first to admit that this implementation is extremely limited and suffers from a bunch of flaws &#8211; BUT hopefully you can see the ideas and use that to implement a much more powerful version. Before I leave you to experiment, let me briefly mention some improvements which could be made to the above code. I&#8217;m sure you can think of many more too:</p>
<ul>
<li>Should the sending component receive its own events? Perhaps the sender should be able to choose.</li>
<li>Should events be processed right away? This is useful for simple programs, but for large systems, you may end up in situations where some components never get to process events because other events are always processed first. A good solution would be to queue up all events, instead of sending them right away and then dispatch them when all event handlers have returned.</li>
<li>Should events be processed sequentially? It may be better to process them in threads. One good solution would be to have a pool of threads which will execute the event handlers. Since communication is done through immutable events, the handlers can all run at once.</li>
<li>The events themselves can be constructed from a memory pool to make creating and destroying events (event large events) a fast and cheap operation.</li>
</ul>
<p>At some point in the future, I will implement (because I will need an implementation soon) and explain an implementation which has all of those features and probably some others too. I cannot commit to a date though, could be tomorrow or it could be next year.. who knows.</p>
<p>I hope that seeing the idea in code has helped you understand what it is I&#8217;m talking about and hopefully this will spark your imagination and creativity and perhaps motivate you to implement your own, more advanced, efficient and powerful versions. I&#8217;d love to hear what people come up with, so if you do implement this yourself, I&#8217;d appreciate a quick comment!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/didntread.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/didntread.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/didntread.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/didntread.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/didntread.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/didntread.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/didntread.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/didntread.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/didntread.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/didntread.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/didntread.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/didntread.wordpress.com/113/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/didntread.wordpress.com/113/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/didntread.wordpress.com/113/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=didntread.wordpress.com&amp;blog=8198040&amp;post=113&amp;subd=didntread&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://didntread.wordpress.com/2009/07/23/some-thoughts-on-flat-hierarchies-in-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/097e0e435050244e030c01837d4ec6c3?s=96&#38;d=wavatar&#38;r=PG" medium="image">
			<media:title type="html">dublindan</media:title>
		</media:content>

		<media:content url="http://didntread.files.wordpress.com/2009/07/components.png?w=254" medium="image">
			<media:title type="html">Component System</media:title>
		</media:content>
	</item>
	</channel>
</rss>
