<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>timburrell.net &#187; Blog</title>
	<atom:link href="http://timburrell.net/topics/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://timburrell.net</link>
	<description>All that is Tim Burrell</description>
	<pubDate>Sun, 29 Jun 2008 13:14:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>D Postmortem</title>
		<link>http://timburrell.net/blog/2008-06-22/d-postmortem/</link>
		<comments>http://timburrell.net/blog/2008-06-22/d-postmortem/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 12:43:17 +0000</pubDate>
		<dc:creator>Tim.</dc:creator>
		
		<category><![CDATA[Blog]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[c++]]></category>

		<category><![CDATA[c++0x]]></category>

		<category><![CDATA[d]]></category>

		<category><![CDATA[language]]></category>

		<category><![CDATA[parallel programming]]></category>

		<category><![CDATA[review]]></category>

		<guid isPermaLink="false">http://timburrell.net/?p=358</guid>
		<description><![CDATA[<p>It&#8217;s been about a year and half since I started actively using D &#8212; I&#8217;ve written (and maintained) a couple of small commercial applications in it, and taken maintainership over a couple of D related open source projects, but most of my experience with the language comes from using it to write my thesis project [...]</p>
<span style="background: none; border: none;"><a style="background: none; border: none;" name="respond"></a><a style="background: none; border: none;" name="comments"></a></span>

<div class="sociable">
<span class="sociable_tagline">
<strong>Share and Enjoy:</strong>
	<span style="font-size: 60%"></span>
</span>

	<a rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F&amp;title=D%20Postmortem" title="Reddit"><img src="http://timburrell.net/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F&amp;title=D%20Postmortem" title="StumbleUpon"><img src="http://timburrell.net/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F&amp;title=D%20Postmortem" title="Digg"><img src="http://timburrell.net/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F&amp;title=D%20Postmortem" title="Mixx"><img src="http://timburrell.net/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F" title="Technorati"><img src="http://timburrell.net/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://slashdot.org/bookmark.pl?title=D%20Postmortem&amp;url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F" title="Slashdot"><img src="http://timburrell.net/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://del.icio.us/post?url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F&amp;title=D%20Postmortem" title="del.icio.us"><img src="http://timburrell.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F&amp;t=D%20Postmortem" title="Facebook"><img src="http://timburrell.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F&amp;title=D%20Postmortem" title="Google"><img src="http://timburrell.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="mailto:?subject=D%20Postmortem&amp;body=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-06-22%2Fd-postmortem%2F" title="E-mail this story to a friend!"><img src="http://timburrell.net/wp-content/plugins/sociable/images/email_link.png" title="E-mail this story to a friend!" alt="E-mail this story to a friend!" class="sociable-hovers" /></a>

</div>
<small><em>posted in <a href="http://timburrell.net/topics/blog/">Blog</a> by Tim. <a href="http://timburrell.net/blog/2008-06-22/d-postmortem/#comments">Comments (17)</a><br />&copy;2008 <a href="http://timburrell.net">timburrell.net</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been about a year and half since I started actively using <a href="http://digitalmars.com/d">D</a> &#8212; I&#8217;ve written (and maintained) a couple of small commercial applications in it, and taken maintainership over a couple of D related open source projects, but most of my experience with the language comes from using it to write my thesis project in &#8212; around 30,000 lines of code spread over 100 source files.  Not exactly a huge project, but large enough to get a good feel for the language.</p>
<p>First of all the good: the bottom line is, D is a great little language, and I say little because in many ways it&#8217;s a lot simpler, and less complicated than any of the other system level object-oriented languages that it competes with (C++).  This doesn&#8217;t mean that D is any less valuable though &#8212; in fact much the opposite.  D&#8217;s inherent simplicity is by design.  It&#8217;s pretty clear by looking at the <a href="http://digitalmars.com/d/1.0/lex.html">language spec</a> that the idea was to take the best elements of some languages, throw out the rest, and add some of the missing features that we all wish we had (built in strings, optional garbage collection, modern language features, etc).</p>
<p>And by modern language features, this is the kind of stuff I&#8217;m talking about: <a href="http://www.digitalmars.com/d/1.0/mixin.html">mixins</a>, <a href="http://www.digitalmars.com/d/1.0/expression.html#FunctionLiteral">lambdas</a>, <a href="http://www.digitalmars.com/d/1.0/variadic-function-templates.html">variadic templates</a>, <a href="http://www.digitalmars.com/d/1.0/lazy-evaluation.html">lazy evaluation</a>, <a href="http://www.digitalmars.com/d/1.0/function.html#closures">delegates</a>, <a href="http://www.digitalmars.com/d/1.0/function.html#nested">nested functions</a>, <a href="http://www.digitalmars.com/d/1.0/struct.html">anonymous unions</a>, <a href="http://www.digitalmars.com/d/1.0/arrays.html#slicing">array slicing</a>, <a href="http://www.digitalmars.com/d/1.0/dbc.html">contract programming</a>, <a href="http://www.digitalmars.com/d/1.0/statement.html#ForeachStatement">handy statements</a>.  Basically, much of C++0x&#8217;s upcoming feature set, and more.</p>
<p>So does D deliver?  The answer yes, a resounding yes in fact.  In terms of core language design and features, D provides exactly what many of us have been yearning for for years &#8212; a system level language that is on par with (or better than) modern scripting languages (such as Python, and Ruby) in terms of development speed, provides the language features we all should have by now, yet compiles to native code that can be as efficient as C++.</p>
<p>The panacea of programming languages?  Well&#8230; no, not quite.  Unfortunately the story doesn&#8217;t end there.</p>
<p>The first problem is a major one, and I don&#8217;t want to downplay it because as it stands it&#8217;s enough of an issue that no development house could even consider D as a prospective language, but fortunately it&#8217;s something that should get better over time.  The issue: compiler bugs, and plenty of them.  Some of them are small, some of them are huge, but there&#8217;s enough that they add up to a serious problem.</p>
<p>The bugs I ran into ranged from little things like floating point printing errors, all the way to compiler segfaults.  Being that D is so young and the compilers aren&#8217;t close to maturity yet, any project complex enough is basically guaranteed to run into problems with either of the existing compilers, and my thesis project was no exception.  Fortunately there are two major compilers that use separate optimization paths (a frequent culprit in the official digitalmars compiler) so one at least has a contingency option, but unfortunately, they share the same front-end, so they tend to exhibit some of the same bugs as well.</p>
<p>There&#8217;s also some serious performance issues with both compilers.   For example, if you look at the assembler output of either of the compilers you can see them doing the same wasteful, redundant memory copies when doing something simple like returning a struct from a function.  The only work around to this compiler bug is to do ugly things like return values from functions using by-reference function parameters.  </p>
<p>Take a moment to think about the case where you can&#8217;t return values from functions &#8212; design goes out the window, along with readability and maintainability, not to mention ease of porting to other languages (should the desire arise).  It extends further than that though &#8212; it means, for example, using custom foreach iterators to do a simple iteration over a collection of stack allocated structs becomes so inefficient that you end up having to put regular for loops in places where they really shouldn&#8217;t be.</p>
<p>Basically these &#8220;little&#8221; compiler issues make it difficult to consistently employ OO design principles, and use all of the nice modern language features that made the language so attractive in the first place.  And after discovering these issues, along with their associated workarounds (wasting time discovering that your program&#8217;s poor performance is due to the compiler and not your code), you&#8217;re basically left with either a slow, inefficient executable, or ugly, unmaintainable code written in a language that was specifically designed to produce clear, concise, elegant code.  </p>
<p>It&#8217;s a terrible shame to have a few minor problems result in such broad consequences, but these issues are all things that can be fixed, and they&#8217;re not nearly as prevalent as this post makes them seem.  In fairness, given how new D is, the overall stability and quality of the available compilers is actually quite impressive.  The language itself shouldn&#8217;t be judged on these compiler issues, but it&#8217;s important that people who may be considering adopting D be aware that there are problems with the compilers before forging ahead.</p>
<p>The next big issue isn&#8217;t technically related to the language itself, but is still a problem because it&#8217;s one of the root causes of much of what&#8217;s stopping D from living up to its potential.  The heart of the matter is that D is currently going through some growing pains, and project leadership isn&#8217;t keeping up with the community.</p>
<p>Right now the D community is split between two incompatible standard libraries (<a href="http://dsource.org/projects/tango">Tango</a>, and <a href="http://www.digitalmars.com/d/1.0/phobos/phobos.html">Phobos</a>) that offer up different design philosophies, and although the majority of the community uses one library (Tango), it&#8217;s not the official standard library.  This tends to create confusion for new users, and forces people to adopt one library or another, or library designers to write and maintain two sets of sources &#8212; neither being optimal solutions.</p>
<p>To come back to the issue of the compiler bugs &#8212; in other projects such a situation might not be as much of an issue, but many of the compiler bugs have been sitting idle in the D bug tracker for many months, and many releases.  It appears as though the project is transitioning between a small niche language, to something that might even be getting close to being considered mainstream (D is currently <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">12<sup>th</sup> on the programming language popularity list</a>, and still moving up), so it&#8217;s understandable that some project leadership issues might crop up along the way.</p>
<p>Regardless of how understandable these growing pains may be, it&#8217;s still something that the project maintainers, and the D user community, are going to have to deal with before the language can really take the next step in terms of public acceptance.</p>
<p>There&#8217;s also one final problem with the language, or rather, the upcoming D2 language spec, and as big as all the other issues are this is actually the biggest thing that&#8217;s keeping me from continuing to use D on future projects.  We all know that multi-core systems are the defacto standard these days, and although we&#8217;re starting to get a handle on developing tools to help programmers deal with the almost always non-trivial task of writing parallel code, we&#8217;ve barely even scratched the surface of what compilers and runtimes can do to help regular joe-six-pack-programmer effectively, and easily, design algorithms that take advantage of today&#8217;s processors.</p>
<p>Given the current state of affairs in terms of SMP and distributed development, and that there&#8217;s a new revision of the D language in the works, D has a great opportunity to assert its intent to be a player in the upcoming multiprogramming language war.  But nothing is in the works.  The D team isn&#8217;t actively working on providing any inclusion of a modern parallel programming paradigm for D2, which means it will likely be pushed back to some future release of D.  This is unfortunate, because I know a great many developers are waiting for tools to help them deal with parallel programming (even if they don&#8217;t know they are).</p>
<p>Aside from <a href="http://en.wikipedia.org/wiki/Erlang_(programming_language)">Erlang</a> and other more obscure functional languages, right now C++ is still one of the best choices around for parallel development.  With the resounding success <a href="http://openmp.org">OpenMP</a> has seen in the last few years, and with <a href="http://en.wikipedia.org/wiki/C%2B%2B0x">C++0x</a> on the horizon and the new <a href="http://terboven.spaces.live.com/blog/cns!EA3D3C756483FECB!316.entry">OpenMP 3 being recently released</a> it looks like C++ is going to continue to be the language of choice for most system level and computationally expensive tasks.</p>
<p>Neither D, nor the upcoming D2 spec, give developers anything beyond raw threading (plus some critical section synchronization and resource locking type mechanisms, along with a controversial <a href="http://www.digitalmars.com/d/2.0/const-faq.html">const system</a>), but definitely nothing in the way of a modern parallel programming methodology.  It&#8217;s another unfortunate oversight that takes a language that should be an ultramodern successor to nearly all current languages in its class and puts it years behind C++, and even Fortran (both of which have OpenMP at their disposal), and let&#8217;s not even try to make a comparison to other languages like <a href="http://www.erlang.org/download/getting_started-5.4.pdf">Erlang</a>, <a href="http://jocaml.inria.fr/">JoCaml</a>, <a href="http://www.haskell.org/ghc/docs/6.4/html/users_guide/concurrent-and-parallel.html">Parallel Haskell</a>, and friends.</p>
<p>I really wish I could recommend D as a natural successor to C++, but given all the issues it&#8217;s currently facing, I just can&#8217;t.  It&#8217;s simply not there yet, and I fear, given it&#8217;s current direction, that it never will be.  I still think it&#8217;s a great project, and I hope that it works out because I&#8217;d like very much to see it succeed, because I think a strong competitor to the multi-paradigm system-level language would be a great boon to the software development and computer science communities.</p>
<p>I&#8217;ll definitely keep watching D to see what happens in the future, but I likely won&#8217;t be using it for any more projects until they can iron out the compiler stability and efficiency issues, and implement some reasonable multiprogramming method.</p>
]]></content:encoded>
			<wfw:commentRss>http://timburrell.net/blog/2008-06-22/d-postmortem/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Garbage Collection: The Joy and the Curse</title>
		<link>http://timburrell.net/blog/2008-03-06/garbage-collection-the-joy-and-the-curse/</link>
		<comments>http://timburrell.net/blog/2008-03-06/garbage-collection-the-joy-and-the-curse/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 14:09:15 +0000</pubDate>
		<dc:creator>Tim.</dc:creator>
		
		<category><![CDATA[Blog]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[d]]></category>

		<category><![CDATA[garbage collection]]></category>

		<category><![CDATA[memory management]]></category>

		<guid isPermaLink="false">http://timburrell.net/research/2008-03-06/garbage-collection-the-joy-and-the-curse/</guid>
		<description><![CDATA[<p>Everyone knows the diatribe spouted by certain types of programming evangelists that a good garbage collector can give a program higher memory throughput than one under manual memory management (or some equivalent scheme like reference counting) &#8212; not only that but manually managing your own memory is pretty much a waste of good development time; [...]</p>
<span style="background: none; border: none;"><a style="background: none; border: none;" name="respond"></a><a style="background: none; border: none;" name="comments"></a></span>

<div class="sociable">
<span class="sociable_tagline">
<strong>Share and Enjoy:</strong>
	<span style="font-size: 60%"></span>
</span>

	<a rel="nofollow" target="_blank" href="http://reddit.com/submit?url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F&amp;title=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse" title="Reddit"><img src="http://timburrell.net/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F&amp;title=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse" title="StumbleUpon"><img src="http://timburrell.net/wp-content/plugins/sociable/images/stumbleupon.png" title="StumbleUpon" alt="StumbleUpon" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F&amp;title=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse" title="Digg"><img src="http://timburrell.net/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.mixx.com/submit?page_url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F&amp;title=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse" title="Mixx"><img src="http://timburrell.net/wp-content/plugins/sociable/images/mixx.png" title="Mixx" alt="Mixx" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://technorati.com/faves?add=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F" title="Technorati"><img src="http://timburrell.net/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://slashdot.org/bookmark.pl?title=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse&amp;url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F" title="Slashdot"><img src="http://timburrell.net/wp-content/plugins/sociable/images/slashdot.png" title="Slashdot" alt="Slashdot" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://del.icio.us/post?url=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F&amp;title=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse" title="del.icio.us"><img src="http://timburrell.net/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F&amp;t=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse" title="Facebook"><img src="http://timburrell.net/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F&amp;title=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse" title="Google"><img src="http://timburrell.net/wp-content/plugins/sociable/images/googlebookmark.png" title="Google" alt="Google" class="sociable-hovers" /></a>
	<a rel="nofollow" target="_blank" href="mailto:?subject=Garbage%20Collection%3A%20The%20Joy%20and%20the%20Curse&amp;body=http%3A%2F%2Ftimburrell.net%2Fblog%2F2008-03-06%2Fgarbage-collection-the-joy-and-the-curse%2F" title="E-mail this story to a friend!"><img src="http://timburrell.net/wp-content/plugins/sociable/images/email_link.png" title="E-mail this story to a friend!" alt="E-mail this story to a friend!" class="sociable-hovers" /></a>

</div>
<small><em>posted in <a href="http://timburrell.net/topics/blog/">Blog</a> by Tim. <a href="http://timburrell.net/blog/2008-03-06/garbage-collection-the-joy-and-the-curse/#comments">Comments (12)</a><br />&copy;2008 <a href="http://timburrell.net">timburrell.net</a>. All Rights Reserved.</em></small>]]></description>
			<content:encoded><![CDATA[<p>Everyone knows the diatribe spouted by certain types of programming evangelists that a good garbage collector can give a program higher memory throughput than one under manual memory management (or some equivalent scheme like reference counting) &#8212; not only that but manually managing your own memory is pretty much a waste of good development time; no real programmer should have to lower him/herself to dealing with <i>memory</i>.  So the appeal of Garbage Collection is pretty obvious.  Why would anyone want to do their own memory management when you can let the computer do it for you, and at the same time have it work out to be more efficient?</p>
<p>The thing is, garbage collection isn&#8217;t a trivial problem, and it&#8217;s certainly not gotten to the point where it&#8217;s perfect.  Cycles aren&#8217;t really an issue for modern conservative style GC&#8217;s, not like they are with reference counting schemes, but that&#8217;s not to say they don&#8217;t still cause a problem.  Discovering cycles isn&#8217;t free, and generally in a complicated memory setup, even with a good fully modern GC you still end up with weak references / pointers like you would using simple reference counting.</p>
<p>I&#8217;m writing this because I&#8217;ve recently fallen onto the GC bandwagon as I&#8217;ve been using <a href="http://digitalmars.com/d">D</a> quite a bit lately.  Prior to D my only experience with GC was some time spent with Objective-C, and 4 years of undergrad <strike>cursing</strike> using Java &#8212; but that doesn&#8217;t really count <img src='http://timburrell.net/smilies/yahoo_wink.gif' alt='&#59;&#41;' class='wp-smiley' width='18' height='18' title='&#59;&#41;' />, and of course a myriad of interpreted languages like Python, PHP, lua, Ruby, etc.  I have used the <a href="http://www.hpl.hp.com/personal/Hans_Boehm/gc/">Hans Boehm GC</a> with C and C++ a few times as well, but that was for select cases where the scenarios were a good match for a garbage collected system.</p>
<p>After spending some time really working with a GC language (under situations that are less than an ideal use for a GC system &#8212; ie a real-time interactive simulation), I&#8217;ve come up with a more rounded opinion of garbage collection, and I thought I ought to share some of the things I&#8217;ve discovered that the GC pundits don&#8217;t seem to want you to know:</p>
<ul>
<li>Managing memory using GC, in complex data structure situations, where weak ref&#8217;s and cyclical dependencies are required (pretty much every largish program every written), can be more complicated and time consuming than manual memory management.  If someone tells you GC is all about &#8220;<b>new</b> and forget&#8221;, while it is true much of the time, you&#8217;re still okay to give them a good kidney punch because they&#8217;ve never really used GC.</li>
<li>Memory leaks are not impossible with GC.  It doesn&#8217;t take much to fool a GC system into believing memory should be retained when it shouldn&#8217;t.  This is a continuation of the above point, as it generally only happens in complicated situations, but nevertheless GC is not the panacea-all-hail-the-mother-of-memory-leak-free-programming that the pundits claim it to be.  If programmers can&#8217;t be trusted to manage their own memory, and GC systems are easy to fool, what makes us think that programmers should be trusted to manage GC memory either?</li>
<li>Using GC is slow.  &#8220;What?!  Didn&#8217;t you say using GC is more efficient and leads to higher memory throughput?&#8221;  I did, but I was baiting a bit, because that&#8217;s what the propaganda says.  Yes using a good, modern, GC leads to higher throughput of memory allocs and frees, this is true.  What the GC evangelists don&#8217;t remind you of is that most [well designed] programs allocate a bunch of memory, use the same memory over and over again, and then release the memory, so most of a program&#8217;s time [usually] isn&#8217;t spent allocating and deleting.  If your GC app needs to run for a lengthy period of time, chances are the GC&#8217;s sweep phase is going to use up more processing power than would have been &#8220;wasted&#8221; on manually allocating your own memory.  Which leads me to the next point.</li>
<li>GC makes it easy to fall into bad programming habits.  This is a bit subjective, and obviously not true in all cases.  But in using a GC language I&#8217;ve noticed a tendency in myself to <b>new</b> things that shouldn&#8217;t necessarily be <b>new</b>ed.  Since I don&#8217;t have to worry about memory management the odd <b>new</b> here or there doesn&#8217;t really matter, right?  In a non-GC language I would certainly have created a temporary on the stack rather than allocate memory on the heap (which as we all know is orders of magnitude slower than a stack alloc &#8212; and it&#8217;s even worse in a GC scenario).  Basically think of any Java code you&#8217;ve ever seen&#8230; how many times have you seen something like: GridCell.setPosition(new Position(x, y)) inside a loop?  Ack!  Granted this is sort of unavoidable in Java, but especially for people who are still learning, this is a terrible habit to pick up.</li>
</ul>
<p>So given all of this, it sounds like I&#8217;m saying GC is complicated, slow, and makes you dumb.  But I&#8217;m not.  I still hold true to the notion that memory management is something a programmer shouldn&#8217;t often have to explicitly deal with.  GC is a good thing!  </p>
<p>But getting the whole story with garbage collection is important.  Like any tool, it&#8217;s one of those things that has good use cases and bad, and knowing where and when to use it is key.  Fortunately, in D&#8217;s case, it&#8217;s ridiculously easy to mix manual and GC memory management, so for me, it&#8217;s not that much of an issue.  I just get sick and tired of hearing the all-pro GC arguments, because in reality GC makes life for a programmer a little bit tougher.  And by tougher I mean that more knowledge is required to complete a task.</p>
<p>In the end though it&#8217;s definitely worth it.  GC might not get rid of memory leaks, and it&#8217;s probably going to make your program slightly less efficient, and it might even introduce a few &#8220;bad&#8221; habits, but in some cases these are reasonable trade offs.  If you know a temporary heap allocation is going to get collected right away, and you&#8217;re not in a tight loop or something, then why not let the GC do some work for you!  If using GC ends up leading to some complicated weak reference scheme, do it manually!  </p>
<p>Basically it comes down to the age old adage of: know your tools.  Garbage collection can save valuable development time by freeing a programmer from having to deal with the bulk of an application&#8217;s memory management, thus leaving more time to focus on those situations where you do need to get dirty with some mallocs and frees (or hopefully on things more interesting than memory management).  But, if used improperly, or in the wrong situation, it&#8217;s pretty easy for GC to end up causing more problems than it solves.</p>
]]></content:encoded>
			<wfw:commentRss>http://timburrell.net/blog/2008-03-06/garbage-collection-the-joy-and-the-curse/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
