<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">

	<title>Planet D</title>
	
	<link href="http://planet.dsource.org/" />
	<id>http://planet.dsource.org/_atom.xml</id>
	<updated>2009-11-10T17:01:04+00:00</updated>
	<generator uri="http://www.planetplanet.org/">Planet/2.0 +http://www.planetplanet.org</generator>

	<link rel="self" href="http://feeds.feedburner.com/dplanet" type="application/atom+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry xml:lang="en">
		<title type="html">Package</title>
		<link href="http://goshawknest.wordpress.com/2009/11/08/new-ldc-d-compiler-tango-packages-for-ubuntu-karmic/" />
		<id>http://goshawknest.wordpress.com/?p=86</id>
		<updated>2009-11-08T12:38:37+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;&lt;img class="aligncenter" title="Package" src="http://www.mattjones.workhorsy.org/wp-content/uploads/2008/12/debian_ubuntu_package.png" alt="" width="196" height="216" /&gt;&lt;/p&gt;
&lt;p&gt;Yesterday Arthur Loiret announced on the #d.tango channel on Freenode.net that he did some work in packaging ldc and tango. I&amp;#8217;ve been working on it for a while, but when i started developing gdc i didn&amp;#8217;t maintain that work anymore.&lt;/p&gt;
&lt;p&gt;Since Arthur gave me all the needed files to reproduce the packages, i&amp;#8217;ve updated the PPA for ldc + tango set. New packages are of revision 1586 of ldc and 5027 of tango.&lt;/p&gt;
&lt;p&gt;Detailed instructions in how to install those packages can be found at the &lt;a href="http://www.dsource.org/projects/ldc/wiki/BuildInstructionsUbuntu"&gt;Ldc Ubuntu packages&lt;/a&gt; page. Let me know if you have troubles with those packages!&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/goshawknest.wordpress.com/86/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/goshawknest.wordpress.com/86/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/goshawknest.wordpress.com/86/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/goshawknest.wordpress.com/86/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/goshawknest.wordpress.com/86/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/goshawknest.wordpress.com/86/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/goshawknest.wordpress.com/86/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/goshawknest.wordpress.com/86/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/goshawknest.wordpress.com/86/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/goshawknest.wordpress.com/86/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=goshawknest.wordpress.com&amp;blog=6236053&amp;post=86&amp;subd=goshawknest&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Vincenzo Ampolo</name>
			<uri>http://goshawknest.wordpress.com</uri>
		</author>
		<source>
			<title type="html">goshawk's digital nest » D</title>
			<subtitle type="html">researches, hacks, thoughts</subtitle>
			<link rel="self" href="http://goshawknest.wordpress.com/category/d/feed/" />
			<id>http://goshawknest.wordpress.com/category/d/feed/</id>
			<updated>2009-11-08T17:00:45+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">DMD frontend 1.051 merged in LDC</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/X7Nxpz22A2M/1a61305a" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/1a61305a</id>
		<updated>2009-11-07T15:08:33+00:00</updated>
		<content type="html">&lt;p&gt;After 5 or 6 &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; versions with important regressions, &lt;a href="http://www.dsource.org/projects/ldc" class="reference external"&gt;LDC&lt;/a&gt; has just been
&lt;a href="http://www.dsource.org/projects/ldc/changeset/1587%3Adef7a1d494fd" class="reference external"&gt;update&lt;/a&gt;d to &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt;'s frontend &lt;a href="http://www.digitalmars.com/d/1.0/changelog.html#new1_051" class="reference external"&gt;1.051&lt;/a&gt;. This brings a lot of bug fixes to the
&lt;a href="http://www.dsource.org/projects/ldc" class="reference external"&gt;LDC&lt;/a&gt; world (&lt;a href="http://www.dsource.org/projects/dstress" class="reference external"&gt;DStress&lt;/a&gt; &lt;a href="http://ldc.octarineparrot.com/x86-32/web/" class="reference external"&gt;results&lt;/a&gt; are looking good! ;).&lt;/p&gt;
&lt;p&gt;Lots of thanks to &lt;a href="http://www.dsource.org/projects/ldc" class="reference external"&gt;LDC&lt;/a&gt; guy for merging the new frontend =)&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/X7Nxpz22A2M" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Patch to make D's GC partially precise</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/qzdRZnM6ypQ/-58b18c1e" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-58b18c1e</id>
		<updated>2009-11-06T20:09:27+00:00</updated>
		<content type="html">&lt;p&gt;David Simcha has &lt;a href="http://www.digitalmars.com/d/archives/digitalmars/D/GC_Precision_99479.html" class="reference external"&gt;announced&lt;/a&gt; a couple of weeks ago that he wanted to work on
making the &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt;'s &lt;a href="http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29" class="reference external"&gt;GC&lt;/a&gt; partially precise (only the heap). I was planning to do
it myself eventually because it looked like something doable with not much work
that could yield a big performance gain, and particularly useful to avoid
memory leaks due to false pointers (which can keep huge blocks of data
artificially alive). But I didn't had the time and I had other priorities.&lt;/p&gt;
&lt;p&gt;Anyway, after some &lt;a href="http://www.digitalmars.com/d/archives/digitalmars/D/More_PC_Precision_Stuff_99665.html" class="reference external"&gt;discussion&lt;/a&gt;, he finally &lt;a href="http://www.digitalmars.com/d/archives/digitalmars/D/Success_Precisely_99757.html" class="reference external"&gt;announced&lt;/a&gt; he got the &lt;a href="http://d.puremagic.com/issues/attachment.cgi?id=489&amp;action=diff" class="reference external"&gt;patch&lt;/a&gt;,
which he added as a &lt;a href="http://d.puremagic.com/issues/show_bug.cgi?id=3463" class="reference external"&gt;bug report&lt;/a&gt;. The patch is being analyzed for inclusion,
but the main problem now is that it is not integrated with the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;new&lt;/span&gt;&lt;/tt&gt;
operator, so if you want to get precise heap scanning, you have to use
a &lt;a href="http://d.puremagic.com/issues/attachment.cgi?id=488" class="reference external"&gt;custom function&lt;/a&gt; to allocate (that creates a map of the type to allocate
at compile-time to pass the information about the location of the pointers to
the GC).&lt;/p&gt;
&lt;p&gt;I'm glad David could work on this and I hope this can be included in D2, since
is a long awaited feature of the GC.&lt;/p&gt;
&lt;div class="admonition-update admonition"&gt;
&lt;p class="first admonition-title"&gt;Update&lt;/p&gt;
&lt;p class="last"&gt;David Schima has been &lt;a href="http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&amp;article_id=100296" class="reference external"&gt;just added&lt;/a&gt; to the list of &lt;a href="http://www.dsource.org/projects/phobos" class="reference external"&gt;Phobos&lt;/a&gt; developers.
Maybe he can integrate his &lt;a href="http://www.dsource.org/projects/aa" class="reference external"&gt;work on associative arrays&lt;/a&gt; too.&lt;/p&gt;
&lt;/div&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/qzdRZnM6ypQ" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">DMD 1.051 and 2.036</title>
		<link href="http://dblog.aldacron.net/2009/11/06/dmd-1-051-and-2-036/" />
		<id>http://dblog.aldacron.net/?p=689</id>
		<updated>2009-11-06T17:41:33+00:00</updated>
		<content type="html">Walter has pushed new versions of DMD out the door. 1.051 is a bugfix release, while 2.036 gets bugfixes and a ton of new features. Methinks the biggest news in these releases is the OPTLINK fix Walter previously announced.
In other news, Tomasz Stachowiak has opened a new wig business. Perhaps a postmortem on how he [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=qbsl3hTD8jQ:rcpUFgWknv8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=qbsl3hTD8jQ:rcpUFgWknv8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=qbsl3hTD8jQ:rcpUFgWknv8:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=qbsl3hTD8jQ:rcpUFgWknv8:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">OPTLINK and ArcLib and AAs, Oh My!</title>
		<link href="http://dblog.aldacron.net/2009/11/05/optlink-and-arclib-and-aas-oh-my/" />
		<id>http://dblog.aldacron.net/?p=687</id>
		<updated>2009-11-05T13:45:07+00:00</updated>
		<content type="html">Three news recent news items that will be of interest to some of you in D Land&amp;#8230;
Walter has let it be known that a long time, and much cursed, bug with OPTLINK has been found and squashed. Specifically, bugzilla #424, which keeps popping up in &amp;#8220;why I&amp;#8217;m fed up with D&amp;#8221; rants. Expect a patched [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=DVR_rW_F76I:ba566TRPgVU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=DVR_rW_F76I:ba566TRPgVU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=DVR_rW_F76I:ba566TRPgVU:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=DVR_rW_F76I:ba566TRPgVU:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">ArcLib v.03 GUI-Physics-Refactor release</title>
		<link href="http://arclib.blogspot.com/2009/11/arclib-v03-gui-physics-refactor-release.html" />
		<id>tag:blogger.com,1999:blog-3190794070849828802.post-7995953099167148456</id>
		<updated>2009-11-03T12:18:57+00:00</updated>
		<content type="html">Dear D community,&lt;br /&gt;&lt;br /&gt;I would like to announce the latest release of ArcLib, Arc v.03 GUI-Physics-Refactor release. See &lt;a href="http://www.dsource.org/projects/arclib/report/6"&gt;http://www.dsource.org/projects/arclib/report/6&lt;/a&gt; for full list of work done on this release.&lt;br /&gt;The greatest changes were made to the structure of the project. Also includes the joystick support, camera, per pixel collision detection, sprite, and 2d lighting system.&lt;br /&gt;&lt;br /&gt;See &lt;a href="http://dmedia.dprogramming.com/?n=Tutorials.ArcIntro"&gt;http://dmedia.dprogramming.com/?n=Tutorials.ArcIntro&lt;/a&gt; for getting started with D and ArcLib.&lt;br /&gt;The real purpose of this release is that I finally got everything working and cleaned up in the trunk. I had ported the hybrid GUI, but don’t have time to support it because of the massive amount of code and my lack of familiarity with the system. I will also drop scenegraph unless others want me to keep it.&lt;br /&gt;&lt;br /&gt;I will now create the stable branch.&lt;br /&gt;- Clay&lt;div class="blogger-post-footer"&gt;&lt;img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/3190794070849828802-7995953099167148456?l=arclib.blogspot.com" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Clay Smith</name>
			<email>noreply@blogger.com</email>
			<uri>http://arclib.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">ArcLib Development Blog</title>
			<link rel="self" href="http://arclib.blogspot.com/feeds/posts/default" />
			<id>tag:blogger.com,1999:blog-3190794070849828802</id>
			<updated>2009-11-04T05:00:20+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Introducing the arc.game Game class</title>
		<link href="http://arclib.blogspot.com/2009/11/introducing-arcgame-game-class.html" />
		<id>tag:blogger.com,1999:blog-3190794070849828802.post-1553246177441218105</id>
		<updated>2009-11-03T08:48:54+00:00</updated>
		<content type="html">&lt;p&gt;Here is the first incarnation of the Game class. The idea behind the class is that the user will overload the this() class for init, process() for game loop, and shutdown() for shutdown code, and the Game class will handle the mundane details, such as input processing and window swapping. After creating their own class to extend the Game class and overloading the correct functions, the main loop simplifies to&lt;/p&gt;&lt;p&gt;// main entry&lt;br /&gt;int main()&lt;br /&gt;{&lt;br /&gt;      // initialize game&lt;br /&gt;      Game g = new MyGame("Arc&lt;br /&gt;      Graphics Primitives", Size.d640x480, false);&lt;br /&gt;     &lt;br /&gt;      // loop game&lt;br /&gt;      g.loop();&lt;br /&gt;&lt;br /&gt;      // shutdown() is called by loop() after loop exits&lt;br /&gt;      return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Here is an example I’ve modified to make use of the game class: &lt;a href="http://svn.dsource.org/projects/arclib/trunk/examples/arc/draw.d"&gt;http://svn.dsource.org/projects/arclib/trunk/examples/arc/draw.d&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Of course, use of this class is optional. It may gain more features in the future, such as setting up game states and integration with the GUI. For now, its very simple. &lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/3190794070849828802-1553246177441218105?l=arclib.blogspot.com" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Clay Smith</name>
			<email>noreply@blogger.com</email>
			<uri>http://arclib.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">ArcLib Development Blog</title>
			<link rel="self" href="http://arclib.blogspot.com/feeds/posts/default" />
			<id>tag:blogger.com,1999:blog-3190794070849828802</id>
			<updated>2009-11-04T05:00:20+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Back from the Round-a-bout</title>
		<link href="http://arclib.blogspot.com/2009/11/back-from-round-bout.html" />
		<id>tag:blogger.com,1999:blog-3190794070849828802.post-6009745083785734241</id>
		<updated>2009-11-02T12:51:36+00:00</updated>
		<content type="html">I’m back from the round-about (South America -&gt; Minnesota -&gt; New Hampshire -&gt; Finding Job)&lt;br /&gt;&lt;br /&gt;I’ve been out for a while, but I’ve decided to clean up my project a little. I left it hanging with a broken subversion for too long.&lt;br /&gt;&lt;br /&gt;Anyways, I want to get ArcLib fully integrated with eclipse, so I’ve installed the descent plug-in and have an eclipse project file. I plan to use xfbuild when I can get it to work, but right now its complaining about not having the –deps flag, and I can’t get the current hg clone to build. So I’m using reliable old dsss until I figure out how to replace it with xfbuild, and then I’ll figure out how to run xfbuild straight from eclipse.&lt;br /&gt;&lt;br /&gt;I find eclipse to be an excellent editor if you have the memory to run it. It has useful features like global project search and replace with the option to use regex, and other neat features.&lt;br /&gt;&lt;br /&gt;The news is this: The current trunk now compiles, yay! I haven’t checked to see if it works, but it should for the most part. Also, I’m not going to support hybrid and the scenegraph anymore, for the sheer amount of code they have, and my lack of familiarity with these systems. If I need, I may write a scenegraph or similar features from scratch in the future. Also, arclib should be able to be compilable with xfbuild, once I get that to work.&lt;br /&gt;&lt;br /&gt;Speaking of Round-a-bouts, a nearby town decided to install two of them on the roads, with one on the highway. Both round-about's are design fails.&lt;div class="blogger-post-footer"&gt;&lt;img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/3190794070849828802-6009745083785734241?l=arclib.blogspot.com" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Clay Smith</name>
			<email>noreply@blogger.com</email>
			<uri>http://arclib.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">ArcLib Development Blog</title>
			<link rel="self" href="http://arclib.blogspot.com/feeds/posts/default" />
			<id>tag:blogger.com,1999:blog-3190794070849828802</id>
			<updated>2009-11-04T05:00:20+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">TDPL Excerpt</title>
		<link href="http://dblog.aldacron.net/2009/10/29/tdpl-excerpt/" />
		<id>http://dblog.aldacron.net/?p=685</id>
		<updated>2009-10-29T13:51:12+00:00</updated>
		<content type="html">Andrei has posted an excerpt from his forthcoming book, The D Programming Language. In his words:
It&amp;#8217;s a rough rough draft, but one for the full chapter on arrays, associative arrays, and strings.
http://erdani.com/d/thermopylae.pdf
Any feedback is welcome. Thanks!
If you want to give feedback, a good place to do so would be in the NG thread where the [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=WVzSWdRsYjg:GrA9HEfgPCo:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=WVzSWdRsYjg:GrA9HEfgPCo:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=WVzSWdRsYjg:GrA9HEfgPCo:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=WVzSWdRsYjg:GrA9HEfgPCo:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">The D Programming Language</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/FFHf3mjhhvA/6921c809" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/6921c809</id>
		<updated>2009-10-29T12:37:40+00:00</updated>
		<content type="html">&lt;img src="http://www.llucax.com.ar/blog/posts/2009/10/29-the-d-programming-language.jpg" align="right" class="align-right" alt="http://www.llucax.com.ar/blog/posts/2009/10/29-the-d-programming-language.jpg" /&gt;
&lt;p&gt;The version &lt;a href="http://www.digitalmars.com/d/2.0/" class="reference external"&gt;2.0&lt;/a&gt; of &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt; will be released in sync with the classic book titled
after the language, in this case, &lt;a href="http://amazon.com/exec/obidos/ASIN/0321635361/modecdesi-20" class="reference external"&gt;The D Programming Language&lt;/a&gt;, written by
the &lt;a href="http://en.wikipedia.org/wiki/Andrei_Alexandrescu" class="reference external"&gt;Andrei Alexandrescu&lt;/a&gt;. You can follow the progress of the book looking at
&lt;a href="http://erdani.com/" class="reference external"&gt;his home page&lt;/a&gt;, where a words and pages counter and a short term objective
are regularly updated.&lt;/p&gt;
&lt;p&gt;He posted a &lt;a href="http://www.informit.com/articles/article.aspx?p=1381876" class="reference external"&gt;little introductory excerpt of the book&lt;/a&gt; a while ago and
yesterday he published a larger excerpt, the whole &lt;a href="http://erdani.com/d/thermopylae.pdf" class="reference external"&gt;chapter 4&lt;/a&gt; about
&lt;a href="http://www.digitalmars.com/d/2.0/arrays.html" class="reference external"&gt;arrays&lt;/a&gt;, &lt;a href="http://www.digitalmars.com/d/2.0/arrays.html#associative" class="reference external"&gt;associative arrays&lt;/a&gt; and &lt;a href="http://www.digitalmars.com/d/2.0/arrays.html#strings" class="reference external"&gt;strings&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you don't know much about &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt;, it could be a good way to take a peek.&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/FFHf3mjhhvA" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/10/26/haskellc-video-and-slides/" />
		<id>http://bartoszmilewski.wordpress.com/?p=1094</id>
		<updated>2009-10-26T20:27:34+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;The video of my talk, &lt;a href="http://vimeo.com/7211030"&gt;Haskell and C++ Template Metaprogramming&lt;/a&gt;, is now available; and so are the &lt;a href="http://www.nwcpp.org/Downloads/2009/Haskell_and_C___Template.pdf"&gt;slides&lt;/a&gt;. I pretty much covered the material from my last &lt;a href="http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/"&gt;blog post&lt;/a&gt;, but many people (including me) find a video presentation easier to follow. &lt;/p&gt;
&lt;p&gt;This is also a plug for the &lt;a href="http://www.nwcpp.org"&gt;Northwest C++ Users Group&lt;/a&gt; that meets in Redmond every third Wednesday of the month. If you live in Seattle or on the east side of Lake Washington, check it out. You won&amp;#8217;t be disappointed. &lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/1094/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/1094/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/1094/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/1094/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/1094/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/1094/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/1094/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/1094/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/1094/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/1094/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=1094&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Olden "em3d" benchmark in D language</title>
		<link href="http://leonardo-m.livejournal.com/90054.html" />
		<id>http://leonardo-m.livejournal.com/90054.html</id>
		<updated>2009-10-25T23:38:20+00:00</updated>
		<content type="html">All the code shown in this article:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/dolden_em3d.zip"&gt;http://www.fantascienza.net/leonardo/js/dolden_em3d.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is a partial port of the Olden benchmarks to the D language. I'll add more Olden benchmarks in future as time allows me to.&lt;br /&gt;&lt;br /&gt;Info on the Olden benchmarks and their Java translation (JOlden):&lt;br /&gt;&lt;a href="http://www-ali.cs.umass.edu/DaCapo/benchmarks.html"&gt;http://www-ali.cs.umass.edu/DaCapo/benchmarks.html&lt;/a&gt;&lt;br /&gt;&lt;a href="http://www.sable.mcgill.ca/~bdufou1/ashes2/"&gt;http://www.sable.mcgill.ca/~bdufou1/ashes2/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;General comments:&lt;br /&gt;&lt;br /&gt;One of my purposes is to test the efficiency of the D1 code compiled with LDC. LDC is usually able to produce efficient binaries when I translate C code to C-like D code. So now I want to see how D is efficient if I start from higher level code, like Java code. It's usually easy to translate such Java code to D, D looks like a super set of C and Java, with some C++ mixed in.&lt;br /&gt;&lt;br /&gt;Olden benchmarks are designed to stress first of all the memory allocations. The D Garbage Collector (GC) is quite less efficient than the Java HotSpot GC, so literal translations of the Olden benchmarks from Java to D are usually lower or quite lower performance (up to 4-16 times slower). So I have to work some to regain performance. Usually D allows me to produce final programs that are 2-6 times faster than the original Java versions, but such optimization requires time, experience, and sometimes it's a little bug-prone.&lt;br /&gt;&lt;br /&gt;Beside having a more efficient GC, Java performs other optimizations not done by LDC, like inlining of virtual methods, and other things. In future the LLVM back-end of LDC will hopefully perform some of such optimizations (obsoleting some of my manual optimizations).&lt;br /&gt;&lt;br /&gt;In all JOlden benchmarks I have packed the Java code of a benchmark in a single source file, that later I have first translated to D, and then optimized for speed and memory usage. Sometimes I have cleaned up some the D code.&lt;br /&gt;&lt;br /&gt;Below I explain the various versions I've created.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;See the Python2 code near the bottom to see the algorithm used by this "em3d" benchmark. This benchmark models the propagation of electromagnetic waves through objects in 3 dimensions. It is a simple computation on an irregular bipartite graph containing nodes representing electric and magnetic field values.&lt;br /&gt;&lt;br /&gt;Update 1.2, Oct 26 2006: &lt;br /&gt;&lt;br /&gt;One of the main purposes of this article is to show show and teach how some manual optimizations are done.&lt;br /&gt;&lt;br /&gt;Timings of the various versions (i is the number of iterations):&lt;br /&gt;&lt;pre&gt;
          i=50   i=200  i=2000
Java1:    4.37    7.13
Java2     3.62    6.87
D01:      6.55   11.40
D02:      4.98    9.36
D03:      3.53    8.01
D04:      3.32    6.44
D05:      2.94    5.95
D06:      2.14    5.23
D07:      1.99    4.72
D08:      1.82    4.04
D09:      1.82    4.03
D10:      1.20    3.06
D11:      1.27    2.96   24.62 (TyIndex=ushort)
D11:      1.52    3.60         (TyIndex=uint)
D11b:     1.27    2.97   23.25 (TyIndex=ushort, TyDelta=ubyte)
D11b:     1.31    3.00         (TyIndex=uint, TyDelta=ushort)
D12:      1.61    3.62
Java3:    3.14    6.24
D01b:     6.33   10.60
Python1: 64.3    ---
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;Java1&lt;br /&gt;&lt;br /&gt;The original JOlden Java code packed in a single source file.&lt;br /&gt;&lt;br /&gt;I have fixed a bug present in the Java code of JOlden Em3d but absent in the original C code:&lt;br /&gt;At line 131 of the Em3d1.java the line:&lt;br /&gt;if (otherNode == toNodes[filled]) break;&lt;br /&gt;Has to be fixed as:&lt;br /&gt;if (otherNode == toNodes[k]) break;&lt;br /&gt;&lt;br /&gt;Such bug was not found probably because this benchmark suite has no unit-tests that test well each class and each method of each class.&lt;br /&gt;&lt;br /&gt;Timings (best of 6, seconds):&lt;br /&gt;&lt;br /&gt;...$ time java -server Em3d1 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 2.725&lt;br /&gt;EM3D compute time 1.277&lt;br /&gt;EM3D total time 4.01&lt;br /&gt;Done!&lt;br /&gt;real 0m4.370s&lt;br /&gt;user 0m3.376s&lt;br /&gt;sys 0m0.380s&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;...$ time java -server Em3d1 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 2.458&lt;br /&gt;EM3D compute time 4.35&lt;br /&gt;EM3D total time 6.812&lt;br /&gt;Done!&lt;br /&gt;real 0m7.128s&lt;br /&gt;user 0m6.568s&lt;br /&gt;sys 0m0.440s&lt;br /&gt;&lt;br /&gt;Used:&lt;br /&gt;java version "1.6.0_16"&lt;br /&gt;Java(TM) SE Runtime Environment (build 1.6.0_16-b01)&lt;br /&gt;Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)&lt;br /&gt;&lt;br /&gt;Code running on Ubuntu, running on VirtualBox, running on Windows Vista, on CPU Celeron 2.13 GHz.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;Java2&lt;br /&gt;&lt;br /&gt;It's like the Java1 version, but it use a very simple portable pseudo-random generator. So when I translate this program to D I can see if it gives the same results.&lt;br /&gt;&lt;br /&gt;The Random.nextInt is a little different, it accepts a max value (min is 0).&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time java -server Em3d2 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 2.209&lt;br /&gt;EM3D compute time 1.109&lt;br /&gt;EM3D total time 3.318&lt;br /&gt;Done!&lt;br /&gt;real 0m3.622s&lt;br /&gt;user 0m3.100s&lt;br /&gt;sys 0m0.416s&lt;br /&gt;&lt;br /&gt;...$ time java -server Em3d2 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 2.197&lt;br /&gt;EM3D compute time 4.354&lt;br /&gt;EM3D total time 6.551&lt;br /&gt;Done!&lt;br /&gt;real 0m6.875s&lt;br /&gt;user 0m6.292s&lt;br /&gt;sys 0m0.448s&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D01&lt;br /&gt;&lt;br /&gt;This is the most direct translation of the Java2 code to D, with the portable pseudo-random generator. I have used printf for maximum portability across different D standard libraries. I have replaced the enumerated with the D opApply.&lt;br /&gt;As you can see D1 allows to program in a style almost equal to Java.&lt;br /&gt;&lt;br /&gt;Code compiled with:&lt;br /&gt;...$ ldc -O5 -release -inline em3d01.d&lt;br /&gt;&lt;br /&gt;With:&lt;br /&gt;LDC compiler, based on DMD v1.045 and llvm 2.6 (Thu Sep 10 23:50:27 2009)&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d01 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 4.96&lt;br /&gt;EM3D compute time 1.38&lt;br /&gt;EM3D total time 6.34&lt;br /&gt;Done!&lt;br /&gt;real 0m6.547s&lt;br /&gt;user 0m5.856s&lt;br /&gt;sys 0m0.576s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d01 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 4.88&lt;br /&gt;EM3D compute time 5.97&lt;br /&gt;EM3D total time 10.86&lt;br /&gt;Done!&lt;br /&gt;real 0m11.398s&lt;br /&gt;user 0m10.801s&lt;br /&gt;sys 0m0.492s&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The first D version, despite being compiled with LDC, is slower than the Java version. As you can see the build time is much bigger, more than two times, that's mostly because of the D GC.&lt;br /&gt;&lt;br /&gt;To test that no bugs are introduced I have created a small Python script that acts like the "diff" command, but ignored small differences in floating point values. The programs of this benchmark are able to print the results, so I can test them:&lt;br /&gt;&lt;br /&gt;...$ java Em3d2 -n 10 -d 4 -i 5 -m -p &amp;gt; outj&lt;br /&gt;...$ ./em3d01 -n 10 -d 4 -i 5 -m -p &amp;gt; outd01&lt;br /&gt;&lt;br /&gt;With it I can test that the results are the same:&lt;br /&gt;&lt;br /&gt;...$ python approx_diff.py outj2 outd01&lt;br /&gt;3) line=26: ['EM3D', 'build', 'time', '0.0040'] ['EM3D', 'build', 'time', '0.00'] 0.004 0.0&lt;br /&gt;3) line=28: ['EM3D', 'total', 'time', '0.0040'] ['EM3D', 'total', 'time', '0.00'] 0.004 0.0&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of computeNewValue() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB11_2:&lt;br /&gt; movl 32(%eax), %esi&lt;br /&gt; movl (%esi,%edx,4), %esi&lt;br /&gt; movl 40(%eax), %edi&lt;br /&gt; movsd (%edi,%edx,8), %xmm1&lt;br /&gt; mulsd 8(%esi), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movsd %xmm0, 8(%eax)&lt;br /&gt; incl %edx&lt;br /&gt; cmpl %ecx, %edx&lt;br /&gt; jl .LBB11_2&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D02&lt;br /&gt;&lt;br /&gt;Olden benchmarks are quite memory-based, so the first way to optimize them is to reduce the number of memory allocations. Also, in D a good basic optimization for this kind of programs is to convert classes that are instantiated many times, into structs.&lt;br /&gt;&lt;br /&gt;A quick scan of the code shows that it contains a single instance of Em3d and BiGraph, and many instances of Node. So this version translated Node into a struct, allocated on the heap and managed by pointer. The code is almost the same. I have also reformatted code to 4 spaces.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d02 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 3.39&lt;br /&gt;EM3D compute time 1.40&lt;br /&gt;EM3D total time 4.79&lt;br /&gt;Done!&lt;br /&gt;real 0m4.982s&lt;br /&gt;user 0m4.416s&lt;br /&gt;sys 0m0.472s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d02 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 3.35&lt;br /&gt;EM3D compute time 5.84&lt;br /&gt;EM3D total time 9.19&lt;br /&gt;Done!&lt;br /&gt;real 0m9.365s&lt;br /&gt;user 0m8.821s&lt;br /&gt;sys 0m0.460s&lt;br /&gt;&lt;br /&gt;The code is faster, but there's a lot to do still. The code is not good yet, there are several inefficiencies.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D03&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;I have converted all the classes (Random, BiGraph and Em3d) to structs with minimal performance changes. So the problem is (as expected) elsewhere.&lt;br /&gt;I have reformatted the Java comments to produce a more compact code that (despite losing being fit for ddoc) allows me to understand the code better.&lt;br /&gt;&lt;br /&gt;I have renamed some Node fields to better names, because better names allow to understand code better:&lt;br /&gt;toNodes =&amp;gt; outbound&lt;br /&gt;fromNodes =&amp;gt; inbound&lt;br /&gt;fromCount =&amp;gt; n_inbound&lt;br /&gt;&lt;br /&gt;Now the main() is a independent function.&lt;br /&gt;&lt;br /&gt;Then I have disabled the GC just before the graph creation, and enabled again after that.&lt;br /&gt;&lt;br /&gt;I have also added extra time printings inside the graph creation method, to study better where the running time goes.&lt;br /&gt;&lt;br /&gt;Then I have added an exit(0) at the end of the main, it kills the program quickly, saving the time needed to call destructors and to free the GC memory. In general this is not a safe thing to do, because destructors may be necessary, but in this program this is OK.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d03 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.14 0.94 0.48 0.43&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 1.99&lt;br /&gt;EM3D compute time 1.36&lt;br /&gt;EM3D total time 3.35&lt;br /&gt;Done!&lt;br /&gt;real 0m3.530s&lt;br /&gt;user 0m2.920s&lt;br /&gt;sys 0m0.524s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d03 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.15 0.93 0.48 0.43&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 1.99&lt;br /&gt;EM3D compute time 5.80&lt;br /&gt;EM3D total time 7.79&lt;br /&gt;Done!&lt;br /&gt;real 0m8.012s&lt;br /&gt;user 0m7.348s&lt;br /&gt;sys 0m0.540s&lt;br /&gt;&lt;br /&gt;As expected the compute time is unchanged, but the build time is decreased significantly.&lt;br /&gt;Now the build time is lower than the Java2 code! So the first benchmark (with just 50 loops) is faster than the Java2 version.&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of computeNewValue() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB10_2:&lt;br /&gt; movl 24(%eax), %esi&lt;br /&gt; movl (%esi,%edx,4), %esi&lt;br /&gt; movl 32(%eax), %edi&lt;br /&gt; movsd (%edi,%edx,8), %xmm1&lt;br /&gt; mulsd (%esi), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movsd %xmm0, (%eax)&lt;br /&gt; incl %edx&lt;br /&gt; cmpl %ecx, %edx&lt;br /&gt; jl .LBB10_2&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D04&lt;br /&gt;&lt;br /&gt;I have renamed a method:&lt;br /&gt;BiGraph.compute() =&amp;gt; graph.computeStep();&lt;br /&gt;&lt;br /&gt;And I have added a test for the sanity of the input numDegree:&lt;br /&gt;if (numDegree &amp;gt; numNodes) {...&lt;br /&gt;&lt;br /&gt;The program allocates a linked list of nodes, and then doesn't change that topology any more, just iterates on them. Both allocating many single nodes, and iterating on a linked list, today are slow operations (the original C code was old). So today it's much more efficient to allocated many or all Nodes in an array (this program contains a bipartite graph, so there are two arrays).&lt;br /&gt;&lt;br /&gt;So I can also remove the "next" pointer field of Node, that was used for the links of the list.&lt;br /&gt;&lt;br /&gt;In this D version the arcs are kept as pointers. Now the opApply isn't needed (this increases speed because I now loop on arrays, but loses some encapsulation).&lt;br /&gt;&lt;br /&gt;The fillTable() method becomes the createTable() because it allocates an array of the nodes.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d04 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.13 0.94 0.48 0.40&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 1.95&lt;br /&gt;EM3D compute time 1.18&lt;br /&gt;EM3D total time 3.13&lt;br /&gt;Done!&lt;br /&gt;real 0m3.326s&lt;br /&gt;user 0m2.696s&lt;br /&gt;sys 0m0.540s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d04 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.13 0.92 0.46 0.40&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 1.91&lt;br /&gt;EM3D compute time 4.35&lt;br /&gt;EM3D total time 6.26&lt;br /&gt;Done!&lt;br /&gt;real 0m6.443s&lt;br /&gt;user 0m5.908s&lt;br /&gt;sys 0m0.432s&lt;br /&gt;&lt;br /&gt;The build time is not changed, I don't know why, probably disabling the GC allows for an efficient enough memory allocation. But now the compute time is decreased, because the program can scan the arrays more efficiently.&lt;br /&gt;&lt;br /&gt;If a program like this gets used in practice, the build time is not important, because the number of iterations is probably large, so the compute time has to be as small as possible.&lt;br /&gt;&lt;br /&gt;Now both timings are better than the Java2 timings.&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of computeNewValue() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB9_2:&lt;br /&gt; movl 12(%eax), %esi&lt;br /&gt; movl (%esi,%edx,4), %esi&lt;br /&gt; movl 20(%eax), %edi&lt;br /&gt; movsd (%edi,%edx,8), %xmm1&lt;br /&gt; mulsd (%esi), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movsd %xmm0, (%eax)&lt;br /&gt; incl %edx&lt;br /&gt; cmpl %ecx, %edx&lt;br /&gt; jb .LBB9_2&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D05&lt;br /&gt;&lt;br /&gt;The CPU is able to use the pointers among Nodes in a quick way, but the number of nodes is probably limited. The program can increase its speed if there is less data traffic through the CPU cache. So I have replaced the pointers by 16 bit (ushort) indexes. This allows up to 2^16 nodes. If you need more, you can replace:&lt;br /&gt;alias ushort TyIndex;&lt;br /&gt;With:&lt;br /&gt;alias uint TyIndex;&lt;br /&gt;But this may produce code slower than D04.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d05 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.06 0.94 0.38 0.42&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 1.80&lt;br /&gt;EM3D compute time 1.00&lt;br /&gt;EM3D total time 2.80&lt;br /&gt;Done!&lt;br /&gt;real 0m2.937s&lt;br /&gt;user 0m2.540s&lt;br /&gt;sys 0m0.324s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d05 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.07 0.95 0.37 0.39&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 1.78&lt;br /&gt;EM3D compute time 4.02&lt;br /&gt;EM3D total time 5.80&lt;br /&gt;Done!&lt;br /&gt;real 0m5.955s&lt;br /&gt;user 0m5.508s&lt;br /&gt;sys 0m0.360s&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of computeNewValue() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB9_2:&lt;br /&gt; movl 20(%eax), %edi&lt;br /&gt; movsd (%edi,%esi,8), %xmm1&lt;br /&gt; movl 12(%eax), %edi&lt;br /&gt; movzwl (%edi,%esi,2), %edi&lt;br /&gt; imull $40, %edi, %edi&lt;br /&gt; mulsd (%edx,%edi), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movsd %xmm0, (%eax)&lt;br /&gt; incl %esi&lt;br /&gt; cmpl %ecx, %esi&lt;br /&gt; jb .LBB9_2&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D06&lt;br /&gt;&lt;br /&gt;Now I look for possible algorithmic improvements.&lt;br /&gt;makeUniqueNeighbors() contains stupid quadratic code to avoid duplicating Neighbors. I have tried to use a D associative array, and then a set implemented as a bit vector (using bt/bts intrinsics), but the most efficient seems a set of booleans implemented with just an array of ubytes.&lt;br /&gt;&lt;br /&gt;I have renamed:&lt;br /&gt;coeffs =&amp;gt; inCoeffs&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d06 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.07 0.11 0.40 0.39&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.97&lt;br /&gt;EM3D compute time 1.03&lt;br /&gt;EM3D total time 2.00&lt;br /&gt;Done!&lt;br /&gt;real 0m2.145s&lt;br /&gt;user 0m1.748s&lt;br /&gt;sys 0m0.324s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d06 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;0.07 0.11 0.37 0.40&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.95&lt;br /&gt;EM3D compute time 4.11&lt;br /&gt;EM3D total time 5.06&lt;br /&gt;Done!&lt;br /&gt;real 0m5.231s&lt;br /&gt;user 0m4.804s&lt;br /&gt;sys 0m0.352s&lt;br /&gt;&lt;br /&gt;The build time for 5000 nodes with 300 arcs is half as before.&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of computeNewValue() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB9_2:&lt;br /&gt; movl 20(%eax), %edi&lt;br /&gt; movsd (%edi,%esi,8), %xmm1&lt;br /&gt; movl 12(%eax), %edi&lt;br /&gt; movzwl (%edi,%esi,2), %edi&lt;br /&gt; imull $40, %edi, %edi&lt;br /&gt; mulsd (%edx,%edi), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movsd %xmm0, (%eax)&lt;br /&gt; incl %esi&lt;br /&gt; cmpl %ecx, %esi&lt;br /&gt; jb .LBB9_2&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D07&lt;br /&gt;&lt;br /&gt;Now the most common optimizations are done, and the code looks good enough. To improve the code some more we have to think more about the CPU cache.&lt;br /&gt;&lt;br /&gt;The computations (of "compute time") are done on an array of large structs Node. But only few fields are actually necessary for such computation: value, inbound and inCoeffs (total 6 words), so if I remove the useless data, the iterations on the array will be (hopefully) faster.&lt;br /&gt;&lt;br /&gt;I don't know how to remove items from the struct. The simpler way to solve this problem is to define a second Node struct, a Node2, with just the essential fields. Creating the two arrays of Node2 is fast, because all arrays of inbound and inCoeffs are just copied by reference.&lt;br /&gt;&lt;br /&gt;So I add the eNodes2 and hNodes2 dynamic arrays of Node2 to BiGraph (now encapsulation looks gone, but in practice I don't think the original design was good. The only data structure that has to know about a collection of Nodes2 has to be BiGraph, and not Node2 itself).&lt;br /&gt;&lt;br /&gt;There's some redundancy too here in a Node2: the inbound and inCoeffs arrays have the same length, so the Node2 can use just 5 words. There are few ways to remove this field, but the first field (the value) is a double, and for max performance it must be aligned to 8 bytes. So I have done few experiments, but they are failed, the program was slower, with a small memory usage reduction. So I have kept all the 6 words.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d07 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.08 0.10 0.37 0.39 0.00&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.94&lt;br /&gt;EM3D compute time 0.92&lt;br /&gt;EM3D total time 1.86&lt;br /&gt;Done!&lt;br /&gt;real 0m1.993s&lt;br /&gt;user 0m1.600s&lt;br /&gt;sys 0m0.316s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d07 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.07 0.10 0.39 0.40 0.00&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.96&lt;br /&gt;EM3D compute time 3.62&lt;br /&gt;EM3D total time 4.58&lt;br /&gt;Done!&lt;br /&gt;real 0m4.718s&lt;br /&gt;user 0m4.292s&lt;br /&gt;sys 0m0.360s&lt;br /&gt;&lt;br /&gt;The build time of the graph is the same, but the computing time is decreased.&lt;br /&gt;The time needed to build the arrays of Node2 is very small.&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of computeNewValue() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB9_2:&lt;br /&gt; movl 20(%eax), %edi&lt;br /&gt; movsd (%edi,%esi,8), %xmm1&lt;br /&gt; movl 12(%eax), %edi&lt;br /&gt; movzwl (%edi,%esi,2), %edi&lt;br /&gt; imull $24, %edi, %edi&lt;br /&gt; mulsd (%edx,%edi), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movsd %xmm0, (%eax)&lt;br /&gt; incl %esi&lt;br /&gt; cmpl %ecx, %esi&lt;br /&gt; jb .LBB9_2&lt;br /&gt;&lt;br /&gt;-----------------------------------&lt;br /&gt;&lt;br /&gt;D08&lt;br /&gt;&lt;br /&gt;We can improve the code more taking a look at how hValues are accessed, a sequential access is faster. But I've seen that the inbound[i] are already sorted.&lt;br /&gt;&lt;br /&gt;So I have to take a better look at the very small loop that performs one of the two halves of a computation step:&lt;br /&gt;&lt;pre&gt;
void computeNewValue(Node2[] otherTable) {
  for (int i; i &amp;lt; inbound.length; i++)
    value -= inCoeffs[i] * otherTable[inbound[i]].value;
}
&lt;/pre&gt;&lt;br /&gt;There's not much that can be improved here. I have drawn on paper the simple data structures involved here, and with that I've seen that inbound[i] performs (forward but) large jumps in an array of largish structs (6 words each) to find the "value" fields. This forces the CPU cache to a lot of traffic. If we reduce this traffic the iterations will get faster.&lt;br /&gt;&lt;br /&gt;The simple way to do this is to pull the values out of the nodes2 and put them in a uniform array, that's used in parallel to the Node2 array.&lt;br /&gt;&lt;pre&gt;
// Node2 of D07:
struct Node2 {
    double value;
    Node.TyIndex[] inbound;
    double[] inCoeffs;
}

// Node2 of D08:
struct Node2 {
    Node.TyIndex[] inbound;
    double[] inCoeffs;
    static double[] eValues, hValues;
}
&lt;/pre&gt;&lt;br /&gt;Now the jumps are performed on arrays (eValues and hValues) with just 2 words/item.&lt;br /&gt;&lt;br /&gt;To perform a better computation I have had to split computeNewValue() into eValuesStep() and hValuesStep(). I have pulled the outer loop like foreach(j, ref n; hNodes2) inside them, this may help the DMD compiler too, because it doesn't inline functions/methods that have a loop inside.&lt;br /&gt;&lt;br /&gt;I also have had to add a "aux_val" auxiliary variable inside the eValuesStep/hValuesStep functions, because it seems LDC/LLVM was not able to pull the access to Node2.hValues[j] out of the loop. I don't know why [see below, the explanation after D01b].&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d08 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.07 0.10 0.37 0.40 0.00&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.94&lt;br /&gt;EM3D compute time 0.74&lt;br /&gt;EM3D total time 1.68&lt;br /&gt;Done!&lt;br /&gt;real 0m1.817s&lt;br /&gt;user 0m1.416s&lt;br /&gt;sys 0m0.332s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d08 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.07 0.10 0.37 0.39 0.00&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.93&lt;br /&gt;EM3D compute time 2.96&lt;br /&gt;EM3D total time 3.89&lt;br /&gt;Done!&lt;br /&gt;real 0m4.038s&lt;br /&gt;user 0m3.628s&lt;br /&gt;sys 0m0.336s&lt;br /&gt;&lt;br /&gt;The compute time is decreased enough.&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of eValuesStep() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB9_4:&lt;br /&gt; movzwl (%esi,%edi,2), %ebp&lt;br /&gt; movsd (%edx,%edi,8), %xmm1&lt;br /&gt; mulsd (%ebx,%ebp,8), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; incl %edi&lt;br /&gt; cmpl %ecx, %edi&lt;br /&gt; jb .LBB9_4&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D09&lt;br /&gt;&lt;br /&gt;There's one last possible optimization of the memory usage that I can see. I can remove again the redundancy from Node2, because now it doesn't contain a double, and now probably I can use 3 32-bit words.&lt;br /&gt;&lt;br /&gt;The new Node2 is:&lt;br /&gt;&lt;pre&gt;
struct Node2 {
  Node.TyIndex* inbound;
  double* inCoeffs;
  int inbound_len;
  static double[] eValues, hValues;
}
&lt;/pre&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d09 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.08 0.10 0.37 0.39 0.00&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.94&lt;br /&gt;EM3D compute time 0.74&lt;br /&gt;EM3D total time 1.68&lt;br /&gt;Done!&lt;br /&gt;real 0m1.821s&lt;br /&gt;user 0m1.444s&lt;br /&gt;sys 0m0.296s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d09 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.07 0.11 0.37 0.39 0.00&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.94&lt;br /&gt;EM3D compute time 2.95&lt;br /&gt;EM3D total time 3.89&lt;br /&gt;Done!&lt;br /&gt;real 0m4.030s&lt;br /&gt;user 0m3.632s&lt;br /&gt;sys 0m0.332s&lt;br /&gt;&lt;br /&gt;The computing time is about the same. The memory saving compared to D08 is very small, something like 40 KB.&lt;br /&gt;&lt;br /&gt;It may be possible to vectorize the computing loop, but I stop here.&lt;br /&gt;&lt;br /&gt;Compared to the Java2 version the speed of this last D09 version is not much higher, because the computing loop is very tight and the JavaVM is able to optimize it very well, quite better than LDC, see the compute time of Java2 compared to the compute time of D01: 4.35 compared to 5.97. A shame for D/LDC/LLVM :-)&lt;br /&gt;&lt;br /&gt;Other Olden benchmarks show a bigger gap between the performance of the Java and optimized D code.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of eValuesStep() compiled with LDC:&lt;br /&gt;&lt;br /&gt; .align 16&lt;br /&gt;.LBB9_4:&lt;br /&gt; movzwl (%esi,%edi,2), %ebp&lt;br /&gt; movsd (%edx,%edi,8), %xmm1&lt;br /&gt; mulsd (%ebx,%ebp,8), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; incl %edi&lt;br /&gt; cmpl %ecx, %edi&lt;br /&gt; jl .LBB9_4&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D10&lt;br /&gt;&lt;br /&gt;Update 1.2, Oct 27 2006: &lt;br /&gt;&lt;br /&gt;There is another simple performance optimization that can be done. The memory for the Nodes and their arcs can be allocated from the C heap (and in some cases such memory can even be allocated with malloc instead of calloc, but in this programs this has no significant performance difference).&lt;br /&gt;&lt;br /&gt;The memory coming from the C heap is usually aligned to 4 bytes, so it's not fit for storing values and coefficients that in this program are doubles, that are used much more efficiently when aligned to 8 bytes. But in this program the actual computations performed on double FP numbers are done on arrays allocated in Node2, that are allocated from the D GC heap that returns memory aligned to 16 bytes. The only problem may come from Node.inCoeffs that's copied as is to Node2 inCoeffs. So this allocation needs a little of extra care (see makeFromNodes()).&lt;br /&gt;&lt;br /&gt;I can even allocate all "outbound" arrays at once, because they are all of the same length, but this change will not change performance significantly, because that time is part of the first timing of the "Detailed creation timings:", that's about 0.03-0.04 seconds for 5000 nodes.&lt;br /&gt;&lt;br /&gt;I have moved the disable() of the GC below, when the computing loops are done, because there's no point in keeping the GC active during those loops, that produce no garbage.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d10 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.10 0.14 0.19 0.00&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.47&lt;br /&gt;EM3D compute time 0.60&lt;br /&gt;EM3D total time 1.07&lt;br /&gt;Done!&lt;br /&gt;real 0m1.203s&lt;br /&gt;user 0m0.968s&lt;br /&gt;sys 0m0.148s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d10 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.03 0.10 0.16 0.18 0.00&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.47&lt;br /&gt;EM3D compute time 2.46&lt;br /&gt;EM3D total time 2.93&lt;br /&gt;Done!&lt;br /&gt;real 0m3.061s&lt;br /&gt;user 0m2.844s&lt;br /&gt;sys 0m0.124s&lt;br /&gt;&lt;br /&gt;Not just (as expected) the build times are lower, but the compute ones too are lower, I don't know why, maybe the memory from the C heap has more coherence (more contiguous, reducing cache misses. The GC adds some spaces, because it returns memory blocks aligned to 16 bytes).&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D11&lt;br /&gt;&lt;br /&gt;Update 1.2, Oct 27 2006:&lt;br /&gt;&lt;br /&gt;To reduce the time used by makeFromNodes(), and hopefully to increase the computation loops (with a better cache coherence) we can cut the inbound and inCoeffs arrays of Node (later copied into Node2) from a large memory block allocated all at once (again, doubles are better alighed to 8 bytes) to do this I have created two memory arenas, with the DoubleArena and IndexArena structs.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.10 0.00 0.42 0.00&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.56&lt;br /&gt;EM3D compute time 0.58&lt;br /&gt;EM3D total time 1.14&lt;br /&gt;Done!&lt;br /&gt;real 0m1.271s&lt;br /&gt;user 0m1.028s&lt;br /&gt;sys 0m0.164s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.09 0.00 0.43 0.01&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.57&lt;br /&gt;EM3D compute time 2.23&lt;br /&gt;EM3D total time 2.80&lt;br /&gt;Done!&lt;br /&gt;real 0m2.961s&lt;br /&gt;user 0m2.652s&lt;br /&gt;sys 0m0.184s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11 -n 5000 -d 300 -i 2000 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.03 0.11 0.00 0.43 0.00&lt;br /&gt;Propagating field values for 2000 iteration(s)...&lt;br /&gt;EM3D build time 0.57&lt;br /&gt;EM3D compute time 23.39&lt;br /&gt;EM3D total time 23.96&lt;br /&gt;Done!&lt;br /&gt;real 0m24.621s&lt;br /&gt;user 0m23.869s&lt;br /&gt;sys 0m0.144s&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now the build time is a little higher (I don't know why), while the computing loops are faster (I don't know why), so when the number of iterations is 200 the total time is lower.&lt;br /&gt;&lt;br /&gt;In the detailed creation timings you can also see that makeFromNodes() is now very fast, while updateFromNodes() is quite slower (I don't know why. Here DMD is twice faster).&lt;br /&gt;&lt;br /&gt;This version also needs a little less RAM compared to D10, about 39 MB with -n 5000 -d 300. Java3 needs about 197 MB for the same graph.&lt;br /&gt;&lt;br /&gt;Now the D11 program is fast enough, and uses a low enough memory, that the limit of 65000 nodes given by the ushort indexes can be felt. Using an uint as TyIndex the memory used by D11 with -n 5000 -d 300 is 51 MB.&lt;br /&gt;&lt;br /&gt;Timings of D11 with TyIndex=uint:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.09 0.11 0.00 0.48 0.00&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.68&lt;br /&gt;EM3D compute time 0.68&lt;br /&gt;EM3D total time 1.36&lt;br /&gt;Done!&lt;br /&gt;real 0m1.525s&lt;br /&gt;user 0m1.220s&lt;br /&gt;sys 0m0.200s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.06 0.12 0.00 0.50 0.00&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.68&lt;br /&gt;EM3D compute time 2.71&lt;br /&gt;EM3D total time 3.39&lt;br /&gt;Done!&lt;br /&gt;real 0m3.597s&lt;br /&gt;user 0m3.252s&lt;br /&gt;sys 0m0.184s&lt;br /&gt;&lt;br /&gt;Using such larger indexes the running time is not much higher, but in this case using just pointers is probably faster.&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of eValuesStep() of D11 compiled with LDC, when TyIndex=uint:&lt;br /&gt;&lt;br /&gt;.LBB14_4:&lt;br /&gt; movl (%esi,%edi,4), %ebp&lt;br /&gt; movsd (%edx,%edi,8), %xmm1&lt;br /&gt; mulsd (%ebx,%ebp,8), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; incl %edi&lt;br /&gt; cmpl %ecx, %edi&lt;br /&gt; jl .LBB14_4&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D11b&lt;br /&gt;(lateral branch)&lt;br /&gt;&lt;br /&gt;Update 1.2, Oct 27 2006:&lt;br /&gt;&lt;br /&gt;When the number of nodes is high, instead of storing ushort indexes, I can store ushort deltas. And because the indexes are ordered such deltas are never negative. If links are well spread, then such deltas are usually small, and they can be used to index far more than 2^16 nodes. If such links are randomly distriuited, you can probably manage millions of nodes in a safe enough way, and it's easy to add a runtime test when they are created to be sure they don't overflow.&lt;br /&gt;&lt;br /&gt;I have done a test, using the usual -n 5000 -d 300 arguments with the same seed=783, in such case the maximum delta is 240, so just one ubyte suffices! ubyte indexes reduce traffic through the cache, so they may speed up the program a little more. The D11b uses such TyDelta in Node2 but I have kept usign TyIndex in Node to keep the program simpler.&lt;br /&gt;&lt;br /&gt;Timings of D11b with TyIndex=ushort, TyDelta=ubyte:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11b -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.10 0.00 0.42 0.02&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.59&lt;br /&gt;EM3D compute time 0.56&lt;br /&gt;EM3D total time 1.15&lt;br /&gt;Done!&lt;br /&gt;real 0m1.266s&lt;br /&gt;user 0m1.032s&lt;br /&gt;sys 0m0.156s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11b -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.11 0.00 0.42 0.02&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.59&lt;br /&gt;EM3D compute time 2.20&lt;br /&gt;EM3D total time 2.79&lt;br /&gt;Done!&lt;br /&gt;real 0m2.968s&lt;br /&gt;user 0m2.676s&lt;br /&gt;sys 0m0.160s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11b -n 5000 -d 300 -i 2000 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.03 0.12 0.00 0.48 0.02&lt;br /&gt;Propagating field values for 2000 iteration(s)...&lt;br /&gt;EM3D build time 0.65&lt;br /&gt;EM3D compute time 21.98&lt;br /&gt;EM3D total time 22.63&lt;br /&gt;Done!&lt;br /&gt;real 0m23.252s&lt;br /&gt;user 0m22.477s&lt;br /&gt;sys 0m0.204s&lt;br /&gt;&lt;br /&gt;The iteration is a bit faster, but the build time of Nodes2 is a little slower (by about 0.02 seconds). So for 200 iterations the running time is about the same, while for 2000 you can see some difference. For TyDelta==ubyte this D11b program is not very useful (unless you have few nodes), but for larger graphs such delta encoding can be useful to keep using ushorts even when there are more than 2^16 nodes.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Timings of D11b with TyIndex=uint, TyDelta=ushort:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11b -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.11 0.00 0.44 0.02&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.61&lt;br /&gt;EM3D compute time 0.56&lt;br /&gt;EM3D total time 1.17&lt;br /&gt;Done!&lt;br /&gt;real 0m1.309s&lt;br /&gt;user 0m1.032s&lt;br /&gt;sys 0m0.180s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d11b -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.05 0.10 0.00 0.43 0.02&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.60&lt;br /&gt;EM3D compute time 2.20&lt;br /&gt;EM3D total time 2.80&lt;br /&gt;Done!&lt;br /&gt;real 0m2.997s&lt;br /&gt;user 0m2.684s&lt;br /&gt;sys 0m0.176s&lt;br /&gt;&lt;br /&gt;D11b with TyDelta=ushort is just a little slower than D11b with TyDelta=ubyte, so in most situations it can be enough for a number of nodes &amp;gt;&amp;gt; 2^16 if the arcs are spread in an uniform random way.&lt;br /&gt;&lt;br /&gt;This em3d program is just a benchmark, but in a real program you want to add class invariants, unittests, several safeties for the memory, and ways to deallocate memory when not used any more, etc.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D12&lt;br /&gt;(this ignores the D11b branch)&lt;br /&gt;&lt;br /&gt;Update 1.3, Oct 27 2006:&lt;br /&gt;&lt;br /&gt;The items of inbound and inCoeffs are accessed in parallel, so it can be useful for them to be close to each other. Ideally the items of inbound and inCoeffs are better kept in the same cache line, that's a block of 64 bytes (and I think it has to be aligned too). But I can't put them into a struct because it wastes a lot of space (such struct has to be 16 bytes long to keep the double it contains aligned to 8 bytes), and wasting space increases cache misses.&lt;br /&gt;&lt;br /&gt;If I want to pack pairs of double + ushort in a struct that inside an array is aligned to 8 bytes, I need to pack 4 doubles and 4 ushorts, this needs 8*4 + 2*4 = 32 + 8 = 40 bytes. But this straddles a cache line, and I think this is negative. So to pack as much as possible in a cache line I can use 6 pairs, that need 8*6 + 2*6 = 48 + 12 = 60 bytes, that needs 4 bytes of padding, this wastes 6.25% of space, I think it's acceptable. I can define it like this:&lt;br /&gt;&lt;pre&gt;
struct PairsPack {
  static if (TyIndex.sizeof == 2)
    const int NPAIRS = 6; // 8*6 + 2*6 + 4 = 48 + 12 + 4 = 64
  else static if (TyIndex.sizeof == 4)
    const int NPAIRS = 5; // 8*5 + 4*5 + 4 = 40 + 20 + 4 = 64
  else
      static assert(0);

  double[NPAIRS] weights;
  TyIndex[NPAIRS] inbounds;
  uint _padding;
}
&lt;/pre&gt;&lt;br /&gt;Just to be sure I'll allocate the array of PairsPack aligned to 64 bytes.&lt;br /&gt;&lt;br /&gt;But generally the number of inbound arcs in a node isn't a multiple of 6, so I need to waste some of those pairs, or use part of an already used PairsPack. Both solutions have advantages and disadvantages. I choose the option to not waste memory, this requires a little more complex indexing of the sub-part of a PairsPack, but allows me to allocate the array of PairsPack in a simpler way.&lt;br /&gt;&lt;br /&gt;This D12 was the hardest version to create, the code is quite hairy, and hard to maintain and understand. And it's slow (the Range!() that I have used is not necessary. LLVM was able to unroll that loop inside eValuesStep/hValuesStep by itself).&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d12o -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.11 0.00 0.43 0.19&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 0.78&lt;br /&gt;EM3D compute time 0.68&lt;br /&gt;EM3D total time 1.46&lt;br /&gt;Done!&lt;br /&gt;real 0m1.614s&lt;br /&gt;user 0m1.240s&lt;br /&gt;sys 0m0.284s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d12o -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.04 0.11 0.00 0.41 0.20&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 0.76&lt;br /&gt;EM3D compute time 2.65&lt;br /&gt;EM3D total time 3.41&lt;br /&gt;Done!&lt;br /&gt;real 0m3.623s&lt;br /&gt;user 0m3.176s&lt;br /&gt;sys 0m0.308s&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The asm of inner loop of eValuesStep() of D11 compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB14_4:&lt;br /&gt; movzwl 50(%eax), %ebp&lt;br /&gt; movsd 8(%eax), %xmm1&lt;br /&gt; mulsd (%esi,%ebp,8), %xmm1&lt;br /&gt; movzwl 48(%eax), %ebp&lt;br /&gt; movsd (%eax), %xmm2&lt;br /&gt; mulsd (%esi,%ebp,8), %xmm2&lt;br /&gt; subsd %xmm2, %xmm0&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movzwl 52(%eax), %ebp&lt;br /&gt; movsd 16(%eax), %xmm1&lt;br /&gt; mulsd (%esi,%ebp,8), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movzwl 54(%eax), %ebp&lt;br /&gt; movsd 24(%eax), %xmm1&lt;br /&gt; mulsd (%esi,%ebp,8), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movzwl 56(%eax), %ebp&lt;br /&gt; movsd 32(%eax), %xmm1&lt;br /&gt; mulsd (%esi,%ebp,8), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; movzwl 58(%eax), %ebp&lt;br /&gt; movsd 40(%eax), %xmm1&lt;br /&gt; mulsd (%esi,%ebp,8), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; addl $64, %eax&lt;br /&gt; decl %ebx&lt;br /&gt; jne .LBB14_4&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;Java3&lt;br /&gt;&lt;br /&gt;Now I can think porting back some of the optimizations I have implemented in D to Java. Java don't uses structs, so several things are not possible.&lt;br /&gt;&lt;br /&gt;In this Java3 I have used the uniqueNeighborsSet set, implemented as the D code.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time java -server Em3d3 -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 1.681&lt;br /&gt;EM3D compute time 1.14&lt;br /&gt;EM3D total time 2.821&lt;br /&gt;Done!&lt;br /&gt;real 0m3.138s&lt;br /&gt;user 0m2.600s&lt;br /&gt;sys 0m0.416s&lt;br /&gt;&lt;br /&gt;...$ time java -server Em3d3 -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 1.649&lt;br /&gt;EM3D compute time 4.29&lt;br /&gt;EM3D total time 5.943&lt;br /&gt;Done!&lt;br /&gt;real 0m6.239s&lt;br /&gt;user 0m5.656s&lt;br /&gt;sys 0m0.452s&lt;br /&gt;&lt;br /&gt;More optimizations may be ported from D to Java.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;D01b&lt;br /&gt;(lateral branch)&lt;br /&gt;&lt;br /&gt;Looking at the asm of the inner loop of computeNewValue for D01 and D09, I think the D01 can be improved with an auxiliary variable:&lt;br /&gt;&lt;pre&gt;
void computeNewValue() {
  auto aux = this.value;
  for (int i = 0; i &amp;lt; fromCount; i++)
    aux -= coeffs[i] * fromNodes[i].value;
  this.value = aux;
}
&lt;/pre&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time ./em3d01b -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 4.89&lt;br /&gt;EM3D compute time 1.28&lt;br /&gt;EM3D total time 6.17&lt;br /&gt;Done!&lt;br /&gt;real 0m6.335s&lt;br /&gt;user 0m5.804s&lt;br /&gt;sys 0m0.464s&lt;br /&gt;&lt;br /&gt;...$ time ./em3d01b -n 5000 -d 300 -i 200 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Propagating field values for 200 iteration(s)...&lt;br /&gt;EM3D build time 4.92&lt;br /&gt;EM3D compute time 5.23&lt;br /&gt;EM3D total time 10.15&lt;br /&gt;Done!&lt;br /&gt;real 0m10.601s&lt;br /&gt;user 0m10.105s&lt;br /&gt;sys 0m0.440s&lt;br /&gt;&lt;br /&gt;LDC/LLVM must be able to perform that optimization (pulling this.value out of the loop) by itself.&lt;br /&gt;&lt;br /&gt;This is the asm of inner loop of computeNewValue() compiled with LDC:&lt;br /&gt;&lt;br /&gt;.LBB11_2:&lt;br /&gt; movl (%edx,%edi,4), %ebx&lt;br /&gt; movsd (%esi,%edi,8), %xmm1&lt;br /&gt; mulsd 8(%ebx), %xmm1&lt;br /&gt; subsd %xmm1, %xmm0&lt;br /&gt; incl %edi&lt;br /&gt; cmpl %ecx, %edi&lt;br /&gt; jl .LBB11_2&lt;br /&gt;&lt;br /&gt;This asm is very short, but it's quite slower than D09 anyway. I don't know what kind of optimizations are done by the JavaVM on the Java1 code (there is a way to look at the asm produced by the JVM, but it's not handy).&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Update 1.1, Oct 26 2006: now I think I know why LDC isn't able to perform that optimization in the computeNewValue() loop: the compiler doesn't know that "value" on the right is always distinct from "value" on the left, because this is a bipartite graph, where no self-loops are allowed. So it can't pull the "value" of the left out of the loop.&lt;br /&gt;&lt;br /&gt;To perform the optimization the compiled need more semantics. Future programming languages may allow the programmer to give such semantics to the compiler.&lt;br /&gt;&lt;br /&gt;I have done a similar optimization (pulling "value" out of the loop) in the Java3 version, with no change in performance, so probably the JavaVM is somehow able to perform that optimization.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;Python1&lt;br /&gt;&lt;br /&gt;I have created a Python version too, that uses Psyco. It's similar to the Java3 version.&lt;br /&gt;I have seen that the faster unique_neighbors_set is using just a Python set.&lt;br /&gt;&lt;br /&gt;I have added __slots__ to both Random and Node, this doubles the performance.&lt;br /&gt;&lt;br /&gt;Timings:&lt;br /&gt;&lt;br /&gt;...$ time python em3d.py -n 5000 -d 300 -i 50 -m&lt;br /&gt;Initializing em3d random graph...&lt;br /&gt;Detailed creation timings: 0.14 3.86 0.16 4.32&lt;br /&gt;Propagating field values for 50 iteration(s)...&lt;br /&gt;EM3D build time 8.48&lt;br /&gt;EM3D compute time 54.70&lt;br /&gt;EM3D total time 63.19&lt;br /&gt;Done!&lt;br /&gt;real 1m4.320s&lt;br /&gt;user 0m59.628s&lt;br /&gt;sys 0m3.876s&lt;br /&gt;&lt;br /&gt;I have used:&lt;br /&gt;Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)&lt;br /&gt;Psyco 1.6.0 final&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;Python2&lt;br /&gt;&lt;br /&gt;While improving the D code, and especially when I have created the Python1 version, I have felt the code as too much complex for the simple operations it performs. So I have reduced the Python code, removing useless parts. The Python2 version is almost the shortest Python code that produces the same output (there are ways to shorten it a little more, but I am not doing code golf here, my purposes are different).&lt;br /&gt;&lt;br /&gt;The Python2 code is 67 lines long, while the Java3 is 481 lines including the comments.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;Python3&lt;br /&gt;&lt;br /&gt;Then I have replaced the random() and sample() with ones from the Python standard library, I have removed the printing code, and I have reorganized the code a little more.&lt;br /&gt;&lt;br /&gt;The result is short enough (21 nonempty lines) to be shown here too:&lt;br /&gt;&lt;pre&gt;
from random import random, sample

class Node:
    def __init__(self, value):
        self.value = value
        self.in_arcs = []

n_nodes, in_degree, n_steps = 15, 5, 5

h_nodes = [Node(random()) for i in xrange(n_nodes)]
e_nodes = [Node(random()) for i in xrange(n_nodes)]

def make_in_arcs(nodes, other_nodes, in_degree):
    for n1 in nodes:
        for n2 in sample(other_nodes, in_degree):
            n2.in_arcs.append((n1, random()))

make_in_arcs(h_nodes, e_nodes, in_degree)
make_in_arcs(e_nodes, h_nodes, in_degree)

def half_step(nodes):
    for n1 in nodes:
        for n2, weight in n1.in_arcs:
            n1.value -= weight * n2.value

for i in xrange(n_steps):
    half_step(e_nodes)
    half_step(h_nodes)
&lt;/pre&gt;&lt;br /&gt;This code shows the essential, and for me it's much simpler to follow and understand. This code may be conveted to C/D again, if necessary. The original C code was harder to understand, and much more complex. Removing the noise and useless parts allows me to understand the algorithm better, this is a simple algorithm. Even if you don't understand this code immediately, the complexity left is necessary, it's not spurious. Generally good programs aren't the clever and complex ones, but ones that look "obvious". This Python code shows that lot of the complexity of the original Java code was spurious.&lt;br /&gt;&lt;br /&gt;------------------------------------&lt;br /&gt;&lt;br /&gt;Python4&lt;br /&gt;&lt;br /&gt;This is similar to the Python3 version, I have just encoded a node in a simpler way, using a single list. The first item is the "value" and all the following ones are pairs of node-weight. This code is just 17 nonempty lines long. For me Python3 version is more readable.&lt;br /&gt;&lt;br /&gt;------------------------------------</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">TDPL Update</title>
		<link href="http://dblog.aldacron.net/2009/10/25/tdpl-update/" />
		<id>http://dblog.aldacron.net/?p=681</id>
		<updated>2009-10-25T10:22:45+00:00</updated>
		<content type="html">Andrei has passed the 100,000 word mark on his forthcoming book, The D Programming Language
Congrats, Andrei!&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=Hh3z4GkAwO4:A2gw0otjr_8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=Hh3z4GkAwO4:A2gw0otjr_8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=Hh3z4GkAwO4:A2gw0otjr_8:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=Hh3z4GkAwO4:A2gw0otjr_8:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">LLVM 2.6</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/ekRpmzoNBkg/33a6d647" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/33a6d647</id>
		<updated>2009-10-24T18:30:41+00:00</updated>
		<content type="html">&lt;p&gt;Just in case you're not that well informed, &lt;a href="http://www.nondot.org/sabre/" class="reference external"&gt;Chris Lattner&lt;/a&gt; has just
&lt;a href="http://permalink.gmane.org/gmane.comp.compilers.llvm.announce/23" class="reference external"&gt;announced&lt;/a&gt; the &lt;a href="http://llvm.org/releases/download.html#2.6" class="reference external"&gt;release&lt;/a&gt; of &lt;a href="http://llvm.org/" class="reference external"&gt;LLVM&lt;/a&gt; &lt;a href="http://llvm.org/releases/2.6/docs/ReleaseNotes.html" class="reference external"&gt;2.6&lt;/a&gt;. Enjoy!&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/ekRpmzoNBkg" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/10/21/what-does-haskell-have-to-do-with-c/" />
		<id>http://bartoszmilewski.wordpress.com/?p=1045</id>
		<updated>2009-10-21T23:02:33+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;If you want to understand C++ template metaprogramming (TMP) you have to know functional programming. Seriously. I want you to think of TMP as maximally obfuscated (subset of) Haskell, and I&amp;#8217;ll illustrate this point by point. If you don&amp;#8217;t know Haskell, don&amp;#8217;t worry, I&amp;#8217;ll explain the syntax as I go. &lt;/p&gt;
&lt;p&gt;The nice thing about single-paradigm languages like Haskell is that they have very simple syntax (think of Lisp that does everything with just a bunch of parentheses). I will start the Haskell-C++TMP mapping with basics, like functions and recursion, but I&amp;#8217;ll try to cover a lot more, including higher-order functions, pattern matching, list comprehension (did you know it was expressible in C++?), and more. &lt;/p&gt;
&lt;p&gt;Keep in mind that my Haskell examples are runtime functions operating on runtime data whereas their C++ TMP equivalents are compile-time templates operating mostly on types. Operation on types are essential in providing correct and efficient implementations of parametrized classes and functions. &lt;/p&gt;
&lt;p&gt;By necessity the examples are simple, but the same mapping may be applied to much more complex templates from the C++ Standard Library and Boost. As a bonus, I&amp;#8217;ll also explain the hot new thing, variadic templates.&lt;/p&gt;
&lt;h2&gt;Functional Approach to Functions&lt;/h2&gt;
&lt;p&gt;How do you implement useful functions if you don&amp;#8217;t have mutable variables, &lt;var&gt;if&lt;/var&gt; statements, or loops? To a C++ programmer that might seem like an impossible task. But that&amp;#8217;s the reality of C++ compile-time language that forms the basis of TMP. Functional programming to the rescue! &lt;/p&gt;
&lt;p&gt;As a warm-up, let&amp;#8217;s see how Haskell implements a simple function, the factorial:&lt;/p&gt;
&lt;pre&gt;fact 0 = 1
fact n = n * fact (n - 1)&lt;/pre&gt;
&lt;p&gt;The first line states that the factorial of zero is one. The second line defines factorial for a non-zero argument, n (strictly speaking it only works for positive non-zero arguments). It does it using recursion: factorial of &lt;var&gt;n&lt;/var&gt; is equal to &lt;var&gt;n&lt;/var&gt; times the factorial of &lt;var&gt;n-1&lt;/var&gt;. The recursion stops when &lt;var&gt;n&lt;/var&gt; is equal to zero, in which case the first definition kicks in. Notice that the definition of the function &lt;var&gt;fact&lt;/var&gt; is split into two sub-definitions. So when you call:&lt;/p&gt;
&lt;pre&gt;fact 4&lt;/pre&gt;
&lt;p&gt;the first definition is looked up first and, if it doesn&amp;#8217;t match the argument (which it doesn&amp;#8217;t), the second one comes into play. This is the simplest case of &lt;i&gt;pattern matching&lt;/i&gt;: 4 doesn&amp;#8217;t match the &amp;#8220;pattern&amp;#8221; 0, but it matches the pattern &lt;var&gt;n&lt;/var&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s almost &lt;i&gt;exactly&lt;/i&gt; the same code expressed in C++ TMP:&lt;/p&gt;
&lt;pre&gt;template&lt;span&gt;&amp;lt;int n&amp;gt;&lt;/span&gt; struct
&lt;span&gt;fact&lt;/span&gt; {
    static const int value = &lt;span&gt;n * fact&amp;lt;n - 1&amp;gt;&lt;/span&gt;::value;
};

template&amp;lt;&amp;gt; struct
&lt;span&gt;fact&amp;lt;0&amp;gt;&lt;/span&gt; { // specialization for n = 0
    static const int value = &lt;span&gt;1&lt;/span&gt;;
};&lt;/pre&gt;
&lt;p&gt;You might notice how the horrible syntax of C++ TMP obscures the simplicity and elegance of this code. But once you are equipped with the C++/Haskell decoder ring, things become a lot clearer. &lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s analyze this code. Just like in Haskell, there are two definitions of &lt;var&gt;fact&lt;/var&gt;, except that their order is inverted. This is because C++ requires template specialization to follow the template&amp;#8217;s general definition (or declaration, as we&amp;#8217;ll see later). The pattern matching of arguments in C++ does not follow the order of declarations but rather is based on &amp;#8220;best match&amp;#8221;. If you instantiate the template with argument zero:&lt;/p&gt;
&lt;pre&gt;cout &amp;lt;&amp;lt; "Factorial of 0 = " &amp;lt;&amp;lt; fact&amp;lt;0&amp;gt;::value &amp;lt;&amp;lt; endl;&lt;/pre&gt;
&lt;p&gt;the second pattern, &lt;var&gt;fact&amp;lt;0&amp;gt;&lt;/var&gt;, is a better fit. Otherwise the first one, &lt;var&gt;&amp;lt;int n&amp;gt;&lt;/var&gt;, is used.&lt;/p&gt;
&lt;p&gt;Notice also the weird syntax for &amp;#8220;function call&amp;#8221;&lt;/p&gt;
&lt;pre&gt;fact&amp;lt;n&amp;gt;::value&lt;/pre&gt;
&lt;p&gt;and for the &amp;#8220;return statement&amp;#8221;&lt;/p&gt;
&lt;pre&gt;static const int value = n * fact&amp;lt;n - 1&amp;gt;::value;&lt;/pre&gt;
&lt;p&gt;This all makes sense if you look at templates as definitions of parameterized types, which was their initial purpose in C++. In that interpretation, we are defining a &lt;var&gt;struct&lt;/var&gt; called &lt;var&gt;fact&lt;/var&gt;, parameterized by an integer &lt;var&gt;n&lt;/var&gt;, whose sole member is a static const integer called &lt;var&gt;value&lt;/var&gt;. Moreover, this template is specialized for the case of &lt;var&gt;n&lt;/var&gt; equal zero. &lt;/p&gt;
&lt;p&gt;Now I want you to forget about what I just said and put on the glasses which make the C++ code look like the corresponding Haskell code. &lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s another example&amp;#8211;this time of a predicate (a function returning a Boolean):&lt;/p&gt;
&lt;pre&gt;is_zero 0 = True
is_zero x = False&lt;/pre&gt;
&lt;p&gt;Let&amp;#8217;s spice it up a little for C++ and define a predicate on types rather than integers. The following compile-time function returns &lt;var&gt;true&lt;/var&gt; only when the type &lt;var&gt;T&lt;/var&gt; is a pointer:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class T&amp;gt; struct
&lt;span&gt;isPtr&lt;/span&gt; {
    static const bool value = false;
};

template&amp;lt;class U&amp;gt; struct
&lt;span&gt;isPtr&amp;lt;U*&amp;gt;&lt;/span&gt; {
    static const bool value = true;
};&lt;/pre&gt;
&lt;p&gt;This time the actual argument to &lt;var&gt;isPtr&lt;/var&gt; is first matched to the more specialized pattern, &lt;var&gt;U*&lt;/var&gt; and, if it fails, the general pattern is used. &lt;/p&gt;
&lt;p&gt;We can add yet another specialization, which will pattern-match a const pointer:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class U&amp;gt; struct
&lt;span&gt;isPtr&amp;lt;U * const&amp;gt;&lt;/span&gt; {
    static const bool value = true;
};&lt;/pre&gt;
&lt;p&gt;These types of type predicates may be, for instance, used to select more flexible and efficient implementations of parameterized containers. Think of the differences between a vector of values vs. a vector of pointers.&lt;/p&gt;
&lt;h2&gt;Lists&lt;/h2&gt;
&lt;p&gt;The basic data structure in functional languages is the list. Haskell&amp;#8217;s lists are introduced using square brackets. For instance, a list of three numbers, 1, 2, 3, looks like:&lt;/p&gt;
&lt;pre&gt;[1, 2, 3]&lt;/pre&gt;
&lt;p&gt;List processing in functional languages follows the standard pattern: a list is split into &lt;var&gt;head&lt;/var&gt; and &lt;var&gt;tail&lt;/var&gt;, an operation is performed on the head, and the tail is processed using recursion. The splitting is done by pattern matching: the Haskell pattern being &lt;var&gt;(head:tail)&lt;/var&gt; (to be precise, the colon in parentheses represents the &lt;var&gt;cons&lt;/var&gt; operation&amp;#8211;the creation of a list by prepending an element to an existing list). &lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a simple function, &lt;var&gt;count&lt;/var&gt;, that calculates the length of a list:&lt;/p&gt;
&lt;pre&gt;count [] = 0
count (head:tail) = 1 + count tail&lt;/pre&gt;
&lt;p&gt;The first pattern, [], matches an empty list; the second a non-empty one. Notice that a function call in Haskell doesn&amp;#8217;t use parentheses around arguments, so &lt;var&gt;count tail&lt;/var&gt; is interpreted as a call to &lt;var&gt;count&lt;/var&gt; with the argument &lt;var&gt;tail&lt;/var&gt;.&lt;/p&gt;
&lt;p&gt;Before C++0x, TMP was severely crippled by the lack of a list primitive. People used separate definitions for a list of zero, one, two, etc.,  elements, and even used special macros to define them. This is no longer true in C++0x, thanks to &lt;i&gt;variadic templates&lt;/i&gt; and &lt;i&gt;template parameter packs&lt;/i&gt;. Here&amp;#8217;s our Haskel &lt;var&gt;count&lt;/var&gt; translated into C++ TMP:&lt;/p&gt;
&lt;pre&gt;// Just a declaration
template&amp;lt;class... list&amp;gt; struct
&lt;span&gt;count&lt;/span&gt;;

template&amp;lt;&amp;gt; struct
&lt;span&gt;count&amp;lt;&amp;gt;&lt;/span&gt; {
    static const int value = 0;
};

template&amp;lt;class head, class... tail&amp;gt; struct
&lt;span&gt;count&amp;lt;head, tail...&amp;gt;&lt;/span&gt; {
    static const int value = 1 + count&amp;lt;tail...&amp;gt;::value;
};&lt;/pre&gt;
&lt;p&gt;First we have a declaration (not a definition) of the template &lt;var&gt;count&lt;/var&gt; that takes a variable number of type parameters (the keyword &lt;var&gt;class&lt;/var&gt; or &lt;var&gt;typename&lt;/var&gt; introduces a type parameter). They are packed into a template parameter pack, &lt;var&gt;list&lt;/var&gt;. &lt;/p&gt;
&lt;p&gt;Once this general declaration is visible, specializations may follow in any order. I arranged them to follow the Haskell example. The first one matches the empty list and returns zero. The second one uses the pattern, &lt;var&gt;&amp;lt;head, tail&amp;#8230;&amp;gt;&lt;/var&gt;. This pattern will match any non-empty list and split it into the &lt;var&gt;head&lt;/var&gt; and the (possibly empty) &lt;var&gt;tail&lt;/var&gt;. &lt;/p&gt;
&lt;p&gt;To &amp;#8220;call&amp;#8221; a variadic template, you initiate it with an arbitrary number of arguments and retrieve its member, &lt;var&gt;value&lt;/var&gt;, e.g.,&lt;/p&gt;
&lt;pre&gt;int n = count&amp;lt;int, char, long&amp;gt;::value; // returns 3&lt;/pre&gt;
&lt;p&gt;A few words about variadic templates: A variadic template introduces a template parameter pack using the notation &lt;var&gt;class&amp;#8230; pack&lt;/var&gt; (or &lt;var&gt;int&amp;#8230; ipack&lt;/var&gt;, etc&amp;#8230;). The only thing you may do with a pack is to expand it and pass to another variadic template. The expansion is done by following the name of the pack with three dots, as in &lt;var&gt;tail&amp;#8230;&lt;/var&gt;. You&amp;#8217;ll see more examples later.&lt;/p&gt;
&lt;p&gt;Variadic templates have many applications such as type-safe printf, tuples (objects that store an arbitrary number of differently typed arguments), variants, and many more. &lt;/p&gt;
&lt;h2&gt;Higher-Order Functions and Closures&lt;/h2&gt;
&lt;p&gt;The real power of functional programming comes from treating functions as first class citizens. It means that you may pass functions to other functions and return functions from functions. Functions operating on functions are called higher-order functions. Surprisingly, it seems like compile-time C++ has better support for higher-order functions than run-time C++.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s start with a Haskell example. I want to define a function that takes two predicate functions and returns another predicate function that combines the two using logical &lt;var&gt;OR&lt;/var&gt;. Here it is in Haskell:&lt;/p&gt;
&lt;pre&gt;or_combinator f1 f2 =
    &amp;lambda; x -&amp;gt; (f1 x) || (f2 x)&lt;/pre&gt;
&lt;p&gt;The &lt;var&gt;or_combinator&lt;/var&gt; returns an anonymous function (the famous &amp;#8220;lambda&amp;#8221;) that takes one argument, &lt;var&gt;x&lt;/var&gt;, calls both &lt;var&gt;f1&lt;/var&gt; and &lt;var&gt;f2&lt;/var&gt; with it, and returns the logical &lt;var&gt;OR&lt;/var&gt; of the two results. The return value of &lt;var&gt;or_combinator&lt;/var&gt; is this freshly constructed function. I can then call this function with an arbitrary argument. For instance, here I&amp;#8217;m checking if 2 is either zero or one (guess what, it isn&amp;#8217;t!):&lt;/p&gt;
&lt;pre&gt;(or_combinator is_zero is_one) 2&lt;/pre&gt;
&lt;p&gt;I put the parentheses around the function and its arguments for readability, although they are not strictly necessary. 2 is the argument to the function returned by &lt;var&gt;or_combinator&lt;/var&gt;. &lt;/p&gt;
&lt;p&gt;The lambda that&amp;#8217;s returned from &lt;var&gt;or_combinator&lt;/var&gt; is actually a closure. It &amp;#8220;captures&amp;#8221; the two arguments, &lt;var&gt;f1&lt;/var&gt; and &lt;var&gt;f2&lt;/var&gt; passed to &lt;var&gt;or_combinator&lt;/var&gt;. They may be used long after the call to &lt;var&gt;or_combinator&lt;/var&gt; has returned. &lt;/p&gt;
&lt;p&gt;It might take some getting used to it before you are comfortable with functions taking functions and returning functions, but it&amp;#8217;s much easier to learn this stuff in Haskell than in the obfuscated C++. Indeed, here&amp;#8217;s an almost direct translation of this example:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;template&amp;lt;class&amp;gt; class &lt;span&gt;f1&lt;/span&gt;, template&amp;lt;class&amp;gt; class &lt;span&gt;f2&lt;/span&gt;&amp;gt; struct
&lt;span&gt;or_combinator&lt;/span&gt; {
    template&amp;lt;class T&amp;gt; struct
    &lt;span&gt;lambda&lt;/span&gt; {
        static const bool value = &lt;span&gt;f1&amp;lt;T&amp;gt;&lt;/span&gt;::value &lt;span&gt;|| f2&amp;lt;T&amp;gt;&lt;/span&gt;::value;
    };
};&lt;/pre&gt;
&lt;p&gt;Since in the metalanguage a function is represented by a template, the template &lt;var&gt;or_combinator&lt;/var&gt; takes two such templates as arguments. It &amp;#8220;calls&amp;#8221; these templates using the standard syntax &lt;var&gt;f&amp;lt;T&amp;gt;::value&lt;/var&gt;. Actually, the &lt;var&gt;or_combinator&lt;/var&gt; doesn&amp;#8217;t call these functions. Instead it defines a new template, which I call &lt;var&gt;lambda&lt;/var&gt;, that takes the argument &lt;var&gt;T&lt;/var&gt; and calls those functions. This template acts like a closure&amp;#8211;it captures the two templates that are the arguments to &lt;var&gt;or_combinator&lt;/var&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s how you may use the &lt;var&gt;or_combinator&lt;/var&gt; to combine two tests, &lt;var&gt;isPtr&lt;/var&gt; and &lt;var&gt;isConst&lt;/var&gt; and apply the result to the type &lt;var&gt;const int&lt;/var&gt;:&lt;/p&gt;
&lt;pre&gt;std::cout
   &amp;lt;&amp;lt; "or_combinator&amp;lt;isPtr, isConst&amp;gt;::lambda&amp;lt;const int&amp;gt;::value = "
   &amp;lt;&amp;lt; or_combinator&amp;lt;isPtr, isConst&amp;gt;::lambda&amp;lt;const int&amp;gt;::value
   &amp;lt;&amp;lt; std::endl;&lt;/pre&gt;
&lt;p&gt;Such logical combinators are essential for predicate composability.&lt;/p&gt;
&lt;h2&gt;Higher-Order Functions Operating on Lists&lt;/h2&gt;
&lt;p&gt;Once you combine higher-order functions with lists you have a powerful functional language at your disposal. Higher-order functions operating on lists look very much like algorithms. Let me show you some classic examples. Here&amp;#8217;s the function (or algorithm), &lt;var&gt;all&lt;/var&gt;, that returns &lt;var&gt;true&lt;/var&gt; if and only if all elements of a list satisfy a given predicate.&lt;/p&gt;
&lt;pre&gt;all pred [] = True
all pred (head:tail) = (pred head) &amp;amp;&amp;amp; (all pred tail)&lt;/pre&gt;
&lt;p&gt;By now you should be familiar with all the techniques I used here, like pattern matching or list recursion. &lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the same code obfuscated by the C++ syntax:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;template&amp;lt;class&amp;gt; class predicate, class... list&amp;gt; struct
&lt;span&gt;all&lt;/span&gt;;

template&amp;lt;template&amp;lt;class&amp;gt; class predicate&amp;gt; struct
&lt;span&gt;all&amp;lt;predicate&amp;gt;&lt;/span&gt; {
    static const bool value = true;
};

template&amp;lt;
    template&amp;lt;class&amp;gt; class predicate,
    class head,
    class... tail&amp;gt; struct
&lt;span&gt;all&amp;lt;predicate, head, tail...&amp;gt;&lt;/span&gt; {
    static const bool value =
        predicate&amp;lt;head&amp;gt;::value
        &amp;amp;&amp;amp; all&amp;lt;predicate, tail...&amp;gt;::value;
};&lt;/pre&gt;
&lt;p&gt;Except for the initial declaration required by C++ there is a one-to-one paradigm match between the two implementations. &lt;/p&gt;
&lt;p&gt;Another useful algorithm, a veritable workhorse of functional programming, is &amp;#8220;fold right&amp;#8221; (together with it&amp;#8217;s dual partner, &amp;#8220;fold left&amp;#8221;). It folds a list while accumulating the results (that&amp;#8217;s why in runtime C++ this algorithm is called &amp;#8220;accumulate&amp;#8221;). Here&amp;#8217;s the Haskell implementation:&lt;/p&gt;
&lt;pre&gt;foldr f init [] = init
foldr f init (head:tail) =
    f head (foldr f init tail)&lt;/pre&gt;
&lt;p&gt;Function &lt;var&gt;f&lt;/var&gt;, which is the first argument to &lt;var&gt;foldr&lt;/var&gt;, takes two arguments, the current element of the list and the accumulated value. Its purpose is to process the element and incorporate the result in the accumulator. The new accumulated value is then returned. It is totally up to the client to decide what kind of processing to perform, how it is accumulated, and what kind of value is used. The second argument, &lt;var&gt;init&lt;/var&gt;, is the initial value for the accumulator.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s how it works: The result of &lt;var&gt;foldr&lt;/var&gt; is generated by acting with &lt;var&gt;f&lt;/var&gt; on the head of the list and whatever has been accumulated by processing the tail of the list. The algorithm recurses until the tail is empty, in which case it returns the initial value. At runtime this type of algorithm would make N recursive calls before starting to pop the stack and accumulate the results. &lt;/p&gt;
&lt;p&gt;For instance, &lt;var&gt;foldr&lt;/var&gt; may be used to sum the elements of a list (&lt;var&gt;so_far&lt;/var&gt; is the accumulator, which is initialized to zero):&lt;/p&gt;
&lt;pre&gt;add_it elem so_far = elem + so_far
sum_it lst = foldr add_it 0 lst&lt;/pre&gt;
&lt;p&gt;The accumulator function is &lt;var&gt;add_it&lt;/var&gt;. If, instead, I wanted to calculate the product of all elements, I&amp;#8217;d use a function &lt;var&gt;mult_it&lt;/var&gt; and the starting value of one. You get the idea.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the same algorithm in C++ TMP:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;template&amp;lt;class, int&amp;gt; class, int, class...&amp;gt; struct
&lt;span&gt;fold_right&lt;/span&gt;;

template&amp;lt;template&amp;lt;class, int&amp;gt; class f, int init&amp;gt; struct
&lt;span&gt;fold_right&amp;lt;f, init&amp;gt;&lt;/span&gt; {
    static const int value = init;
};

template&amp;lt;template&amp;lt;class, int&amp;gt; class f, int init, class head, class...tail&amp;gt; struct
&lt;span&gt;fold_right&amp;lt;f, init, head, tail...&amp;gt;&lt;/span&gt; {
    static const int value = f&amp;lt;head, fold_right&amp;lt;f, init, tail...&amp;gt;::value&amp;gt;::value;
};&lt;/pre&gt;
&lt;p&gt;Once you understand the Haskell version, this complex code suddenly becomes transparent (if it doesn&amp;#8217;t, try squinting &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_wink.gif" alt=";-)" class="wp-smiley" /&gt;  ). &lt;/p&gt;
&lt;h2&gt;Lists of Numbers&lt;/h2&gt;
&lt;p&gt;Let&amp;#8217;s now switch to integers for a moment. Haskell defines a function &lt;var&gt;sum&lt;/var&gt; that adds all elements of a list:&lt;/p&gt;
&lt;pre&gt;sum [] = 0
sum (head:tail) = head + (sum tail)&lt;/pre&gt;
&lt;p&gt;We can do the same in C++ TMP (in five times as many lines of code):&lt;/p&gt;
&lt;pre&gt;template&amp;lt;int...&amp;gt; struct
&lt;span&gt;sum&lt;/span&gt;;

template&amp;lt;&amp;gt; struct
&lt;span&gt;sum&amp;lt;&amp;gt;&lt;/span&gt; {
    static const int value = 0;
};

template&amp;lt;int i, int... tail&amp;gt; struct
&lt;span&gt;sum&amp;lt;i, tail...&amp;gt;&lt;/span&gt; {
    static const int value = i + sum&amp;lt;tail...&amp;gt;::value;
};&lt;/pre&gt;
&lt;h2&gt;List Comprehension&lt;/h2&gt;
&lt;p&gt;Haskell has one more trick up its sleeve for operating on lists without explicit recursion. It&amp;#8217;s called &lt;i&gt;list comprehension&lt;/i&gt;. It&amp;#8217;s a way of defining new lists based on existing lists. The nomenclature and notation are borrowed from Set Theory, where you often encounter definitions such as: S is a set of elements, where&amp;#8230; Let&amp;#8217;s look at a simple Haskell example:&lt;/p&gt;
&lt;pre&gt;[x * x | x &amp;lt;- [3, 4, 5]]&lt;/pre&gt;
&lt;p&gt;This is a set (list) of elements &lt;var&gt;x * x&lt;/var&gt;, where &lt;var&gt;x&lt;/var&gt; is from the list &lt;var&gt;[3, 4, 5]&lt;/var&gt;. &lt;/p&gt;
&lt;p&gt;Remember our recursive definition of &lt;var&gt;count&lt;/var&gt;? Using list comprehension it&amp;#8217;s reduced to a one-liner:&lt;/p&gt;
&lt;pre&gt;count lst = sum [1 | x &amp;lt;- lst]&lt;/pre&gt;
&lt;p&gt;Here, we create a list of ones, one for each element of the list. Our result is the sum of those ones. To make this definition more amenable to translation into C++, let&amp;#8217;s define an auxiliary function &lt;var&gt;one&lt;/var&gt; that, for any argument &lt;var&gt;x&lt;/var&gt;, returns 1.&lt;/p&gt;
&lt;pre&gt;one x = 1&lt;/pre&gt;
&lt;p&gt;Here&amp;#8217;s the modified definition of &lt;var&gt;count&lt;/var&gt;:&lt;/p&gt;
&lt;pre&gt;count lst = sum [one x | x &amp;lt;- lst]&lt;/pre&gt;
&lt;p&gt;Now we are ready to convert this code to C++ TMP:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class T&amp;gt; struct
&lt;span&gt;one&lt;/span&gt; {
    static const int value = 1;
};

template&amp;lt;class... lst&amp;gt; struct
&lt;span&gt;count&lt;/span&gt; {
    static const int value = sum&amp;lt;one&amp;lt;lst&amp;gt;::value...&amp;gt;::value;
};&lt;/pre&gt;
&lt;p&gt;Here our list is stored in a template parameter pack, &lt;var&gt;lst&lt;/var&gt;. If we wanted to expand this pack, we&amp;#8217;d use the notation &lt;var&gt;lst&amp;#8230;&lt;/var&gt;, but that&amp;#8217;s not what&amp;#8217;s happening here. The ellipsis appears after the pattern containing the pack:&lt;/p&gt;
&lt;pre&gt;one&amp;lt;lst&amp;gt;::value...&lt;/pre&gt;
&lt;p&gt;Compare this with the equivalent Haskell:&lt;/p&gt;
&lt;pre&gt;[one x | x &amp;lt;- lst]&lt;/pre&gt;
&lt;p&gt;In C++, when the ellipsis follows a pattern that contains a pack, it&amp;#8217;s not the pack that&amp;#8217;s expanded, but the whole pattern is repeated for each element of the pack. Here, if our list were &lt;var&gt;&amp;lt;int, char, void*&amp;gt;&lt;/var&gt;, the pattern would be expanded to:&lt;/p&gt;
&lt;pre&gt;&amp;lt;one&amp;lt;int&amp;gt;::value, one&amp;lt;char&amp;gt;::value, one&amp;lt;void*&amp;gt;::value&amp;gt;&lt;/pre&gt;
&lt;p&gt;The subsequent call to &lt;var&gt;sum&lt;/var&gt; would be made with those arguments. &lt;/p&gt;
&lt;p&gt;Notice that a different positioning of the ellipsis would result in a completely different expansion. This pattern:&lt;/p&gt;
&lt;pre&gt;one&amp;lt;lst...&amp;gt;::value&lt;/pre&gt;
&lt;p&gt;would result in the call to &lt;var&gt;one&lt;/var&gt; with the list of types, which would be an error.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s another example of pattern expansion: a function that counts the number of pointers in a list of types:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class... lst&amp;gt; struct
&lt;span&gt;countPtrs&lt;/span&gt; {
    static const int value = sum&amp;lt;isPtr&amp;lt;lst&amp;gt;::value ...&amp;gt;::value;
};&lt;/pre&gt;
&lt;p&gt;In this case the pattern is:&lt;/p&gt;
&lt;pre&gt;isPtr&amp;lt;lst&amp;gt;::value ...&lt;/pre&gt;
&lt;p&gt;and it expands into a list of Booleans. (I&amp;#8217;m taking advantage of the fact that &lt;var&gt;false&lt;/var&gt; is zero and &lt;var&gt;true&lt;/var&gt; is one, when converted to integers.)&lt;/p&gt;
&lt;p&gt;You may find a more complex practical example in the Gregor, J&amp;auml;rvi, and Powell paper (see bibliography).&lt;/p&gt;
&lt;h2&gt;Continuations&lt;/h2&gt;
&lt;p&gt;List comprehension can be used to define some very useful higher-order functions. One of such functions is &lt;var&gt;map&lt;/var&gt;, which takes a list and applies a unary function to each element, resulting in a new list. You might be familiar with the runtime implementation of this algorithm in C++ STL under the name of &lt;var&gt;transform&lt;/var&gt;. This is what &lt;var&gt;map&lt;/var&gt; looks like in Haskell:&lt;/p&gt;
&lt;pre&gt;map f lst = [f x | x &amp;lt;- lst]&lt;/pre&gt;
&lt;p&gt;Here, &lt;var&gt;f&lt;/var&gt; is the unary function and &lt;var&gt;lst&lt;/var&gt; is the input list. You have to admire the terseness and elegance of this notation. &lt;/p&gt;
&lt;p&gt;The first impulse would be to translate it into C++ TMP as:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;template&amp;lt;class&amp;gt; class f, class... lst&amp;gt; struct
&lt;span&gt;map&lt;/span&gt; {
    typedef f&amp;lt;lst&amp;gt;... type;
};&lt;/pre&gt;
&lt;p&gt;This is surprisingly terse too. The problem is that it doesn&amp;#8217;t compile. As far as I know there is no way for a template to &amp;#8220;return&amp;#8221; a variable list of elements. In my opinion, this is a major language design flaw, but that&amp;#8217;s just me. &lt;/p&gt;
&lt;p&gt;There are several workarounds, none of them too exciting. One is to define a separate entity called a &lt;var&gt;typelist&lt;/var&gt; along the lines of:&lt;/p&gt;
&lt;pre&gt;template struct
&lt;span&gt;typelist&amp;lt;hd, tl...&amp;gt;&lt;/span&gt; {
    typedef hd head;
    typedef typelist&amp;lt;tl...&amp;gt; tail;
};&lt;/pre&gt;
&lt;p&gt;(As a matter of fact I have implemented typelists and related algorithms both in C++ and D.)&lt;/p&gt;
&lt;p&gt;Another approach is to use continuations. Template parameter packs cannot be returned, but they can be passed to variadic templates (after expansion). So how about defining an algorithm like &lt;var&gt;map&lt;/var&gt; to take one additional function that would consume the list that is the result of mapping? Such a function is often called a continuation, since it continues the calculation where normally one would return the result. First, let&amp;#8217;s do it in Haskell:&lt;/p&gt;
&lt;pre&gt;map_cont cont f lst = cont [f x | x &amp;lt;- lst]&lt;/pre&gt;
&lt;p&gt;The function &lt;var&gt;map_cont&lt;/var&gt; is just like &lt;var&gt;map&lt;/var&gt; except that it takes a continuation, &lt;var&gt;cont&lt;/var&gt;, and applies it to the result of mapping. We can test it by defining yet another implementation of &lt;var&gt;count&lt;/var&gt;:&lt;/p&gt;
&lt;pre&gt;count_cont lst = map_cont sum one lst&lt;/pre&gt;
&lt;p&gt;The continuation here is the function &lt;var&gt;sum&lt;/var&gt; that will be applied to the list produced by acting with function &lt;var&gt;one&lt;/var&gt; on the list &lt;var&gt;lst&lt;/var&gt;. Since this is quite a handful, let me rewrite it in a more familiar notation of runtime C++:&lt;/p&gt;
&lt;pre&gt;int map_cont(int (*cont)(list), int (*f)(int), list lst) {
    list tmp;
    for (auto it = lst.begin(); it != lst.end(); ++it)
        tmp.push_front(f(*it));
    return cont(tmp);
}&lt;/pre&gt;
&lt;p&gt;Now for the same thing in compile-time C++:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;template&amp;lt;class...&amp;gt; class cont,
         template&amp;lt;class&amp;gt; class f,
         class... lst&amp;gt; struct
&lt;span&gt;map_cont&lt;/span&gt; {
    static const int value =
        cont&amp;lt;typename f&amp;lt;lst&amp;gt;::type ...&amp;gt;::value;
};&lt;/pre&gt;
&lt;p&gt;It&amp;#8217;s a one-to-one mapping of Haskell code&amp;#8211;and it has very little in common with the iterative runtime C++ implementation. Also notice how loose the typing is in the TMP version as compared with the runtime version. The continuation is declared as a variadic template taking types, function &lt;var&gt;f&lt;/var&gt; is declared as taking a type, and the list is a variadic list of types. Nothing is said about return types, except for the constraints that &lt;var&gt;f&lt;/var&gt; returns a type (because &lt;var&gt;cont&lt;/var&gt; consumes a list of types) and &lt;var&gt;cont&lt;/var&gt; returns an &lt;var&gt;int&lt;/var&gt;. Actually, this last constraint can be relaxed if we turn integers into types&amp;#8211;a standard trick (hack?) in TMP:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;int n&amp;gt; struct
&lt;span&gt;Int&lt;/span&gt; {
    static const int value = n;
};&lt;/pre&gt;
&lt;p&gt;Loose typing&amp;#8211;or &amp;#8220;kinding,&amp;#8221; as it is called for types of types&amp;#8211;is an essential part of compile-time programming. In fact the popularity of the above trick shows that C++ kinding might be already too strong.&lt;/p&gt;
&lt;h2&gt;The D Digression&lt;/h2&gt;
&lt;p&gt;I&amp;#8217;m grateful to Andrei Alexandrescu for reviewing this post. Since he objected to the sentence, &amp;#8220;I&amp;#8217;m disappointed that the D programming language followed the same path as C++ rather than lead the way,&amp;#8221; I feel compelled to support my view with at least one example.  Consider various implementations of &lt;var&gt;all&lt;/var&gt;. &lt;/p&gt;
&lt;p&gt;In Haskell, beside the terse and elegant version I showed before:&lt;/p&gt;
&lt;pre&gt;all pred [] = True
all pred (head:tail) = (pred head) &amp;amp;&amp;amp; (all pred tail)&lt;/pre&gt;
&lt;p&gt;there is also a slightly more verbose one:&lt;/p&gt;
&lt;pre&gt;all pred list =
    if null list then True
    else pred (head list) &amp;amp;&amp;amp; all pred (tail list)&lt;/pre&gt;
&lt;p&gt;which translates better into D. The D version (taken from its standard library, Phobos) is not as short as Haskell&amp;#8217;s, but follows the same functional paradigm:&lt;/p&gt;
&lt;pre&gt;template allSatisfy(alias F, T...) {
    static if (T.length == 1)
    {
        alias F!(T[0]) &lt;span&gt;allSatisfy&lt;/span&gt;;
    }
    else
    {
        enum bool &lt;span&gt;allSatisfy&lt;/span&gt; = F!(T[0]) &amp;amp;&amp;amp; allSatisfy!(F, T[1 .. $]);
    }
}&lt;/pre&gt;
&lt;p&gt;It definitely beats C++, there&amp;#8217;s no doubt about it. There are some oddities about it though. Notice that the type tuple, &lt;var&gt;T&amp;#8230;&lt;/var&gt; gets the standard list treatment, but the split into the head and tail follows the array/slice notation. The head is &lt;var&gt;T[0]&lt;/var&gt; and the tail is an array slice, &lt;var&gt;T[1..$]&lt;/var&gt;. Instead of using &lt;var&gt;value&lt;/var&gt; for the return value, D uses the &amp;#8220;eponymous hack,&amp;#8221; as I call it. The template &amp;#8220;returns&amp;#8221; the value using its own name. It&amp;#8217;s a hack because it breaks down if you want to define the equivalent of &amp;#8220;local variable&amp;#8221; inside a template. For instance, the following code doesn&amp;#8217;t compile:&lt;/p&gt;
&lt;pre&gt;template allSatisfy(alias F, T...) {
    static if (T.length == 1)
    {
        alias F!(T[0]) allSatisfy;
    }
    else
    {
        &lt;span&gt;private enum bool tailResult = allSatisfy!(F, T[1..$]);&lt;/span&gt;
        enum bool allSatisfy = F!(T[0]) &amp;amp;&amp;amp; tailResult;
    }
}&lt;/pre&gt;
&lt;p&gt;This breaks one of the fundamental property of any language: decomposability. You want to be able to decompose your calculation into smaller chunks and then combine them together. Of course, you may still use decomposition if you don&amp;#8217;t use the eponymous hack and just call your return value &lt;var&gt;value&lt;/var&gt;. But that means modifying all the calling sites. &lt;/p&gt;
&lt;p&gt;By the way, this is how decomposition works in Haskell:&lt;/p&gt;
&lt;pre&gt;all2 pred [] = True;
all2 pred (head:tail) = (pred head) &amp;amp;&amp;amp; tailResult
    where tailResult = all2 pred tail&lt;/pre&gt;
&lt;p&gt;Anyway, the important point is that there is &lt;i&gt;no reason&lt;/i&gt; to force functional programming paradigm at compile-time. The following hypothetical syntax would be much easier for programmers who are used to imperative programming:&lt;/p&gt;
&lt;pre&gt;template allSatisfy(alias Pred, T...) {
    foreach(t; T)
        if (!Pred!(t))
            return false;
    return true;
}&lt;/pre&gt;
&lt;p&gt;In fact it&amp;#8217;s much closer to the parameterized runtime function proposed by Andrei:&lt;/p&gt;
&lt;pre&gt;bool all(alias pred, Range)(Range r) {
    foreach (e; r)
        if (!pred(e))
            return false;
    return true;
}&lt;/pre&gt;
&lt;p&gt;This is why I&amp;#8217;m disappointed that the D programming language followed the same path as C++ rather than lead the way.&lt;/p&gt;
&lt;h2&gt;Conclusions&lt;/h2&gt;
&lt;p&gt;I have argued that some familiarity with Haskell may be really helpful in understanding and designing templates in C++. You might ask why C++ chose such horrible syntax to do compile-time functional programming. Well, it didn&amp;#8217;t. The ability to do compile-time calculations in C++ was &lt;i&gt;discovered&lt;/i&gt; rather than built into the language. It was a very fruitful discovery, as the subsequent developments, especially the implementation of the Boost MPL, have shown. However, once the functional paradigm and its weird syntax took root in C++ TMP, it stayed there forever. I&amp;#8217;m aware of only one effort to rationalize C++ TMP by Daveed Vandevoorde in &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1471.pdf"&gt;Reflective Metaprogramming in C++&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;I have tested all code in this blog using the Hugs interpreter for Haskell and the GNU C++ compiler v. 4.4.1 with the special switch &lt;var&gt;-std=c++0x&lt;/var&gt;. The names I used in the blog might conflict with the standard definitions. For instance, Hugs defines its own &lt;var&gt;map&lt;/var&gt; and &lt;var&gt;foldr&lt;/var&gt;.&lt;/p&gt;
&lt;p&gt;If you want to learn more about template metaprogramming, I recommend two books:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Andrei Alexandrescu, Modern C++ Design&lt;/li&gt;
&lt;li&gt;David Abrahams and Aleksey Gurtvoy, C++ Template Metaprogramming&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The reference I used for variadic templates was the paper by &lt;a href="http://www.osl.iu.edu/~dgregor/cpp/variadic-templates.pdf"&gt;Douglas Gregor, Jaakko J&amp;auml;rvi, and Gary Powell&lt;/a&gt;&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/1045/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/1045/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/1045/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/1045/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/1045/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/1045/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/1045/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/1045/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/1045/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/1045/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=1045&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">vincenzoampolo7</title>
		<link href="http://goshawknest.wordpress.com/2009/10/20/funds-for-gdc/" />
		<id>http://goshawknest.wordpress.com/?p=80</id>
		<updated>2009-10-20T14:47:31+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;&lt;!--StartFragment--&gt;Today i received a very good mail which stated that what we are doing in developing gdc is appreciated.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;The mail is from &lt;a href="http://www.github.com/tomash/rudy"&gt;Tomasz Stachewicz&lt;/a&gt;, the developer of &lt;a href="http://blip.tv/file/2599266"&gt;RuDy&lt;/a&gt; project to enable and ease writing Ruby native extensions in D programming language.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;
&lt;p&gt;After congratulating for the work we are doing, he stated something new: &lt;strong&gt;&amp;#8220;Is there a book wishlist or donation account I could use to word my appreciation in a more material way?&lt;/strong&gt;&amp;#8220;&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&lt;span&gt;If i&amp;#8217;m not wrong (sorry i&amp;#8217;m not a native English speaker), he is asking for an account for a donation. I think that maybe he is not the only one which wants to give some founds to the gdc project&amp;#8230;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;Well&amp;#8230; If everybody agrees (well for now me, Michael and David Friedman, the ones which did work for gdc) i can get this moneys with paypal (or with one of the pay-for-feature websites). Moneys will be reserved to develop gdc in a issue/task basis (for porting gdc to lastest gcc you take X, for updating to dmd version Y you take Z and so on)&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;Of course i don&amp;#8217;t think that gdc is so famous to make a lot of people contribute to it, but i think that we should decide about this issue to allow&lt;/p&gt;
&lt;p&gt;people to support the gdc project.&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;
&lt;p&gt;This message is on the news.digitalmars.com NG too.&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/goshawknest.wordpress.com/80/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/goshawknest.wordpress.com/80/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/goshawknest.wordpress.com/80/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/goshawknest.wordpress.com/80/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/goshawknest.wordpress.com/80/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/goshawknest.wordpress.com/80/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/goshawknest.wordpress.com/80/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/goshawknest.wordpress.com/80/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/goshawknest.wordpress.com/80/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/goshawknest.wordpress.com/80/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=goshawknest.wordpress.com&amp;blog=6236053&amp;post=80&amp;subd=goshawknest&amp;ref=&amp;feed=1" /&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;/div&gt;</content>
		<author>
			<name>Vincenzo Ampolo</name>
			<uri>http://goshawknest.wordpress.com</uri>
		</author>
		<source>
			<title type="html">goshawk's digital nest » D</title>
			<subtitle type="html">researches, hacks, thoughts</subtitle>
			<link rel="self" href="http://goshawknest.wordpress.com/category/d/feed/" />
			<id>http://goshawknest.wordpress.com/category/d/feed/</id>
			<updated>2009-11-08T17:00:45+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">KLEE, automatically generating tests that achieve high coverage</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/c617wRX_-l4/-2bb897fd" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-2bb897fd</id>
		<updated>2009-10-20T11:20:51+00:00</updated>
		<content type="html">&lt;p&gt;This is the &lt;a href="http://llvm.org/pubs/2008-12-OSDI-KLEE.html" class="reference external"&gt;abstract&lt;/a&gt; of the &lt;a href="http://llvm.org/pubs/2008-12-OSDI-KLEE.pdf" class="reference external"&gt;paper&lt;/a&gt; describing &lt;a href="http://klee.llvm.org/" class="reference external"&gt;KLEE&lt;/a&gt;, a new &lt;a href="http://llvm.org/" class="reference external"&gt;LLVM&lt;/a&gt;
sub-project announced with the upcoming &lt;a href="http://llvm.org/docs/ReleaseNotes.html" class="reference external"&gt;2.6 release&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
We present a new symbolic execution tool, &lt;a href="http://klee.llvm.org/" class="reference external"&gt;KLEE&lt;/a&gt;, capable of automatically
generating tests that achieve high coverage on a diverse set of complex and
environmentally-intensive programs. We used &lt;a href="http://klee.llvm.org/" class="reference external"&gt;KLEE&lt;/a&gt; to thoroughly check all 89
stand-alone programs in the &lt;a href="http://www.gnu.org/" class="reference external"&gt;GNU&lt;/a&gt; &lt;a href="http://www.gnu.org/software/coreutils/" class="reference external"&gt;COREUTILS&lt;/a&gt; utility suite, which form the
core user-level environment installed on millions of Unix systems, and
arguably are the single most heavily tested set of open-source programs in
existence. &lt;a href="http://klee.llvm.org/" class="reference external"&gt;KLEE&lt;/a&gt;-generated tests achieve high line coverage — on average
over 90% per tool (median: over 94%) — and significantly beat the coverage
of the developers' own hand-written test suites. When we did the same for
75 equivalent tools in the &lt;a href="http://www.busybox.net/" class="reference external"&gt;BUSYBOX&lt;/a&gt; embedded system suite, results were even
better, including 100% coverage on 31 of them. We also used &lt;a href="http://klee.llvm.org/" class="reference external"&gt;KLEE&lt;/a&gt; as a bug
finding tool, applying it to 452 applications (over 430K total lines of
code), where it found 56 serious bugs, including three in &lt;a href="http://www.gnu.org/software/coreutils/" class="reference external"&gt;COREUTILS&lt;/a&gt; that
had been missed for over 15 years. Finally, we used &lt;a href="http://klee.llvm.org/" class="reference external"&gt;KLEE&lt;/a&gt; to cross-check
purportedly identical &lt;a href="http://www.busybox.net/" class="reference external"&gt;BUSYBOX&lt;/a&gt; and &lt;a href="http://www.gnu.org/software/coreutils/" class="reference external"&gt;COREUTILS&lt;/a&gt; utilities, finding functional
correctness errors and a myriad of inconsistencies.&lt;/blockquote&gt;
&lt;p&gt;I &lt;strong&gt;have&lt;/strong&gt; to try this...&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/c617wRX_-l4" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Slow allocation of D objects</title>
		<link href="http://leonardo-m.livejournal.com/89105.html" />
		<id>http://leonardo-m.livejournal.com/89105.html</id>
		<updated>2009-10-19T10:10:43+00:00</updated>
		<content type="html">Allocating objects in D language, usign the good and efficient LDC compiler, may seem slower than doing the same thing in C++, but the situation is a little more complex, so few examples can show what's going on.&lt;br /&gt;&lt;br /&gt;This is a syntetic C++ benchmark, it allocates an array of n pointers to Foo object, and then allocates the instances, that contain ten 32 bit integers:&lt;br /&gt;&lt;pre&gt;// C++ version 1, 0.46 s
#include "stdio.h"
#include "stdlib.h"

using namespace std;

class Foo {
    public:
        int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
        Foo(int, int, int, int, int, int, int, int, int, int);
};

Foo::Foo(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10):
  y1(x1), y2(x2), y3(x3), y4(x4), y5(x5), y6(x6), y7(x7), y8(x8), y9(x9), y10(x10) {}

int main(int argc, char *argv[]) {
    int n = (argc == 2) ? atoi(argv[1]) : 5;
    Foo* foos[n];

    for (int i = 0; i &amp;lt; n; i++)
        foos[i] = new Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);

    printf("%d %d %d\n", foos[n-1]-&amp;gt;y1, foos[n-1]-&amp;gt;y2, foos[n-1]-&amp;gt;y10);
    return 0;
}&lt;/pre&gt;&lt;br /&gt;This is an almost equivalent D code. I use printf and those imports are so hairy because this code is designed to work with both Phobos or Tango standard libraries, and with D1 and D2 languages:&lt;br /&gt;&lt;pre&gt;// D version 1, 0.89 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
} else {
    import std.c.stdio: printf;
    version (D_Version2) {
        import std.conv: to;
        alias to!(int, char[]) toInt;
    } else
        import std.conv: toInt;
}

class Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;

    this(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10) {
        y1 = x1;
        y2 = x2;
        y3 = x3;
        y4 = x4;
        y5 = x5;
        y6 = x6;
        y7 = x7;
        y8 = x8;
        y9 = x9;
        y10 = x10;
    }
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    Foo[] foos = new Foo[n];

    for (int i = 0; i &amp;lt; n; i++)
        foos[i] = new Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);

    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;Replacing in the C++ the class like this doesn't change the running time of the program:&lt;br /&gt;&lt;pre&gt;// piece of the C++ version 2, 0.47 s
class Foo {
    public:
        int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
        Foo(int, int, int, int, int, int, int, int, int, int);
};

Foo::Foo(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10) {
    y1 = x1;
    y2 = x2;
    y3 = x3;
    y4 = x4;
    y5 = x5;
    y6 = x6;
    y7 = x7;
    y8 = x8;
    y9 = x9;
    y10 = x10;
}&lt;/pre&gt;&lt;br /&gt;The running times on a Ubuntu running on VirtualBox, running on Vista 32 bit, running on a Celeron CPU, using LDC compiler based on DMD v1.045 and llvm 2.6 (Thu Sep 10 23:50:27 2009):&lt;br /&gt;&lt;pre&gt;Timings, n = 1_000_000, best of 3, seconds:
  C++ 1: 0.46  |#########                |
  C++ 2: 0.47  |#########                |
  D 1:   0.89  |##################       |
  D 2:   0.82  |################         |
  D 3:   0.87  |#################        |
  D 4:   0.46  |#########                |
  D 5:   0.46  |#########                |
  D 6:   1.22  |#########################|
  D 6b:  0.86  |#################        |
  D 7:   0.63  |############             |
  D 8:   0.71  |##############           |&lt;/pre&gt;&lt;br /&gt;I have compiled the C++ code with gcc V.4.3.3 with:&lt;br /&gt;g++ -Wall -O3 -s -fomit-frame-pointer -msse3 -march=native objbench1_cpp.cpp -o objbench1_cpp&lt;br /&gt;And the D code with:&lt;br /&gt;ldc -O5 -release -inline objbench1_d.d&lt;br /&gt;&lt;br /&gt;As you can see the D version is about twice slower than the C++ code, despite usually the LDC compiler is almost as efficient as GCC (LLVM is not able to perform some optimizations yet, like auto-vectorization, but things are already good and they will improve).&lt;br /&gt;&lt;br /&gt;D classes are different from C++ ones, D objects always contain a pointer to the virtual table (even if no virtual methods are present, it's used by the reflection and GC too) and a monitor, so on 32 bit systems they need 8 extra bytes. So we may try to remove such memory (and bookeeping) overhead using a struct (this version can be changed a little, so it works with Phobos of D2 too):&lt;br /&gt;&lt;pre&gt;// D version 2, 0.82 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
}

struct Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    
    Foo*[] foos = new Foo*[n];

    for (int i = 0; i &amp;lt; n; i++) {
        foos[i] = new Foo;
        *foos[i] = Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);  
    }
    
    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;But you can see the performance improves only a little, so the problem is elsewhere. I have had to use that two-line initialization because only in D2 language structs are allowed to have an explicit constructor.&lt;br /&gt;&lt;br /&gt;We can try allocating the pointer array on the stack but the performance gets a little worse:&lt;br /&gt;&lt;pre&gt;// D version 3, 0.87 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
    import tango.stdc.stdlib: alloca;
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
    import std.c.stdlib: alloca;
}

struct Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    Foo** ptr = cast(Foo**)alloca((Foo*).sizeof * n);
    Foo*[] foos = ptr[0 .. n];
    
    for (int i = 0; i &amp;lt; n; i++) {
        foos[i] = new Foo;
        *foos[i] = Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);  
    }

    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;A next step is to allocate the structs from the C heap, this time the performance is about the same as the C++ code, showing that the cause of the slowdown is the (not efficient yet) D Garbage Collector:&lt;br /&gt;&lt;pre&gt;// D version 4, 0.46 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
    import tango.stdc.stdlib: alloca, malloc;
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
    import std.c.stdlib: alloca, malloc;
}

struct Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    Foo** ptr = cast(Foo**)alloca((Foo*).sizeof * n);
    Foo*[] foos = ptr[0 .. n];
    
    for (int i = 0; i &amp;lt; n; i++) {
        foos[i] = cast(Foo*)malloc(Foo.sizeof);
        *foos[i] = Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);  
    }

    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;So we can restore the original allocation of the dynamic array of pointers, the performance improves a tiny bit (less than 0.01 s):&lt;br /&gt;&lt;pre&gt;// D version 5, 0.46 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
    import tango.stdc.stdlib: malloc;
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
    import std.c.stdlib: malloc;
}

struct Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    Foo*[] foos = new Foo*[n];
    
    for (int i = 0; i &amp;lt; n; i++) {
        foos[i] = cast(Foo*)malloc(Foo.sizeof);
        *foos[i] = Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);  
    }

    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;We may think that the problem is in the double initalization of the structs, it seems that's not the case, as the following code is the slowest, here I use uninitialized memory from the GC heap:&lt;br /&gt;&lt;pre&gt;// D version 6, 1.22 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
    import tango.core.Memory: GC;
    alias GC.malloc gcmalloc;
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
    import std.gc: gcmalloc = malloc;
}

struct Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    Foo*[] foos = new Foo*[n];
    
    for (int i = 0; i &amp;lt; n; i++) {
        foos[i] = cast(Foo*)gcmalloc(Foo.sizeof);
        *foos[i] = Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);  
    }

    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;I don't fully know why the performance of the version 6 is so low (if you have ideas please tell me), part of that lower performance comes from the GC that scans the memory of those structs. You can see it in the version 6b, where I have disabled the scanning of those memory blocks, there's indeed a significant performance improvement:&lt;br /&gt;&lt;pre&gt;// D version 6b, 0.86 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
    import tango.core.Memory: GC;
    alias GC.malloc gcmalloc;
    void hasNoPointers(void* p) {
        GC.setAttr(p, GC.BlkAttr.NO_SCAN);
    }
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
    import std.gc: gcmalloc = malloc, hasNoPointers;
}

struct Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    Foo*[] foos = new Foo*[n];

    for (int i = 0; i &amp;lt; n; i++) {
        foos[i] = cast(Foo*)gcmalloc(Foo.sizeof);
        hasNoPointers(foos[i]);
        *foos[i] = Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);
    }

    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;But even if the GC doesn't scan those memory blocks, it performs several operations anyway, so when you allocate many pieces of memory and you need performance, you may want to disable the GC (and enable it just after the allocation, here I have not added the enable(), but in your code you are supposed to put it), the performance is intermediate:&lt;br /&gt;&lt;pre&gt;// D version 7, 0.63 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
    import tango.core.Memory: GC;
    alias GC.disable disable;
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
    import std.gc: disable;
}

struct Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    disable();
    
    Foo*[] foos = new Foo*[n];

    for (int i = 0; i &amp;lt; n; i++) {
        foos[i] = new Foo;
        *foos[i] = Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);  
    }
    
    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;We can also go back ot the object-based version, with a further little reduction of performance:&lt;br /&gt;&lt;pre&gt;// D version 8, 0.71 s
version (Tango) {
    import tango.stdc.stdio: printf;
    import Integer = tango.text.convert.Integer;
    alias Integer.parse toInt;
    import tango.core.Memory: GC;
    alias GC.disable disable;
} else {
    import std.c.stdio: printf;
    import std.conv: toInt;
    import std.gc: disable;
}

class Foo {
    int y1, y2, y3, y4, y5, y6, y7, y8, y9, y10;

    this(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8, int x9, int x10) {
        y1 = x1;
        y2 = x2;
        y3 = x3;
        y4 = x4;
        y5 = x5;
        y6 = x6;
        y7 = x7;
        y8 = x8;
        y9 = x9;
        y10 = x10;
    }
}

void main(char[][] args) {
    int n = (args.length == 2) ? toInt(args[1]) : 5;
    disable();
    Foo[] foos = new Foo[n];

    for (int i = 0; i &amp;lt; n; i++)
        foos[i] = new Foo(i+1, i+2, i+3, i+4, i+5, i+6, i+7, i+8, i+9, i+10);

    printf("%d %d %d\n", foos[$-1].y1, foos[$-1].y2, foos[$-1].y10);
}&lt;/pre&gt;&lt;br /&gt;Having a garbage collector is handy, and sometimes safer too, but it has a price too (in the size of the binary too). D allows you to not use the GC when you need C++-like performance, but then you have to remember to manage and deallocate memory manually as in C, or you need to implement/use other forms or memory management as in C++ (and D allows the scope(exit) idiom too to deallocate memory when a scope ends). If the D language will get widespread, its GC will improve, restoring part of the lost performance.</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">pybugz, a python and command line interface to Bugzilla</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/mqZt-wtyoSI/-2a5a0f08" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-2a5a0f08</id>
		<updated>2009-10-16T11:14:48+00:00</updated>
		<content type="html">&lt;p&gt;Tired of the clumsy &lt;a href="http://www.bugzilla.org/" class="reference external"&gt;Bugzilla&lt;/a&gt; web interface? Meet &lt;a href="http://code.google.com/p/pybugz/" class="reference external"&gt;pybugz&lt;/a&gt;, a command line
interface for &lt;a href="http://www.bugzilla.org/" class="reference external"&gt;Bugzilla&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;An example workflow from the &lt;a href="http://github.com/ColdWind/pybugz/blob/master/README" class="reference external"&gt;README&lt;/a&gt; file:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$ bugz search "version bump" --assigned liquidx@gentoo.org

 * Using http://bugs.gentoo.org/ ..
 * Searching for "version bump" ordered by "number"
 101968 liquidx net-im/msnlib version bump
 125468 liquidx version bump for dev-libs/g-wrap-1.9.6
 130608 liquidx app-dicts/stardict version bump: 2.4.7

$ bugz get 101968

 * Using http://bugs.gentoo.org/ ..
 * Getting bug 130608 ..
Title : app-dicts/stardict version bump: 2.4.7
Assignee : liquidx@gentoo.org
Reported : 2006-04-20 07:36 PST
Updated : 2006-05-29 23:18:12 PST
Status : NEW
URL : http://stardict.sf.net
Severity : enhancement
Reporter : dushistov@mail.ru
Priority : P2
Comments : 3
Attachments : 1

[ATTACH] [87844] [stardict 2.4.7 ebuild]

[Comment #1] dushistov@----.ru : 2006-04-20 07:36 PST
...

$ bugz attachment 87844

 * Using http://bugs.gentoo.org/ ..
 * Getting attachment 87844
 * Saving attachment: "stardict-2.4.7.ebuild"

$ bugz modify 130608 --fixed -c "Thanks for the ebuild. Committed to
portage"
&lt;/pre&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/mqZt-wtyoSI" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">D and open development model</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/8dEUqawKimE/6cac01e1" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/6cac01e1</id>
		<updated>2009-10-15T17:09:23+00:00</updated>
		<content type="html">&lt;div class="warning"&gt;
&lt;p class="first admonition-title"&gt;Warning&lt;/p&gt;
&lt;p class="last"&gt;Long post ahead =)&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;I'm very glad that yesterday &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; had the first releases (&lt;a href="http://www.digitalmars.com/d/1.0/changelog.html#new1_050" class="reference external"&gt;DMD 1.050&lt;/a&gt; and
&lt;a href="http://www.digitalmars.com/d/2.0/changelog.html#new2_035" class="reference external"&gt;DMD 2.035&lt;/a&gt;) with a decent revision &lt;a href="http://www.dsource.org/projects/dmd/timeline?from=10%2F14%2F09&amp;daysback=2&amp;changeset=on" class="reference external"&gt;history&lt;/a&gt;.  It took some time to &lt;a href="http://www.walterbright.com/" class="reference external"&gt;Walter
Bright&lt;/a&gt; to understand how the open source development model works, and I think
he still has a lot more to learn, but I have some hope now about the future of
&lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Not much time ago, neither &lt;a href="http://www.dsource.org/projects/phobos" class="reference external"&gt;Phobos&lt;/a&gt;, &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; nor &lt;a href="http://www.dsource.org/projects/druntime" class="reference external"&gt;Druntime&lt;/a&gt; had revision control.
&lt;a href="http://www.dsource.org/projects/druntime" class="reference external"&gt;Druntime&lt;/a&gt; didn't even exist, making &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt; 1 split in two because of the &lt;a href="http://www.dsource.org/projects/phobos" class="reference external"&gt;Phobos&lt;/a&gt; vs
&lt;a href="http://www.dsource.org/projects/tango" class="reference external"&gt;Tango&lt;/a&gt; dichotomy. &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; back-end sources were not available either, and &lt;a href="http://www.walterbright.com/" class="reference external"&gt;Walter
Bright&lt;/a&gt; was the only person writing stuff (sometimes not because people didn't
want to, but because he was too &lt;a href="http://www.urbandictionary.com/define.php?term=anal+retentive" class="reference external"&gt;anal retentive&lt;/a&gt; to let them ;). It was
almost impossible to make patches back then (your only chance was hacking &lt;a href="http://bitbucket.org/goshawk/gdc" class="reference external"&gt;GDC&lt;/a&gt;,
which is pretty hard).&lt;/p&gt;
&lt;p&gt;Now I can say that &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt;, &lt;a href="http://www.dsource.org/projects/phobos" class="reference external"&gt;Phobos&lt;/a&gt; and &lt;a href="http://www.dsource.org/projects/druntime" class="reference external"&gt;Druntime&lt;/a&gt; have full source availability
(&lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; back-end is not &lt;a href="http://en.wikipedia.org/wiki/Free_and_open_source_software" class="reference external"&gt;free/libre&lt;/a&gt; though), almost all the parts of &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; have
the sources published under a source control system. The &lt;em&gt;core&lt;/em&gt; team has been
expanded and even when &lt;a href="http://www.walterbright.com/" class="reference external"&gt;Walter Bright&lt;/a&gt; is still in charge, at least
3 developers are now very committed to &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt;: &lt;a href="http://erdani.com/" class="reference external"&gt;Andrei Alexandrescu&lt;/a&gt; (in charge
of &lt;a href="http://www.dsource.org/projects/phobos" class="reference external"&gt;Phobos&lt;/a&gt;), &lt;a href="http://www.dsource.org/projects/tango/wiki/SeanK" class="reference external"&gt;Sean Kelly&lt;/a&gt; (in charge of &lt;a href="http://www.dsource.org/projects/druntime" class="reference external"&gt;Druntime&lt;/a&gt;) and &lt;a href="http://prowiki.org/wiki4d/wiki.cgi?DonClugston" class="reference external"&gt;Don Clugston&lt;/a&gt;
(squashing &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; bugs at full speed, specially in the back-end). Other people
are contributing patches in a regular basis. There were about &lt;a href="http://d.puremagic.com/issues/buglist.cgi?keywords=patch&amp;chfieldto=2009-03-03&amp;query_format=advanced&amp;keywords_type=allwords&amp;chfieldfrom=2000-03-03&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;bug_status=RESOLVED&amp;bug_status=VERIFIED&amp;bug_status=CLOSED" class="reference external"&gt;72 patches&lt;/a&gt;
submitted to &lt;a href="http://d.puremagic.com/issues/" class="reference external"&gt;bugzilla&lt;/a&gt; before &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; was distributed with full source (&lt;strong&gt;72&lt;/strong&gt;
patches in &lt;strong&gt;~10 years&lt;/strong&gt;) , since then, &lt;a href="http://d.puremagic.com/issues/buglist.cgi?keywords=patch&amp;chfieldto=Now&amp;query_format=advanced&amp;keywords_type=allwords&amp;chfieldfrom=2009-03-03&amp;bug_status=NEW&amp;bug_status=ASSIGNED&amp;bug_status=REOPENED&amp;bug_status=RESOLVED&amp;bug_status=VERIFIED&amp;bug_status=CLOSED" class="reference external"&gt;206 patches&lt;/a&gt; were submitted (that
is, &lt;strong&gt;206&lt;/strong&gt; patches in less than &lt;strong&gt;8 months&lt;/strong&gt;).&lt;/p&gt;
&lt;p&gt;But even with this great improvement, there is much left to do yet (and I'm
talking &lt;strong&gt;only&lt;/strong&gt; about the development model). This is a small list of what
I think it's necessary to keep moving to a more open development model:&lt;/p&gt;
&lt;div id="releases" class="section"&gt;
&lt;h1&gt;Releases&lt;/h1&gt;
&lt;p&gt;The release process should be improved. Me and other people are suggesting
release candidates. This will allow people to test the new releases to find any
regressions. As things are now, releases are not much different from a nightly
build, except that you don't have one available every night :).  People get
very frustrated when downloading a new version of the compiler and things stop
working, and this holds back front-end updates in other compilers, like &lt;a href="http://www.dsource.org/projects/ldc" class="reference external"&gt;LDC&lt;/a&gt;
(which is frozen at &lt;a href="http://www.digitalmars.com/d/1.0/changelog.html#new1_045" class="reference external"&gt;1.045&lt;/a&gt; because of the &lt;a href="http://d.puremagic.com/issues/buglist.cgi?query_format=advanced&amp;field0-0-0=content&amp;bug_severity=regression&amp;version=1.046&amp;version=1.047&amp;version=1.048&amp;version=1.049&amp;version=1.050&amp;type0-0-0=allwords" class="reference external"&gt;regressions&lt;/a&gt; found in the next
5 versions).&lt;/p&gt;
&lt;p&gt;I think &lt;a href="http://www.walterbright.com/" class="reference external"&gt;Walter Bright&lt;/a&gt; is suffering from &lt;em&gt;premature releasing&lt;/em&gt; too. Releases
comes from nowhere, when nobody expects them. Nobody knows when a new compiler
version will be released.  I think that hurts the language reliability.&lt;/p&gt;
&lt;p&gt;I think the releases should be more predictable. A release schedule (even when
not very accurate, like in many other open source projects) gives you some
peace of mind.&lt;/p&gt;
&lt;/div&gt;
&lt;div id="peer-review" class="section"&gt;
&lt;h1&gt;Peer review&lt;/h1&gt;
&lt;p&gt;Even when commits are fairly small now in &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt;, I think they are far from
ideal. Is very common to see unrelated changes in a commit (the classic example
is the compiler version number being bumped in an bug fix). See &lt;a href="http://www.dsource.org/projects/dmd/changeset/214" class="reference external"&gt;revision
214&lt;/a&gt; for example: the compiler version is bumped and there are some changes
to the new JSON output, totally unrelated to &lt;a href="http://d.puremagic.com/issues/show_bug.cgi?id=3401" class="reference external"&gt;bug 3401&lt;/a&gt;, which is supposed to
fix; or &lt;a href="http://www.dsource.org/projects/dmd/changeset/213" class="reference external"&gt;revision 213&lt;/a&gt;, which &lt;em&gt;announces&lt;/em&gt; the release of &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; 1.050 and &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt;
2.035, introducing a bunch of changes that who knows what are supposed to do
(well, they look like the introduction of the new type &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;T[new]&lt;/span&gt;&lt;/tt&gt;, but that's
not even documented in the release changelog :S).  This is bad for several
reasons:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Reviewing a patch with unrelated changes is hard.&lt;/li&gt;
&lt;li&gt;If you want to fold in a individual patch (let's say, &lt;a href="http://www.dsource.org/projects/ldc" class="reference external"&gt;LDC&lt;/a&gt; guys want to fold
a bug fix), you have a lot of junk to take care of.&lt;/li&gt;
&lt;li&gt;If you want to do some sort of &lt;a href="http://jbowes.wordpress.com/2007/02/18/git-bisect-a-practical-example-with-yum/" class="reference external"&gt;bisection&lt;/a&gt; to find a regression, you still
have to figure out which is the group of related changes that introduced the
regression.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I'm sure there are more...&lt;/p&gt;
&lt;p&gt;Commit messages lacks a good description of the problem and the solution. Most
commit messages in &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; are "bugzilla N". You have to go to the bugzilla bug to
know what's all about. For example, Don's patches usually comes with very good
and juicy information about the bug causes and why the patch fixes it (see an
&lt;a href="http://d.puremagic.com/issues/show_bug.cgi?id=1969#c2" class="reference external"&gt;example&lt;/a&gt;). &lt;strong&gt;That&lt;/strong&gt; is a good commit message. You can learn a lot about the
code by reading well commented patches, which can lead to more contributions in
the future.&lt;/p&gt;
&lt;p&gt;Commits in &lt;a href="http://www.dsource.org/projects/phobos" class="reference external"&gt;Phobos&lt;/a&gt; can be even worse. The commits with a message "bugzilla N"
are usually the good ones.  There are &lt;a href="http://www.dsource.org/projects/phobos/search?q=minor&amp;changeset=on" class="reference external"&gt;56 commits&lt;/a&gt; that have "minor" as the
commit message. Yes, just "minor". That's pretty useless, it's very hard to
review a patch when you don't know what is supposed to do. Commit messages are
the base of peer reviewing, and peer reviewing is the base for high quality
code.&lt;/p&gt;
&lt;p&gt;So I think that &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt; developers should focus a lot more in commit message. I know
it can sound silly at first, but I think I would be a huge gain with too little
effort.&lt;/p&gt;
&lt;p&gt;Besides this, commits should be mailed to a &lt;a href="http://www.digitalmars.com/NewsGroup.html" class="reference external"&gt;newsgroup&lt;/a&gt; or mailing list to easy
peer review. Now it's a little hard to make comments about a commit, you have
to post the comment in the &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt; &lt;a href="http://www.digitalmars.com/NewsGroup.html" class="reference external"&gt;newsgroup&lt;/a&gt; or make the comment by personal e-mail
to the author. The former is not that bad but it's not easy to include context
and people reading the comment will probably have to open a browser and search
for the commented commit. This clearly make peer reviewing more difficult when
the ideal would be to encourage it. The private mail is simply wrong because
other people can't see the comments.&lt;/p&gt;
&lt;/div&gt;
&lt;div id="source-control-and-versioning" class="section"&gt;
&lt;h1&gt;Source control and versioning&lt;/h1&gt;
&lt;p&gt;This one is tightly related to the previous two topics. Using a good &lt;a href="http://en.wikipedia.org/wiki/Distributed_revision_control" class="reference external"&gt;DVCS&lt;/a&gt; can
make help a lot too. &lt;a href="http://subversion.tigris.org/" class="reference external"&gt;Subversion&lt;/a&gt; has a lot of problems with branching, which
makes releases harder too (as having a branch for each release is very
painful). Is bad for commit messages too, because there is no real difference
in branches and directories, so know every commit is duplicated (both changes
for &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; 1 and 2 are included). It's not easy to cherry-pick single commits
either, and you can't fix you commits if you messed up, which leads to a lot of
commits of the style "Woops! Fix the typo in the previous commit.".&lt;/p&gt;
&lt;p&gt;I'm sure both the release process and peer reviewing can be greatly improved by
using a better &lt;a href="http://en.wikipedia.org/wiki/Distributed_revision_control" class="reference external"&gt;DVCS&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Easy branching can also lead to a more fast evolving and reliable language.
Yes, both are possible with branches. Now there are 2 branches: stable (D1) and
experimental (D2). D1 is almost frozen and people is seeing less and less
interest on it as it goes old, and D2 is too unstable for real use. Having some
intermediate can be really helpful. For example, it has been announced that the
concurrency model proposed by &lt;a href="http://bartoszmilewski.wordpress.com/" class="reference external"&gt;Bartosz Milewski&lt;/a&gt; will be not part of D2
because there is not enough time to implement it, since D2 should be release
fairly soon as &lt;a href="http://erdani.com/" class="reference external"&gt;Andrei Alexandrescu&lt;/a&gt; is writing a &lt;a href="http://www.amazon.com/exec/obidos/ASIN/0321635361/modecdesi-20" class="reference external"&gt;book&lt;/a&gt; that has a deadline
and the language has to be finalized by the time the book is published.&lt;/p&gt;
&lt;p&gt;So concurrency (as AST macros) are delayed to D3. D2 is more than 2 years old,
so one should expect that D3 will be not available in less than 5 years from
now (assuming D2 would take 2.5 years and D3 would take the same). This might
be too much time.&lt;/p&gt;
&lt;p&gt;I think the language should adopt a model closer to &lt;a href="http://www.python.org/" class="reference external"&gt;Python&lt;/a&gt;, where a minor
language version (with backward compatible improvements) is release every
1 ~ 1.5 years. Last mayor version took about 8 years, but considering how many
new features &lt;a href="http://www.python.org/" class="reference external"&gt;Python&lt;/a&gt; included in minor versions that's not a big issue. The
last mayor version was mostly a clean up of old stuff/nasty stuff, not huge
changes to the language.&lt;/p&gt;
&lt;/div&gt;
&lt;div id="licensing" class="section"&gt;
&lt;h1&gt;Licensing&lt;/h1&gt;
&lt;p&gt;I think the &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; back-end should have a better license. Personal use is simply
not enough for a reference implementation of a language that wants to hit
mainstream. If you plan to do business with it, not being able to patch the
compiler if you need to and distribute it is not an option.&lt;/p&gt;
&lt;p&gt;This is for the sake of &lt;a href="http://www.dsource.org/projects/dmd" class="reference external"&gt;DMD&lt;/a&gt; only, because other compilers (like &lt;a href="http://www.dsource.org/projects/ldc" class="reference external"&gt;LDC&lt;/a&gt; and &lt;a href="http://bitbucket.org/goshawk/gdc" class="reference external"&gt;GDC&lt;/a&gt;)
are fully free/libre.&lt;/p&gt;
&lt;/div&gt;
&lt;div id="conclusion" class="section"&gt;
&lt;h1&gt;Conclusion&lt;/h1&gt;
&lt;p&gt;Some of the things I mention are really hard to change, as they modify how
people work and imply learning new tools. But other are fairly easy, and can be
done progressively (like providing release candidates and improving commits and
commit messages).&lt;/p&gt;
&lt;p&gt;I hope &lt;a href="http://www.walterbright.com/" class="reference external"&gt;Walter Bright&lt;/a&gt;  &amp;amp; Co. keep walking the openness road =)&lt;/p&gt;

&lt;/div&gt;

      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/8dEUqawKimE" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">DMD 1.050 and 2.035</title>
		<link href="http://dblog.aldacron.net/2009/10/15/dmd-1-050-and-2-035/" />
		<id>http://dblog.aldacron.net/?p=679</id>
		<updated>2009-10-15T14:33:11+00:00</updated>
		<content type="html">Walter has pushed new releases of DMD out the door, 1.050 and 2.035. The purpose was to fix regressions blocking Qtd and Tango. Additionally, both releases now include an option to output some symbol data in JSON format in an effort to assist IDE developers. This feature is likely to evolve as it is used [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=G2bLf0A9KQ0:V_-mDXZmypI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=G2bLf0A9KQ0:V_-mDXZmypI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=G2bLf0A9KQ0:V_-mDXZmypI:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=G2bLf0A9KQ0:V_-mDXZmypI:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">LLVM developer meeting videos available</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/wvxxGe2W3SM/-687c651f" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-687c651f</id>
		<updated>2009-10-15T13:35:57+00:00</updated>
		<content type="html">&lt;p&gt;&lt;a href="http://www.nondot.org/sabre/" class="reference external"&gt;Chris Lattner&lt;/a&gt; &lt;a href="http://thread.gmane.org/gmane.comp.compilers.clang.devel/6400" class="reference external"&gt;announced&lt;/a&gt; that the &lt;a href="http://llvm.org/devmtg/2009-10/#proceedings" class="reference external"&gt;videos&lt;/a&gt; for the &lt;a href="http://llvm.org/devmtg/2009-10/" class="reference external"&gt;last&lt;/a&gt; &lt;a href="http://llvm.org/devmtg/" class="reference external"&gt;LLVM developer
meeting&lt;/a&gt; are now available. They are usually very interesting, so I'd
recommend to watch them if you have some time.&lt;/p&gt;
&lt;div class="admonition-update admonition"&gt;
&lt;p class="first admonition-title"&gt;Update&lt;/p&gt;
&lt;p&gt;Big WTF and many &lt;em&gt;anti-cool-points&lt;/em&gt; for Apple:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
On Oct 15, 2009, at 8:29 AM, Anton Korobeynikov wrote:
[...]
&amp;gt; I'm a bit curious: is there any reason why are other slides / videos
&amp;gt; not available (it seems that the ones missing are from Apple folks)?

Unfortunately, we found out at the last minute that Apple has a rule
which prevents its engineers from giving video taped talks or
distributing slides.  We will hold onto the video and slide assets in
case this rule changes in the future.

-Chris
&lt;/pre&gt;
&lt;p class="last"&gt;Fragment from a &lt;a href="http://article.gmane.org/gmane.comp.compilers.clang.devel/6417" class="reference external"&gt;response&lt;/a&gt; to the announcement.&lt;/p&gt;
&lt;/div&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/wvxxGe2W3SM" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Mutt patched with NNTP support for Debian (and friends)</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/NUhwE1EyhJE/0d270874" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/0d270874</id>
		<updated>2009-10-14T01:01:05+00:00</updated>
		<content type="html">&lt;p&gt;Did you ever wanted &lt;a href="http://www.mutt.org/" class="reference external"&gt;Mutt&lt;/a&gt; with &lt;a href="http://en.wikipedia.org/wiki/Network_News_Transfer_Protocol" class="reference external"&gt;NNTP&lt;/a&gt; support packed up for your &lt;a href="http://www.debian.org/" class="reference external"&gt;Debian&lt;/a&gt; (or
&lt;a href="http://www.debian.org/" class="reference external"&gt;Debian&lt;/a&gt;-ish) box, but you are too lazy to do it yourself? Did you even tried
to report a &lt;a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=488868" class="reference external"&gt;bug&lt;/a&gt; so the patch can be applied to the &lt;a href="http://packages.debian.org/sid/mutt" class="reference external"&gt;official Debian
package&lt;/a&gt; but the maintainers told you they wont do it?&lt;/p&gt;
&lt;p&gt;If so, this is a great day for you, because I did it and I'm giving it away
with no charge in this one time only opportunity!!! =P&lt;/p&gt;
&lt;p&gt;Seriously, I can understand why the maintainers don't want to support it
officially, it a big patch and can be some work to fold it in. So I did it
myself, and it turned out it's wasn't that bad.&lt;/p&gt;
&lt;p&gt;I adjusted the &lt;a href="http://mutt.org.ua/download/mutt-1.5.20/" class="reference external"&gt;patch&lt;/a&gt; maintained by Vsevolod Volkov to work on top of all the
other patches included in the &lt;a href="http://packages.debian.org/sid/mutt-patched" class="reference external"&gt;mutt-patched&lt;/a&gt; &lt;a href="http://www.debian.org/" class="reference external"&gt;Debian&lt;/a&gt; package (the only
conflicting patch is the &lt;a href="http://www.lunar-linux.org/index.php?page=mutt-sidebar" class="reference external"&gt;sidebar patch&lt;/a&gt; and some files that doesn't exist
because the patch should be applied after autotools files are generated and
&lt;a href="http://www.debian.org/" class="reference external"&gt;Debian&lt;/a&gt; apply the patches &lt;em&gt;before&lt;/em&gt; that) and built the package using the latest
&lt;a href="http://www.debian.org/" class="reference external"&gt;Debian&lt;/a&gt; source (1.5.20-4).&lt;/p&gt;
&lt;p&gt;You can find the source package and the binary packages for &lt;a href="http://www.debian.org/" class="reference external"&gt;Debian&lt;/a&gt; unstable
i386 &lt;a href="http://www.lug.fi.uba.ar/~luca/debian/" class="reference external"&gt;here&lt;/a&gt;. You can find there the modified &lt;a href="http://en.wikipedia.org/wiki/Network_News_Transfer_Protocol" class="reference external"&gt;NNTP&lt;/a&gt; patch too.&lt;/p&gt;
&lt;p&gt;If you have &lt;a href="http://www.ubuntu.com/" class="reference external"&gt;Ubuntu&lt;/a&gt; or other &lt;a href="http://www.debian.org/" class="reference external"&gt;Debian&lt;/a&gt; based distribution, you can compile the
binary package by downloading the files &lt;a href="http://www.lug.fi.uba.ar/~luca/debian/mutt_1.5.20-4luca1.diff.gz" class="reference external"&gt;mutt_1.5.20-4luca1.diff.gz&lt;/a&gt;,
&lt;a href="http://www.lug.fi.uba.ar/~luca/debian/mutt_1.5.20-4luca1.dsc" class="reference external"&gt;mutt_1.5.20-4luca1.dsc&lt;/a&gt; and &lt;a href="http://ftp.de.debian.org/debian/pool/main/m/mutt/mutt_1.5.20.orig.tar.gz" class="reference external"&gt;mutt_1.5.20.orig.tar.gz&lt;/a&gt;, then run:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
$ sudo apt-get build-dep mutt
$ dpkg-source -x mutt_1.5.20-4luca1.dsc
$ cd mutt-1.5.20
$ dpkg-buildpackage -rfakeroot
$ cd ..
$ sudo dpkg -i mutt_1.5.20-4luca1_i386.deb \
        mutt-patched_1.5.20-4luca1_i386.deb
&lt;/pre&gt;
&lt;p&gt;Now you can enjoy reading the &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt; &lt;a href="http://www.digitalmars.com/NewsGroup.html" class="reference external"&gt;newsgroups&lt;/a&gt; and your favourite mailing lists
via &lt;a href="http://gmane.org/" class="reference external"&gt;Gmane&lt;/a&gt; with &lt;a href="http://www.mutt.org/" class="reference external"&gt;Mutt&lt;/a&gt; without leaving the beauty of your packaging system.  No
need to thank me, I'm glad to be helpful ;)&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/NUhwE1EyhJE" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Walter Bright: Geek of the Week</title>
		<link href="http://dblog.aldacron.net/2009/10/12/walter-bright-geek-of-the-week/" />
		<id>http://dblog.aldacron.net/?p=675</id>
		<updated>2009-10-12T14:16:55+00:00</updated>
		<content type="html">Walter is simple-talk.com&amp;#8217;s Geek of the Week. In the interview, he talks about some of the rationale for D, some of the problems it solves, and why people should use it, with a few opinions of C and C++ tossed in for good measure.
There&amp;#8217;s a long list of previous Geeks of the Week, some whose [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=B_afrHjljF0:PYM2gawrGiQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=B_afrHjljF0:PYM2gawrGiQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=B_afrHjljF0:PYM2gawrGiQ:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=B_afrHjljF0:PYM2gawrGiQ:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Rational Lib and Another Demo</title>
		<link href="http://dblog.aldacron.net/2009/10/12/rational-lib-and-another-demo/" />
		<id>http://dblog.aldacron.net/?p=671</id>
		<updated>2009-10-12T13:57:20+00:00</updated>
		<content type="html">Two items that may be of interest to some of you.
First, dsimcha has released a small library for working with rational numbers. It&amp;#8217;s D2 only and can be seen in the Scrapple trunk. From the announcement:
It&amp;#8217;s templated to work on any integer type that supports the relevant operators.  Usually this would be used with [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=QjUov9CHtnY:qs-5DRg2P9s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=QjUov9CHtnY:qs-5DRg2P9s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=QjUov9CHtnY:qs-5DRg2P9s:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=QjUov9CHtnY:qs-5DRg2P9s:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">DMD 1.049 and 2.034</title>
		<link href="http://dblog.aldacron.net/2009/10/12/dmd-1-049-and-2-034/" />
		<id>http://dblog.aldacron.net/?p=668</id>
		<updated>2009-10-12T13:45:40+00:00</updated>
		<content type="html">Two new DMD versions have been rolled out, 1.049 and 2.034. Both feature a number of bug fixes. According to Don Clugston,
A small milestone &amp;#8212; This release fixes the last remaining compiler  segfaults and internal compiler errors from DStress.
This will probably be the last &amp;#8220;stability release&amp;#8221; &amp;#8212; there aren&amp;#8217;t many  ICE bugs left [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=QxmxilVqBu0:XLMtVCzGdas:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=QxmxilVqBu0:XLMtVCzGdas:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=QxmxilVqBu0:XLMtVCzGdas:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=QxmxilVqBu0:XLMtVCzGdas:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Link Time Optimization</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/7stRbRaHFpM/-5a9ca842" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-5a9ca842</id>
		<updated>2009-10-10T15:34:21+00:00</updated>
		<content type="html">&lt;p&gt;The upcoming &lt;a href="http://llvm.org/" class="reference external"&gt;LLVM&lt;/a&gt; &lt;a href="http://llvm.org/docs/ReleaseNotes-2.6.html" class="reference external"&gt;2.6&lt;/a&gt; will include a &lt;a href="http://llvm.org/docs/GoldPlugin.html" class="reference external"&gt;plug-in&lt;/a&gt; for &lt;a href="http://sourceware.org/binutils/" class="reference external"&gt;Gold&lt;/a&gt; to implement Link
Time Optimization (&lt;a href="http://en.wikipedia.org/wiki/Link-time_optimization" class="reference external"&gt;LTO&lt;/a&gt;) using &lt;a href="http://llvm.org/" class="reference external"&gt;LLVM&lt;/a&gt;'s &lt;a href="http://llvm.org/docs/LinkTimeOptimization.html#lto" class="reference external"&gt;LibLTO&lt;/a&gt;.  There is a &lt;a href="http://gcc.gnu.org/wiki/LinkTimeOptimization" class="reference external"&gt;similar
project&lt;/a&gt; for &lt;a href="http://gcc.gnu.org/" class="reference external"&gt;GCC&lt;/a&gt;, &lt;a href="http://gcc.gnu.org/ml/gcc/2009-10/msg00060.html" class="reference external"&gt;merged&lt;/a&gt; into the main trunk about a week ago. It will be
available in &lt;a href="http://gcc.gnu.org/" class="reference external"&gt;GCC&lt;/a&gt; &lt;a href="http://gcc.gnu.org/gcc-4.5/changes.html" class="reference external"&gt;4.5&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is all fairly new, and will be not enabled by default in &lt;a href="http://llvm.org/" class="reference external"&gt;LLVM&lt;/a&gt; (I don't
know what about &lt;a href="http://gcc.gnu.org/" class="reference external"&gt;GCC&lt;/a&gt;), but it will add a lot of new optimization oportunities
in the future.&lt;/p&gt;
&lt;p&gt;So people using &lt;a href="http://www.dsource.org/projects/ldc/" class="reference external"&gt;LDC&lt;/a&gt; and &lt;a href="http://bitbucket.org/goshawk/gdc/" class="reference external"&gt;GDC&lt;/a&gt; will probably be able to enjoy &lt;a href="http://en.wikipedia.org/wiki/Link-time_optimization" class="reference external"&gt;LTO&lt;/a&gt; in a near
future =)&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/7stRbRaHFpM" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Stats for the basic GC</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/ioQCtqx8w2Y/-2bbcf4c0" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-2bbcf4c0</id>
		<updated>2009-10-08T20:08:03+00:00</updated>
		<content type="html">&lt;p&gt;Here are some graphs made from my &lt;a href="http://git.llucax.com.ar/w/software/dgc/dgcbench.git" class="reference external"&gt;D GC benchmarks&lt;/a&gt; using the &lt;a href="http://www.dsource.org/projects/tango/" class="reference external"&gt;Tango&lt;/a&gt;
(0.99.8) basic collector, similar to the &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git" class="reference external"&gt;naive&lt;/a&gt; &lt;a href="http://llucax.com.ar/blog/blog/post/37e6cb2a" class="reference external"&gt;ones&lt;/a&gt; but using histograms
for allocations (time and space):&lt;/p&gt;
&lt;div class="center container"&gt;
&lt;a href="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/big_arrays.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/big_arrays.mini.png" alt="big_arrays" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/rnd_data.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/rnd_data.mini.png" alt="rnd_data" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/rnd_data_2.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/rnd_data_2.mini.png" alt="rnd_data_2" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/split.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/split.mini.png" alt="split" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/tree.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/10/08-stats-for-the-basic-gc/tree.mini.png" alt="tree" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;Some comments:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;The &lt;em&gt;Wasted&lt;/em&gt; space is the &lt;em&gt;Uncommitted&lt;/em&gt; space (since the basic GC doesn't
track the real size of the stored object).&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;Stop-the-world&lt;/em&gt; time is the time all the threads are stopped, which is
almost the same as the time spent scanning the heap.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;Collect&lt;/em&gt; time is the total time spent in a collection. The
difference with the &lt;em&gt;Stop-the-world&lt;/em&gt; time is almost the same as the time
spent in the sweep phase, which is done after the threads have being resumed
(except the thread that triggered the collection).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There are a few observations to do about the results:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;The &lt;em&gt;stop the world&lt;/em&gt; time varies a lot. There are tests where is almost
unnoticeable (&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;tree&lt;/span&gt;&lt;/tt&gt;), tests where it's almost equals to the total
collection time (&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;rnd_data&lt;/span&gt;&lt;/tt&gt;, &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;rnd_data_2&lt;/span&gt;&lt;/tt&gt;, &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;split&lt;/span&gt;&lt;/tt&gt;) and test where it's
in the middle (&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;big_arrays&lt;/span&gt;&lt;/tt&gt;). I can't see a pattern though (like heap
occupancy).&lt;/li&gt;
&lt;li&gt;There are tests where it seems that collections are triggered for no reason;
there is plenty of free space when it's triggered (&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;tree&lt;/span&gt;&lt;/tt&gt; and
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;big_arrays&lt;/span&gt;&lt;/tt&gt;).  I haven't investigated this yet, so if you can see
a reason, please let me know.&lt;/li&gt;
&lt;/ul&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/ioQCtqx8w2Y" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">rae_gui_lib_first_demo</title>
		<link href="http://pihlaja.wordpress.com/2009/10/07/rae-gui-library-first-demo-screencapture/" />
		<id>http://pihlaja.wordpress.com/?p=23</id>
		<updated>2009-10-07T17:29:34+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;I thought I&amp;#8217;d keep a low profile until my new project was finished, but as it now seems that it is progressing quite slowly, I might as well make it public for others to see.&lt;/p&gt;
&lt;p&gt;Rae is going to be a general purpose GUI library. It&amp;#8217;s nowhere near finished, and it is not usable for anything but making nice little demos of it. (Well you could make something like a calculator with it. Or possibly a pictureviewer of some sort with some effort. So, it&amp;#8217;s not entirely useless&amp;#8230;)&lt;/p&gt;
&lt;p&gt;The keywords go something like this: D programming language, OpenGL, X11/MIT licence, (GtkD, cairo, pango), Linux, OS X, Windows.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a link to the video:&lt;/p&gt;
&lt;div id="attachment_24" class="wp-caption alignnone"&gt;&lt;a href="http://www.vimeo.com/6918620"&gt;&lt;img class="size-medium wp-image-24" title="rae_gui_lib_first_demo" src="http://pihlaja.files.wordpress.com/2009/10/rae_gui_lib_first_demo.png?w=300&amp;h=168" alt="Rae GUI first demo" width="300" height="168" /&gt;&lt;/a&gt;&lt;p class="wp-caption-text"&gt;Rae GUI first demo&lt;/p&gt;&lt;/div&gt;
&lt;p&gt;And there&amp;#8217;s also a project page at &lt;a href="http://www.dsource.org/projects/rae"&gt;http://www.dsource.org/projects/rae&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The source in the repository is up to date, but a bigger example like seen on the video is missing. I might add it there later, when I get the time. But feel free to try and compile it. Shouldn&amp;#8217;t be too easy. Lot&amp;#8217;s of nasty big dependencies, that I&amp;#8217;d want to drop later. The code is a bit hacky, but pragmatic, so if you prefer projects with perfect code, look elsewhere. One of the main features is that it uses 0% CPU when doing nothing. Yes, that&amp;#8217;s just how it&amp;#8217;s supposed to be, but not any of the OpenGL GUIs that I&amp;#8217;ve seen, do that. It&amp;#8217;s full of small graphic glithces, unfinished widgets and buggy behaviour and sometimes even bad design. But I&amp;#8217;m willing to change all that if anyone wants to start participating in this weird and wonderful project. Progress is slow, as always, but there&amp;#8217;s a start. Feel free to donate me time, hardware or anything useful. (I&amp;#8217;d put a smiley here, but I&amp;#8217;m trying to quit using them.)&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/pihlaja.wordpress.com/23/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/pihlaja.wordpress.com/23/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/pihlaja.wordpress.com/23/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/pihlaja.wordpress.com/23/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/pihlaja.wordpress.com/23/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/pihlaja.wordpress.com/23/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/pihlaja.wordpress.com/23/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/pihlaja.wordpress.com/23/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/pihlaja.wordpress.com/23/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/pihlaja.wordpress.com/23/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=pihlaja.wordpress.com&amp;blog=1055143&amp;post=23&amp;subd=pihlaja&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Jonas Kivi</name>
			<uri>http://pihlaja.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Pihlaja | scene based editor development</title>
			<subtitle type="html">Just another WordPress.com weblog</subtitle>
			<link rel="self" href="http://pihlaja.wordpress.com/feed/" />
			<id>http://pihlaja.wordpress.com/feed/</id>
			<updated>2009-11-08T11:00:23+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">DMD 1.048 and 2.033</title>
		<link href="http://dblog.aldacron.net/2009/10/06/dmd-1-048-and-2-033/" />
		<id>http://dblog.aldacron.net/?p=664</id>
		<updated>2009-10-06T12:51:20+00:00</updated>
		<content type="html">Walter recently announced DMD 1.048 and 2.033. Both versions now sport contract inheritance, which has been missing for a long, long time. Also, both branches can now catch some null dereferences when compiling with the -O switch. So if you build exclusively in debug mode when testing, you may want to start building with -O [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=Tem0FVkWbdc:tnb45xK0HdE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=Tem0FVkWbdc:tnb45xK0HdE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=Tem0FVkWbdc:tnb45xK0HdE:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=Tem0FVkWbdc:tnb45xK0HdE:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">GDC resurrection</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/2dThu-K7adA/4454a90b" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/4454a90b</id>
		<updated>2009-10-05T11:31:26+00:00</updated>
		<content type="html">&lt;p&gt;About a month ago, the &lt;a href="http://www.digitalmars.com/d/archives/D/gnu/index.html" class="reference external"&gt;GDC newsgroup&lt;/a&gt; started to get some activity when
Michael P. and Vincenzo Ampolo &lt;a href="http://www.digitalmars.com/d/archives/D/gnu/merging_latest_dmd_frontend_to_gdc_3494.html" class="reference external"&gt;started working on updating GCD&lt;/a&gt;. Yesterday
they announced that they successfully merged the DMD frontend 1.038 and
2.015, and a new &lt;a href="http://bitbucket.org/goshawk/gdc/changesets/" class="reference external"&gt;repository for GDC&lt;/a&gt;. They will be hanging on &lt;a href="irc://irc.freenode.net#d.gdc" class="reference external"&gt;#d.gdc&lt;/a&gt; if
you have any questions or want to help out.&lt;/p&gt;
&lt;p&gt;So great news for the D ecosystem! Kudos for this two brave men! =)&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/2dThu-K7adA" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">DGC page is back</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/DUuq8hNfrVE/-7ff97d22" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-7ff97d22</id>
		<updated>2009-10-02T13:17:58+00:00</updated>
		<content type="html">&lt;p&gt;I've migrated the wiki pages about &lt;a href="http://llucax.com.ar/proj/dgc/" class="reference external"&gt;DGC&lt;/a&gt; from &lt;a href="http://www.redmine.org/" class="reference external"&gt;Redmine&lt;/a&gt; to &lt;a href="http://sphinx.pocoo.org/" class="reference external"&gt;Sphinx&lt;/a&gt;.&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/DUuq8hNfrVE" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Tree visits in D</title>
		<link href="http://leonardo-m.livejournal.com/88868.html" />
		<id>http://leonardo-m.livejournal.com/88868.html</id>
		<updated>2009-09-29T19:28:12+00:00</updated>
		<content type="html">On the RosettaCode site there's this Programming Task:&lt;br /&gt;&lt;a href="http://rosettacode.org/wiki/Tree_traversal"&gt;http://rosettacode.org/wiki/Tree_traversal&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Problem: Implement a binary tree where each node carries an integer, and implement preoder, inorder, postorder and level-order traversal. Use those traversals to output the following tree:&lt;br /&gt;&lt;pre&gt;         1
        / \
       /   \
      /     \
     2       3
    / \     /
   4   5   6
  /       / \
 7       8   9

The correct output should look like this:

preorder:    1 2 4 7 5 3 6 8 9
inorder:     7 4 2 5 1 8 6 9 3
postorder:   7 4 5 2 8 9 6 3 1
level-order: 1 2 3 4 5 6 7 8 9
&lt;/pre&gt;The following is my D implementation. I have used the D Version 2 language (to compile the code I am using DMD v2.032, with the Phobos std lib, but it uses only the printing of Phobos, so adapting the code to Tango is easy), but a very similar version can be adapted for D V1.&lt;br /&gt;&lt;br /&gt;Disclaimer: The following isn't an example of common (or good) D code. It's very generic and it's a bit tricky. In practice you usually write simpler code, because you don't need such genericity, and to keep the code simpler to write and understand. Simpler code is also simpler to debug. You may need to write code so much generic only in library-like routines, that are usually limited in number and size. So there are surely ways to write simpler/shorter D code, but here I show this version because it can be useful to explain some features of the D language, and because it's more fun.&lt;br /&gt;&lt;br /&gt;&lt;div class="d"&gt;&lt;span&gt;import&lt;/span&gt; std.&lt;span&gt;stdio&lt;/span&gt;&lt;span&gt;:&lt;/span&gt; write&lt;span&gt;,&lt;/span&gt; writeln&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;class&lt;/span&gt; Node&lt;span&gt;(&lt;/span&gt;T&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; T data&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; Node left&lt;span&gt;,&lt;/span&gt; right&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;this&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;T data&lt;span&gt;,&lt;/span&gt; Node left&lt;span&gt;=&lt;/span&gt;&lt;span&gt;null&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; Node right&lt;span&gt;=&lt;/span&gt;&lt;span&gt;null&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;this&lt;/span&gt;.&lt;span&gt;data&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; data&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;this&lt;/span&gt;.&lt;span&gt;left&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; left&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;this&lt;/span&gt;.&lt;span&gt;right&lt;/span&gt; &lt;span&gt;=&lt;/span&gt; right&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;// static templated opCall can't be used in Node&lt;/span&gt;&lt;br /&gt;&lt;span&gt;auto&lt;/span&gt; node&lt;span&gt;(&lt;/span&gt;T&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;T data&lt;span&gt;,&lt;/span&gt; Node&lt;span&gt;!&lt;/span&gt;T left&lt;span&gt;=&lt;/span&gt;&lt;span&gt;null&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; Node&lt;span&gt;!&lt;/span&gt;T right&lt;span&gt;=&lt;/span&gt;&lt;span&gt;null&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;return&lt;/span&gt; &lt;span&gt;new&lt;/span&gt; Node&lt;span&gt;!&lt;/span&gt;T&lt;span&gt;(&lt;/span&gt;data&lt;span&gt;,&lt;/span&gt; left&lt;span&gt;,&lt;/span&gt; right&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;void&lt;/span&gt; show&lt;span&gt;(&lt;/span&gt;T&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;T x&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; write&lt;span&gt;(&lt;/span&gt;x&lt;span&gt;,&lt;/span&gt; &lt;span&gt;" "&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;enum&lt;/span&gt; Visit &lt;span&gt;{&lt;/span&gt; pre&lt;span&gt;,&lt;/span&gt; inv&lt;span&gt;,&lt;/span&gt; post &lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;// visitor can be any kind of callable or it uses a default visitor.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;// TNode can be any kind of Node, with data, left and right fields,&lt;/span&gt;&lt;br /&gt;&lt;span&gt;// so this is more generic than a member function of Node.&lt;/span&gt;&lt;br /&gt;&lt;span&gt;void&lt;/span&gt; backtrackingOrder&lt;span&gt;(&lt;/span&gt;Visit v&lt;span&gt;,&lt;/span&gt; TNode&lt;span&gt;,&lt;/span&gt; TyF&lt;span&gt;=&lt;/span&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;TNode node&lt;span&gt;,&lt;/span&gt; TyF visitor&lt;span&gt;=&lt;/span&gt;&lt;span&gt;null&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;&lt;span&gt;is&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;TyF &lt;span&gt;==&lt;/span&gt; &lt;span&gt;void&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;auto&lt;/span&gt; truevisitor &lt;span&gt;=&lt;/span&gt; &lt;span&gt;&amp;amp;&lt;/span&gt;show&lt;span&gt;!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;else&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;auto&lt;/span&gt; truevisitor &lt;span&gt;=&lt;/span&gt; visitor&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;node &lt;span&gt;!&lt;/span&gt;&lt;span&gt;is&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;v &lt;span&gt;==&lt;/span&gt; Visit.&lt;span&gt;pre&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &amp;nbsp; truevisitor&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; backtrackingOrder&lt;span&gt;!&lt;/span&gt;v&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;left&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; visitor&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;v &lt;span&gt;==&lt;/span&gt; Visit.&lt;span&gt;inv&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&amp;nbsp; truevisitor&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; backtrackingOrder&lt;span&gt;!&lt;/span&gt;v&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;right&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; visitor&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;v &lt;span&gt;==&lt;/span&gt; Visit.&lt;span&gt;post&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; truevisitor&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;void&lt;/span&gt; levelOrder&lt;span&gt;(&lt;/span&gt;TNode&lt;span&gt;,&lt;/span&gt; TyF&lt;span&gt;=&lt;/span&gt;&lt;span&gt;void&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;TNode node&lt;span&gt;,&lt;/span&gt; TyF visitor&lt;span&gt;=&lt;/span&gt;&lt;span&gt;null&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; TNode&lt;span&gt;[&lt;/span&gt;&lt;span&gt;]&lt;/span&gt; more&lt;span&gt;=&lt;/span&gt;&lt;span&gt;[&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;static&lt;/span&gt; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;&lt;span&gt;is&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;TyF &lt;span&gt;==&lt;/span&gt; &lt;span&gt;void&lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;auto&lt;/span&gt; truevisitor &lt;span&gt;=&lt;/span&gt; &lt;span&gt;&amp;amp;&lt;/span&gt;show&lt;span&gt;!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;typeof&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;else&lt;/span&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span&gt;auto&lt;/span&gt; truevisitor &lt;span&gt;=&lt;/span&gt; visitor&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;node &lt;span&gt;!&lt;/span&gt;&lt;span&gt;is&lt;/span&gt; &lt;span&gt;null&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; more &lt;span&gt;~=&lt;/span&gt; &lt;span&gt;[&lt;/span&gt;node.&lt;span&gt;left&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; node.&lt;span&gt;right&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; truevisitor&lt;span&gt;(&lt;/span&gt;node.&lt;span&gt;data&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;if&lt;/span&gt; &lt;span&gt;(&lt;/span&gt;more.&lt;span&gt;length&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; levelOrder&lt;span&gt;(&lt;/span&gt;more&lt;span&gt;[&lt;/span&gt;0&lt;span&gt;]&lt;/span&gt;&lt;span&gt;,&lt;/span&gt; truevisitor&lt;span&gt;,&lt;/span&gt; more&lt;span&gt;[&lt;/span&gt;1&lt;span&gt;..&lt;/span&gt;$&lt;span&gt;]&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span&gt;void&lt;/span&gt; main&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt; &lt;span&gt;{&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &lt;span&gt;auto&lt;/span&gt; tree &lt;span&gt;=&lt;/span&gt; node&lt;span&gt;(&lt;/span&gt;1&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; node&lt;span&gt;(&lt;/span&gt;2&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; node&lt;span&gt;(&lt;/span&gt;4&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; node&lt;span&gt;(&lt;/span&gt;7&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; node&lt;span&gt;(&lt;/span&gt;5&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; node&lt;span&gt;(&lt;/span&gt;3&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; node&lt;span&gt;(&lt;/span&gt;6&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; node&lt;span&gt;(&lt;/span&gt;8&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; node&lt;span&gt;(&lt;/span&gt;9&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; write&lt;span&gt;(&lt;/span&gt;&lt;span&gt;" &amp;nbsp;preOrder: "&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; backtrackingOrder&lt;span&gt;!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;Visit.&lt;span&gt;pre&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;tree&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; write&lt;span&gt;(&lt;/span&gt;&lt;span&gt;"&lt;span&gt;\n&lt;/span&gt; &amp;nbsp; inOrder: "&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; backtrackingOrder&lt;span&gt;!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;Visit.&lt;span&gt;inv&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;tree&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; write&lt;span&gt;(&lt;/span&gt;&lt;span&gt;"&lt;span&gt;\n&lt;/span&gt; postOrder: "&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; backtrackingOrder&lt;span&gt;!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;Visit.&lt;span&gt;post&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;tree&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; write&lt;span&gt;(&lt;/span&gt;&lt;span&gt;"&lt;span&gt;\n&lt;/span&gt;levelorder: "&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; levelOrder&lt;span&gt;(&lt;/span&gt;tree&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&amp;nbsp; &amp;nbsp; writeln&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;br /&gt;&lt;span&gt;}&lt;/span&gt;&lt;/div&gt;&lt;pre&gt;Output:
  preOrder: 1 2 4 7 5 3 6 8 9
   inOrder: 7 4 2 5 1 8 6 9 3
 postOrder: 7 4 5 2 8 9 6 3 1
levelorder: 1 2 3 4 5 6 7 8 9
&lt;/pre&gt;A possible design for Java is to create a Node class (using generics to allow for different types of data) that has preOrder, InOrder, etc, methods. This simple design can be used in D too. But it conflates data structure and algorithms, so you can't use the same algorithms (the tree visits) for other kinds of nodes.&lt;br /&gt;&lt;br /&gt;So if your language is flexible enough (like C++, D, Haskell, or Python) it's better to follow the strategy used in the C++ STL, and implement generic algorithms, that work with more kinds of binary tree nodes and allow for a more flexible management of the node being visited.&lt;br /&gt;&lt;br /&gt;Another design that can be natural in modern versions of Python is to create iterators, that yield the current node. This is very handy, and such strategy can be used in D too (with opApply or with the second iteration protocol of D2) but I have not used it in my D code. In Python (and in some other languages, in D too if you use opApply) this strategy leads to O(n^2) tree visits. (There is a Python PEP that if well implemented may solve this problem).&lt;br /&gt;&lt;br /&gt;Th flexibility of D language has allowed me to merge the three backtracking visits (pre, in and post - order) in a single templated function with zero overehead.&lt;br /&gt;&lt;br /&gt;In the code I have used a class to represent the node to keep code a little simpler, but a struct too can be used with very small changes. Such structs are smaller 8 bytes less on a 32 bit system) and it's simpler to allocate them with a memory pool that can halve the time needed to create and allocate the tree.&lt;br /&gt;&lt;br /&gt;I have added a helper node() templated function, it just allocates a new node and returns it. In D something similar can also be done with a static opCall inside Node, but here it's also templated, and templatd methods can't replace opCall of object (I may be wrong on this, but I don't think so). If you have a different Node class/struct you need a different helper function, or you have to use opCall (if the Node isn't generic) or you have to build the tree in a simpler way.&lt;br /&gt;&lt;br /&gt;Node!T is the new compact syntax introduced in D2 to instantiate a template when you have a single argument. The standard older syntax is Node!(T), that equals to C++ Node.&lt;br /&gt;&lt;br /&gt;show() is a little function that's used as default visitor of the node. It's templated, so you have to instantiate it before taking its address to use it as function pointer.&lt;br /&gt;&lt;br /&gt;backtrackingOrder() merges the three tree visits, its code is a little tricky.&lt;br /&gt;&lt;br /&gt;The enum Visit is used to represent one of the three possible visits. To specify it you can first partial specify backtrackingOrder() according to visit type known a compile-time, and then you can fully specify it automatically with the given root node and an optional callable.&lt;br /&gt;&lt;br /&gt;The node can be any type that has a left, right and node attributes.&lt;br /&gt;&lt;br /&gt;visitor can be any callable, a delegate, function pointer, or callable object. If visitor is unspecified you can omit it, and it uses show() instantiated on the type of the data.&lt;br /&gt;&lt;br /&gt;The static ifs are done at compile time, and they don't create a scope, so truevisitor (its type is found automatically) is then visible under the static if. The is() syntax is used to test if types are the same (a better simpler design for the D language is just to allow == between them).&lt;br /&gt;&lt;br /&gt;In library code you may add few more static asserts inside backtrackingOrder() to test that visitor is a callable, with a line of code like:&lt;br /&gt;static assert(IsCallable!(typeof(truevisitor)), "...");</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/09/22/ownership-systems-against-data-races/" />
		<id>http://bartoszmilewski.wordpress.com/?p=1041</id>
		<updated>2009-09-22T21:24:27+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;Here&amp;#8217;s the &lt;a href="http://www.vimeo.com/6689999"&gt;video from my recent talk&lt;/a&gt; to the &lt;a href="http://www.nwcpp.org"&gt;Northwest C++ Users Group (NWCPP)&lt;/a&gt; about how to translate the data-race free type system into a system of user-defined annotations in C++. I start with the definition of a data race and discuss various ways to eliminate them. Then I describe the ownership system and give a few examples of annotated programs.&lt;/p&gt;
&lt;p&gt;Here are the &lt;a href="http://www.nwcpp.org/Downloads/2009/Ownership_Systems_against_Data_Races.pdf"&gt;slides from the presentation&lt;/a&gt;. They include extensive notes.&lt;/p&gt;
&lt;p&gt;By the way, we are looking for speakers at the NWCPP, not necessarily  related to C++. We are thinking of changing the charter to include all programming languages. If you are near Seattle on Oct 21 09 (or any third Wednesday of the month), and you are ready to give a 60 min presentation, please contact me.&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/1041/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/1041/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/1041/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/1041/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/1041/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/1041/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/1041/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/1041/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/1041/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/1041/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=1041&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">vincenzoampolo7</title>
		<link href="http://goshawknest.wordpress.com/2009/09/20/gdc-d2-with-gcc-4-3-4-sees-light/" />
		<id>http://goshawknest.wordpress.com/?p=75</id>
		<updated>2009-09-20T10:30:43+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;I&amp;#8217;ve been working with ldc for a long time. I enjoyed it, i helped the development with tickets and hacking ldc a bit. I even tried to compile &lt;a href="http://www.dsource.org/projects/tango/ticket/857"&gt;Tango as shared library&lt;/a&gt; but i got an error, probably caused by the compiler since people reported that in gdc they were able to do it. I then started guessing if &lt;a href="http://llvm.org"&gt;llvm&lt;/a&gt; is so stable as it seems and if it can substitute the &lt;a href="http://gcc.gnu.org/"&gt;gnu compiler collection&lt;/a&gt;. Then i came to these &lt;a href="http://www.phoronix.com/scan.php?page=article&amp;item=apple_llvm_gcc&amp;num=1"&gt;llvm vs gcc benchmarks&lt;/a&gt;. Well the result is that llvm is not so fast and reliable as promised. In the same days, a &lt;a href="http://www.digitalmars.com/d/archives/D/gnu/merging_latest_dmd_frontend_to_gdc_3494.html#N3494"&gt;message posted on the D newsgroup got me&lt;/a&gt;. I started thinking that resurrection gdc is the only way to make a stable and reliable compiler accepted in the FOSS community for the D programming language. But it should resurrect it should implement the D2 specs: there are no other compilers than dmd which support D2 around. So, me and Michael joined to the challenge to work on gdc &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley" /&gt; &lt;/p&gt;
&lt;p&gt;We got the lastest working branch of gdc, the one who relies on gcc 4.3.1. We then copied in &lt;a href="http://bitbucket.org/goshawk/gdc/wiki/Home"&gt;our repository in bitbucket&lt;/a&gt; and applied some changes, after two days of works, gdc for D2.014 worked under gcc 4.3.4 (there were some problems in the default version when compiling the Phobos library). As a proof that it works look at it &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley" /&gt; &lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;goshawk@earth:/tmp/test/usr/local/gcc-4.3/bin$ ./gdc ~/test.d&lt;br /&gt;
goshawk@earth:/tmp/test/usr/local/gcc-4.3/bin$ ./a.out&lt;br /&gt;
Hello World, Reloaded&lt;/strong&gt;&lt;br /&gt;
goshawk@earth:/tmp/test/usr/local/gcc-4.3/bin$ ./gdc -v&lt;br /&gt;
Using built-in specs.&lt;br /&gt;
Target: x86_64-unknown-linux-gnu&lt;br /&gt;
Configured with: ../configure &amp;#8211;prefix=/usr/local/gcc-4.3 &amp;#8211;enable-languages=c,d,c++ &amp;#8211;disable-multilib &amp;#8211;disable-shared&lt;br /&gt;
Thread model: posix&lt;br /&gt;
&lt;strong&gt; gcc version 4.3.4 (GCC)&lt;/strong&gt;&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Nice, isn&amp;#8217;t it?&lt;/p&gt;
&lt;p&gt;Now while Michael is focusing in fixing the D1 part, i started merging the lastest dmd D2 compiler in gdc. Making a diff against dmd2.014 and gdc2.014 i&amp;#8217;m applying all the necessary patches in gdc for D2 2.032.&lt;/p&gt;
&lt;p&gt;We opened a dedicated IRC channel in &lt;strong&gt;irc.freenode.net #d.gdc&lt;/strong&gt;. Feel free to join!&lt;/p&gt;
&lt;p&gt;You can find full instructions in how &lt;a href="http://bitbucket.org/goshawk/gdc/wiki/Home"&gt;to compile gdc in our wiki page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Any help, documentation, word on this challenge is appreciated. See you soon &lt;img src="http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley" /&gt; &lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/goshawknest.wordpress.com/75/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/goshawknest.wordpress.com/75/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/goshawknest.wordpress.com/75/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/goshawknest.wordpress.com/75/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/goshawknest.wordpress.com/75/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/goshawknest.wordpress.com/75/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/goshawknest.wordpress.com/75/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/goshawknest.wordpress.com/75/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/goshawknest.wordpress.com/75/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/goshawknest.wordpress.com/75/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=goshawknest.wordpress.com&amp;blog=6236053&amp;post=75&amp;subd=goshawknest&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Vincenzo Ampolo</name>
			<uri>http://goshawknest.wordpress.com</uri>
		</author>
		<source>
			<title type="html">goshawk's digital nest » D</title>
			<subtitle type="html">researches, hacks, thoughts</subtitle>
			<link rel="self" href="http://goshawknest.wordpress.com/category/d/feed/" />
			<id>http://goshawknest.wordpress.com/category/d/feed/</id>
			<updated>2009-11-08T17:00:45+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Code performance in D/Java</title>
		<link href="http://leonardo-m.livejournal.com/88482.html" />
		<id>http://leonardo-m.livejournal.com/88482.html</id>
		<updated>2009-09-19T15:05:44+00:00</updated>
		<content type="html">The code discussed in this post:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/life_bench.zip"&gt;http://www.fantascienza.net/leonardo/js/life_bench.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To try to find "performance bugs" in both the LDC D compiler and the LLVM back-end I am exploring the performance signature of many small programs, often translating them to D. To perform such tests I compare the timings of the D code with the original C or Java code.&lt;br /&gt;&lt;br /&gt;Java here is useful because its performance profiles are a little different from the usual C ones. Java HotSpot is able to inline many virtual calls, and its GarbageCollector is quite efficient (both things aren't good in all current D implementations).&lt;br /&gt;&lt;br /&gt;I've found a small Life (Horton Conway's game) implementation in Java that shows a higher performance compared to D code (the original Java code isn't mine), so I cleaned up the Java code, I have removed the useless stuff from it (see the zip for the Java code), and I have translated it to as much close as possible D code (able to run both on Tango and Phobos). The result is the first D program (life1_d.d).&lt;br /&gt;&lt;br /&gt;I have taken care of setting as final the main class in the D code, to allow inlining.&lt;br /&gt;&lt;br /&gt;The Java GC (of Sun) is more efficient than the nonmoving D GC, so first of all I have taken a look at the number of memory allocations, bue they weren't the cause of the performance difference. I've profiled both the D and Java code, and I've seen that the calc_new() method was the one taking most time. I've also seen that the amount of inlining with LDC (using -O5 -release -inline) was not enough, so I've compiled the D code with the following, that forces a more aggressive inlining, that improves performance:&lt;br /&gt;&lt;br /&gt;ldc -O5 -release -inline -inline-threshold=2000000001 life1_d.d&lt;br /&gt;&lt;br /&gt;I have also seen that for this program Link-Time Optimization plus Interning improve the performance of the code:&lt;br /&gt;&lt;br /&gt;ldc -O5 -release -inline -inline-threshold=2000000001 -output-bc life1_d.d&lt;br /&gt;&lt;br /&gt;opt -std-compile-opts life1_d.bc &amp;gt; life1_do.bc&lt;br /&gt;&lt;br /&gt;llvm-ld -native -ltango-base-ldc -ltango-user-ldc -ldl -lm -lpthread -internalize-public-api-list=_Dmain -o=life1_do life1_do.bc&lt;br /&gt;&lt;br /&gt;I have done many more experiments, here you can find the ones that have given good results. I have split the Life class in its methods plus global values, I don't know why this increases performance with the LDC compiler (see the timings), see life2_d.d.&lt;br /&gt;&lt;br /&gt;Later I have uses simple pointers as function arguments instead of arrays (see see life3_d.d), again I don't know why this increases the performance with the LDC compiler, also because most of sych functions get inlined anyway.&lt;br /&gt;&lt;br /&gt;Now the performance of life3_d.d was bad only for large values (the last values of the use_Sizes array). After several more experiments I have by chance found that the cause was in the inner loop of the calc_new() function, where the whole botRow array is reset to zero. I think here the Java compiler recognizes such loop as a clearing, and replaces it with a call to a function like memset(). This makes the Java code slower than the D one for small botRow arrays, but faster for the longer ones (because it seems an inlined loop is faster than a memset when the length is small, about 50-100 or so if array items are 4 byte long).&lt;br /&gt;&lt;br /&gt;So in life4_d.d I have replaced the loop with something a little more complex that takes a look at botRow length:&lt;br /&gt;&lt;pre&gt;if (botRow.length &amp;gt; 100)
    botRow[] = 0;
else
    for (int c = 0; c &amp;lt; botRow.length; c++)
        botRow[c] = 0;
&lt;/pre&gt;The timings of the 4th D version are now good enough, but not the best still, I don't know why. (I am now trying to find a faster array reset that uses an asm routine that contains the movntps SSE instuction).&lt;br /&gt;&lt;br /&gt;------------------------&lt;br /&gt;&lt;br /&gt;Scores on Windows Vista, using DMD compiler for the D code (bigger is better):&lt;br /&gt;&lt;pre&gt;
java -server Life
Size    average
Adjusting 6744 to 2811246
5       14288
6       14974
8       14125
10      15697
15      14175
25      15369
50      14595
250     6331
1000    2218
2500    880


life1_d.exe
Size    average
5       9248
6       8938
8       10213
10      10469
15      10974
25      9898
50      7189
250     1694
1000    421
2500    170


life2_d.exe
Size    average
5       9424
6       8270
8       8083
10      7876
15      8389
25      7191
50      5288
250     1331
1000    331
2500    147


life3_d.exe
Size    average
5       10156
6       9172
8       9353
10      9043
15      8802
25      8452
50      5865
250     1357
1000    356
2500    151


life4_d.exe
Size    average
Adjusting 917315 to 0
5       10145
6       9275
8       9631
10      10282
15      10061
25      9083
50      6286
250     4747
1000    1596
2500    743
&lt;/pre&gt;&lt;br /&gt;Home Vista Basic with 2 GB RAM, Celeron 2.13 GHz&lt;br /&gt;&lt;br /&gt;Compilers used:&lt;br /&gt;&lt;br /&gt;Java version "1.7.0-ea"&lt;br /&gt;Java(TM) SE Runtime Environment (build 1.7.0-ea-b66)&lt;br /&gt;Java HotSpot(TM) Client VM (build 16.0-b06, mixed mode, sharing)&lt;br /&gt;&lt;br /&gt;DMD Digital Mars D Compiler v1.042&lt;br /&gt;&lt;br /&gt;------------------------&lt;br /&gt;&lt;br /&gt;Scores on Ubuntu running on VirtualBox running on Vista, using LDC compiler for the D code (bigger is better):&lt;br /&gt;&lt;pre&gt;java -server Life
Size	average
Adjusting 28766 to 951466
Adjusting 951466 to 2616313
5	13740
6	16494
8	14922
10	19481
15	20602
25	21249
50	19979
250	7493
1000	2609
2500	1004


ldc -O5 -release -inline life1_d.d
Size	average
5	17810
6	16661
8	15147
10	15201
15	14818
25	12901
50	4384
250	1893
1000	485
2500	198


ldc -O5 -release -inline -inline-threshold=2000000001 life1_d.d
Size	average
5	16016
6	14690
8	13183
10	11823
15	11100
25	10144
50	5203
250	2305
1000	571
2500	256
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;ldc -O5 -release -inline -inline-threshold=2000000001 -output-bc life1_d.d&lt;br /&gt;opt -std-compile-opts life1_d.bc &amp;gt; life1_do.bc&lt;br /&gt;llvm-ld -native -ltango-base-ldc -ltango-user-ldc -ldl -lm -lpthread -internalize-public-api-list=_Dmain -o=life1_do life1_do.bc&lt;br /&gt;&lt;pre&gt;Size	average
5	22628
6	18773
8	14326
10	18820
15	17558
25	15264
50	10155
250	2329
1000	578
2500	251


ldc -O5 -release -inline -inline-threshold=2000000001 life2_d.d
Size	average
5	16557
6	15205
8	13149
10	12037
15	10870
25	10051
50	6470
250	2327
1000	571
2500	247


ldc -O5 -release -inline -inline-threshold=2000000001 life3_d.d
Size	average
5	18205
6	17032
8	15948
10	17798
15	17907
25	15656
50	10191
250	2310
1000	574
2500	248


ldc -O5 -release -inline -inline-threshold=2000000001 life4_d.d
Size	average
5	18169
6	16576
8	16129
10	17616
15	17937
25	15486
50	9667
250	6714
1000	2006
2500	886
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;ldc -O5 -release -inline -inline-threshold=2000000001 -output-bc life4_d.d&lt;br /&gt;opt -std-compile-opts life4_d.bc &amp;gt; life4_do.bc&lt;br /&gt;llvm-ld -native -ltango-base-ldc -ltango-user-ldc -ldl -lm -lpthread -internalize-public-api-list=_Dmain -o=life4_do life4_do.bc&lt;br /&gt;&lt;pre&gt;Size	average
5	25522
6	22085
8	21079
10	20964
15	21987
25	19300
50	13160
250	6774
1000	1986
2500	900
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This version (not included in the zip) is the first D one, but the cleaning of the botRow array in calc_new() is done as in life4_d.d:&lt;br /&gt;ldc -O5 -release -inline -inline-threshold=2000000001 -output-bc life1b_d.d&lt;br /&gt;opt -std-compile-opts life1b_d.bc &amp;gt; life1b_do.bc&lt;br /&gt;llvm-ld -native -ltango-base-ldc -ltango-user-ldc -ldl -lm -lpthread -internalize-public-api-list=_Dmain -o=life1b_do life1b_do.bc&lt;br /&gt;&lt;pre&gt;Size	average
5	22957
6	19394
8	16457
10	17208
15	18177
25	15522
50	5089
250	6638
1000	1971
2500	889
&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Code running on Ubuntu 9.4 running on VirtualBox 3.0.6 r52128.&lt;br /&gt;&lt;br /&gt;Compilers used:&lt;br /&gt;&lt;br /&gt;LDC based on DMD v1.045 and llvm 2.6 (Thu Sep 10 23:50:27 2009)&lt;br /&gt;&lt;br /&gt;Java version "1.6.0_16"&lt;br /&gt;Java(TM) SE Runtime Environment (build 1.6.0_16-b01)&lt;br /&gt;Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)&lt;br /&gt;&lt;br /&gt;------------------------</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/09/08/template-metaprogramming-made-easy-huh/" />
		<id>http://bartoszmilewski.wordpress.com/?p=1016</id>
		<updated>2009-09-08T16:49:52+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;&amp;#8220;I&amp;#8217;ve been doing some template metaprogramming lately,&amp;#8221; he said nonchallantly. &lt;/p&gt;
&lt;p&gt;Why is it funny? Because template metaprogramming is considered &lt;i&gt;really&lt;/i&gt; hard. I mean, &amp;uuml;ber-guru-level hard. I&amp;#8217;m lucky to be friends with two such gurus, Andrei Alexandrescu who wrote the seminal &amp;#8220;&lt;a href="http://www.amazon.com/exec/obidos/ASIN/0201704315/modecdesi-20"&gt;Modern C++ Programming&lt;/a&gt;,&amp;#8221; and Eric Niebler, who implemented the &lt;a href="http://www.boost.org/doc/libs/1_38_0/doc/html/xpressive.html"&gt;Xpressive&lt;/a&gt; library for Boost; so I know the horrors. &lt;/p&gt;
&lt;p&gt;But why is template metaprogramming so hard? Big part of it is that C++ templates are rather ill suited for metaprogramming, to put it mildly. They are fine for simple tasks like parameterized containers and some generic algorithms, but not for operations on types or lists of types. To make things worse, C++ doesn&amp;#8217;t provide a lot in terms of reflection, so even such simple tasks like deciding whether a given type is a pointer are hard (see the example later). Granted, C++0x offers some improvements, like template parameter packs; but guru-level creds are still required.&lt;/p&gt;
&lt;p&gt;So, I&amp;#8217;ve been doing some template metaprogramming lately&amp;#8230; in D. The D programming language doesn&amp;#8217;t have the baggage of compatibility with previous botched attempts, so it makes many things considerably easier on programmers. But before I get to it, I&amp;#8217;d like to talk a little about the connection between generic programming and functional programming, give a short intro to functional programming; and then show some examples in C++ and D that involve pattern matching and type lists.&lt;/p&gt;
&lt;h2&gt;It&amp;#8217;s not your father&amp;#8217;s language&lt;/h2&gt;
&lt;p&gt;The key to understanding metaprogramming is to realize that it&amp;#8217;s done in a different language than the rest of your program. Both in C++ and D you use a form of functional language for that purpose. First of all, no mutation! If you pass a list of types to a template, it won&amp;#8217;t be able to append another type to it. It will have to create a completely new list using the old list and the new type as raw materials.&lt;/p&gt;
&lt;p&gt;Frankly, I don&amp;#8217;t know why mutation should be disallowed at compile time (all template calculations are done at compile time). In fact, for templates that are used in D mixins, I proposed not to invent a new language but to use a subset of D that included mutation. It worked just fine and made mixins much easier to use (for an example, see my &lt;a href="http://www.ddj.com/cpp/212201754"&gt;DrDobbs article&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Once you disallow mutation, you&amp;#8217;re pretty much stuck with functional paradigm. For instance, you can&amp;#8217;t have loops, which require a mutable loop counter or some other mutable state, so you have to use recursion. &lt;/p&gt;
&lt;p&gt;You&amp;#8217;d think functional programmers would love template metaprogramming; except that they flip over horrendous syntax of C++ templates. The one thing going for functional programming is that it&amp;#8217;s easy to define and implement. You can describe typeless lambda calculus with just a few formulas in operational semantics. &lt;/p&gt;
&lt;p&gt;One thing is important though: meta-language can&amp;#8217;t be strongly typed, because a strongly typed language requires another language to implement generic algorithms on top of it. So to terminate the succession of meta-meta-meta&amp;#8230; languages there&amp;#8217;s a need for either a typeless, or at least dynamically-typed, top-level meta-language. My suspicion is that C++0x concepts failed so miserably because they dragged the metalanguage in the direction of strong typing. The nails in the coffin for C++ concepts were concept maps, the moral equivalent of implicit conversions in strongly-typed languages. &lt;/p&gt;
&lt;p&gt;Templates are still not totally typeless. They distinguish between type arguments (introduced by &lt;var&gt;typename&lt;/var&gt; or &lt;var&gt;class&lt;/var&gt; in C++), template template arguments, and typed template arguments. Here&amp;#8217;s an example that shows all three kinds:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class T, template&amp;lt;class X&amp;gt; class F, int n&amp;gt;&lt;/pre&gt;
&lt;h2&gt;Functional Programming in a Nutshell&lt;/h2&gt;
&lt;p&gt;&amp;#8220;Functions operating on functions&amp;#8221;&amp;#8211;that&amp;#8217;s the gist of functional programming. The rest is syntactic sugar. Some of this sugar is very important. For instance, you want to have built-in integers and lists for data types, and pattern matching for dispatching. &lt;/p&gt;
&lt;h3&gt;-Functions&lt;/h3&gt;
&lt;p&gt;Here&amp;#8217;s a very simple compile-time function in the C++ template language:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class T&amp;gt;
struct IsPtr {
    static const bool apply = false;
}&lt;/pre&gt;
&lt;p&gt;If it doesn&amp;#8217;t look much like a function to you, here it is in more normal ad-hoc notation:&lt;/p&gt;
&lt;pre&gt;IsPtr(T) {
    return false;
}&lt;/pre&gt;
&lt;p&gt;You can &amp;#8220;execute&amp;#8221; or &amp;#8220;call&amp;#8221; this meta-function by instantiating the template &lt;var&gt;IsPtr&lt;/var&gt; with a type argument and accessing its member &lt;var&gt;apply&lt;/var&gt;:&lt;/p&gt;
&lt;pre&gt;IsPtr&amp;lt;int&amp;gt;::apply;&lt;/pre&gt;
&lt;p&gt;There is nothing magical about &amp;#8220;apply&amp;#8221;, you can call it anything (&amp;#8220;result&amp;#8221; or &amp;#8220;value&amp;#8221; are other popular identifiers). This particular meta-function returns a Boolean, but any compile-time constant may be returned. What&amp;#8217;s more important, any type or a template may be returned. But let&amp;#8217;s not get ahead of ourselves.&lt;/p&gt;
&lt;h3&gt;-Pattern matching&lt;/h3&gt;
&lt;p&gt;You might be wondering what the use is for a function (I&amp;#8217;ll be dropping the &amp;#8220;meta-&amp;#8221; prefix in what follows) that always returns &lt;var&gt;false&lt;/var&gt; and is called &lt;var&gt;IsPtr&lt;/var&gt;. Enter the next weapon in the arsenal of functional programmers: pattern matching. What we need here is to be able to match function arguments to different patterns and execute different code depending on the match. In particular, we&amp;#8217;d like to return a different value, &lt;var&gt;true&lt;/var&gt;, for T matching the pattern &lt;var&gt;T*&lt;/var&gt;. In the C++ metalanguage this is done by partial template specialization. It&amp;#8217;s enough to define another template of the same name that matches a more specialized pattern, &lt;var&gt;T*&lt;/var&gt;:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class T&amp;gt;
struct IsPtr&amp;lt;T*&amp;gt; {
    static const bool apply = true;
}&lt;/pre&gt;
&lt;p&gt;When faced with the call, &lt;/p&gt;
&lt;pre&gt;IsPtr&amp;lt;int*&amp;gt;::apply&lt;/pre&gt;
&lt;p&gt;the compiler will first look for specializations of the template &lt;var&gt;IsPtr&lt;/var&gt;, starting with the most specialized one. In our case, the argument &lt;var&gt;int*&lt;/var&gt; matches the pattern &lt;var&gt;T*&lt;/var&gt; so the version returning &lt;var&gt;true&lt;/var&gt; will be instantiated. Accessing the &lt;var&gt;apply&lt;/var&gt; member of this instantiation will result in the Boolean value &lt;var&gt;true&lt;/var&gt;, which is exactly what we wanted. Let me rewrite this example using less obfuscated syntax.&lt;/p&gt;
&lt;pre&gt;IsPtr(T*) {
    return true;
}
IsPtr(T) { // default case
    return false;
}&lt;/pre&gt;
&lt;p&gt;D template syntax is slightly less complex than that of C++. The above example will read:&lt;/p&gt;
&lt;pre&gt;template IsPtr(T) {
    static if (is (T dummy: U*, U))
        enum IsPtr = true;
    else
        enum IsPtr = false;
}
// Compile-time tests
static assert( IsPtr!(int*) );
static assert( !IsPtr!(int) );
&lt;/pre&gt;
&lt;p&gt;As you can see, D offers compile-time &lt;var&gt;if&lt;/var&gt; statements and more general pattern matching. The syntax of pattern matching is not as clear as it could be (what&amp;#8217;s with the &lt;var&gt;dummy&lt;/var&gt;?), but it&amp;#8217;s more flexible. Compile-time constants are declared as &lt;var&gt;enum&lt;/var&gt;s. &lt;/p&gt;
&lt;p&gt;There is one little trick (a hack?) that makes the syntax of &amp;#8220;function call&amp;#8221; a little cleaner. If, inside the template, you define a member of the same name as the template itself (I call it the &amp;#8220;eponymous&amp;#8221; member) than you don&amp;#8217;t have to use the &amp;#8220;apply&amp;#8221; syntax. The &amp;#8220;call&amp;#8221; looks more like a call, except for the exclamation mark before the argument list (a D tradeoff for not using angle brackets). You&amp;#8217;ll see later how the eponymous trick fails for more complex cases.&lt;/p&gt;
&lt;h3&gt;-Lists&lt;/h3&gt;
&lt;p&gt;The fundamental data structure in all functional languages is a list. Lists are very easy to operate upon using recursive algorithms and, as it turns out, they can be used to define arbitrarily complex data structures. No wonder C++0x felt obliged to introduce a compile-time type list as a primitive. It&amp;#8217;s called a &lt;i&gt;template parameter pack&lt;/i&gt; and the new syntax is:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;class... T&amp;gt;Foo&lt;/pre&gt;
&lt;p&gt;You can instantiate such a template with zero arguments,&lt;/p&gt;
&lt;pre&gt;Foo&amp;lt;&amp;gt;&lt;/pre&gt;
&lt;p&gt;one argument,&lt;/p&gt;
&lt;pre&gt;Foo&amp;lt;int&amp;gt;&lt;/pre&gt;
&lt;p&gt;or more arguments,&lt;/p&gt;
&lt;pre&gt;Foo&amp;lt;int, char*, void*&amp;gt;&lt;/pre&gt;
&lt;p&gt;How do you iterate over a type list? Well, there is no iteration in the metalanguge so the best you can do is to use recursion. To do that, you have to be able to separate the head of the list from its tail. Then you perform the action on the head and call yourself recursively with the tail. The head/tail separation is done using pattern matching. &lt;/p&gt;
&lt;p&gt;Let me demonstrate a simple example from the paper &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf"&gt;Variadic Templates&lt;/a&gt; by Garry Powell et al. It calculates the length of a pack using recursion. First, the basic case&amp;#8211;length-zero list:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;&amp;gt;
struct count &amp;lt;&amp;gt; {
    static const int value = 0;
}&lt;/pre&gt;
&lt;p&gt;That is the full specialization of a template, so it will be tried first. Here&amp;#8217;s the general case:&lt;/p&gt;
&lt;pre&gt;template&amp;lt;typename Head, typename... Tail&amp;gt;
struct count&amp;lt;Head, Tail...&amp;gt; {
    static const int value = 1 + count&amp;lt;Tail...&amp;gt;::value;
}&lt;/pre&gt;
&lt;p&gt;Let&amp;#8217;s see what it would look like in &amp;#8220;normal&amp;#8221; notation:&lt;/p&gt;
&lt;pre&gt;count() {
    return 0;
}
count(head, tail) {
    return 1 + count(tail);
}&lt;/pre&gt;
&lt;p&gt;And here&amp;#8217;s the D version:&lt;/p&gt;
&lt;pre&gt;template count(T...) {
    static if (T.length == 0)
        enum count = 0;
    else
        enum count = 1 + count!(T[1..$]);
}
// tests
static assert( count!() == 0);
static assert( count!(int, char*, char[]) == 3);&lt;/pre&gt;
&lt;p&gt;&lt;var&gt;T&amp;#8230;&lt;/var&gt; denotes a type tuple, which supports array-like access. To get to the tail of the list, D uses array slicing, where &lt;var&gt;T[1..$]&lt;/var&gt; denotes the slice of the array starting from index 1 up to the length of the array (denoted by the dollar sign). I&amp;#8217;ll explain the important differences between C++ pack and D tuple (including pack expansion) in the next installment.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;When looked upon from the functional perspective, template metaprogramming doesn&amp;#8217;t look as intimidating as it it seems at first. Knowing this interpretation makes you wonder if there isn&amp;#8217;t a better syntax or even a better paradigm for metaprogramming.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ll discuss more interesting parts of template metaprogramming in the next installment (this one is getting too big already). In particular, I&amp;#8217;ll show examples of higher order meta-functions like &lt;var&gt;Filter&lt;/var&gt; or &lt;var&gt;Not&lt;/var&gt; and some interesting tricks with type lists.&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/1016/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/1016/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/1016/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/1016/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/1016/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/1016/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/1016/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/1016/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/1016/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/1016/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=1016&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Life in hell</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/z_JhK6zXU6U/-11ccf34d" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-11ccf34d</id>
		<updated>2009-09-06T18:24:31+00:00</updated>
		<content type="html">&lt;div class="warning"&gt;
&lt;p class="first admonition-title"&gt;Warning&lt;/p&gt;
&lt;p class="last"&gt;Long post ahead =)&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As I said before, &lt;a href="http://proj.llucax.com.ar/blog/dgc/blog/post/-288428a1" class="reference external"&gt;debug is hell&lt;/a&gt; in &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt;, at least if you're using
a compiler that doesn't write proper debug information and you're writing
a garbage collector. But you have to do it when things go wrong. And things
usually go wrong.&lt;/p&gt;
&lt;p&gt;This is a small chronicle about how I managed to debug a weird problem =)&lt;/p&gt;
&lt;p&gt;I had my &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git" class="reference external"&gt;Naive GC&lt;/a&gt; working and getting &lt;a href="http://proj.llucax.com.ar/blog/dgc/blog/post/37e6cb2a" class="reference external"&gt;good stats&lt;/a&gt; with some small
&lt;a href="http://git.llucax.com.ar/w/software/dgc/dgcbench.git" class="reference external"&gt;micro-benchmarks&lt;/a&gt;, so I said &lt;em&gt;let's benchmark something real&lt;/em&gt;. There is almost
no real &lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt; applications out there, suitable for an automated GC benchmark at
least &lt;a href="http://feeds.feedburner.com/llucax-d#benchapp" id="id2" class="footnote-reference"&gt;[1]&lt;/a&gt;. &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; looked like a good candidate so I said &lt;em&gt;let's use Dil
in the benchmark suite!&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;And I did. But &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; didn't work as I expected. Even when running it without
arguments, in which case a nice help message like this should be displayed:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
dil v1.000
Copyright (c) 2007-2008 by Aziz Köksal. Licensed under the GPL3.

Subcommands:
  help (?)
  compile (c)
  ddoc (d)
  highlight (hl)
  importgraph (igraph)
  python (py)
  settings (set)
  statistics (stats)
  tokenize (tok)
  translate (trans)

Type 'dil help &amp;lt;subcommand&amp;gt;' for more help on a particular subcommand.

Compiled with Digital Mars D v1.041 on Sat Aug 29 18:04:34 2009.
&lt;/pre&gt;
&lt;p&gt;I got this instead:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
Generate an XML or HTML document from a D source file.
Usage:
  dil gen file.d [Options]

Options:
  --syntax         : generate tags for the syntax tree
  --xml            : use XML format (default)
  --html           : use HTML format

Example:
  dil gen Parser.d --html --syntax &amp;gt; Parser.html
&lt;/pre&gt;
&lt;p&gt;Which it isn't even a valid &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; command (it looks like a &lt;em&gt;dead&lt;/em&gt; string in some
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;data/lang_??.d&lt;/span&gt;&lt;/tt&gt; &lt;a href="http://github.com/azizk/dil/blob/e284797bb48769a67f4b3d2d61f3bc0b4fcf5011/data/lang_en.d#L77" class="reference external"&gt;files&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;I ran &lt;a href="http://valgrind.org/" class="reference external"&gt;Valgrind&lt;/a&gt; on it and detected a suspicious invalid read of size 4 when
reading the last byte of a 13 bytes long class instance. I thought maybe the
compiler was assuming the GC allocated block with size multiples of the word
size, so I made &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l502" class="reference external"&gt;gc_malloc()&lt;/a&gt; &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/commitdiff/39707a88bed116fbda8c590c9b6ff9193f30f58f" class="reference external"&gt;allocate multiples of the word size&lt;/a&gt;, but
nothing happened. Then I thought that maybe the memory blocks should be aligned
to a multiple of a word, so I made &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l502" class="reference external"&gt;gc_malloc()&lt;/a&gt; &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/commitdiff/39707a88bed116fbda8c590c9b6ff9193f30f58f" class="reference external"&gt;align the data portion of
the cell to a multiple of a word&lt;/a&gt;, but nothing.&lt;/p&gt;
&lt;p&gt;Since &lt;a href="http://valgrind.org/" class="reference external"&gt;Valgrind&lt;/a&gt; only detected that problem, which was at the static constructor
of the module &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;tango.io.Console&lt;/span&gt;&lt;/tt&gt;, I though it might be a &lt;a href="http://www.dsource.org/projects/tango" class="reference external"&gt;Tango&lt;/a&gt; bug, so
I &lt;a href="http://www.dsource.org/projects/tango/ticket/1734" class="reference external"&gt;report&lt;/a&gt;ed it. But it wasn't &lt;a href="http://www.dsource.org/projects/tango" class="reference external"&gt;Tango&lt;/a&gt;'s fault. The invalid read looked
like a DMD 1.042 bug; DMD 1.041 didn't have that problem, but my collector
still failed to run &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt;. So I was back to zero.&lt;/p&gt;
&lt;p&gt;I tried the &lt;a href="http://www.dsource.org/projects/tango/browser/tags/releases/0.99.8/lib/gc/stub/gc.d" class="reference external"&gt;Tango stub collector&lt;/a&gt; and it worked, so I tried mine disabling
the collections, and it worked too. So finally I could narrow the problem to
the collection phase (which isn't much, but it's something). The first thing
I could think it could be wrong in a collection is that cells still in use are
swept as if they were unused, so I then disabled the sweep phase only, and it
kept working.&lt;/p&gt;
&lt;p&gt;So, everything pointer to prematurely freed cells. But why my collector was
freeing cells prematurely being so, so simple? I reviewed the code a couple of
times and couldn't find anything evidently wrong. To confirm my theory and with
the hope of getting some extra info, I decided to &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/commitdiff/bc664a95db5c7bab194f2e64cf96b6f092c5e60c" class="reference external"&gt;write a weird pattern&lt;/a&gt; in
the swept cells and then check if that pattern was intact when giving them back
to the mutator (the &lt;a href="http://www.dsource.org/projects/tango/browser/tags/releases/0.99.8/lib/gc/basic" class="reference external"&gt;basic GC&lt;/a&gt; can do that too if compiled with
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;-debug=MEMSTOMP&lt;/span&gt;&lt;/tt&gt;). That would confirm that the swept memory were still in
use. And it did.&lt;/p&gt;
&lt;p&gt;The I tried this modified GC with &lt;em&gt;memory stomp&lt;/em&gt; with my &lt;a href="http://git.llucax.com.ar/w/software/dgc/dgcbench.git" class="reference external"&gt;micro-benchmarks&lt;/a&gt; and
they worked just fine, so I started to doubt again that it was my GC's problem.
But since those benchmarks didn't use much of the GC API, I thought maybe &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt;
was using some strange features of making some assumptions that were only true
for the current implementation, so I asked Aziz Köksal (&lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; creator) and he
pointed me to some &lt;a href="http://github.com/azizk/dil/blob/e284797bb48769a67f4b3d2d61f3bc0b4fcf5011/src/dil/lexer/Token.d#L262" class="reference external"&gt;portion of code&lt;/a&gt; that allocated memory from the C heap,
overriding the operators &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;new&lt;/span&gt;&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;delete&lt;/span&gt;&lt;/tt&gt; for the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;Token&lt;/span&gt;&lt;/tt&gt; struct. There
is a &lt;a href="http://code.google.com/p/dil/issues/detail?id=11" class="reference external"&gt;bug&lt;/a&gt; in &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; there, because apparently that struct store pointers to the
GC heap but it's not registered as a root, so it looks like a good candidate.&lt;/p&gt;
&lt;p&gt;So I commented out the overridden &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;new&lt;/span&gt;&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;delete&lt;/span&gt;&lt;/tt&gt; operators, so the
regular GC-based operators were used. But I still got nothing, the wrong help
message were printed again. Then I saw that &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; was manually freeing memory
using &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;delete&lt;/span&gt;&lt;/tt&gt;. So I decided to make my &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l661" class="reference external"&gt;gc_free()&lt;/a&gt; implementation a &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;NOP&lt;/span&gt;&lt;/tt&gt;
to let the GC take over of &lt;strong&gt;all&lt;/strong&gt; memory management... And &lt;em&gt;finally&lt;/em&gt; all
&lt;a href="http://feeds.feedburner.com/llucax-d#all" id="id13" class="footnote-reference"&gt;[2]&lt;/a&gt; worked out fine!  =)&lt;/p&gt;
&lt;p&gt;So, the problem should be either my &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l661" class="reference external"&gt;gc_free()&lt;/a&gt; implementation (which is
really simple) or a  &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; bug.&lt;/p&gt;
&lt;p&gt;In order to get some extra information on where the problem is, I changed the
&lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/346f04b3e1026ded5af3ac95a483b2c3d05a6d60:/gc/cell.d#l86" class="reference external"&gt;Cell.alloc()&lt;/a&gt; implementation to use &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mmap.2.html" class="reference external"&gt;mmap&lt;/a&gt; to &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/commitdiff/cc637a89be9b51945246bd65fa15080464a90aca" class="reference external"&gt;allocate whole pages&lt;/a&gt;, one
for the cell's header, and one or more for the cell &lt;em&gt;data&lt;/em&gt;. This way, could
easily &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mprotect.2.html" class="reference external"&gt;mprotect&lt;/a&gt; the cell &lt;em&gt;data&lt;/em&gt; when the cell was swept (and un-&lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mprotect.2.html" class="reference external"&gt;mprotect&lt;/a&gt;ing them when they were give back to the program) in order to make &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt;
segfault exactly where the freed memory was used.&lt;/p&gt;
&lt;p&gt;I ran &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; using &lt;a href="http://en.wikipedia.org/wiki/Strace" class="reference external"&gt;strace&lt;/a&gt; and this is what happened:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
[...]
 (a)  write(1, "Cell.alloc(80)\n", 15)        = 15
 (b)  mmap2(NULL, 8192, PROT_READ|PROT_WRITE, ...) = 0xb7a2e000
[...]
 (c)  mprotect(0xb7911000, 4096, PROT_NONE)   = 0
      mprotect(0xb7913000, 4096, PROT_NONE)   = 0
[...]
      mprotect(0xb7a2b000, 4096, PROT_NONE)   = 0
      mprotect(0xb7a2d000, 4096, PROT_NONE)   = 0
 (d)  mprotect(0xb7a2f000, 4096, PROT_NONE)   = 0
      mprotect(0xb7a43000, 4096, PROT_NONE)   = 0
      mprotect(0xb7a3d000, 4096, PROT_NONE)   = 0
[...]
      mprotect(0xb7a6b000, 4096, PROT_NONE)   = 0
 (e)  mprotect(0xb7a73000, 4096, PROT_NONE)   = 0
 (f)  mprotect(0xb7a73000, 4096, PROT_READ|PROT_WRITE) = 0
      mprotect(0xb7a6b000, 4096, PROT_READ|PROT_WRITE) = 0
[...]
      mprotect(0xb7a3f000, 4096, PROT_READ|PROT_WRITE) = 0
 (g)  mprotect(0xb7a3d000, 4096, PROT_READ|PROT_WRITE) = 0
      --- SIGSEGV (Segmentation fault) @ 0 (0) ---
      +++ killed by SIGSEGV (core dumped) +++
&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;(a)&lt;/strong&gt; is a debug print, showing the size of the &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l502" class="reference external"&gt;gc_malloc()&lt;/a&gt; call  that got
the address &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;0xb7a2e000&lt;/span&gt;&lt;/tt&gt;. The &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mmap.2.html" class="reference external"&gt;mmap&lt;/a&gt; &lt;strong&gt;(b)&lt;/strong&gt; is &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;8192&lt;/span&gt;&lt;/tt&gt; bytes in size because
I allocate a page for the cell header (for internal GC information) and another
separated page for the data (so I can only &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mprotect.2.html" class="reference external"&gt;mprotect&lt;/a&gt; the data page and keep the
header page read/write); that allocation asked for a new fresh couple of pages
to the OS (that's why you see a &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mmap.2.html" class="reference external"&gt;mmap&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;From &lt;strong&gt;(c)&lt;/strong&gt; to &lt;strong&gt;(e)&lt;/strong&gt; you can see a sequence of several &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mprotect.2.html" class="reference external"&gt;mprotect&lt;/a&gt;, that are
cells being swept by a collection (protecting the cells against read/write so
if the mutator tries to touch them, a &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;SIGSEGV&lt;/span&gt;&lt;/tt&gt; is on the way).&lt;/p&gt;
&lt;p&gt;From &lt;strong&gt;(f)&lt;/strong&gt; to &lt;strong&gt;(g)&lt;/strong&gt; you can see another sequence of &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mprotect.2.html" class="reference external"&gt;mprotect&lt;/a&gt;, this time
giving the mutator permission to touch that pages, so that's &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l502" class="reference external"&gt;gc_malloc()&lt;/a&gt;
recycling the recently swept cells.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;(d)&lt;/strong&gt; shows the cell allocated in &lt;strong&gt;(a)&lt;/strong&gt; being swept. Why the address is not
the same (this time is &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;0xb7a2f000&lt;/span&gt;&lt;/tt&gt; instead of &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;0xb7a2e000&lt;/span&gt;&lt;/tt&gt;)? Because, as
you remember, the first page is used for the cell header, so the data should be
at &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;0xb7a2e000&lt;/span&gt; &lt;span class="pre"&gt;+&lt;/span&gt; &lt;span class="pre"&gt;4096&lt;/span&gt;&lt;/tt&gt;, which is exactly &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;0xb7a2f000&lt;/span&gt;&lt;/tt&gt;, the start of the
memory block that the sweep phase (and &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l661" class="reference external"&gt;gc_free()&lt;/a&gt; for that matter) was
protecting.&lt;/p&gt;
&lt;p&gt;Finally we see the program getting his nice &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;SIGSEGV&lt;/span&gt;&lt;/tt&gt; and dumping a nice
little &lt;a href="http://en.wikipedia.org/wiki/Core_dump" class="reference external"&gt;core&lt;/a&gt; for touching what it shouldn't.&lt;/p&gt;
&lt;p&gt;Then I opened the &lt;a href="http://en.wikipedia.org/wiki/Core_dump" class="reference external"&gt;core&lt;/a&gt; with &lt;a href="http://www.gnu.org/software/gdb/" class="reference external"&gt;GDB&lt;/a&gt; and did something like this &lt;a href="http://feeds.feedburner.com/llucax-d#demangle" id="id15" class="footnote-reference"&gt;[3]&lt;/a&gt;:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
Program terminated with signal 11, Segmentation fault.
(a)  #0  0x08079a96 in getDispatchFunction ()
     (gdb) print $pc
(b)  $1 = (void (*)()) 0x8079a96 &amp;lt;getDispatchFunction+30&amp;gt;
     (gdb) disassemble $pc
     Dump of assembler code for function
     getDispatchFunction:
     0x08079a78 &amp;lt;getDispatchFunction+0&amp;gt;:  push   %ebp
     0x08079a79 &amp;lt;getDispatchFunction+1&amp;gt;:  mov    %esp,%ebp
     0x08079a7b &amp;lt;getDispatchFunction+3&amp;gt;:  sub    $0x8,%esp
     0x08079a7e &amp;lt;getDispatchFunction+6&amp;gt;:  push   %ebx
     0x08079a7f &amp;lt;getDispatchFunction+7&amp;gt;:  push   %esi
     0x08079a80 &amp;lt;getDispatchFunction+8&amp;gt;:  mov    %eax,-0x4(%ebp)
     0x08079a83 &amp;lt;getDispatchFunction+11&amp;gt;: mov    -0x4(%ebp),%eax
     0x08079a86 &amp;lt;getDispatchFunction+14&amp;gt;: call   0x80bccb4 &amp;lt;objectInvariant&amp;gt;
     0x08079a8b &amp;lt;getDispatchFunction+19&amp;gt;: push   $0xb9
     0x08079a90 &amp;lt;getDispatchFunction+24&amp;gt;: mov    0x8(%ebp),%edx
     0x08079a93 &amp;lt;getDispatchFunction+27&amp;gt;: add    $0xa,%edx
(c)  0x08079a96 &amp;lt;getDispatchFunction+30&amp;gt;: movzwl (%edx),%ecx
     [...]
     (gdb) print /x $edx
(d)  $2 = 0xb7a2f000
&lt;/pre&gt;
&lt;p&gt;First, in &lt;strong&gt;(a)&lt;/strong&gt;, &lt;a href="http://www.gnu.org/software/gdb/" class="reference external"&gt;GDB&lt;/a&gt; tells where the program received the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;SIGSEGV&lt;/span&gt;&lt;/tt&gt;. In
&lt;strong&gt;(b)&lt;/strong&gt; I print the program counter register to get a more readable  hint on
where the program segfaulted. It was at &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;getDispatchFunction+30&lt;/span&gt;&lt;/tt&gt;, so
I disassemble that function to see that the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;SIGSEGV&lt;/span&gt;&lt;/tt&gt; was received when doing
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;movzwl&lt;/span&gt; &lt;span class="pre"&gt;(%edx),%ecx&lt;/span&gt;&lt;/tt&gt; (moving the contents of the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;ECX&lt;/span&gt;&lt;/tt&gt; register to the
memory pointed to by the address in the register &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;EDX&lt;/span&gt;&lt;/tt&gt;) at &lt;strong&gt;(c)&lt;/strong&gt;. In
&lt;strong&gt;(d)&lt;/strong&gt; I get the value of the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;EDX&lt;/span&gt;&lt;/tt&gt; register, and it's &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;0xb7a2f000&lt;/span&gt;&lt;/tt&gt;. Do
you remember that value? Is the data address for the cell at &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;0xb7a2e000&lt;/span&gt;&lt;/tt&gt;,
the one that was recently swept (and &lt;a href="http://www.kernel.org/doc/man-pages/online/pages/man2/mprotect.2.html" class="reference external"&gt;mprotect&lt;/a&gt;ed). That's not good for
business.&lt;/p&gt;
&lt;p&gt;This is the offending method (at &lt;a href="http://github.com/azizk/dil/blob/e284797bb48769a67f4b3d2d61f3bc0b4fcf5011/src/dil/ast/Visitor.d" class="reference external"&gt;dil/src/ast/Visitor.d&lt;/a&gt;):&lt;/p&gt;
&lt;pre class="literal-block"&gt;
Node function(Visitor, Node) getDispatchFunction()(Node n)
{
    return cast(Node function(Visitor, Node))dispatch_vtable[n.kind];
}
&lt;/pre&gt;
&lt;p&gt;Since I can't get any useful information from &lt;a href="http://www.gnu.org/software/gdb/" class="reference external"&gt;GDB&lt;/a&gt; (I can't even get a proper
backtrace &lt;a href="http://feeds.feedburner.com/llucax-d#backtrace" id="id17" class="footnote-reference"&gt;[4]&lt;/a&gt;) except for the mangled function name (because the
wrong debug information produced by DMD), I had to split that function into
smaller functions to confirm that the problem was in &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;n.kind&lt;/span&gt;&lt;/tt&gt; (I guess
I could figure that out by eating some more assembly, but I'm not &lt;em&gt;that&lt;/em&gt; well
trained at eating asm yet =). This means that the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;Node&lt;/span&gt;&lt;/tt&gt; instance &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;n&lt;/span&gt;&lt;/tt&gt; is
the one prematurely freed.&lt;/p&gt;
&lt;p&gt;This is particularly weird, because it looks like the node is being swept, not
prematurely freed using an explicit &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;delete&lt;/span&gt;&lt;/tt&gt;. So it seems like the GC is
missing some roots (or there are non-aligned pointers or weird stuff like
that). The fact that this works fine with the &lt;a href="http://www.dsource.org/projects/tango" class="reference external"&gt;Tango&lt;/a&gt; basic collector is
intriguing too. One thing I can come up with to explain why it works in the
basic collector is because it makes a lot less collections than the &lt;cite&gt;naive GC&lt;/cite&gt;
(the latter is really lame =). So maybe the &lt;em&gt;rootless&lt;/em&gt; object becomes really
free before the basic collector has a chance to run a collection and because of
that the problem is never detected.&lt;/p&gt;
&lt;p&gt;I spent over 10 days now investigating this issue (of course this is not near
a full-time job for me so I can only dedicate a couple of days a week to this
=), and I still can't find a clear cause for this problem, but I'm a little
inclined towards a &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; bug, so I &lt;a href="http://code.google.com/p/dil/issues/detail?id=12" class="reference external"&gt;report&lt;/a&gt;ed one =). So we'll see how this
evolves; for now I'll just make &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git/blob/2d8639409b4749afd92266347f20b99da80e14c9:/gc/gc.d#l661" class="reference external"&gt;gc_free()&lt;/a&gt; a NOP to continue my testing...&lt;/p&gt;
&lt;table rules="none" frame="void" id="benchapp" class="docutils footnote"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a href="http://feeds.feedburner.com/llucax-d#id2" class="fn-backref"&gt;[1]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;Please let me know if you have any working, real, Tango-based
&lt;a href="http://www.digitalmars.com/d/" class="reference external"&gt;D&lt;/a&gt; application suitable for GC benchmarks (i.e., using the GC and easily
scriptable to run it automatically).&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table rules="none" frame="void" id="all" class="docutils footnote"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a href="http://feeds.feedburner.com/llucax-d#id13" class="fn-backref"&gt;[2]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;em&gt;all&lt;/em&gt; being running &lt;a href="http://code.google.com/p/dil" class="reference external"&gt;Dil&lt;/a&gt; without arguments to get the right help
message =)&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table rules="none" frame="void" id="demangle" class="docutils footnote"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a href="http://feeds.feedburner.com/llucax-d#id15" class="fn-backref"&gt;[3]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;I have shortened the name of the functions because they were
huge, cryptic, mangled names =). The real name of &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;getDispatchFunction&lt;/span&gt;&lt;/tt&gt; is
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;_D3dil3ast7Visitor7Visitor25__T19getDispatchFunctionZ19getDispatchFunctionMFC3dil3ast4Node4NodeZPFC3dil3ast7Visitor7VisitorC3dil3ast4Node4NodeZC3dil3ast4Node4Node&lt;/span&gt;&lt;/tt&gt;
(is not much better when demangled: &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;class&lt;/span&gt; &lt;span class="pre"&gt;dil.ast.Node.Node&lt;/span&gt; &lt;span class="pre"&gt;function(class&lt;/span&gt;
&lt;span class="pre"&gt;dil.ast.Visitor.Visitor,&lt;/span&gt; &lt;span class="pre"&gt;class&lt;/span&gt; &lt;span class="pre"&gt;dil.ast.Node.Node)*&lt;/span&gt;
&lt;span class="pre"&gt;dil.ast.Visitor.Visitor.getDispatchFunction!().getDispatchFunction(class&lt;/span&gt;
&lt;span class="pre"&gt;dil.ast.Node.Node)&lt;/span&gt;&lt;/tt&gt; =). The real name of &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;objectInvariant&lt;/span&gt;&lt;/tt&gt; is
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;D9invariant12_d_invariantFC6ObjectZv&lt;/span&gt;&lt;/tt&gt; and has no demagled name that
I know of, but I guessed is the Object class invariant.&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;table rules="none" frame="void" id="backtrace" class="docutils footnote"&gt;
&lt;colgroup&gt;&lt;col class="label" /&gt;&lt;col /&gt;&lt;/colgroup&gt;
&lt;tbody valign="top"&gt;
&lt;tr&gt;&lt;td class="label"&gt;&lt;a href="http://feeds.feedburner.com/llucax-d#id17" class="fn-backref"&gt;[4]&lt;/a&gt;&lt;/td&gt;&lt;td&gt;&lt;p class="first"&gt;Here is what I get from &lt;a href="http://www.gnu.org/software/gdb/" class="reference external"&gt;GDB&lt;/a&gt;:&lt;/p&gt;
&lt;pre class="literal-block"&gt;
(gdb) bt
#0  0x08079a96 in getDispatchFunction ()
#1  0xb78d5000 in ?? ()
#2  0xb789d000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
&lt;/pre&gt;
&lt;p class="last"&gt;(function name unmangled and shortened for readbility)&lt;/p&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/z_JhK6zXU6U" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">DMD 1.047 and 2.032</title>
		<link href="http://dblog.aldacron.net/2009/09/06/dmd-1-047-and-2-032/" />
		<id>http://dblog.aldacron.net/?p=661</id>
		<updated>2009-09-06T03:59:21+00:00</updated>
		<content type="html">Sorry for being so quiet here. I&amp;#8217;ve been largely out of the D loop for a bit, though I do check the newsgroups once every week or so for major announcements. The big news this week is the release of the shiny new DMD 1.047 and 2.032.
Both versions include updates to the Compile Time Function [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=shWgtBRGf4M:CEj4Su2EMtE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=shWgtBRGf4M:CEj4Su2EMtE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=shWgtBRGf4M:CEj4Su2EMtE:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=shWgtBRGf4M:CEj4Su2EMtE:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/09/01/spawning-a-thread-the-d-way/" />
		<id>http://bartoszmilewski.wordpress.com/?p=960</id>
		<updated>2009-09-01T21:51:24+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;Spawning a thread in non-functional languages is considered a very low-level primitive. Often &lt;var&gt;spawn&lt;/var&gt; or &lt;var&gt;CreateThread&lt;/var&gt; takes a function pointer and an untyped (void) pointer to &amp;#8220;data&amp;#8221;. The newly created thread will execute the function, passing it the untyped pointer, and it&amp;#8217;s up to the function to cast the data into something more palatable. This is indeed the lowest of the lowest. It&amp;#8217;s the stinky gutters of programming. &lt;/p&gt;
&lt;p&gt;Isn&amp;#8217;t it much nicer to create a &lt;var&gt;Thread&lt;/var&gt; or a &lt;var&gt;Runnable&lt;/var&gt; object and let the ugly casting be done under the covers? But, as I argued before, the &lt;var&gt;Thread&lt;/var&gt; object doesn&amp;#8217;t really buy you much in terms of the most important safety issue: the avoidance of data races. So we can have a &lt;var&gt;Thread&lt;/var&gt; object instead of a void pointer, and a &lt;var&gt;run&lt;/var&gt; method that understands the format of the &lt;var&gt;Thread&lt;/var&gt; object (or &lt;var&gt;Runnable&lt;/var&gt;, take your pick). But because the &lt;var&gt;Thread&lt;/var&gt; /&lt;var&gt;Runnable&lt;/var&gt; object has reference semantics, we still end up inadvertently sharing data between threads. Unless the programmer consciously avoids or synchronizes shared access, he or she is left exposed to the most vile concurrency bugs&amp;#8211;&lt;i&gt;by default&lt;/i&gt;!&lt;/p&gt;
&lt;p&gt;As they say, Cooks cover their mistakes with sauces; doctors, with six feet of dirt; language designers, with objects. &lt;/p&gt;
&lt;h2&gt;Requirements&lt;/h2&gt;
&lt;p&gt;But enough ranting! I have the opportunity to design the &lt;var&gt;spawn&lt;/var&gt; function for D and I don&amp;#8217;t want to do any more cover-ups beyond hiding the ugly systems&amp;#8217; APIs. Here are my design requirements:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;var&gt;spawn&lt;/var&gt; should take an arbitrary function as the main argument. It should refuse (at compile time) delegates or closures, which would introduce back-door sharing. (This might be relaxed later as we gain experience in controlling the sharing.)&lt;/li&gt;
&lt;li&gt;It should take a variable number of arguments of the types compatible with those of the function parameters. It should detect type mismatches at compile time.&lt;/li&gt;
&lt;li&gt;It should refuse the types of arguments that are prone to introducing data races. For now, I&amp;#8217;ll allow only value types, immutable types, and explicitly shared types (&lt;var&gt;shared&lt;/var&gt; is a type modifier in D).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I wish I could use the more precise race-free type system that I&amp;#8217;ve been describing in my previous posts, but since I can&amp;#8217;t get it into D2, there&amp;#8217;s still a little bit of &amp;#8220;programmer beware&amp;#8221; in this implementation.&lt;/p&gt;
&lt;p&gt;These requirement seem like a tall order for any language other than D. I wouldn&amp;#8217;t say it&amp;#8217;s a piece of cake in D, but it&amp;#8217;s well within the reach of a moderately experienced programmer.&lt;/p&gt;
&lt;h2&gt;Unit Tests&lt;/h2&gt;
&lt;p&gt;Let me start by writing a little use case for my design (Oh, the joys of extreme programming!):&lt;/p&gt;
&lt;pre&gt;S s = { 3.14 };
Tid tid = &lt;span&gt;spawn&lt;/span&gt;(&amp;amp;thrFun, 2, s, "hello");
tid.join;&lt;/pre&gt;
&lt;p&gt;Here&amp;#8217;s the definition of the function, &lt;var&gt;thrFun&lt;/var&gt;:&lt;/p&gt;
&lt;pre&gt;void thrFun(int i, S s, string str) {
    writeln("thread function called with: ", i, ", ", s.fl, " and ", str);
}&lt;/pre&gt;
&lt;p&gt;Its parameter types fulfill the restrictions I listed above. The &lt;var&gt;int&lt;/var&gt; is a value and so is &lt;var&gt;S&lt;/var&gt; (structs are value types in D, unless they contain references):&lt;/p&gt;
&lt;pre&gt;struct S {
    float fl;
}&lt;/pre&gt;
&lt;p&gt;Interestingly, the string is okay too, because its reference part is immutable. In D, a string is defined as an array of immutable characters, &lt;var&gt;immutable (char)[]&lt;/var&gt;.&lt;/p&gt;
&lt;p&gt;Besides positive tests, the even more important cases are negative. For instance, I don&amp;#8217;t want &lt;var&gt;spawn&lt;/var&gt; to accept a function that takes an &lt;var&gt;Object&lt;/var&gt; as argument. Objects are reference types and (if not declared &lt;var&gt;shared&lt;/var&gt;) can sneak in unprotected sharing. &lt;/p&gt;
&lt;p&gt;How do you build unit tests whose compilation should fail? Well, D has a trick for that (ignore the ugly syntax): &lt;/p&gt;
&lt;pre&gt;void fo(Object o) {}
assert (!__traits(compiles,
    (Object o) { return spawn(&amp;amp;fo, o); }));&lt;/pre&gt;
&lt;p&gt;This code asserts that the function literal (a lambda), &lt;/p&gt;
&lt;pre&gt;(Object o){ return spawn(&amp;amp;fo, o); }&lt;/pre&gt;
&lt;p&gt;does not compile with the thread function &lt;var&gt;fo&lt;/var&gt;. Now that&amp;#8217;s one useful construct worth remembering!&lt;/p&gt;
&lt;h2&gt;Implementation&lt;/h2&gt;
&lt;p&gt;Without further ado, I present you with the implementation of &lt;var&gt;spawn&lt;/var&gt; that passes all the above tests (and more):&lt;/p&gt;
&lt;pre&gt;Tid spawn(T...)(void function(T) fp, T args)
    if (isLocalMsgTypes!(T))
{
    return core.thread.spawn( &lt;span&gt;(){ fp(args); }&lt;/span&gt;);
}&lt;/pre&gt;
&lt;p&gt;This attractively terse code uses quite a handful of D features, so let me first read it out loud for kicks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;var&gt;spawn&lt;/var&gt; is a function template returning the &lt;var&gt;Tid&lt;/var&gt; (Thread ID) structure. &lt;var&gt;Tid&lt;/var&gt; is a reference-counted handle, see my previous blog.&lt;/li&gt;
&lt;li&gt;It is parameterized by a type tuple &lt;var&gt;T&amp;#8230;&lt;/var&gt;.&lt;/li&gt;
&lt;li&gt;It takes the following parameters:
&lt;ul&gt;
&lt;li&gt;a pointer to a function, &lt;var&gt;fp&lt;/var&gt;, taking arguments of the types specified by the tuple &lt;var&gt;T&amp;#8230;&lt;/var&gt;&lt;/li&gt;
&lt;li&gt;a variable number of parameters, &lt;var&gt;args&lt;/var&gt;, of types &lt;var&gt;T&amp;#8230;&lt;/var&gt;. &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The type tuple &lt;var&gt;T&amp;#8230;&lt;/var&gt; must obey the predicate &lt;var&gt;isLocalMsgTypes&lt;/var&gt;, which is defined elsewhere.&lt;/li&gt;
&lt;li&gt;The implementation of &lt;var&gt;spawn&lt;/var&gt; calls the (in general, unsafe) function &lt;var&gt;core.thread.spawn&lt;/var&gt; (defined in the module &lt;var&gt;core.thread&lt;/var&gt;) with the following closure (nested function):
&lt;pre&gt;    (){ fp(args); }&lt;/pre&gt;
&lt;p&gt;which captures local variables, &lt;var&gt;args&lt;/var&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As you may guess, the newly spawned thread runs the closure, so it has access to captured &lt;var&gt;args&lt;/var&gt; from the original thread. In general, that&amp;#8217;s a recipe for a data race. What saves the day is the predicate &lt;var&gt;isLocalMsgTypes&lt;/var&gt;, which defines what types are safe to pass as inter-thread messages. &lt;/p&gt;
&lt;p&gt;Note the important point: there should be no difference between the constraints imposed on the types of parameters passed to &lt;var&gt;spawn&lt;/var&gt; and the types of messages that can be sent to a thread. You can think of spawn parameters as initial messages sent to a nascent thread. As I said before, message types include value types, immutable types and shared types (no support for unique types yet).&lt;/p&gt;
&lt;h2&gt;Useful D features&lt;/h2&gt;
&lt;p&gt;Let me explain some of D novelties I used in the definition of &lt;var&gt;spawn&lt;/var&gt;. &lt;/p&gt;
&lt;p&gt;A function with two sets of parenthesized parameters is automatically a template&amp;#8211;the first set are template parameters, the second, runtime parameters. &lt;/p&gt;
&lt;h3&gt;-Tuples&lt;/h3&gt;
&lt;p&gt;Type tuples, like &lt;var&gt;T&amp;#8230;&lt;/var&gt;, represent arbitrary lists of types. Similar constructs have also been introduced in C++0x, presumably under pressure from Boost, to replace the unmanageably complex type lists. &lt;/p&gt;
&lt;p&gt;What are the things that you can do with a type-tuple in D? You can retrieve its length (&lt;var&gt;T.length&lt;/var&gt;), access its elements by index, or slice it; all at compile time. You can also define a variable-argument-list function, like &lt;var&gt;spawn&lt;/var&gt; and use one symbol for a whole list of arguments, as in &lt;var&gt;T args&lt;/var&gt;:&lt;/p&gt;
&lt;pre&gt;Tid spawn(T...)(void function(T) fp, T args)&lt;/pre&gt;
&lt;p&gt;Now let&amp;#8217;s go back to my test:&lt;/p&gt;
&lt;pre&gt;Tid tid = &lt;span&gt;spawn&lt;/span&gt;(&amp;amp;f, 2, s, "hello");&lt;/pre&gt;
&lt;p&gt;I spawn a thread to execute a function of three arguments, &lt;var&gt;void f(int i, S s, string str)&lt;/var&gt;. The &lt;var&gt;spawn&lt;/var&gt; template is instantiated with a type tuple &lt;var&gt;(int, S, string)&lt;/var&gt;. At compile time, this tuple is successfully tested by the predicate &lt;var&gt;isLocalMsgTypes&lt;/var&gt;. The actual arguments to &lt;var&gt;spawn&lt;/var&gt;, besides the pointer to function, are &lt;var&gt;(2, s, &amp;#8220;hello&amp;#8221;)&lt;/var&gt;, which indeed are of correct types. They appear inside &lt;var&gt;spawn&lt;/var&gt; under the collective name, &lt;var&gt;args&lt;/var&gt;. They are then used as a collective argument to &lt;var&gt;fp&lt;/var&gt; inside the closure, &lt;var&gt;(){ fp(args); }&lt;/var&gt;. &lt;/p&gt;
&lt;h3&gt;-Closures&lt;/h3&gt;
&lt;p&gt;The closure captures the arguments to &lt;var&gt;spawn&lt;/var&gt;. It is then passed to the internal function (not a template anymore), &lt;/p&gt;
&lt;pre&gt;core.thread.spawn(void delegate() dlg)&lt;/pre&gt;
&lt;p&gt;When the new thread is created, it calls the closure &lt;var&gt;dlg&lt;/var&gt;, which calls &lt;var&gt;fp&lt;/var&gt; with the captured arguments. At that point, the value arguments, &lt;var&gt;i&lt;/var&gt; and &lt;var&gt;s&lt;/var&gt; are copied, along with the shallow part of the string, &lt;var&gt;str&lt;/var&gt;. The deep part of the string, the buffer, is not copied&amp;#8211;and for a good reason too&amp;#8211; it is immutable, so it can safely be read concurrently. At that point, the thread function is free to use those arguments without worrying about races. &lt;/p&gt;
&lt;h3&gt;-Restricted Templates&lt;/h3&gt;
&lt;p&gt;The &lt;var&gt;if&lt;/var&gt; statement before the body of a template is D&amp;#8217;s response to C++0x DOA concepts (yes, after years of design discussions, concepts were finally killed with extreme prejudice). &lt;/p&gt;
&lt;pre&gt;if (isLocalMsgTypes!(T))&lt;/pre&gt;
&lt;p&gt;The &lt;var&gt;if&lt;/var&gt; is used to create &amp;#8220;restricted templates&amp;#8221;. It contains a logical compile-time expression that is checked before the template is instantiated. If the expression is &lt;var&gt;false&lt;/var&gt;, the template doesn&amp;#8217;t match and you get a compile error. Notice that template restrictions not only produce better error messages, but can also impose restrictions that are otherwise impossible or very hard to enforce. Without the restriction, &lt;var&gt;spawn&lt;/var&gt; could be called with an unsuitable type, e.g. an &lt;var&gt;Object&lt;/var&gt; not declared as &lt;var&gt;shared&lt;/var&gt; and the compiler wouldn&amp;#8217;t even blink. &lt;/p&gt;
&lt;p&gt;(I will talk about template restrictions and templates in general in a future blog.)&lt;/p&gt;
&lt;h3&gt;&amp;#8211;Message Types&lt;/h3&gt;
&lt;p&gt;Besides values, we may also pass to &lt;var&gt;spawn&lt;/var&gt; objects that are declared as &lt;var&gt;immutable&lt;/var&gt; or &lt;var&gt;shared&lt;/var&gt; (in fact, we may pass them inside values as well). In D, &lt;var&gt;shared&lt;/var&gt; objects are supposed to provide their own synchronization&amp;#8211;their methods must either be &lt;var&gt;synchronized&lt;/var&gt; or lock free. An example of a shared object that you&amp;#8217;d want to pass to &lt;var&gt;spawn&lt;/var&gt; is a message queue&amp;#8211;to be shared between the parent thread and the spawned thread.&lt;/p&gt;
&lt;p&gt;You might remember that my race-free type system proposal included &lt;var&gt;unique&lt;/var&gt; types, which would be great for message passing, and consequently as arguments to &lt;var&gt;spawn&lt;/var&gt; (there is a uniqueness proposal for Scala, and there&amp;#8217;s the Kilim message-passing system for Java based on unique types). Unfortunately, unique types won&amp;#8217;t be available in D2. Instead some kind of specialized &lt;var&gt;Unique&lt;/var&gt; library classes might be defined for that purpose.&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;The D programming language has two faces. On the one hand, it&amp;#8217;s easy to use even for a beginner. On the other hand, it provides enough expressive power to allow for the creation of sophisticated and safe libraries. What I tried to accomplish in this post is to give a peek at D from the perspective of a library writer. In particular I described mechanisms that help make the concurrency library safer to use. &lt;/p&gt;
&lt;p&gt;This is still work in progress, so don&amp;#8217;t expect to see it in the current releases of D2. &lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/960/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/960/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/960/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/960/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/960/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/960/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/960/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/960/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/960/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/960/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=960&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">"Silly benchmark" in D/C++</title>
		<link href="http://leonardo-m.livejournal.com/88088.html" />
		<id>http://leonardo-m.livejournal.com/88088.html</id>
		<updated>2009-08-30T19:45:46+00:00</updated>
		<content type="html">All the code discussed here:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/silly_bench.zip"&gt;http://www.fantascienza.net/leonardo/js/silly_bench.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Slava Pestov, author of the programming language Factor, has created a very simple benchmark. Despite being defined "silly" such benchmark has shown me some interesting things.&lt;br /&gt;&lt;br /&gt;This the original posts:&lt;br /&gt;"Performance comparison between Factor and Java on a contrived benchmark"&lt;br /&gt;&lt;a href="http://factor-language.blogspot.com/2009/08/performance-comparison-between-factor.html"&gt;http://factor-language.blogspot.com/2009/08/performance-comparison-between-factor.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;"Struct arrays benchmark revisited: trig function calls are slow in Java, but without them Factor is still 3x faster":&lt;br /&gt;&lt;a href="http://factor-language.blogspot.com/2009/08/struct-arrays-benchmark-revisited.html"&gt;http://factor-language.blogspot.com/2009/08/struct-arrays-benchmark-revisited.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;What the benchmark does:&lt;br /&gt;- It works on points, which are triplets of single-precision floats, (x,y,z)&lt;br /&gt;- First, the benchmark creates a list of 5000000 points for i=0..4999999, where the ith point is (sin(i),cos(i)*3,sin(i)*sin(i)/2).&lt;br /&gt;-Then, each point is normalized; the x, y, and z components are divided by sqrt(x*x+y*y+z*z).&lt;br /&gt;- Finally, the maximum x, y, and z components are found, for all points, and this is printed out.&lt;br /&gt;&lt;br /&gt;The purpose of this benchmark is to compare performance of an array of struct in Factor to an array of class references in Java. It also shows how trigonometric functions are managed.&lt;br /&gt;&lt;br /&gt;Slava has given Java code, that I have modified a bit, adding more timings inside, pulling out a subclass, making it static. The overall running time of the Java version is improved just a little.&lt;br /&gt;&lt;br /&gt;The Java version is slow for the large amount of memory allocations, and also because it doesn't use the CPU native trigonometric instructions (sin, cos or sincos) when the input is arge, because of cross platform issues and because the Intel CPU instructions return quite inaccurate results in some cases, like when the input numers are large.&lt;br /&gt;&lt;br /&gt;So I have created a second Java version, that uses an helper class (probably written by Razzi, &lt;a href="http://shootout.alioth.debian.org/gp4/benchmark.php?test=partialsums〈=java&amp;id=4"&gt;http://shootout.alioth.debian.org/gp4/benchmark.php?test=partialsums〈=java&amp;amp;id=4&lt;/a&gt; ) to reduce the input range of trig functions. The result is much faster. (2.4 seconds instead of 11.4).&lt;br /&gt;&lt;br /&gt;Then I have created three D versions:&lt;br /&gt;- The first version is designed to be very similar to the Java version, the array is filled with class references. It's slower on performing the sqrt() and other code, but even in non-release mode it's overall quite faster than the first Java version. Bothe the Java versions and this D version use lot of RAM on each iteration of the program, the GC doesn't free it efficiently.&lt;br /&gt;- The second D version is more optimized. The rray is now composed of struct values. I also delete the array at the end of each loop, so the memory used by the program is about constant. I have also used free functions instead of Silly class, but this has not much effect. D1 structs don't allow constructors (D2 has struct constructors), so I have had to change code a bit there too. The result is much faster, almost two times faster than the second Java version.&lt;br /&gt;- In the third D version I've tried to manually optimize what possible. The DMD compiler doesn't inline functions with ref arguments and some other things. I have avoided an useless inizialization of the struct array and I have manually inlined its filling. I have used for loops insead of foreach, and allocated memory from the GC heap in a raw way. I have optimized the code using only one call to sin() because the DMD compiler isn't able to see the two calls to sin() have the same results. I have hand-optimized the computation of the max struct, even if takes only a small percentage of the whole runtime. The result is a nice speeup compared to the second D version. In D there's no simple way to allocate an array of uninitialized structs (I have to test something with LDC: it may not initialize the array if the struct data is float x=void,y=void,z=void; To be tested). LDC compiler can probably improve such timings.&lt;br /&gt;&lt;br /&gt;Later, to have a baseline timing, I have translated the code to C++, and I have compiled it with G++ and LLVM-GCC. The second compiler uses calls to tle libc even using the -ffast-math compilation argument, so the running time is quite slower. Compiled with G++ the program is quite faster than the D code compiled with DMD.&lt;br /&gt;&lt;br /&gt;This code in Haskell (or Python, or D with my dlibs) can be lazy, and reduce a lot memory used and probably running time too.&lt;br /&gt;&lt;br /&gt;When possible I'll add timings with the LDC D compiler.&lt;br /&gt;&lt;br /&gt;(I have not put the Python+Psyco timings here because I have not enough RAM to test it with n=5 millions. With n=1 million the best Python+Psyco time is about 3700 milliseconds. With the first Java program the best timing with n=1 million is 577 milliseconds, about seven times faster).&lt;br /&gt;&lt;br /&gt;--------------------&lt;br /&gt;&lt;pre&gt;Timings on Windows:

...&amp;gt;java -Xms512m -Xmx512m -server Silly1
Run #0
0.8944272, 1.0, 0.4472136
10810 422 234 0  Time: 11466

...&amp;gt;java -Xms512m -Xmx512m -server Silly2
Run #0
0.8944272, 1.0, 0.4472136
1966 406 124 0  Time: 2496

...&amp;gt;silly_bench_cpp (g++)
Run #0
0.894427, 1.000000, 0.447214
334 255 36 5  Total=632

...&amp;gt;silly_bench_cpp (llvm-g++)
Run #2
0.894427, 1.000000, 0.447214
1304 374 21 5  Total=1705

...&amp;gt;silly_bench1_d (No -release mode):
Run #0
0.894427, 1.000000, 0.447214
6941 444 80 0  total = 7466

...&amp;gt;silly_bench2_d
Run #1
0.894427, 1.000000, 0.447214
785 446 74 0  total = 1305

...&amp;gt;silly_bench3_d
Run #2
0.894427, 1.000000, 0.447214
488 443 28 0  Total = 960
&lt;/pre&gt;------------------&lt;br /&gt;&lt;br /&gt;Compilation arguments for g++ and llvm-g++:&lt;br /&gt;g++ -Wall -O3 -s -fomit-frame-pointer -msse -msse2 -msse3 -march=native -ffast-math silly_bench_cpp.cpp -o silly_bench_cpp&lt;br /&gt;&lt;br /&gt;Compilation arguments for DMD:&lt;br /&gt;dmd -O -release -inline:&lt;br /&gt;&lt;br /&gt;Intel CPU Celeron 560 at 2.13 GHz, 1GB RAM, Vista Home Basic.&lt;br /&gt;&lt;br /&gt;Compilers used:&lt;br /&gt;DMD v1.042&lt;br /&gt;gcc v. 4.3.3-dw2-tdm-1 (GCC)&lt;br /&gt;LLVM-G++ gcc version 4.2.1 (Based on Apple Inc. build 5636) (LLVM build)&lt;br /&gt;Java HotSpot(TM) Client VM (build 16.0-b06, mixed mode, sharing)</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Updates and links</title>
		<link href="http://leonardo-m.livejournal.com/87980.html" />
		<id>http://leonardo-m.livejournal.com/87980.html</id>
		<updated>2009-08-27T22:36:39+00:00</updated>
		<content type="html">Updated two toy raytracers (Sphereflake and Yopyra) in my two software pages.&lt;br /&gt;&lt;br /&gt;I have also added a new benchmark, about the Boggle game:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/boggle.zip"&gt;http://www.fantascienza.net/leonardo/js/boggle.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;---------------------&lt;br /&gt;&lt;br /&gt;A nice and probably useful hierarchical allocator for C programs:&lt;br /&gt;&lt;a href="http://swapped.cc/halloc/"&gt;http://swapped.cc/halloc/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Why colors are important in scientific visualizations, and the risks of their bad usage:&lt;br /&gt;&lt;a href="http://www.research.ibm.com/people/l/lloydt/color/color.HTM"&gt;http://www.research.ibm.com/people/l/lloydt/color/color.HTM&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Theo discusses about what's important for young people to learn, the risks of violent video games, the low quality of educational software:&lt;br /&gt;&lt;a href="http://theodoregray.com/BrainRot/index.html"&gt;http://theodoregray.com/BrainRot/index.html&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Allocations graphs</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/NbYfzmMh0UE/37e6cb2a" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/37e6cb2a</id>
		<updated>2009-08-26T21:54:31+00:00</updated>
		<content type="html">&lt;p&gt;Here are a set of improved statistics graphs, now including allocation
statistics. All the data is plotted together and using the same timeline to
ease the analysis and comparison.&lt;/p&gt;
&lt;p&gt;Again, all graphs (as the graph title says), are taken using the &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git" class="reference external"&gt;Naive GC&lt;/a&gt;
(stats code still not public yet :) and you can find the code for it in my &lt;a href="http://git.llucax.com.ar/w/software/dgc/dgcbench.git" class="reference external"&gt;D
GC benchmark&lt;/a&gt; repository.&lt;/p&gt;
&lt;p&gt;This time the (big) graphs are in EPS format because I could render them in PNG
as big as I wanted and I didn't had the time to fix that =S&lt;/p&gt;
&lt;div class="center container"&gt;
&lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/big_arrays.eps" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/big_arrays.m.png" alt="big_arrays" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/rnd_data.eps" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/rnd_data.m.png" alt="rnd_data" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/rnd_data_2.eps" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/rnd_data_2.m.png" alt="rnd_data_2" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/shootout_binarytrees.eps" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/shootout_binarytrees.m.png" alt="shootout_binarytrees" /&gt;&lt;/a&gt;
&lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/split.eps" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/split.m.png" alt="split" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/startup.eps" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/startup.m.png" alt="startup" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/tree.eps" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/allocations-graphs/tree.m.png" alt="tree" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;The graphs shows the same as in the &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git" class="reference external"&gt;previous post&lt;/a&gt; with the addition of
allocation time (how long it took to perform the allocation) and space (how
many memory has been requested), which are rendered in the same graph, and an
histogram of cell sizes. The histogram differentiates cells with and without
the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;NO_SCAN&lt;/span&gt;&lt;/tt&gt; bit, which might be useful in terms on seeing how bad the
effect of false positives could be.&lt;/p&gt;
&lt;p&gt;You can easily see how allocation time peeks match allocations that triggered
a collection for example, and how bad can it be the effect of false positives,
even when almost all the heap (99.99%) has the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;NO_SCAN&lt;/span&gt;&lt;/tt&gt; bit (see
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;rnd_data_2&lt;/span&gt;&lt;/tt&gt;).&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/NbYfzmMh0UE" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/08/19/the-anatomy-of-reference-counting/" />
		<id>http://bartoszmilewski.wordpress.com/?p=997</id>
		<updated>2009-08-19T19:27:06+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;What is there to reference counting that is not obvious? In any language that supports deterministic destruction and the overloading of the copy constructor and the assignment operator it should be trivial. Or so I though until I decided to implement a simple ref-counted thread handle in D. Two problems popped up: &lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;How does reference counting interact with garbage collection?&lt;/li&gt;
&lt;li&gt;How to avoid data races in a multithreaded environment?&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;In purely garbage-collected languages, like Java, you don&amp;#8217;t implement reference counting, period. Which is pretty bad, if you ask me. GC is great at managing memory, but not so good at managing other resources. When a program runs out of memory, it forces a collection and reclaims unused memory. When it runs out of, say, system thread handles, it doesn&amp;#8217;t reclaim unused handles&amp;#8211;it just dies. You can&amp;#8217;t use GC to manage system handles. So, as far as system resources go, Java forces the programmer to use the moral equivalent of C&amp;#8217;s &lt;var&gt;malloc&lt;/var&gt; and &lt;var&gt;free&lt;/var&gt;. The programmer must free the resources explicitly.&lt;/p&gt;
&lt;p&gt;In C++ you have &lt;var&gt;std::shared_ptr&lt;/var&gt; for all your reference-counting needs, but you don&amp;#8217;t have garbage collection for memory&amp;#8211;at least not yet. (There is also the Microsoft&amp;#8217;s C++/CLI which mixes the two systems.)&lt;/p&gt;
&lt;p&gt;D offers the best of both worlds: GC &lt;i&gt;and&lt;/i&gt; deterministic destruction. So let&amp;#8217;s use GC to manage memory and reference counting (or other policies, like uniqueness) to manage other limited resources. &lt;/p&gt;
&lt;h2&gt;First attempt&lt;/h2&gt;
&lt;p&gt;The key to reference counting is to have a &amp;#8220;value&amp;#8221; type, like the &lt;var&gt;shared_ptr&lt;/var&gt; in C++, that can be cloned and passed between functions at will. Internally this value type must have access to a shared chunk of memory that contains the reference count. In &lt;var&gt;shared_ptr&lt;/var&gt; this chunk is a separately allocated integral type&amp;#8211;the counter. The important thing is that all clones of the same resource share the same counter. The counter&amp;#8217;s value reflects how many clones there are. Copy constructors and assignment operators take care of keeping the count exact. When the count goes to zero, that is the last copy of the resource goes out of scope, the resource is automatically freed (for instance, by calling &lt;var&gt;CloseHandle&lt;/var&gt;). &lt;/p&gt;
&lt;p&gt;In my first attempt, I decided that the memory allocated for the counter should be garbage-collected. After all, the important thing is to release the handle&amp;#8211;the memory will take care of itself. &lt;/p&gt;
&lt;pre&gt;struct RcHandle {
   shared Counter _counter; // GC'd shared Counter object
   HANDLE _h;
   ~this() { // destructor
      if (_counter.dec() == 0) // access the counter
         CloseHandle(_h);
   }
   // methods that keep the counter up to date
}&lt;/pre&gt;
&lt;p&gt;&lt;var&gt;RcHandle&lt;/var&gt; is a struct, which is a value type in D. &lt;var&gt;Counter&lt;/var&gt; is a class, which is a reference type; so &lt;var&gt;_counter&lt;/var&gt; really hides a pointer to shared memory.&lt;/p&gt;
&lt;p&gt;A few tests later I got a nasty surprise. My program faulted while trying to access an already deallocated counter. How did that happen? How could garbage collector deallocate my counter if I still had a reference to it?&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s what I did in my test: I embedded the ref-counted handle inside another garbage-collected object:&lt;/p&gt;
&lt;pre&gt;class Embedder { // GC'd class object
   RcHandle _rc;
}&lt;/pre&gt;
&lt;p&gt;When the time came to collect that object (which happened after the program ran to completion), its finalizer was called. Whenever an object contains fields that have non-trivial destructors, the compiler generates a finalizer that calls the destructors of those embedded objects&amp;#8211;&lt;var&gt;_rc&lt;/var&gt; in this case. The destructor of the ref-counted handle checks the reference count stored in the counter. Unfortunately the counter didn&amp;#8217;t exist anymore. Hours of debugging later I had the answer.&lt;/p&gt;
&lt;p&gt;What happened is that the garbage collector had two objects on its list: the embedder and the counter. It just so happened that the collector decided to collect those two objects in reverse order: the counter first, then the embedding object. So, by the time it got to the finalizer of the embedding object, the counter was gone! &lt;/p&gt;
&lt;p&gt;What I discovered (with the help of other members of the D team who were involved in the discussion)  was that there are some limitations on mixing garbage collection with deterministic destruction. There is a general rule:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;An object&amp;#8217;s destructor must not access any garbage-collected objects embedded in it.&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;Since the destructor of the ref-counted handle must have access to the counter, the counter must not be garbage-collectible. That means only one thing: it has to be allocated using &lt;var&gt;malloc&lt;/var&gt; and explicitly deallocated using &lt;var&gt;free&lt;/var&gt;. Which brings us to the second problem.&lt;/p&gt;
&lt;h2&gt;Concurrency&lt;/h2&gt;
&lt;p&gt;What can be simpler than an atomic reference count? On most processors you can atomically increment and decrement a memory location. You can even decrement and test the value in one uninterruptible operation. Problem solved! Or is it?&lt;/p&gt;
&lt;p&gt;There is one tiny complication&amp;#8211;the location that you are atomically modifying might disappear. I know, this is totally counter-intuitive. After all the management of the counter follows the simple rule: the last to leave the room turns off the light. If the destructor of &lt;var&gt;RcHandle&lt;/var&gt; sees the reference count going from one to zero, it knows that no other &lt;var&gt;RcHandle&lt;/var&gt; has access it, and it can safely &lt;var&gt;free&lt;/var&gt; the counter. Who can argue with cold logic?&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s the troubling scenario: &lt;var&gt;RcHandle&lt;/var&gt; is embedded in an object that is visible from two threads: &lt;/p&gt;
&lt;pre&gt;class Embedder {
   RcHandle _rcH;
}
shared Embedder emb;&lt;/pre&gt;
&lt;p&gt;Thread 1 tries to overwrite the handle:&lt;/p&gt;
&lt;pre&gt;RcHandle myHandle1;
emb._rcH = myHandle1;&lt;/pre&gt;
&lt;p&gt;while Thread 2 tries to copy the same handle to a local variable:&lt;/p&gt;
&lt;pre&gt;RcHandle myHandle2 = emb._rcH;&lt;/pre&gt;
&lt;p&gt;Consider the following interleaving:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;T2: Load the address of the &lt;var&gt;_counter&lt;/var&gt; embedded in &lt;var&gt;_rcH&lt;/var&gt;.&lt;/li&gt;
&lt;li&gt;T1: Swap &lt;var&gt;emb._rcH&lt;/var&gt; with &lt;var&gt;myHandle&lt;/var&gt;&lt;/li&gt;
&lt;li&gt;T1: Decrement the counter that was embedded in &lt;var&gt;_rcH&lt;/var&gt;. If it&amp;#8217;s zero (and it is, in this example), free the counter.&lt;/li&gt;
&lt;li&gt;T2: Increment the &lt;var&gt;_counter&lt;/var&gt;. Oops! This memory location has just been freed.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The snag is that there is a window between T2 reading the pointer in (1), and incrementing the location it&amp;#8217;s pointing to in (4). Within that window, the reference count does not match the actual number of clients having access to the pointer. If T1 happens to do its ugly deed of freeing the counter within that window, the race may turn out deadly. (This problem has been known for some time and there were various proposals to fix it, for instance using DCAS, as in this paper on &lt;a href="http://research.sun.com/people/moir/pubs/LFRC-DC02.pdf"&gt;Lock-Free Reference Counting&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;Should we worry? After all the C++ &lt;var&gt;shared_ptr&lt;/var&gt; also exposes this race and nobody is crying havoc. It turns out that it all boils down to the responsibilities of the shared object (and I&amp;#8217;m grateful to &lt;a href="http://erdani.org/"&gt;Andrei&lt;/a&gt; for pointing it out). &lt;/p&gt;
&lt;p&gt;&lt;b&gt;A shared object should not willy-nilly expose its implementation to clients&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;If the clients of &lt;var&gt;Embedder&lt;/var&gt; want access to the handle, they should call a &lt;var&gt;synchronized&lt;/var&gt; method. Here&amp;#8217;s the correct, race-free implementation of the &lt;var&gt;Embedder&lt;/var&gt; in the scenario I just described.&lt;/p&gt;
&lt;pre&gt;class Embedder {
private:
   RcHandle _rcH;
public:
   synchronized RcHandle GetHandle() const { return _rcH; }
   synchronized void SetHandle(RcHandle h) { _rcH = h; }
   ...
}&lt;/pre&gt;
&lt;p&gt;The method &lt;var&gt;GetHandle&lt;/var&gt; copies &lt;var&gt;_rcH&lt;/var&gt; and increments its count under the &lt;var&gt;Embedder&lt;/var&gt;&amp;#8217;s lock. Another thread calling &lt;var&gt;SetHandle&lt;/var&gt; has no chance of interleaving with that action, because it is forced to use the same lock. D2 actually enforces this kind of protection for shared objects, so my original example wouldn&amp;#8217;t even compile.&lt;/p&gt;
&lt;p&gt;You might be thinking right now that all this is baloney because I&amp;#8217;m trying to fit a square peg into a round hole. I&amp;#8217;m imposing value semantics on a non-atomic object, and you cannot atomically overwrite a non-atomic object. However, using this logic, you could convince yourself that a &lt;var&gt;double&lt;/var&gt; cannot have value semantics (on most common architectures doubles are too large to be atomic). And yet you can safely pass doubles between threads and assign them to each other (which is the same as overwriting). It&amp;#8217;s only when you embed a &lt;var&gt;double&lt;/var&gt; inside a shared object, you &lt;i&gt;have to&lt;/i&gt; protect it from concurrent access. And it&amp;#8217;s not the &lt;var&gt;double&lt;/var&gt; protecting itself&amp;#8211;it&amp;#8217;s the shared embedder that is responsible for synchronization. It&amp;#8217;s exactly the same with &lt;var&gt;RcHandle&lt;/var&gt;.&lt;/p&gt;
&lt;h2&gt;Conclusions&lt;/h2&gt;
&lt;p&gt;Just when you thought you knew everything about reference counting you discover something you haven&amp;#8217;t though about. The take-home message is that mixing garbage collection with deterministic destruction is not a trivial matter, and that a race-free reference-counted object is vulnerable to races when embedded it in another shared object. Something to keep in mind when programming in D or in C++.&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/997/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/997/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/997/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/997/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/997/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/997/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/997/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/997/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/997/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/997/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=997&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Graphs</title>
		<link href="http://feedproxy.google.com/~r/llucax-d/~3/tiItJRC8QIM/-4529577" />
		<id>http://www.llucax.com.ar/blog/blog.cgi/post/-4529577</id>
		<updated>2009-08-18T00:26:33+00:00</updated>
		<content type="html">&lt;p&gt;It's been exactly 3 months since the last post. I spent the last months writing
my &lt;a href="http://git.llucax.com.ar/w/facultad/75.00/informe.git" class="reference external"&gt;thesis document (in Spanish)&lt;/a&gt;, working, and being unproductive because of
the lack of inspiration =)&lt;/p&gt;
&lt;p&gt;But in the last couple of days I decided to go back to the code, and finish the
statistics gathering in the &lt;a href="http://git.llucax.com.ar/w/software/dgc/naive.git" class="reference external"&gt;Naive GC&lt;/a&gt; (the new code is not published yet
because it needs some polishing). Here are some nice graphs from my
little &lt;a href="http://git.llucax.com.ar/w/software/dgc/dgcbench.git" class="reference external"&gt;D GC benchmark&lt;/a&gt;:&lt;/p&gt;
&lt;div class="center container"&gt;
&lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/graphs/big_arrays.c.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/graphs/big_arrays.c.mini.png" alt="big_arrays" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/graphs/rnd_data.c.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/graphs/rnd_data.c.mini.png" alt="rnd_data" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/graphs/rnd_data_2.c.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/graphs/rnd_data_2.c.mini.png" alt="rnd_data_2" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/graphs/shootout_binarytrees.c.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/graphs/shootout_binarytrees.c.mini.png" alt="shootout_binarytrees" /&gt;&lt;/a&gt;
&lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/graphs/split.c.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/graphs/split.c.mini.png" alt="split" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/graphs/startup.c.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/graphs/startup.c.mini.png" alt="startup" /&gt;&lt;/a&gt; &lt;a href="http://www.llucax.com.ar/blog/posts/2009/08/graphs/tree.c.png" class="reference external"&gt;&lt;img src="http://www.llucax.com.ar/blog/posts/2009/08/graphs/tree.c.mini.png" alt="tree" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;The graphs shows the space and time costs for each collection in the programs
life. The collection time is divided in the time spent in the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;malloc()&lt;/span&gt;&lt;/tt&gt; that
triggered the collection, the time spent in the collection itself, and the time
the world has to be stopped (meaning the time all the threads were paused
because of the collection). The space is measured before and after the
collection, and the total memory consumed by the program is divided in 4 areas:
used space, free space, wasted space (space that the user can't use but it's
not used by the collector either) and overhead (space used by the collector
itself).&lt;/p&gt;
&lt;p&gt;As you can see, the &lt;em&gt;naive&lt;/em&gt; collector pretty much sucks, specially for periods
of lots of allocation (since it just allocated what it's asked in the
&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;gc_malloc()&lt;/span&gt;&lt;/tt&gt; call if the collection failed).&lt;/p&gt;
&lt;p&gt;The next step is to modify the &lt;a href="http://www.dsource.org/projects/tango/" class="reference external"&gt;Tango&lt;/a&gt;'s &lt;em&gt;Basic&lt;/em&gt; collector to gather the same
data and see how things are going with it.&lt;/p&gt;


      &lt;img src="http://feeds.feedburner.com/~r/llucax-d/~4/tiItJRC8QIM" height="1" width="1" /&gt;</content>
		<author>
			<name>Leandro Lucarella</name>
			<uri>http://www.llucax.com.ar/blog/blog.cgi</uri>
		</author>
		<source>
			<title type="html">Luca's meaningless thoughts</title>
			<link rel="self" href="http://feeds.feedburner.com/llucax-d" />
			<id>http://www.llucax.com.ar/blog/blog.cgi</id>
			<updated>2009-11-10T17:00:09+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Updates and links</title>
		<link href="http://leonardo-m.livejournal.com/87801.html" />
		<id>http://leonardo-m.livejournal.com/87801.html</id>
		<updated>2009-08-15T21:25:16+00:00</updated>
		<content type="html">"Boostbench", a benchmark, in C, Java and D, the zip contains all the code, timings and information:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/boostbench.zip"&gt;http://www.fantascienza.net/leonardo/js/boostbench.zip&lt;/a&gt;&lt;br /&gt;Original code by Rene Grothmann:&lt;br /&gt;&lt;a href="http://mathsrv.ku-eichstaett.de/MGF/homes/grothmann/java/bench/"&gt;http://mathsrv.ku-eichstaett.de/MGF/homes/grothmann/java/bench/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With the LDC compiler the performance is poor without Link-Time Optimization plus Interning, I don't know why. (If someone is able to tell me I'll be interested to know.)&lt;br /&gt;&lt;br /&gt;-------------------&lt;br /&gt;&lt;br /&gt;Theo Jansen demonstrates the amazingly lifelike kinetic sculptures he builds from plastic tubes and lemonade bottles, and then lets walk and live on a beach. They have even a brain made of bottles. Windosaurs, etc:&lt;br /&gt;&lt;a href="http://www.youtube.com/watch?v=b694exl_oZo"&gt;http://www.youtube.com/watch?v=b694exl_oZo&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Jarvis March in D</title>
		<link href="http://leonardo-m.livejournal.com/87388.html" />
		<id>http://leonardo-m.livejournal.com/87388.html</id>
		<updated>2009-08-14T13:17:35+00:00</updated>
		<content type="html">Robert C. Martin in his blog has written an implementation of the Jarvis March algorithm in Clojure, and was looking for ways to speed up the code:&lt;br /&gt;&lt;a href="http://blog.objectmentor.com/articles/2009/08/11/jarvis-march-in-clojure"&gt;http://blog.objectmentor.com/articles/2009/08/11/jarvis-march-in-clojure&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;See also:&lt;br /&gt;&lt;a href="http://www.butunclebob.com/ArticleS.UncleBob.ConvexHullTiming"&gt;http://www.butunclebob.com/ArticleS.UncleBob.ConvexHullTiming&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;So I have translated the Java code to D (and later C), and then I have done some timing tests.&lt;br /&gt;&lt;br /&gt;The Java results are quite good compared to the D ones.&lt;br /&gt;&lt;br /&gt;Number of points in the hull in all tests is just 14.&lt;br /&gt;&lt;pre&gt;Timings, n = 2_000_000:

On Windows XP, best of 6, seconds:
  D 1:    1.88 (DMD compiler)
  Java 1: 1.83
  C 2:    1.55 (GCC compiler)
  Java 2: 1.55
  Java 1: 1.47 (-server)
  Java 2: 1.47 (-server -Xms40M)
  C 2:    1.46 (LLVM-GCC compiler)
  Java 2: 1.45 (-server)
  D 2:    1.32 (DMD compiler)

On Pubuntu, best of 6, seconds:
  Java 1: 2.71
  C 2:    2.59 (GCC compiler)
  Java 1: 2.42 (-server)
  Java 2: 2.39
  Java 2: 2.37 (-server)
  D 1:    2.06 (LDC compiler)
  D 1:    2.06 (LDC compiler, LTO+I)
  D 2:    2.02 (LDC compiler, LTO+I)  
  D 2:    2.00 (LDC compiler)
&lt;/pre&gt;Notes:&lt;br /&gt;- The code of the D 1 version is similar to the Java 1 version. The code of the D 2 version is similar to the Java 2 version and C 2 version.&lt;br /&gt;- On Pubuntu all timings are increased because it has a slower access to memory.&lt;br /&gt;- I have used a (low quality) portable rnd generator to assure equal test cases on all compilers and operating systems. (And because while the D std library Tango has a gaussian generator, the Phobos std lib of Dv.1 doesn't have it).&lt;br /&gt;- Currently the seed of the random generator can't be changed.&lt;br /&gt;- All the programs give the same output, but the results aren't equal up to the last floating point digits anyway because different FP instructions produce sligtly different results. FP numbers are approximations.&lt;br /&gt;- The C code is slower, I don't know why.&lt;br /&gt;- The D 2 code is much faster than D 1 with DMD because DMD has limited inlining capabilities (this is why I have created the D 2 version).&lt;br /&gt;- In the D code the abs function is not taken from Tango because LDC has a performance bug, and otherwise it's not able to inline it.&lt;br /&gt;- For the LTO+I see below.&lt;br /&gt;&lt;br /&gt;More info and all the code can be found here:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/jarvism.zip"&gt;http://www.fantascienza.net/leonardo/js/jarvism.zip&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html" />
		<link href="http://leonardo-m.livejournal.com/86620.html" />
		<id>http://leonardo-m.livejournal.com/86620.html</id>
		<updated>2009-08-11T18:10:41+00:00</updated>
		<content type="html">I have improved the code of the Sphereflake raytracer and thanks to Tomas Lindquist Olsen I have fixed my LDC installation, so there I have redone the benchmarks on Pubuntu:&lt;br /&gt;&lt;pre&gt;
Timings on Pubuntu, w=h=1024, lvl=6, best of 3, seconds:
(66_430 spheres, WITH_SHADOWS=true, FASTER_LDC=true)
  D:    4.33  (claiming 4.6 MB) (first fast version + LTO+I)
  D:    4.51  (claiming 2.5 MB) (second fast version + LTO+I)
  D:    4.55  (claiming 4.6 MB) (basic version + LTO+I)
  D:    4.70  (claiming 2.5 MB) (second fast version)
  D:    4.72  (claiming 4.6 MB) (first fast version)
  D:    4.97  (claiming 4.6 MB) (basic version)
  C++:  5.04  (claiming 4.6 MB) (+4 bytes padding)
  C++:  5.75  (claiming 4.3 MB) (original version)

Timings on Pubuntu, w=h=1024, lvl=7, best of 3, seconds:
(597_871 spheres, WITH_SHADOWS=true, FASTER_LDC=true)
  D:    5.51  (claiming 23 MB) (second fast version + LTO+I)
  D:    5.74  (claiming 41 MB) (first fast version + LTO+I)

Timings on Pubuntu, w=h=1024, lvl=8, best of 3, seconds:
  D:   10.84  (claiming 205 MB) (second fast version + LTO+I)
  D:   11.21  (claiming 205 MB) (second fast version)
  D:   23.34  (claiming 369 MB) (first fast version + LTO+I)
  D:   23.84  (claiming 369 MB) (basic version + LTO+I)
  D:   24.06  (claiming 369 MB) (first fast version)
  D:   24.55  (claiming 369 MB) (basic version)
  C++: 24.61  (claiming 369 MB) (+4 bytes padding)
&lt;/pre&gt;&lt;br /&gt;For more information, and for the updated Sphereflake code:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/index.html#flake"&gt;http://www.fantascienza.net/leonardo/js/index.html#flake&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;----------------&lt;br /&gt;&lt;br /&gt;I have added a new benchmark, a sparse matrix multiplication, this time the performance of D code (with LDC) isn't much good. Info and timings inside the zip:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/index.html#jaspa"&gt;http://www.fantascienza.net/leonardo/js/index.html#jaspa&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Sphereflake ray-tracing benchmark in C++ and D</title>
		<link href="http://leonardo-m.livejournal.com/86431.html" />
		<id>http://leonardo-m.livejournal.com/86431.html</id>
		<updated>2009-08-05T15:33:32+00:00</updated>
		<content type="html">Timings of a small ray-tracing "Spereflake" benchmark (you can find a copy of this Html page in the references directory of the zip too):&lt;br /&gt;&lt;a href="http://ompf.org/ray/sphereflake/"&gt;http://ompf.org/ray/sphereflake/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;center&gt;&lt;img src="http://www.fantascienza.net/leonardo/js/sphereflake5_ico.png" border="1" /&gt;&lt;/center&gt;&lt;br /&gt;&lt;br /&gt;The D-LDC results of this benchmark are good. I have also created a faster D version where the output is now in P5 pgm format (bytes are represented as single chars, this speeds up the output) and where the trascendental values are precomputed (G++ 4.3.3 is able to pre-compute them, while the current LDC isn't able to).&lt;br /&gt;&lt;br /&gt;A possible way to further speed up the code: when lvl=8 it creates 5_380_840 visible spheres and node_t, but it needs only 597_871 bounding spheres (the leaves don't need such bounding spheres and most of the nodes of a tree are leaves).&lt;br /&gt;&lt;br /&gt;So it may be useful to split the array of node_t into two arrays, one much larger that just contains the visible spheres and the skip pointer, and one smaller that contains the bounding spheres (and maybe another skip pointer). In the end the CPU cache has to manage two arrays, so the program may be slower.&lt;br /&gt;&lt;br /&gt;With that idea with lvl=8 the memory used becomes 205 MB (or 228 MB if doubles are aligned to 8 bytes) instead of the current 369 MB, this lowers the CPU cache traffic.&lt;br /&gt;&lt;br /&gt;I have 2 GB RAM on my PC, so I can't run it with lvl=9. But removing just visible sphere radiuses it needs less than 2 GB RAM:&lt;br /&gt;( 48427561 * (8 + 3 * 8) + 5380840 * (8 + 4 * 8) ) / (1024*1024) = 1683.15&lt;br /&gt;&lt;pre&gt;
Timings on Windows, w=h=1024, lvl=6, best of 3, seconds:
  C++:  4.60  (claiming 4.6 MB) (+4 bytes padding)
  C++:  4.60  (claiming 4.6 MB)
  C++:  4.63  (claiming 4.6 MB) (+4 bytes padding, LLVM-G++)
  C++:  4.64  (claiming 4.6 MB) (LLVM-G++)
  C++:  4.68  (claiming 4.6 MB) (+4 bytes padding, PGO)
  D:   11.78  (claiming 4.6 MB) (DMD v1.043, with "ref", fast version)
  D:   17.34  (claiming 4.6 MB) (DMD v1.043, with "ref")
  D:   17.34  (claiming 4.6 MB) (DMD v1.043, with "ref", no GC)
  D:   28.24  (claiming 4.6 MB) (DMD v2.031, with no "ref")
  D:   28.27  (claiming 4.6 MB) (DMD v2.031, with no "ref", gs)
  D:   29.78  (claiming 4.6 MB) (DMD v1.043, with no "ref")
  D:   29.79  (claiming 4.6 MB) (DMD v1.046, with no "ref")
(Those DMD-Windows timings are not reliable, I have timed it as low ad 12.5 seconds)


Timings on Pubuntu, w=h=1024, lvl=6, best of 3, seconds:
(66_430 spheres, WITH_SHADOWS=true, FASTER_LDC=true)
  D:    4.81  (claiming 4.6 MB) (with fast output)
  C++:  4.86  (claiming 4.6 MB) (+4 bytes padding)
  D:    4.91  (claiming 4.6 MB) (fast version)
  D:    4.93  (claiming 4.6 MB)
  C++:  5.75  (claiming 4.3 MB)

Timings on Pubuntu, w=h=1024, lvl=8, best of 3, seconds:
(5_380_840 spheres)
  C++: 25.00  (claiming 369 MB) (+4 bytes padding)
  D:   25.27  (claiming 369 MB) (fast version)
  D:   25.62  (claiming 369 MB) (with "ref")
&lt;/pre&gt;&lt;br /&gt;Key:&lt;br /&gt;  no GC = Garbage collector disabled in the whole running&lt;br /&gt;  +4 bytes padding = 4 bytes of padding added to the Node struct&lt;br /&gt;  PGO = profile-guided optimization&lt;br /&gt;  gs = all global variables are annotated with __gshared&lt;br /&gt;&lt;br /&gt;Args:&lt;br /&gt;  g++ -O3 -s -fomit-frame-pointer -msse3 -march=native -ffast-math&lt;br /&gt;  llvm-g++ -O3 -s -fomit-frame-pointer -msse3 -march=native -ffast-math&lt;br /&gt;  dmd -O -release -inline&lt;br /&gt;  ldc -O5 -release -inline&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;All the tested code:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/sphereflake.zip"&gt;http://www.fantascienza.net/leonardo/js/sphereflake.zip&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">A small raytracing benchmark</title>
		<link href="http://leonardo-m.livejournal.com/86110.html" />
		<id>http://leonardo-m.livejournal.com/86110.html</id>
		<updated>2009-08-05T14:38:44+00:00</updated>
		<content type="html">To test the LDC D compiler, its LLVM backend and to look for more possible optimizations, I have translated to D a small ray tracing benchmark present on Jon Harrop site:&lt;br /&gt;&lt;a href="http://www.ffconsultancy.com/languages/ray_tracer/benchmark.html"&gt;http://www.ffconsultancy.com/languages/ray_tracer/benchmark.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;It contains translations in several languages of progressively more optimized versions of a toy ray tracer program. As reference I have used the first C++ implementation, the slowest one hoping it can show me where LDC misses some possible optimizations (if I translate to D1 the faster C++ version I may offer less chances to LDC and G++ compilers to show their optimization capabilities).&lt;br /&gt;&lt;br /&gt;To translate the code to D I have had to change few things, so to have a more fair comparison I have  back-ported those changes to C++.&lt;br /&gt;&lt;br /&gt;The two main changes I have performed to the first C++ version are:&lt;br /&gt;1) vector is used instead of list. This speeds up the code a little. I have done this because D has no built-in list type (there are lists in Phobos2 and Tango that I have not used).&lt;br /&gt;&lt;br /&gt;2) Inside the Group class "bound" is a Sphere* instead of a Sphere, because in D classes are used by reference only. This has slowed down code. So I have created a "ray1_scoped_cpp" C++ version that keeps "bound" as a value. It shows where D misses a possible optimization. Some people have asked for a 'scope' among class attributes, but the discussion is gone nowhere (I think Walter has never answered). But in some situations LDC is recently able to 'scope' classes by itself, as an optimization. So can LDC perform such optimization anyway, with no change to the language, as a way to optimize? It's not a very quick to do, you have to see if no references to the class "f" in this class escape. It may be doable.&lt;br /&gt;&lt;pre&gt;Timings on Windows:
  ray1_scoped_cpp  6.52
  ray1_cpp         6.77
  ray1_d          16.01 (DMD v1.043)

Timings on Pubuntu:
  ray1_scoped_cpp  7.99
  ray1_d           8.51 (LDC Aug 3 2009)
  ray1_cpp         8.66
&lt;/pre&gt;CPU used: Core2 at 2 GHz.&lt;br /&gt;&lt;br /&gt;Compilers:&lt;br /&gt;LDC LLVM D Compiler based on DMD v1.045 and llvm 2.6svn (Mon Aug  3 22:09:36 2009)&lt;br /&gt;On Pubuntu G++ version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)&lt;br /&gt;DMD v1.042&lt;br /&gt;On Windows gcc version 4.3.3-dw2-tdm-1 (GCC)&lt;br /&gt;&lt;br /&gt;Compilation arguments:&lt;br /&gt;Windows:&lt;br /&gt;llvm-g++ -Wall -O3 -s -fomit-frame-pointer -msse3 -march=native ray1d_cpp.cpp -o ray1d_cpp&lt;br /&gt;&lt;br /&gt;Ubuntu:&lt;br /&gt;g++ -Wall -O3 -s -fomit-frame-pointer -msse3 -march=native ray1d_cpp.cpp -o ray1d_cpp&lt;br /&gt;&lt;br /&gt;All the D and C++ code tested here:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/ray.zip"&gt;http://www.fantascienza.net/leonardo/js/ray.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In future I may add a D translation of the 5th (the fastest) C++ version too, as reference point.</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Update and links</title>
		<link href="http://leonardo-m.livejournal.com/85528.html" />
		<id>http://leonardo-m.livejournal.com/85528.html</id>
		<updated>2009-07-29T11:00:26+00:00</updated>
		<content type="html">A small benchmark, computing digits of Pi, compared D, C++, Java:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/pi_bench.zip"&gt;http://www.fantascienza.net/leonardo/js/pi_bench.zip&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;------------------------&lt;br /&gt;&lt;br /&gt;Case study: Improving the performance of matrix multiplication by 296,260x&lt;br /&gt;&lt;a href="http://stellar.mit.edu/S/course/6/fa08/6.197/courseMaterial/topics/topic2/lectureNotes/Intro_and_MxM/Intro_and_MxM.pdf"&gt;http://stellar.mit.edu/S/course/6/fa08/6.197/courseMaterial/topics/topic2/lectureNotes/Intro_and_MxM/Intro_and_MxM.pdf&lt;/a&gt;&lt;br /&gt;&lt;a href="http://stellar.mit.edu/S/course/6/fa08/6.197/"&gt;http://stellar.mit.edu/S/course/6/fa08/6.197/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What's the fastest programming language? It may be Python, because there are CorePy and PyCuda that allow you to write very fast programs:&lt;br /&gt;&lt;a href="http://www.corepy.org/"&gt;http://www.corepy.org/&lt;/a&gt;&lt;br /&gt;&lt;a href="http://mathema.tician.de/software/pycuda"&gt;http://mathema.tician.de/software/pycuda&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;One of the best biology blogs I have found so far:&lt;br /&gt;&lt;a href="http://bytesizebio.net/"&gt;http://bytesizebio.net/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Sig.ma - Live views on the Web of Data (a demo video):&lt;br /&gt;&lt;a href="http://vimeo.com/5703809"&gt;http://vimeo.com/5703809&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Lot of people know Java-style Object Oriented programming, while knowledge of pure mathematics is much less common (even if knowing some group theory, etc, can be quite useful. Such topics are part of courses at the university if you want a degree in computer science). Marc Conrad has shown ways to explain some of those mathematics ideas using the OOP ideas. It may be a good idea:&lt;br /&gt;&lt;a href="http://ring.perisic.com/"&gt;http://ring.perisic.com/&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Linpack benchmark in D</title>
		<link href="http://leonardo-m.livejournal.com/85364.html" />
		<id>http://leonardo-m.livejournal.com/85364.html</id>
		<updated>2009-07-20T11:32:55+00:00</updated>
		<content type="html">I have translated a C Linpack benchmark to D, and I have timed it compared to the C and a similar Java version.&lt;br /&gt;&lt;br /&gt;Some of the D Link-Time optimized (+ interning) versions segfault (binaries produced by DMD here never segfault). The C code compiled with GCC with -msse3 -march=core2 compilation arguments too segfaults (that's why I have used llvm-gcc that has never produced a segfault), I don't know why, it may be a pointer aliasing problem.&lt;br /&gt;&lt;br /&gt;For bigger matrices Java shows to be about as fast as gcc-C and LDC-D. Both float and real versions are very slow. Static arrays are a bit faster with LDC but not much, I don't know why.&lt;br /&gt;&lt;br /&gt;See inside the zip for the full timings:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/linpack.zip"&gt;http://www.fantascienza.net/leonardo/js/linpack.zip&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Review of The Case For D</title>
		<link href="http://dblog.aldacron.net/2009/07/18/review-of-the-case-for-d/" />
		<id>http://dblog.aldacron.net/?p=659</id>
		<updated>2009-07-18T10:56:09+00:00</updated>
		<content type="html">Andy Glew attended Andrei&amp;#8217;s The Case for D presentation and has posted his reactions on his blog.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=GC6pdUHaYwc:XsRzrK5geUk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=GC6pdUHaYwc:XsRzrK5geUk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=GC6pdUHaYwc:XsRzrK5geUk:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=GC6pdUHaYwc:XsRzrK5geUk:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Updates</title>
		<link href="http://leonardo-m.livejournal.com/85166.html" />
		<id>http://leonardo-m.livejournal.com/85166.html</id>
		<updated>2009-07-17T00:52:16+00:00</updated>
		<content type="html">Updated the rectangle packing code: added a D and ShedSkin version of the first algorithm:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/so/index.html#rectpack"&gt;http://www.fantascienza.net/leonardo/so/index.html#rectpack&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Added a D version (fvd) of the fv tool shown here, the D version compiled with LDC is a bit faster than the C++ version (probably thanks to unlocked_get/set that can also be used in C++):&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/ar/string_repetition_statistics/string_repetition_statistics.html"&gt;http://www.fantascienza.net/leonardo/ar/string_repetition_statistics/string_repetition_statistics.html&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/07/16/on-actors-and-casting/" />
		<id>http://bartoszmilewski.wordpress.com/?p=935</id>
		<updated>2009-07-16T18:28:01+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;Is the Actor model just another name for message passing between threads? In other words, can you consider a Java &lt;var&gt;Thread&lt;/var&gt; object with a message queue an Actor? Or is there more to the Actor model? Bartosz investigates. &lt;/p&gt;
&lt;p&gt;I&amp;#8217;ll start with listing various properties that define the Actor Model. I will discuss implementation options in several languages.&lt;/p&gt;
&lt;h2&gt;Concurrency&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;Actors are objects that execute concurrently.&lt;/b&gt; Well, sort of. Erlang, for instance, is not an object-oriented language, so we can&amp;#8217;t really talk about &amp;#8220;objects&amp;#8221;. An actor in Erlang is represented by a thing called a Process ID (Pid). But that&amp;#8217;s nitpicking. The second part of the statement is more interesting. Strictly speaking, an actor may execute concurrently but at times it will not. For instance, in Scala, actor code may be executed by the calling thread. &lt;/p&gt;
&lt;p&gt;Caveats aside, it&amp;#8217;s convenient to think of actors as objects with a thread inside.&lt;/p&gt;
&lt;h2&gt;Message Passing&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;Actors communicate through message passing.&lt;/b&gt; Actors don&amp;#8217;t communicate using shared memory (or at least pretend not to). The only way data may be passed between actors is through messages. &lt;/p&gt;
&lt;p&gt;Erlang has a primitive send operation denoted by the exclamation mark. To send a message &lt;var&gt;Msg&lt;/var&gt; to the process (actor) &lt;var&gt;Pid&lt;/var&gt; you write:&lt;/p&gt;
&lt;pre&gt;Pid ! Msg&lt;/pre&gt;
&lt;p&gt;The message is copied to the address space of the receiver, so there is no sharing. &lt;/p&gt;
&lt;p&gt;If you were to imitate this mechanism in Java, you would create a &lt;var&gt;Thread&lt;/var&gt; object with a mailbox (a concurrent message queue), with no public methods other than &lt;var&gt;put&lt;/var&gt; and &lt;var&gt;get&lt;/var&gt; for passing messages. Enforcing copy semantics in Java is impossible so, strictly speaking, mailboxes should only store built-in types. Note that passing a Java &lt;var&gt;String&lt;/var&gt;s is okay, since strings are immutable. &lt;/p&gt;
&lt;h3&gt;-Typed messages&lt;/h3&gt;
&lt;p&gt;Here&amp;#8217;s the first conundrum: in Java, as in any statically typed language, messages have to be typed. If you want to process more than one type of messages, it&amp;#8217;s not enough to have just one mailbox per actor. In Erlang, which is dynamically typed, one canonical mailbox per actor suffices. In Java, mailboxes have to be abstracted from actors. So an actor may have one mailbox for accepting strings, another for integers, etc. You build actors from those smaller blocks.&lt;/p&gt;
&lt;p&gt;But having multiple mailboxes creates another problem: How to block, waiting for messages from more than one mailbox at a time without breaking the encapsulation? And when one of the mailboxes fires, how to retrieve the correct type of a message from the appropriate mailbox? I&amp;#8217;ll describe a few approaches.&lt;/p&gt;
&lt;h3&gt;-Pattern matching&lt;/h3&gt;
&lt;p&gt;Scala, which is also a statically typed language, uses the power of functional programming to to solve the typed messages problem. The &lt;var&gt;receive&lt;/var&gt; statement uses pattern matching, which can match different types. It looks like a switch statements whose &lt;var&gt;case&lt;/var&gt; labels are patterns. A pattern may specify the type it expects. You may send a string, or an integer, or a more complex data structure to an actor. A single &lt;var&gt;receive&lt;/var&gt; statement inside the actor code may match any of those.&lt;/p&gt;
&lt;pre&gt;receive {
    case s: String =&amp;gt; println("string: "+ s)
    case i: Int =&amp;gt; println("integer: "+ i)
    case m =&amp;gt; println("unknown: "+ m)
}&lt;/pre&gt;
&lt;p&gt;In Scala the type of a variable is specified after the colon, so &lt;var&gt;s:String&lt;/var&gt; declares the variable &lt;var&gt;s&lt;/var&gt; of the type &lt;var&gt;String&lt;/var&gt;. The last case is a catch-all.&lt;/p&gt;
&lt;p&gt;This is a very elegant solution to a difficult problem of marrying object-oriented programming to functional programming&amp;#8211;a task at which Scala exceeds. &lt;/p&gt;
&lt;h3&gt;-Casting&lt;/h3&gt;
&lt;p&gt;Of course, we always have the option of escaping the type system. A mailbox could be just a queue of &lt;var&gt;Object&lt;/var&gt;s. When a message is received, the actor could try casting it to each of the expected types in turn or use reflection to find out the type of the message. Here&amp;#8217;s what Martin Odersky, the creator of Scala,  has to say about it:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;The most direct (some would say: crudest) form of decomposition uses the type-test and type-cast instructions available in Java and many other languages.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;In the paper he co-authored with Emir and Williams (&lt;a href="http://lampwww.epfl.ch/~emir/written/MatchingObjectsWithPatterns-TR.pdf"&gt;Matching Objects With Patterns&lt;/a&gt;) he gives the following evaluation of this method:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Evaluation: Type-tests and type-casts require zero overhead for the class hierarchy. The pattern matching itself is very verbose, for both shallow and deep patterns. In particular, every match appears as both a type-test and a subsequent type-cast. The scheme raises also the issue that type-casts are potentially unsafe because they can raise ClassCastExceptions. Type-tests and type-casts completely expose representation. They have mixed characteristics with respect to extensibility. On the one hand, one can add new variants without changing the framework (because there is nothing to be done in the framework itself). On the other hand, one cannot invent new patterns over existing variants that use the same syntax as the type-tests and type-casts.
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;The best one could do in C++ or D is to write generic code that hides casting from the client. Such generic code could use &lt;i&gt;continuations&lt;/i&gt; to process messages after they&amp;#8217;ve been cast. A continuation is a function that you pass to another function to be executed after that function completes (strictly speaking, a real continuation never returns, so I&amp;#8217;m using this word loosely). The above example could be rewritten in C++ as:&lt;/p&gt;
&lt;pre&gt;void onString(std::string const &amp;amp; s) {
    cout &amp;lt;&amp;lt; "string: " &amp;lt;&amp;lt; s &amp;lt;&amp;lt; std::endl;
}
void onInt(int i) {
    cout &amp;lt;&amp;lt; "integer: " &amp;lt;&amp;lt; i &amp;lt;&amp;lt; std::endl;
}

receive&amp;lt;std::string, int&amp;gt; (&amp;amp;onString, &amp;amp;onInt);&lt;/pre&gt;
&lt;p&gt;where &lt;var&gt;receive&lt;/var&gt; is a variadic template (available in C++0x). It would do the dynamic casting and call the appropriate function to process the result. The syntax is awkward and less flexible than that of Scala, but it works. &lt;/p&gt;
&lt;p&gt;The use of lambdas might make things a bit clearer. Here&amp;#8217;s an example in D using lambdas (function literals), courtesy Sean Kelly and Jason House:&lt;/p&gt;
&lt;pre&gt;receive(
    (string s){ writefln("string: %s", s); },
    (int i){ writefln("integer: %s", i); }
);&lt;/pre&gt;
&lt;p&gt;Interestingly enough, Scala&amp;#8217;s &lt;var&gt;receive&lt;/var&gt; is a library function with the pattern matching block playing the role of a continuation. Scala has syntactic sugar to make lambdas look like curly-braced blocks of code. Actually, each case statement is interpreted by Scala as a &lt;i&gt;partial function&lt;/i&gt;&amp;#8211;a function that is not defined for all values (or types) of arguments. The pattern matching part of &lt;var&gt;case&lt;/var&gt; becomes the &lt;var&gt;isDefinedAt&lt;/var&gt; method of this partial function object, and the code after that becomes its &lt;var&gt;apply&lt;/var&gt; method. Of course, partial functions could also be implemented in C++ or D, but with a lot of superfluous awkwardness&amp;#8211;lambda notation doesn&amp;#8217;t help when partial functions are involved.&lt;/p&gt;
&lt;h3&gt;-Isolation&lt;/h3&gt;
&lt;p&gt;Finally, there is the problem of &lt;b&gt;isolation&lt;/b&gt;. A message-passing system must be protected from data sharing. As long as the message is a primitive type and is passed by value (or an immutable type passed by reference), there&amp;#8217;s no problem. But when you pass a mutable &lt;var&gt;Object&lt;/var&gt; as a message, in reality you are passing a reference (a handle) to it. Suddenly your message is shared and may be accessed by more than one thread at a time. You either need additional synchronization outside of the Actor model or risk data races. Languages that are not strictly functional, including Scala, have to deal with this problem. They usually pass this responsibility, conveniently, to the programmer.&lt;/p&gt;
&lt;h3&gt;-Kilim&lt;/h3&gt;
&lt;p&gt;Java is not a good language to implement the Actor model. You can extend Java though, and there is one such extension worth mentioning called &lt;a href="http://www.malhar.net/sriram/kilim/kilim_ecoop08.pdf"&gt;Kilim&lt;/a&gt; by Sriram Srinivasan and Alan Mycroft from Cambridge, UK. Messages in Kilim are restricted to objects with no internal aliasing, which have move semantics. The pre-processor (weaver) checks the structure of messages and generates appropriate Java code for passing them around. I tried to figure out how Kilim deals with waiting on multiple mailboxes, but there isn&amp;#8217;t enough documentation available on the Web. The authors mention using the &lt;var&gt;select&lt;/var&gt; statement, but never provide any details or examples.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;Correction: Sriram was kind enough to provide an example of the use of &lt;var&gt;select&lt;/var&gt;:&lt;/i&gt;&lt;/p&gt;
&lt;pre&gt;int n = Mailbox.select(mb0, mb1, .., timeout);&lt;/pre&gt;
&lt;p&gt;&lt;i&gt;The return value is the index of the mailbox, or -1 for the timeout. Composability is an important feature of the message passing model.&lt;/i&gt;&lt;/p&gt;
&lt;h2&gt;Dynamic Networks&lt;/h2&gt;
&lt;p&gt;Everything I described so far is common to CSP (Communicating Sequential Processes) and the Actor model. Here&amp;#8217;s what makes actors more general:&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Connections between actors are dynamic.&lt;/b&gt; Unlike processes in CSP, actors may establish communication channels dynamically. They may pass messages containing references to actors (or mailboxes). They can then send messages to those actors. Here&amp;#8217;s a Scala example:&lt;/p&gt;
&lt;pre&gt;receive {
    case (name: String, actor: Actor) =&amp;gt;
        actor ! lookup(name)
}&lt;/pre&gt;
&lt;p&gt;The original message is a tuple combining a string and an actor object. The receiver sends the result of &lt;var&gt;lookup(name)&lt;/var&gt; to the actor it has just learned about. Thus a new communication channel between the receiver and the unknown actor can be established at runtime. (In Kilim the same is possible by passing mailboxes via messages.)&lt;/p&gt;
&lt;h2&gt;Actors in D&lt;/h2&gt;
&lt;p&gt;The D programming language with &lt;a href="http://bartoszmilewski.wordpress.com/2009/05/26/race-free-multithreading/"&gt;my proposed race-free type system&lt;/a&gt; could dramatically improve the safety of message passing. Race-free type system distinguishes between various types of sharing and enforces synchronization when necessary. For instance, since an &lt;var&gt;Actor&lt;/var&gt; would be shared between threads, it would have to be declared &lt;var&gt;shared&lt;/var&gt;. All objects inside a shared actor, including the mailbox, would automatically inherit the shared property. A shared message queue inside the mailbox could only store value types, &lt;var&gt;unique&lt;/var&gt; types with move semantics, or reference types that are either immutable or are monitors (provide their own synchronization). These are exactly the types of messages that may be safely passed between actors. Notice that this is more than is allowed in Erlang (value types only) or Kilim (unique types only), but doesn&amp;#8217;t include &amp;#8220;dangerous&amp;#8221; types that even Scala accepts (not to mention Java or C++). &lt;/p&gt;
&lt;p&gt;I will discuss message queues in the next installment.&lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/935/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/935/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/935/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/935/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/935/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/935/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/935/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/935/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/935/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/935/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=935&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Rectangle packing</title>
		<link href="http://leonardo-m.livejournal.com/84867.html" />
		<id>http://leonardo-m.livejournal.com/84867.html</id>
		<updated>2009-07-15T00:01:26+00:00</updated>
		<content type="html">Efficient packing of many rectangles inside a bigger one:&lt;br /&gt;&lt;img src="http://www.fantascienza.net/leonardo/so/rect_pack.png" alt="" border="1" /&gt;&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/so/index.html#rectpack"&gt;http://www.fantascienza.net/leonardo/so/index.html#rectpack&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Improved from this C# code:&lt;br /&gt;&lt;a href="http://kossovsky.net/index.php/2009/07/cshar-rectangle-packing/"&gt;http://kossovsky.net/index.php/2009/07/cshar-rectangle-packing/&lt;/a&gt;&lt;br /&gt;&lt;a href="https://devel.nuclex.org/framework/browser/game/Nuclex.Game/trunk/Source/Packing"&gt;https://devel.nuclex.org/framework/browser/game/Nuclex.Game/trunk/Source/Packing&lt;/a&gt;</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">DMD 1.046 &amp;amp; 2.031</title>
		<link href="http://dblog.aldacron.net/2009/07/12/dmd-1-046-2-031/" />
		<id>http://dblog.aldacron.net/?p=657</id>
		<updated>2009-07-12T10:43:03+00:00</updated>
		<content type="html">I crawled out from under my rock to discover that Walter has released new versions of the D1 and D2 compilers, 1.046 and 2.031 respectively. Both releases include a laundry list of bug fixes and a patch to the front in from Tomasz Stachowiak that allows DMD to put out a detailed set of dependencies, [...]&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=zVAhX0_g6sk:zrlZie3qpLQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=yIl2AUoC8zA" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=zVAhX0_g6sk:zrlZie3qpLQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?i=zVAhX0_g6sk:zrlZie3qpLQ:F7zBnMyn0Lo" border="0" /&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/TheOneWithD?a=zVAhX0_g6sk:zrlZie3qpLQ:cGdyc7Q-1BI"&gt;&lt;img src="http://feeds.feedburner.com/~ff/TheOneWithD?d=cGdyc7Q-1BI" border="0" /&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<author>
			<name>Michael Parker</name>
			<uri>http://dblog.aldacron.net</uri>
		</author>
		<source>
			<title type="html">The One With D</title>
			<subtitle type="html">News and Opinions of the Digital Mars D Programming Language</subtitle>
			<link rel="self" href="http://feeds.feedburner.com/TheOneWithD" />
			<id>http://feeds.feedburner.com/TheOneWithD</id>
			<updated>2009-11-07T05:00:25+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Current plans...</title>
		<link href="http://arclib.blogspot.com/2009/07/current-plans.html" />
		<id>tag:blogger.com,1999:blog-3190794070849828802.post-2365382997744410844</id>
		<updated>2009-07-09T12:37:31+00:00</updated>
		<content type="html">No decent internet connection until the 20th.&lt;br /&gt;&lt;br /&gt;I've been thinking of hooking ArcLib up to the minid scripting language to provide rapid prototyping of games.&lt;br /&gt;&lt;br /&gt;Some more extensions I plan on to help provide the rapid development of games as well.&lt;br /&gt;&lt;br /&gt;arc_actors - keep track of actors in game&lt;br /&gt;&lt;br /&gt;arc_menu - in game menu capability&lt;br /&gt;&lt;br /&gt;arc_credits - end credits capability&lt;br /&gt;&lt;br /&gt;arc_hud - in game hud capability&lt;br /&gt;&lt;br /&gt;arc_tilemap - bird eye tilemap&lt;br /&gt;&lt;br /&gt;arc_scrolling- scrolling tilemap&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Some other tools in consideration...&lt;br /&gt;&lt;br /&gt;Map Editor&lt;br /&gt;&lt;br /&gt;Sprite Editor&lt;br /&gt;&lt;br /&gt;Tools to facilitate rapid game development plans are the current future.&lt;div class="blogger-post-footer"&gt;&lt;img width="1" height="1" src="https://blogger.googleusercontent.com/tracker/3190794070849828802-2365382997744410844?l=arclib.blogspot.com" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Clay Smith</name>
			<email>noreply@blogger.com</email>
			<uri>http://arclib.blogspot.com/</uri>
		</author>
		<source>
			<title type="html">ArcLib Development Blog</title>
			<link rel="self" href="http://arclib.blogspot.com/feeds/posts/default" />
			<id>tag:blogger.com,1999:blog-3190794070849828802</id>
			<updated>2009-11-04T05:00:20+00:00</updated>
		</source>
	</entry>

	<entry xml:lang="en">
		<title type="html">Bartosz Milewski</title>
		<link href="http://bartoszmilewski.wordpress.com/2009/07/07/whats-wrong-with-the-thread-object/" />
		<id>http://bartoszmilewski.wordpress.com/?p=923</id>
		<updated>2009-07-07T22:37:55+00:00</updated>
		<content type="html">&lt;div class="snap_preview"&gt;&lt;br /&gt;&lt;p&gt;I started writing a post about implementing actors in D when I realized that there was something wrong with the way thread spawning interacts with data sharing. Currently D&amp;#8217;s &lt;var&gt;Thread&lt;/var&gt; class closely mimics its Java counterpart, so I started wondering if this may be a more general problem&amp;#8211;a problem with mixing object-oriented paradigm with multithreading.&lt;/p&gt;
&lt;p&gt;In functional languages like Erlang or Concurrent ML, you start a thread by calling a function&amp;#8211;&lt;var&gt;spawn&lt;/var&gt; or &lt;var&gt;create&lt;/var&gt;, respectively. The argument to this function is another function&amp;#8211;the one to be executed in a new thread. If you think of a new thread as a semi-separate application, the thread function is its &amp;#8220;main&amp;#8221;. You may also pass arguments to it&amp;#8211;the equivalent of &lt;var&gt;argc&lt;/var&gt;, &lt;var&gt;argv&lt;/var&gt;, only more general. Those arguments are, of course, passed by value (we&amp;#8217;re talking &lt;i&gt;functional&lt;/i&gt; programming after all).&lt;/p&gt;
&lt;p&gt;In non-functional languages it&amp;#8217;s possible and often desirable to &lt;i&gt;share&lt;/i&gt; data between threads. It&amp;#8217;s very important to know which variables are shared and which aren&amp;#8217;t, because shared variables require special handling&amp;#8211;they need synchronization. You may share global variables with a thread, or you may pass shared variables to it during thread creation. You may also provide access to more shared variables during the thread&amp;#8217;s lifetime by attaching and detaching them from the original shared variables&amp;#8211;that&amp;#8217;s how message queues may be described in this language.&lt;/p&gt;
&lt;p&gt;In the object-oriented world everything is an object so, predictably, a (capital letter) &lt;var&gt;Thread&lt;/var&gt; is an object too. An object combines data with code. There is a piece of data associated with every thread&amp;#8211;the thread ID or a handle&amp;#8211;and there are things you can do to a thread, like pause it, wait for its termination, etc.&lt;/p&gt;
&lt;p&gt;But there&amp;#8217;s more: A &lt;var&gt;Thread&lt;/var&gt; in Java has a thread function. It&amp;#8217;s a method called &lt;var&gt;run&lt;/var&gt;. The user defines his or her own thread by inheriting from &lt;var&gt;Thread&lt;/var&gt; and overriding &lt;var&gt;run&lt;/var&gt;. Since &lt;var&gt;run&lt;/var&gt; takes no arguments, data has to be passed to the new thread by making it part of the derived thread object. In general a thread object contains two types of data: shared and non-shared. The non-shared data are the value arguments passed by the creator to the thread function, possibly some return values, plus state used internally by the thread function. Thread data may form some logical abstraction or, as it often happens, have the structure of a kitchen sink after a dinner party. &lt;/p&gt;
&lt;p&gt;Because of the presence of shared state, a &lt;var&gt;Thread&lt;/var&gt; object must be considered shared, thus requiring synchronization. As I described in my previous posts, public methods of a shared object must either be synchronized or lock free. But what about the &lt;var&gt;run&lt;/var&gt; method? It cannot be synchronized because that would make the whole thread object inaccessible to other threads, including its creator (which may be okay for a daemon thread, but wold be a fatal flaw in general). &lt;/p&gt;
&lt;p&gt;It makes perfect sense for &lt;var&gt;run&lt;/var&gt; to be private, since nobody should call it from the outside (or, for that matter, from the inside). But the reason for private methods not requiring synchronization is that they are only called from public methods, which must be synchronized. This is not true for &lt;var&gt;run&lt;/var&gt;&amp;#8211;&lt;var&gt;run&lt;/var&gt; is not called from under any lock! So essentially &lt;var&gt;run&lt;/var&gt; has unfettered access to all (potentially shared) data stored in &lt;var&gt;this&lt;/var&gt;. Unless the programmer is &lt;i&gt;very&lt;/i&gt; disciplined, the potential for data races is high. And that&amp;#8217;s where Java stands right now (the &lt;var&gt;Runnable&lt;/var&gt; interface has the same problems).&lt;/p&gt;
&lt;p&gt;If you&amp;#8217;ve been following my blog, you know that I&amp;#8217;m working on a &lt;a href="http://bartoszmilewski.wordpress.com/2009/05/26/race-free-multithreading/"&gt;type system that eliminates races&lt;/a&gt;. If I can convince Walter and Andrei, this system might be implemented in the D programming language. As I mentioned, D&amp;#8217;s treatment of threads comes directly from Java and therefore is inherently unsafe. Like in Java, D&amp;#8217;s &lt;var&gt;Thread&lt;/var&gt; object has a &lt;var&gt;run&lt;/var&gt; method. &lt;/p&gt;
&lt;p&gt;So how could D, with the race-free type system, improve on Java? One possibility is to make the &lt;var&gt;run&lt;/var&gt; method &lt;var&gt;lockfree&lt;/var&gt;. A &lt;var&gt;lockfree&lt;/var&gt; method (public or private) is not synchronized but its access to &lt;var&gt;this&lt;/var&gt; is severely restricted. It can only operate on &lt;var&gt;lockfree&lt;/var&gt; data members (if any), unless it takes the object&amp;#8217;s lock or calls a synchronized method (all public methods of a shared object are, by default, synchronized). Let me give you a small example:&lt;/p&gt;
&lt;pre&gt;class Counter: Thread {
public:
    // public methods are implicitly synchronized
    void inc() { ++_cnt; }
    void dec() { --_cnt; }
private:
    override void run() &lt;span&gt;lockfree&lt;/span&gt; {
        inc(); // ok: calling a synchronized method
        wait(10000);
        synchronized(this) { // ok: explicit synchronization on this
            _cnt = _cnt * _cnt;
        }
        // _cnt /= 2; // error: not synchronized!
    }
    int _cnt;
}
// usage:
auto cnt = new &lt;span&gt;shared&lt;/span&gt; Counter;
cnt.start;
cnt.inc;
cnt.join;&lt;/pre&gt;
&lt;p&gt;This approach would work and guarantee freedom from races, but I don&amp;#8217;t think it fits D. Unlike Java, which is so OO that even &lt;var&gt;main&lt;/var&gt; is a method of an object, D is a multi-paradigm language. It doesn&amp;#8217;t &lt;i&gt;have to&lt;/i&gt; force threads into an OO paradigm. And the thread function, being a thread equivalent of &lt;var&gt;main&lt;/var&gt; doesn&amp;#8217;t &lt;i&gt;have to&lt;/i&gt; be a method of any object. In my opinion, the functional approach to thread creation would serve D much better.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s how I see it:&lt;/p&gt;
&lt;pre&gt;class Counter {
public:
    void inc() { ++_cnt; }
    void dec() { --_cnt; }
    int get() const { return _cnt; }
    void set(int cnt) { _cnt = cnt; }
private:
    int _cnt;
}

void counterFun(shared Counter cnt) {
    cnt.inc;
    Thread.sleep(10000);
    synchronized(cnt) {
        int c = cnt.get;
        cnt.set(c * c);
    }
}
// usage:
auto cnt = new shared Counter;
Thread thr = Thread.spawn(&amp;amp;counterFun, cnt);
thr.start;
cnt.inc;
thr.join;&lt;/pre&gt;
&lt;p&gt;I find it more logical to have &lt;var&gt;start&lt;/var&gt; and &lt;var&gt;join&lt;/var&gt; operate on a different object, &lt;var&gt;thr&lt;/var&gt;, rather than on the counter, &lt;var&gt;cnt&lt;/var&gt;. The static template method &lt;var&gt;spawn&lt;/var&gt; accepts a function that takes an arbitrary number of arguments that are either values or shared or unique objects. In particular, you could pass to it your (shared) communication channels or message queues to implement the message-passing paradigm. &lt;/p&gt;
&lt;p&gt;Such &lt;var&gt;spawn&lt;/var&gt; primitive could be used to build more complex classes&amp;#8211;including the equivalents of a Java&amp;#8217;s &lt;var&gt;Thread&lt;/var&gt; or a Scala&amp;#8217;s &lt;var&gt;Actor&lt;/var&gt;. &lt;/p&gt;
  &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bartoszmilewski.wordpress.com/923/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bartoszmilewski.wordpress.com/923/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bartoszmilewski.wordpress.com/923/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bartoszmilewski.wordpress.com/923/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bartoszmilewski.wordpress.com/923/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bartoszmilewski.wordpress.com/923/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bartoszmilewski.wordpress.com/923/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bartoszmilewski.wordpress.com/923/" /&gt;&lt;/a&gt; &lt;a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bartoszmilewski.wordpress.com/923/"&gt;&lt;img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bartoszmilewski.wordpress.com/923/" /&gt;&lt;/a&gt; &lt;img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bartoszmilewski.wordpress.com&amp;blog=3549518&amp;post=923&amp;subd=bartoszmilewski&amp;ref=&amp;feed=1" /&gt;&lt;/div&gt;</content>
		<author>
			<name>Bartosz Milewski</name>
			<uri>http://bartoszmilewski.wordpress.com</uri>
		</author>
		<source>
			<title type="html">Bartosz Milewski's Programming Cafe</title>
			<subtitle type="html">Concurrency, Multicore, Language Design, D, C++</subtitle>
			<link rel="self" href="http://bartoszmilewski.wordpress.com/feed/" />
			<id>http://bartoszmilewski.wordpress.com/feed/</id>
			<updated>2009-11-07T17:00:08+00:00</updated>
		</source>
	</entry>

	<entry>
		<title type="html">Richards benchmark</title>
		<link href="http://leonardo-m.livejournal.com/84408.html" />
		<id>http://leonardo-m.livejournal.com/84408.html</id>
		<updated>2009-07-04T21:57:38+00:00</updated>
		<content type="html">This old post of mine is about virtual methods and devirtualizations:&lt;br /&gt;&lt;a href="http://leonardo-m.livejournal.com/76547.html"&gt;http://leonardo-m.livejournal.com/76547.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;I have performed more benchmarks about virtual methods and its costs with LDC. I have used a little well known benchmark, the Richards one. I have used the code from here (on the Web Archive because it seems to be not online anymore):&lt;br /&gt;&lt;a href="http://web.archive.org/web/20060715074131/lissett.port5.com/ben/bench1.htm"&gt;http://web.archive.org/web/20060715074131/lissett.port5.com/ben/bench1.htm&lt;/a&gt;&lt;br /&gt;&lt;a href="http://web.archive.org/web/20060715074131/http://lissett.port5.com/ben/bench3.htm"&gt;http://web.archive.org/web/20060715074131/http://lissett.port5.com/ben/bench3.htm&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All the code of the following benchmarks:&lt;br /&gt;&lt;a href="http://www.fantascienza.net/leonardo/js/richards.zip"&gt;http://www.fantascienza.net/leonardo/js/richards.zip&lt;/a&gt;&lt;br /&gt;&lt;pre&gt;
Timing results:

Windows, n = 10_000_000:
  C:       1.26
  D ~C:    2.01
  Java:    2.04 (final classes, -server)
  D2 ~C#:  2.36 (final classes)
  D3 ~C#:  2.36 (final classes, no getters/setters)  
  Java:    2.73 (final classes)
  D4 ~C#:  3.07 (no getters/setters)  
  C#:      3.98
  D1 ~C#:  4.23
  
Windows, n = 100_000_000:
  C:      12.16
  Java:   18.73 (final classes, -server)
  D ~C:   18.86
  D2 ~C#: 23.11 (final classes)
  D3 ~C#: 23.12 (final classes, no getters/setters)  
  Java:   25.40 (final classes)
  D4 ~C#: 30.16 (no getters/setters)    
  C#:     38.39
  D1 ~C#: 41.64


Pubuntu, n = 10_000_000:
  D ~C:    1.35
  C:       1.39
  D2 ~C#:  1.98 (final classes)  
  D3 ~C#:  2.00 (final classes, no getters/setters) 
  Java:    2.73 (final classes)  
  D4 ~C#:  2.94 (no getters/setters)      
  C#:      -  
  D1 ~C#:  4.03
  
Pubuntu, n = 100_000_000:
  D ~C:   13.24
  C:      13.77
  D2 ~C#: 19.64 (final classes)
  D3 ~C#: 19.92 (final classes, no getters/setters) 
  Java:   25.16 (final classes)    
  D4 ~C#: 29.16 (no getters/setters)       
  C#:      -
  D1 ~C#:  40.17

Key:
  D ~C# means D code that comes from the C# version.
  D ~C means D code that comes and looks from the C version.
&lt;/pre&gt;&lt;br /&gt;Note that the classes in C# code aren't final. As usual Java shows very good performance.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;On WindowsXp:&lt;br /&gt;DMD Digital Mars D Compiler v1.042&lt;br /&gt;gcc version 4.3.3-dw2-tdm-1 (GCC)&lt;br /&gt;&lt;br /&gt;dmd used with:&lt;br /&gt;dmd -O -release -inline&lt;br /&gt;&lt;br /&gt;ldc used with:&lt;br /&gt;ldc -O5 -release -inline&lt;br /&gt;&lt;br /&gt;gcc used with:&lt;br /&gt;gcc -Wall -O3 -s -fomit-frame-pointer -msse3 -march=core2&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;On Pubuntu:&lt;br /&gt;gcc version 4.2.4 (Ubuntu 4.2.4-1ubuntu4)&lt;br /&gt;ldc based on DMD v1.045 and llvm 2.6svn (Thu Jul  2 23:07:48 2009)&lt;br /&gt;&lt;br /&gt;ldc used with:&lt;br /&gt;ldc -O5 -release -inline&lt;br /&gt;&lt;br /&gt;gcc used with:&lt;br /&gt;gcc -Wall -O3 -s -fomit-frame-pointer -msse3 -march=native</content>
		<author>
			<name>leonardo maffi</name>
			<uri>http://leonardo-m.livejournal.com/</uri>
		</author>
		<source>
			<title type="html">leonardo</title>
			<subtitle type="html">leonardo - LiveJournal.com</subtitle>
			<link rel="self" href="http://leonardo-m.livejournal.com/data/rss?tag=d%20language" />
			<id>http://leonardo-m.livejournal.com/data/rss?tag=d%20language</id>
			<updated>2009-10-28T05:00:24+00:00</updated>
		</source>
	</entry>

</feed>
