<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>www.hans-eric.com</title>
	
	<link>http://www.hans-eric.com</link>
	<description>Hans-Eric Grönlund on software development</description>
	<pubDate>Sat, 05 Jul 2008 14:40:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<geo:lat>60.666667</geo:lat><geo:long>17.132975</geo:long><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><image><link>http://www.hans-eric.com</link><url>http://www.hans-eric.com/hans-eric.png</url><title>Hans-Eric Grönlund</title></image><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/hans-eric" type="application/rss+xml" /><feedburner:emailServiceId>1129066</feedburner:emailServiceId><feedburner:feedburnerHostname>http://www.feedburner.com</feedburner:feedburnerHostname><item>
		<title>ModRewrite Problems</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/327403966/</link>
		<comments>http://www.hans-eric.com/2008/07/05/modrewrite-problems/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 14:26:05 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[blogging]]></category>

		<category><![CDATA[off-topic]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/?p=119</guid>
		<description><![CDATA[As you may or may not have discovered I have been on a long vacation, and intentionally stayed far away from any computer. Unfortunately my blog seems to have broken while I have been gone, particularely the single post pages.
Somehow the ModRewrite rules got screwed up, no idea how. Anyway, it has been taken care [...]]]></description>
			<content:encoded><![CDATA[<p>As you may or may not have discovered I have been on a long vacation, and intentionally stayed far away from any computer. Unfortunately my blog seems to have broken while I have been gone, particularely the single post pages.</p>
<p>Somehow the ModRewrite rules got screwed up, no idea how. Anyway, it has been taken care of now and the site should be up and running as usual. Many thank&#8217;s to <a href="http://www.robertames.com">Robert Ames</a> who pointed it out for me.</p>
<p>Now, back to vacationing (I still have a week left).</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=8iDMrm"><img src="http://feeds.feedburner.com/~a/hans-eric?i=8iDMrm" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=QkRESJ"><img src="http://feeds.feedburner.com/~f/hans-eric?i=QkRESJ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=0kJmlj"><img src="http://feeds.feedburner.com/~f/hans-eric?i=0kJmlj" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=VzNXlJ"><img src="http://feeds.feedburner.com/~f/hans-eric?i=VzNXlJ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=iY0X3j"><img src="http://feeds.feedburner.com/~f/hans-eric?i=iY0X3j" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Caaexj"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Caaexj" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=6C9hSJ"><img src="http://feeds.feedburner.com/~f/hans-eric?i=6C9hSJ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=2XZXwj"><img src="http://feeds.feedburner.com/~f/hans-eric?i=2XZXwj" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=YoU9dJ"><img src="http://feeds.feedburner.com/~f/hans-eric?i=YoU9dJ" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Dc015J"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Dc015J" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/327403966" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/07/05/modrewrite-problems/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/07/05/modrewrite-problems/</feedburner:origLink></item>
		<item>
		<title>The Functional Subset of D</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/294215543/</link>
		<comments>http://www.hans-eric.com/2008/05/20/the-functional-subset-of-d/#comments</comments>
		<pubDate>Tue, 20 May 2008 12:00:11 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[D Programming Language]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/?p=117</guid>
		<description><![CDATA[As I wrote about in an earlier post, the future of D lies in the field of functional programming. More specifically, what the creators of D are trying to do, is to construct a pure functional subset that can be utilized within the otherwise imperative language.
Let&#8217;s take a closer look at that functional subset that [...]]]></description>
			<content:encoded><![CDATA[<p>As I <a title="The Future of D is Functional" href="http://www.hans-eric.com/2008/04/16/the-future-of-d-is-functional/">wrote about in an earlier post</a>, the future of D lies in the field of functional programming. More specifically, what the creators of D are trying to do, is to construct a pure functional subset that can be utilized within the otherwise imperative language.</p>
<p>Let&#8217;s take a closer look at that functional subset that is taking form in the experimental 2.0 version of D.</p>
<p><strong>Immutable data</strong></p>
<p>The most fundamental difference between a purely functional language and an imperative one is how they treat data. Many of us are used to think of data in terms of state, where variables can be changed through assignments. But in a functional program there are no states. There are only constant values and functions that operate on them.</p>
<p>In D, immutability is achieved with the <em>invariant</em> keyword, either as a storage class:</p>
<pre><code>invariant int i = 3;</code></pre>
<p>or as a type constructor:</p>
<pre><code>invariant(int) i = 3;</code></pre>
<p><strong>Transitive invariance</strong></p>
<p>The side-effect free nature that comes with immutable data has some great advantages.  For one thing it simplifies testing since the result of a function only depends on its input. There are also some optimizations that can be done by the compiler, but the biggest advantage is that programs written in this way are thread-safe by default.</p>
<p>To take advantage of these things the compiler needs to be able to trust the immutability of our data. This is where transitivity comes in.  In D, invariance is transitive, which basically means that no data reachable from an invariant reference can be changed. Here&#8217;s an example.</p>
<pre><code>int ga = 2; // mutable

struct A {
  int *p = &amp;ga; // pointer to mutable
}

invariant(A) a; // a is immutable
A b; // b is mutable

// invariant is transitive
a = b; // ERROR, a is immutable
a.p = null; // ERROR, a.p is immutable
*a.p = 3; // ERROR, data pointed to by a.p is also immutable
</code></pre>
<p><strong>Garbage collection</strong></p>
<p>Since data must never change in a functional program, and consequently must not be destroyed while the data is in use, it&#8217;s usually a good idea for a functional language to utilize automatic memory management. Like most functional languages, D features garbage collection (<a title="Managing Object Lifetimes in D" href="http://www.hans-eric.com/2008/02/07/managing-object-lifetimes-in-d/">alongside with explicit memory management</a>.)</p>
<p><strong>Higher class functions</strong></p>
<p>In order to do anything interesting in a purely functional language you need higher order functions, or - in other words - the ability to send functions as arguments to other functions. For this we can use the function pointers (or delegates for methods and nested functions).</p>
<p>As an example, let&#8217;s say that we want to create a function that calculates the sum of two adjacent Fibonacci numbers. Here&#8217;s one way to do that.</p>
<pre><code>int nth_fib(int n) {
  if(n == 0) return 0;
  if(n == 1) return 1;
  return nth_fib(n-1) + nth_fib(n-2);
}

int add_next_fib(int n) {
  return nth_fib(n) + nth_fib(n+1);
}</code></pre>
<p>Now, let&#8217;s say that we want to do the same operation on a different sequence, for example natural numbers. Well, we could use the good old copy and paste but that isn&#8217;t very <a title="Don't Repeat Yourself" href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a>. Let&#8217;s make add_next a higher order function instead so that it could be used with any sequence function.</p>
<pre><code>int add_next(int n, <em>int function(int) nth</em>) {
  return nth(n) + nth(n+1);
}

int i = add_next(3, &amp;nth_fib);
// i is 8 (3+5)</code></pre>
<p>Now, we can write any sequence function we want and have add_next apply it.</p>
<pre><code>// Sequence function for natural numbers
int nth_nat(int n) {
  return n;
}

int i = add_next(3, &amp;nth_nat);
// i is 7 (3+4)
</code></pre>
<p>Note: For methods and nested functions, the keyword <em>function</em> is replaced with the keyword <em>delegate</em>, otherwise it&#8217;s the same syntax.</p>
<p><strong>Closures</strong></p>
<p>Closures is another indispensable feature of functional languages. In short, it&#8217;s the ability to extract a function pointer for later use, and when invoked the function will still have access to the context in which it was created, even though that context has gone out of scope.</p>
<p>In D, closures are created with the <em>delegate</em> keyword.</p>
<pre><code>int delegate() create_closure() {
  int x = 3;

  int f() {
    return x;
  }

  return &amp;f;
}

int delegate() a_closure = create_closure();
int i = a_closure();
// i is 3
</code></pre>
<p>Note that the extracted function f (referenced by the a_closure variable) accesses the local variable x, although it has gone out of scope at the time of execution. D got this ability with the 2.07 version, before that <a href="http://www.hans-eric.com/2007/09/11/d-doesnt-have-real-closures/">it didn&#8217;t have real closures</a>.</p>
<p><strong>Currying</strong></p>
<p>Closures provide an easy way to do currying, which is common in functional languages. Simply put, currying is a technique where functions take a general function and return a new, more specialized one.</p>
<p>For instance, we could curry our add_next function in our previous example and create a specialized version of it, say add_next_fib (and thus get back to where we started).</p>
<pre><code>int delegate(int) curry_add_next(int function(int) nth) {
  int curry_f(int n) {
    return add_next(n, nth);
  }
  return &amp;curry_f;
}

int delegate(int) add_next_fib = curry_add_next(&amp;nth_fib);
int i = add_next_fib(5);
// i is still 8
</code></pre>
<p><strong>Pure functions</strong></p>
<p>These features are all we need to write purely functional code, but in order to take full advantage of the functional programming paradigm some major things remain unsolved.</p>
<p>For one thing, the compiler needs to know whether or not our code is functional in order to apply possible optimizations. The easiest way to do this is to give the programmer a keyword to tell the compiler she wishes purity, and then have the compiler enforce it. In D this is the purpose of the <em>pure storage class</em>.</p>
<pre><code><em>pure</em> int a_pure_square_function(invariant(int) x) {
  return x * x;
}</code></pre>
<p>A pure function must not access non-invariant data, and may not invoke other non-pure functions. As per D2.13, the pure storage class has not had its semantics implemented and are therefore not enforcing purity. I sense this is not a trivial matter, so it may take some time before we have it.</p>
<p>Cheers!</p>
<p>Update: Added a link and rewrote the section on garbage collection.</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=nNReS2"><img src="http://feeds.feedburner.com/~a/hans-eric?i=nNReS2" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=hJeZWH"><img src="http://feeds.feedburner.com/~f/hans-eric?i=hJeZWH" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=LKRKNh"><img src="http://feeds.feedburner.com/~f/hans-eric?i=LKRKNh" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=qPDbOH"><img src="http://feeds.feedburner.com/~f/hans-eric?i=qPDbOH" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=2Gp8th"><img src="http://feeds.feedburner.com/~f/hans-eric?i=2Gp8th" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=5jy8Eh"><img src="http://feeds.feedburner.com/~f/hans-eric?i=5jy8Eh" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=0b5b3H"><img src="http://feeds.feedburner.com/~f/hans-eric?i=0b5b3H" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=ZIUMYh"><img src="http://feeds.feedburner.com/~f/hans-eric?i=ZIUMYh" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=SVGO0H"><img src="http://feeds.feedburner.com/~f/hans-eric?i=SVGO0H" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=L4vQCH"><img src="http://feeds.feedburner.com/~f/hans-eric?i=L4vQCH" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/294215543" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/05/20/the-functional-subset-of-d/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/05/20/the-functional-subset-of-d/</feedburner:origLink></item>
		<item>
		<title>Alan Cooper: Open-Source is a Sign of Failure</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/279308428/</link>
		<comments>http://www.hans-eric.com/2008/04/28/alan-cooper-open-source-is-a-sign-of-failure/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 10:45:47 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/04/28/alan-cooper-open-source-is-a-sign-of-failure/</guid>
		<description><![CDATA[In the keynote where Alan Cooper proclaimed that Agile processes are bad for developing quality software, he made another provoking statement: that Open-Source is ultimately a symptom of management failure. His point is that with the right enthusiasm and commitment to your products, why would anyone go and work in an Open-Source project on their [...]]]></description>
			<content:encoded><![CDATA[<p>In the keynote where <a href="http://www.hans-eric.com/2008/03/28/is-agile-only-for-elites/" title="Is Agile Only For Elites?">Alan Cooper proclaimed</a> that Agile processes are bad for developing quality software, he made another provoking statement: that Open-Source is ultimately a symptom of management failure. His point is that with the right enthusiasm and commitment to <em>your</em> products, why would anyone go and work in an Open-Source project on their spare time?</p>
<p>Well, there are plenty of good reasons for doing Open-Source pro bono work; it&#8217;s a great way to get experience and widen perspectives for instance, but still, Alan has a point. Many of us are not as content as we could be with our regular work. Instead we&#8217;re seeking satisfaction elsewhere.</p>
<p>So, what should our employers do to get our full attention? Here&#8217;s my list.</p>
<ul>
<li><strong>Creative freedom</strong><br />
Give me a chance to contribute, to be innovative and creative. Let me spend a part of my time doing research and follow paths that interest and inspires me. Google is <a href="http://www.hans-eric.com/2007/09/19/the-google-example/" title="The Google Example">a great example</a> of a company that understands the importance of this.</li>
<li><strong>Personal Development</strong><br />
As <a href="http://www.xprogramming.com/Blog/Page.aspx?display=GoodEnough" title="Good Enough">Ron Jeffries has said</a>, &#8220;the river is moving, and if we don&#8217;t keep rowing, we are going to drift back downstream.&#8221; I think self improvement is a spice of life. If my company provides me with all the books I need (and want), and lets me attend courses and conferences of my choice, chances are I&#8217;ll stay with it for life.</li>
<li><strong>Ownership</strong><br />
People usually do a better job, are more careful and thorough, if they own the thing they&#8217;re working on. This is true for software as well. Make me a business partner and I&#8217;ll optimize my work according to your business goals.</li>
<li><strong>Appreciation</strong><br />
The human race seems to be immensely better at criticizing than at giving appreciation. Yet, this is what we all crave, and - it has a great impact on how we see our employers. A rewarding salary is one form of showing appreciation, but I also need the outspoken forms.</li>
<li><strong>Closures</strong><br />
No one can go on for ever without reaching a finish line. I want to work in a team that is long-term efficient and gets  to <em>get done</em> often. Help me divide and I&#8217;ll conquer for you.</li>
</ul>
<p>That was my list, what&#8217;s on yours?</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=jtqB6q"><img src="http://feeds.feedburner.com/~a/hans-eric?i=jtqB6q" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=lbrBlG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=lbrBlG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=MIpcAg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=MIpcAg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=WMVLSG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=WMVLSG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=8nO3zg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=8nO3zg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=w2Uvgg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=w2Uvgg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=kfsmEG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=kfsmEG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=0HfWog"><img src="http://feeds.feedburner.com/~f/hans-eric?i=0HfWog" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=xJZ72G"><img src="http://feeds.feedburner.com/~f/hans-eric?i=xJZ72G" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=7CefnG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=7CefnG" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/279308428" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/04/28/alan-cooper-open-source-is-a-sign-of-failure/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/04/28/alan-cooper-open-source-is-a-sign-of-failure/</feedburner:origLink></item>
		<item>
		<title>The Future of D is Functional</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/271334655/</link>
		<comments>http://www.hans-eric.com/2008/04/16/the-future-of-d-is-functional/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 10:33:44 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[D Programming Language]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/04/16/the-future-of-d-is-functional/</guid>
		<description><![CDATA[The D Programming Language has an impressive list of cool features. That is not always a good thing. A feature should contribute to the philosophy and foundation on which the language was built. If it doesn’t, harmony breaks down and the result is a language that is harder to learn and to use.
Some people think [...]]]></description>
			<content:encoded><![CDATA[<p>The D Programming Language has an impressive list of cool features. That is not always a good thing. A feature should contribute to the philosophy and foundation on which the language was built. If it doesn’t, harmony breaks down and the result is a language that is harder to learn and to use.</p>
<p>Some people think D suffers from such a feature creep. To some degree I can agree. D has <a href="http://www.hans-eric.com/2007/08/27/contract-programming-in-d/" title="Contract Programming in D">features that are unlikely to become widespread</a>, but most of them are aligned towards a common goal. That goal is bringing productivity to the world of low-level programming.</p>
<p>Lately, a new goal has emerged from the D community, and it has triggered some real intense activity. The future of D seems to lie in the field of functional programming, making the imperative and the functional paradigms truly come together.</p>
<p>Why is this important? Let me quote Walter Bright from <a href="http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&amp;article_id=68443" title="Walter Bright on const">a discussion at the D forums</a>:</p>
<blockquote><p>The future of programming will be multicore, multithreaded. Languages that<br />
make it easy to program them will supplant languages that don&#8217;t.<br />
[…]<br />
The surge in<br />
use of Haskell and Erlang is evidence of this coming trend (the killer<br />
feature of those languages is they make it easy to do multiprogramming).</p></blockquote>
<p>As we all know, multithread programming in an imperative language is a real pain. It’s complicated and easy to get wrong, but that is not the case in a functional language. A pure functional program is thread-safe by design, since it’s free from mutable state and side-effects.</p>
<blockquote><p>You never have to worry about deadlocks and race conditions because you don&#8217;t need to use locks! No piece of data in a functional program is modified twice by the same thread, let alone by two different threads. That means you can easily add threads without ever giving conventional problems that plague concurrency applications a second thought!</p></blockquote>
<p>Quote from Slava Akhmechet’s excellent article <a href="http://www.defmacro.org/ramblings/fp.html">Functional Programming For the Rest of Us</a>.</p>
<p>What the people behind D want to do is to create a true functional subset of the D Programming Language, and create a safe interfacing to parts of the program that are imperative. The functional subset would enforce pure functional programming, like disallowing access to mutable global state and calls to non-pure functions. In effect that would enable you to write parts of your program that need to be thread-safe in a functional style, while using the style of programming that most of us are used to for the rest.</p>
<p>But, it might not stop there. Andrei Alexandrescu, who’s one of the driving forces behind the functional subset, has suggested that the enforcements inside a pure function can be relaxed to allow mutability of what he calls “automatic state,” thus allowing imperative techniques to be used as long as the mutability doesn’t leak across the function barrier. Here’s an example from <a href="http://www.digitalmars.com/d/2.0/accu-functional.pdf" title="Grafting Functional Support on Top of an Imperative Language">Andrei’s slides on the subject</a>:</p>
<pre><code>int fun(invariant(Node) n) pure {
  int i = 42;
  if (n.value) ++i;
  int accum = 0;
  for (i = 0; i != n.value; ++i) ++accum;
  return n.value + i;
}</code></pre>
<p>This code doesn’t look a bit functional, but the result of fun() is solely dependent on its arguments, so seen from the outside it’s pure.</p>
<p>Mixing pure functional and main stream imperative programming is certainly bleeding-edge. As far as I know it has never been done in any other language. But even though I’m excited, I can’t help wondering whether this is the right way to go. There’s a risk that D spreads itself too thin, and that the pure functional subset of D will be too noisy; I anticipate a heavy use of the invariant keyword for instance.</p>
<p>Would it be a better option to create a completely new language, say Functional D, and make D and Functional D interoperable on a binary level? At least that would battle the noise by reducing the need for explicitly expressing things like immutability, which can be taken for granted in a functional language. I also suspect that the compilers would be less difficult to implement than a compiler that has to support both styles.</p>
<p>But then again, I don’t know much about making compilers. I just happen to be more of a minimalist when it comes to computer languages. (As opposed to my preferences for APIs and Framworks.)</p>
<p>Expect more posts on this subject as I plan to delve into details next.</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=MUsnek"><img src="http://feeds.feedburner.com/~a/hans-eric?i=MUsnek" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=Fpxu4DG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Fpxu4DG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=xQrANsg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=xQrANsg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=gBReOoG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=gBReOoG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=pPT2cTg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=pPT2cTg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=i70ED9g"><img src="http://feeds.feedburner.com/~f/hans-eric?i=i70ED9g" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=X3umz9G"><img src="http://feeds.feedburner.com/~f/hans-eric?i=X3umz9G" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Kk2ZBMg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Kk2ZBMg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=7pq5yhG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=7pq5yhG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Bqw6wYG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Bqw6wYG" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/271334655" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/04/16/the-future-of-d-is-functional/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/04/16/the-future-of-d-is-functional/</feedburner:origLink></item>
		<item>
		<title>Steve Yegge: D is the Next Cool Language</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/262101993/</link>
		<comments>http://www.hans-eric.com/2008/04/01/steve-yegge-d-is-the-next-cool-language/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 17:36:19 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[D Programming Language]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/04/01/steve-yegge-d-is-the-next-cool-language/</guid>
		<description><![CDATA[I just watched an interview with Steve Yegge on the Google Code Blog. The interview was mostly about his current project Rhino on Rails. It was interesting, although not interesting enough to keep my attention for the entire 25 minutes. After some time I kind of tuned out, but I kept the video cast running [...]]]></description>
			<content:encoded><![CDATA[<p>I just watched <a href="http://google-code-updates.blogspot.com/2008/01/interview-with-steve-yegge-on-rhino-on.html" title="Interview with Steve Yegge on Rhino on Rails">an interview with Steve Yegge</a> on the Google Code Blog. The interview was mostly about his current project Rhino on Rails. It was interesting, although not interesting enough to keep my attention for the entire 25 minutes. After some time I kind of tuned out, but I kept the video cast running in the background.</p>
<p>Good thing I did, because at the end of the interview Steve surprised me big time. If you&#8217;ve followed my blog lately you know that the <a href="http://www.hans-eric.com/2007/08/21/agile-low-level-programming-with-d/" title="Agile Low Level Programming With D">D Programming Language is my favorite toy</a> at the moment, so when he mentioned it in the interview I was all ears again. For your convenience, I made a transcript of the best parts:</p>
<blockquote><p><strong>You&#8217;re a language geek. What new cool language would you want to play with next?</strong></p>
<p>To be honest I really wish I knew more about D. I&#8217;ve programmed in the D language and it&#8217;s D-lightful. It was quite expressive. I did a bunch of programs that I kind of ported from ruby scripts that I&#8217;ve written, and I swear it was only like 20% harder than in the ruby code. It was super tight, except that it was lightning fast. It was like C++ or faster.</p></blockquote>
<p>Steve also gives his opinion on what&#8217;s needed for D to become really big.</p>
<blockquote><p>If it [the D language] were link compatible with C++, which is hard, then it could be used with all the C++ libraries. Then it could be the replacement of C++.</p></blockquote>
<p>In case you&#8217;d like to hear and see for yourself, the part when he mentions D starts at about 22 minutes and 35 seconds in.</p>
<p>Steve Yegge as part of the D community? Wouldn&#8217;t that be something.</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=ffpAEn"><img src="http://feeds.feedburner.com/~a/hans-eric?i=ffpAEn" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=3gBq3eG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=3gBq3eG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=6ttHKjg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=6ttHKjg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=iRN7bZG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=iRN7bZG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=bjFMwIg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=bjFMwIg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Vnq5Qxg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Vnq5Qxg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=2AjJB7G"><img src="http://feeds.feedburner.com/~f/hans-eric?i=2AjJB7G" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=mVO2EFg"><img src="http://feeds.feedburner.com/~f/hans-eric?i=mVO2EFg" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=kx9bVoG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=kx9bVoG" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=otiKEDG"><img src="http://feeds.feedburner.com/~f/hans-eric?i=otiKEDG" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/262101993" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/04/01/steve-yegge-d-is-the-next-cool-language/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/04/01/steve-yegge-d-is-the-next-cool-language/</feedburner:origLink></item>
		<item>
		<title>Is agile only for elites?</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/259586949/</link>
		<comments>http://www.hans-eric.com/2008/03/28/is-agile-only-for-elites/#comments</comments>
		<pubDate>Fri, 28 Mar 2008 11:35:44 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[software development]]></category>

		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/03/28/is-agile-only-for-elites/</guid>
		<description><![CDATA[I’m back from the ESRI Developer Summit. While suffering from severe jet lag I’ve spent the last couple of days in slow reflection. The biggest impact the conference had on me was a keynote held by Alan Cooper.
Early in his talk he put me in a defensive mode by stating that agile processes are bad [...]]]></description>
			<content:encoded><![CDATA[<p>I’m back from the <a href="http://www.esri.com/events/devsummit/index.html">ESRI Developer Summit</a>. While suffering from severe jet lag I’ve spent the last couple of days in slow reflection. The biggest impact the conference had on me was a keynote held by <a href="http://en.wikipedia.org/wiki/Alan_Cooper">Alan Cooper</a>.</p>
<p>Early in his talk he put me in a defensive mode by stating that <a href="http://en.wikipedia.org/wiki/Agile_software_development" title="Agile Software Development">agile</a> processes are bad for developing quality software. Alan means that the idea of little or no upfront design is ridiculous and will result in either expensive development costs or crappy software.<br />
Instead he believes in having all outstanding uncertainties removed with a thorough and detailed design, thus developing a &#8220;blueprint&#8221; for a production team to follow. Additionally, in opposition to the agile manifesto, change is nothing he seems to embrace.</p>
<blockquote><p>Most business executives believe that writing production code is a good thing. They assume that getting to production coding early is better than getting to it later. This is not correct. Writing production code is extremely expensive and extremely permanent. Once you&#8217;ve written it, it tends to stay written. Any changes you might make to production code are 1) harmful to the conceptual integrity of the code, and 2) distracting and annoying to the programmers. Annoying your programmers is more self-destructive to a company than is annoying the Board of Directors. The annoyed programmers hold your company&#8217;s operations, products, and morale in the palms of their hands.</p></blockquote>
<p>So he wants us to go back to Waterfall. Doesn’t that give me the right to discard his thoughts without further reflection? No, I don’t think so.</p>
<p>It&#8217;s easy to forget that the “traditional” development processes were not created to make our lives as developers miserable. They emerged from common knowledge of that time, and they were formulated to address real problems. We would be foolish to disregard that experience from the past.</p>
<p>Let me be clear with one thing. I don’t agree with Alan. I do believe we can produce high quality software with agile methods, where design evolves with the production code. But I did, after my initial defensive reflex, find his perspective refreshing.</p>
<p>Alan’s talk is not published anywhere, but <a href="http://www.cooper.com/insights/journal_of_design/articles/design_engineering_the_next_st.html" title="Design engineering: the next step">the general ideas are documented</a> on his company’s website.</p>
<blockquote><p>Software construction is slow, costly, and unpredictable.<br />
[…]<br />
Unpredictable is by far the nastiest of these three horsemen of the software apocalypse. Unpredictable means 1) you don&#8217;t know what you are going to get; and 2) you won&#8217;t get what you want. In badness, slow and costly pale in comparison to unpredictable.<br />
[…]<br />
The key, it seems, is vanquishing unpredictability, which means determining in advance what the right product design is, determining the resources necessary to build it, and doing so. As the airline pilots say, &#8220;Plan your flight, and fly your plan.&#8221;</p></blockquote>
<p>Alan’s solution to the development problems of today is to divide work into three separate fields of responsibilities, something he calls “The Triad”.</p>
<blockquote><p>Interaction design is design for humans, design engineering is design for computers, and production engineering is implementation. Recognizing these three separate divisions and organizing the work accordingly is something I call &#8220;The Triad.&#8221; While it cannot exist without interaction designers, it depends utterly on teasing apart the two kinds of engineering which today, in most organizations, are almost inextricably linked. It will take some heroic efforts to segregate them.</p></blockquote>
<p>Collaboration with the customer (or users), as the agile methodologies suggest, is out of the question according to Alan. Why let the least qualified make the most important decisions, he reasons. Instead, Alan Cooper advocates the use of interaction designers (<a href="http://en.wikipedia.org/wiki/Human-computer_interaction" title="Human Computer Interaction">HCI</a> experts). Thus, he identifies three key roles: design engineers, production engineers and interaction designers.</p>
<blockquote><p>Production engineers are good programmers who are personally most highly motivated by seeing their work completed and used for practical purposes by other people. Design engineers are good programmers who are personally most highly motivated by assuring that their solutions are the most elegant and efficient possible.<br />
Interaction designers&#8217; motivations are very similar to those of design engineers, but interaction designers are not programmers. Although most programmers imagine that they are also excellent interaction designers, all you have to do to dissuade them of this mistaken belief is to explain that interaction designers spend much of their time interviewing users.</p></blockquote>
<p>Alan doesn’t rule out agile methods completely. He thinks they have a place, but only as a part of the design process.</p>
<blockquote><p>Currently there is a pitched battle raging in the programmer world between conventional engineering methods and Agile methods. What neither side sees is a path of reconciliation; where Agile and conventional methods can effectively coexist. Providentially, the Triad reconciles them very well. The lean, iterative, problem-solving work of the software design engineer is the archetype of Agile programming. The purposeful, methodical construction work of the production engineer is the quintessence of conventional software engineering, particularly the type espoused by disciples of Grady Booch&#8217;s Rational Unified Process, or RUP. Both methods are correct, but only when used at the correct time and with the correct medium.</p></blockquote>
<p>Despite Alan’s thought provoking keynote, I’m still a believer of agile methods for the whole development process. I think it’s possible to build rigid software with little upfront design, a readiness for change, rapid feedback and customer collaboration. The problem I see is that it demands a lot more from us developers. Knowing the language and how to program the platform is no longer enough. We need system and interface design skills, as well as social skills. We also need to master important but difficult techniques like <a href="http://en.wikipedia.org/wiki/Unit_testing">unit testing</a> and <a href="http://en.wikipedia.org/wiki/Refactoring">code refactoring</a>.</p>
<p>Maybe agile is only for teams of elites?</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=eMbfTb"><img src="http://feeds.feedburner.com/~a/hans-eric?i=eMbfTb" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=HBu9DIF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=HBu9DIF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=TlKbDlf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=TlKbDlf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Xe3LnLF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Xe3LnLF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=32ibvWf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=32ibvWf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=cOA6uDf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=cOA6uDf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=PC7GDyF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=PC7GDyF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=R695iRf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=R695iRf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=PLjML2F"><img src="http://feeds.feedburner.com/~f/hans-eric?i=PLjML2F" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=tNXaTFF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=tNXaTFF" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/259586949" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/03/28/is-agile-only-for-elites/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/03/28/is-agile-only-for-elites/</feedburner:origLink></item>
		<item>
		<title>D update mitigates comparison gotcha</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/249647914/</link>
		<comments>http://www.hans-eric.com/2008/03/11/d-update-mitigates-comparison-gotcha/#comments</comments>
		<pubDate>Tue, 11 Mar 2008 18:12:25 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[D Programming Language]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/03/11/d-update-mitigates-comparison-gotcha/</guid>
		<description><![CDATA[The D programming language tries to make a clear distinction between comparison by equality and comparison by identity. It does so by offering two different operators, one for each purpose.
// Are a and b equal?
if (a == b) { &#8230; }

// Are a and b the same object?
if (a is b) { &#8230; }
As I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>The D programming language tries to make a clear distinction between comparison by equality and comparison by identity. It does so by offering two different operators, one for each purpose.</p>
<pre><code>// Are a and b <strong>equal</strong>?
if (a <strong>==</strong> b) { &#8230; }

// Are a and b the <strong>same</strong> object?
if (a <strong>is</strong> b) { &#8230; }</code></pre>
<p>As I&#8217;ve written about in <a href="http://www.hans-eric.com/2007/11/06/d-gotchas/" title="D gotchas">a previous post</a> this could be a source of confusion for D newbies, like myself. Someone who&#8217;s used to the comparison semantics of Java, for instance, is likely to learn to separate equality and identity the hard way. Until now, that is.</p>
<p>This code, where the equality operator is (wrongly) used to compare identities, used to produce a nasty Access violation error at runtime.</p>
<pre><code>SomeObject a = null;
if (a == null) { ... } //&lt;-- Access Violation
</code></pre>
<p>Now, with the newly released versions of the D compiler (the stable <a href="http://www.digitalmars.com/d/1.0/changelog.html#new1_028" title="DMD 1.028 Change Log">1.028</a> and the experimental <a href="http://ftp.digitalmars.com/dmd.2.012.zip" title="DMD 2.012 Change Log">2.012</a>,) this error is nicely caught by the compiler, which kindly instructs us to use the identity operator instead.</p>
<p><code>Error: use 'is' instead of '==' when comparing with null</code></p>
<p>Unfortunately, it won&#8217;t help us discover all cases of wrongly used equality operators. For instance, this piece of code still produces the dreadful runtime AV.</p>
<pre><code>SomeObject a = null;
if (a == a) { ... } // &lt;= Access Violation</code></pre>
<p>Still, the update is a big improvement and will make it easier for a lot of people while learning the language.</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=LJ5ej4"><img src="http://feeds.feedburner.com/~a/hans-eric?i=LJ5ej4" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=piOBCgF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=piOBCgF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=t793IOf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=t793IOf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=YWu6XnF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=YWu6XnF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=8EKCgQf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=8EKCgQf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=mXBHnmf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=mXBHnmf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=S08tKeF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=S08tKeF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Exm4nVf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Exm4nVf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=M0tQl9F"><img src="http://feeds.feedburner.com/~f/hans-eric?i=M0tQl9F" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=lg4wz0F"><img src="http://feeds.feedburner.com/~f/hans-eric?i=lg4wz0F" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/249647914" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/03/11/d-update-mitigates-comparison-gotcha/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/03/11/d-update-mitigates-comparison-gotcha/</feedburner:origLink></item>
		<item>
		<title>Off to the land of opportunity</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/248835312/</link>
		<comments>http://www.hans-eric.com/2008/03/10/off-to-the-land-of-opportunity/#comments</comments>
		<pubDate>Mon, 10 Mar 2008 12:05:37 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[off-topic]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/03/10/off-to-the-land-of-opportunity/</guid>
		<description><![CDATA[Next week I&#8217;m going to attend the 2008 ESRI Developer Summit in Palm Springs. It will be my first time in the USA and I&#8217;m really looking forward to the trip. Who knows, I might even meet one of you guys over there.
]]></description>
			<content:encoded><![CDATA[<p>Next week I&#8217;m going to attend the <a href="http://esri.com/events/devsummit/index.html">2008 ESRI Developer Summit</a> in Palm Springs. It will be my first time in the USA and I&#8217;m really looking forward to the trip. Who knows, I might even meet one of you guys over there.</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=9lUq3S"><img src="http://feeds.feedburner.com/~a/hans-eric?i=9lUq3S" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=Idl3ZAF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Idl3ZAF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=CDZdcyf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=CDZdcyf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=gxlGdNF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=gxlGdNF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=FADlayf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=FADlayf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Rinxx7f"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Rinxx7f" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=8Ia1sMF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=8Ia1sMF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=j5jJJHf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=j5jJJHf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=9tgcDVF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=9tgcDVF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=glY97wF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=glY97wF" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/248835312" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/03/10/off-to-the-land-of-opportunity/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/03/10/off-to-the-land-of-opportunity/</feedburner:origLink></item>
		<item>
		<title>OT: Rest in peace Gary</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/246856519/</link>
		<comments>http://www.hans-eric.com/2008/03/06/ot-rest-in-peace-gary/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 17:13:37 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[off-topic]]></category>

		<category><![CDATA[role-playing]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/03/06/ot-rest-in-peace-gary/</guid>
		<description><![CDATA[I&#8217;m sad to see that the original author of the role-playing game AD&#38;D, Gary Gygax, has died. I&#8217;d like to send a warm, thankful thought to the one who&#8217;s work meant so much to me and my role-playing friends in our youths.
I would like the world to remember me as the guy who really enjoyed [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sad to see that the original author of <em>the</em> role-playing game AD&amp;D, <a href="http://en.wikipedia.org/wiki/Gary_Gygax">Gary Gygax</a>, has died. I&#8217;d like to send a warm, thankful thought to the one who&#8217;s work meant so much to me and my role-playing friends in our youths.</p>
<blockquote><p>I would like the world to remember me as the guy who really enjoyed playing games and sharing his knowledge and his fun pastimes with everybody else.</p></blockquote>
<p>Rest in peace man.</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=lzSN7r"><img src="http://feeds.feedburner.com/~a/hans-eric?i=lzSN7r" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=5BL8R2F"><img src="http://feeds.feedburner.com/~f/hans-eric?i=5BL8R2F" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=KvF5Ltf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=KvF5Ltf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=oXsWjbF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=oXsWjbF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=0KWr7wf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=0KWr7wf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=ncmBOIf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=ncmBOIf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=om3BUgF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=om3BUgF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=5grBu6f"><img src="http://feeds.feedburner.com/~f/hans-eric?i=5grBu6f" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=l3b7u5F"><img src="http://feeds.feedburner.com/~f/hans-eric?i=l3b7u5F" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=SWdzm4F"><img src="http://feeds.feedburner.com/~f/hans-eric?i=SWdzm4F" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/246856519" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/03/06/ot-rest-in-peace-gary/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/03/06/ot-rest-in-peace-gary/</feedburner:origLink></item>
		<item>
		<title>Who wants a sloppy workplace?</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/246833045/</link>
		<comments>http://www.hans-eric.com/2008/03/06/who-wants-a-sloppy-workplace/#comments</comments>
		<pubDate>Thu, 06 Mar 2008 16:30:22 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[habits]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/03/06/who-wants-a-sloppy-workplace/</guid>
		<description><![CDATA[I&#8217;m not the kind of person who is easily annoyed, but there is one thing that gets into my skin - all the time. Inconsistently structured code. I hate arbitrary indentation, spacing and line breaks. It is close to impossible for me to assimilate a piece of sloppy code without first running it through a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not the kind of person who is easily annoyed, but there is one thing that gets into my skin - all the time. Inconsistently structured code. I hate arbitrary indentation, spacing and line breaks. It is close to impossible for me to assimilate a piece of sloppy code without first running it through a beautifier.</p>
<p>I ran into such a code again today, and for some reason I started to reflect upon my negative reactions. What is it about messy looking code that makes me dislike it so much? The first thing that came to my mind was this: The source code is where I spend most of my time at work, and who wants a sloppy workplace?</p>
<p>At second thought, that didn&#8217;t seem to hold - at least not for me. Here are a couple of pictures of my desk at work.</p>
<p><a href="http://www.hans-eric.com/wp-content/uploads/2008/03/work1.jpg" title="My workplace 1"><img src="http://www.hans-eric.com/wp-content/uploads/2008/03/work1.thumbnail.jpg" alt="My workplace 1" /></a><a href="http://www.hans-eric.com/wp-content/uploads/2008/03/work2.jpg" title="My workplace 2"><img src="http://www.hans-eric.com/wp-content/uploads/2008/03/work2.thumbnail.jpg" alt="My workplace 2" /></a></p>
<p>My computer corner at home is even worse. Clearly, I&#8217;m not a person who cares about a tidy workplace. So what&#8217;s the reason then? Why can&#8217;t I stand to look at sloppy code while I&#8217;m perfectly OK with turning my desk into a dump? Well, it beats me.</p>
<p>If you have an idea, please let me know.</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=UdwEWd"><img src="http://feeds.feedburner.com/~a/hans-eric?i=UdwEWd" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=z5gyiXF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=z5gyiXF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=DECsdAf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=DECsdAf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=jNfUYlF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=jNfUYlF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=2aWLHqf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=2aWLHqf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=UioXzZf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=UioXzZf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=kvjXGIF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=kvjXGIF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=lrD0wcf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=lrD0wcf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=BsNC1xF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=BsNC1xF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=K9fwapF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=K9fwapF" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/246833045" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/03/06/who-wants-a-sloppy-workplace/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/03/06/who-wants-a-sloppy-workplace/</feedburner:origLink></item>
		<item>
		<title>Virtual or non-virtual by default, do we really have to choose?</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/245440831/</link>
		<comments>http://www.hans-eric.com/2008/03/04/virtual-or-non-virtual-by-default-do-we-really-have-to-choose/#comments</comments>
		<pubDate>Tue, 04 Mar 2008 11:53:56 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[C#]]></category>

		<category><![CDATA[java]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/03/04/virtual-or-non-virtual-by-default-do-we-really-have-to-choose/</guid>
		<description><![CDATA[When it comes to the question of whether methods should be virtual by default or not, there are two schools of thought. Anders Hejlsberg, lead architect of C#, describes them in an interview from 2003.
The academic school of thought says, &#8220;Everything should be virtual, because I might want to override it someday.&#8221; The pragmatic school [...]]]></description>
			<content:encoded><![CDATA[<p>When it comes to the question of whether methods should be virtual by default or not, there are two schools of thought. Anders Hejlsberg, lead architect of C#, describes them in <a href="http://www.artima.com/intv/nonvirtual.html" title="Versioning, Virtual, and Override: A Conversation with Anders Hejlsberg, Part IV">an interview from 2003</a>.</p>
<blockquote><p>The academic school of thought says, &#8220;Everything should be virtual, because I might want to override it someday.&#8221; The pragmatic school of thought, which comes from building real applications that run in the real world, says, &#8220;We&#8217;ve got to be real careful about what we make virtual.&#8221;</p></blockquote>
<p>As I told you about in <a href="http://www.hans-eric.com/2008/02/28/virtual-by-default-is-better/" title="Virtual by default is better">my post from last week</a>, I have left the “pragmatic school of thought” to join the “academic” camp. The main reason was unit-testing, that - in my opinion - calls for a more flexible object model than the one of C#. When unit-testing, I often want to use components in unusual ways, all in the name of dependency breaking, and therefore I like their methods to be virtual.</p>
<p>But, it wasn&#8217;t - and still isn&#8217;t - an easy pick; Virtual by default does bring some serious problems to the table. Again from the interview with Anders:</p>
<blockquote><p>Every time you say virtual in an API, you are creating a call back hook. As an OS or API framework designer, you&#8217;ve got to be real careful about that. You don&#8217;t want users overriding and hooking at any arbitrary point in an API, because you cannot necessarily make those promises.</p></blockquote>
<blockquote><p>Whenever they ship a new version of the Java class libraries, breakage occurs. Whenever they introduce a new method in a base class, if someone in a derived class had a method of that same name, that method is now an override—except if it has a different return type, it no longer compiles. The problem is that Java, and also C++, does not capture the intent of the programmer with respect to virtual.</p></blockquote>
<p>C# captures the intent better and avoids versioning problems, and Java offers the flexibility needed for unit-testing. Which is better? The answer seems to be: it depends. But, do we really have to choose? Why can’t we have both? Well, I think we can, and Java has shown the way to achieve it.</p>
<p>Java annotations is a powerful language feature. (The concept was rightfully stolen from C# where it is called custom attributes.) With it one can attach metadata to parts of a program, to give additional information to the compiler or other external agents. In other words, annotations can be used to extend the programming language without the need for changing the language itself.</p>
<p>A good example is the <em>@override</em> annotation.</p>
<pre><code>class SomeClass extends SomeBaseClass {

  <strong>@override</strong>
  void someMethod() { … }

}</code></pre>
<p>From <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Override.html" title="Annotation Type Override">the Java documentation</a>:</p>
<blockquote><p>[@override indicates] that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.</p></blockquote>
<p>The use of the <em>@override</em> annotation takes care of the problem when name changes to virtual methods silently breaks behavior of descending classes; Or, which is more common, when misspelled names of intended overrides aren&#8217;t captured at compile-time. Now, with the introduction of the <em>@override</em> annotation, you can help the compiler help you to <a href="http://www.hans-eric.com/2007/10/02/tools-of-the-effective-developer-fail-fast/" title="Tools of the Effective Developer: Fail Fast!">fail fast</a>. It is now possible to show your intention better than what was possible in the pre annotation days.</p>
<p>Unfortunately Java doesn’t take this concept all the way. They could have introduced an <em>@virtual</em> annotation as a complement to <em>@override</em>, and thus reach the same level of expressiveness as C#, but without forgoing the flexibility of the Java object model. It would be the perfect middle-way, and provide the best of both worlds.</p>
<pre><code>Class SomeBaseClass {

  <strong>@virtual</strong>
  void someMethod() { … }

}</code></pre>
<p>The benefit of an annotation (or custom attribute) based solution is that it’s configurable. It would be possible to alter the compiler’s behavior based on context or environment. For instance one could enforce the use of @virtual and @override in production code. Additionally, one could relax the controls when necessary, like in test projects or legacy code, to mere warnings or complete silence.</p>
<p>Wouldn&#8217;t that be better than the all or nothing solutions of today?</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=MjY6jW"><img src="http://feeds.feedburner.com/~a/hans-eric?i=MjY6jW" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=SsBLWQF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=SsBLWQF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=7Xfydsf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=7Xfydsf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=dTFEmVF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=dTFEmVF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=WydEucf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=WydEucf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=oXN8BLf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=oXN8BLf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=EJaKl1F"><img src="http://feeds.feedburner.com/~f/hans-eric?i=EJaKl1F" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=cJShrhf"><img src="http://feeds.feedburner.com/~f/hans-eric?i=cJShrhf" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=bb33rGF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=bb33rGF" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=cl3oeIF"><img src="http://feeds.feedburner.com/~f/hans-eric?i=cl3oeIF" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/245440831" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/03/04/virtual-or-non-virtual-by-default-do-we-really-have-to-choose/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/03/04/virtual-or-non-virtual-by-default-do-we-really-have-to-choose/</feedburner:origLink></item>
		<item>
		<title>Virtual by default is better</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/242865874/</link>
		<comments>http://www.hans-eric.com/2008/02/28/virtual-by-default-is-better/#comments</comments>
		<pubDate>Thu, 28 Feb 2008 18:42:23 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/28/virtual-by-default-is-better/</guid>
		<description><![CDATA[I’ve taken quite a few paradigm shifting journeys in my life. Some have been quick insights, instant moments of clarity. Others have been slow processes, spanning over several years. One such slow journey for me has been how I look upon virtual methods of object oriented languages.
Java methods are virtual by default. Unless explicitly marked [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve taken quite a few paradigm shifting journeys in my life. Some have been quick insights, instant moments of clarity. Others have been slow processes, spanning over several years. One such slow journey for me has been how I look upon virtual methods of object oriented languages.</p>
<p>Java methods are virtual by default. Unless explicitly marked as final, a method may be overridden in a deriving class.</p>
<pre><code>class A {

  a() { … }

  <strong>final</strong> b() { … }

}

Class B extends A {

  // B::a overrides A::a
  a() { … }

  // Compile error, A::b is non-virtual
  b() { … }

}</code></pre>
<p>C# on the other hand, takes the opposite approach. There you have to explicitly mark a method as virtual, and an overriding method must be marked with the override keyword.</p>
<pre><code>class A {

  <strong>virtual</strong> a() { … }

  b() { … }

}

class B {

  <strong>override</strong> a() { … }

  // This won’t compile since A::b is non-virtual.
  // Without the override keyword though,
  // B::b only hides A::b which produces a
  // warning instead of an error.

  override b() { … }

}</code></pre>
<p>In that sense C# is more expressive, and intention is better communicated with the explicit marks. On the other hand, Java is more flexible and less restrictive.</p>
<p>I used to favor the non-virtual by default approach. Partly because I was kind of born with it - my first OOP language was Object Pascal and Delphi - but also because I appreciate the better control as to how my components are being used. The ability to restrict polymorphism is good because usage in a way that wasn’t intended can create a lot of mess.<br />
To give one non-obvious example, consider a library class A with a method a.</p>
<pre><code>class A {

  a { … }

}<code></code></code></pre>
<p>A library user decides he needs to add functionality to <em>A</em>, so he creates a descender <em>B</em> with a method <em>b</em>.</p>
<pre><code>class B: A {

  b { … }

}<code></code></code></pre>
<p>Everything works just fine, but two year later a new version of the library is released. In this new version a new method b was added to class A. Suddenly B::b overrides A::b although this was not the original intention. In a language like C# compiling class B will result in an error (since b is not virtual), but in Java and most other object-oriented languages the upgrade may have introduced a subtle bug.</p>
<p>My standpoint regarding virtual methods used to be that the need for control outweighs the need for flexibility, but some five years ago I started to re-evaluate that opinion. The reason was automated testing. I have slowly come to realize that the C# object model is a pain, at least when it comes to putting a piece of legacy code under a testing harness. While there are plenty of situations where sub classing is a bad idea, unit-testing is not one of them. Sub classing can be a powerful dependency breaking technique, and it allows for testing of code that isn’t otherwise testable without refactoring.</p>
<p>One (contrived) example:</p>
<pre><code>class SpecialConnection {

  //…

  send_string(String s) {
    //…
  };

  //…
}

class SomeLegacyClass {

  SpecialConnection _conn;

  SomeLegacyClass(SpecialConnection connection) {
    //…
  }

  //…

  create_and_send_string() {
    String s;

    // some code that builds
    // the string to send

    _connection.send_string(s);
  }

  //…
}</code></pre>
<p>How can I test the <em>create_and_send_string</em> method? Well, if <em>SpecialConnection::send_string</em> is virtual the answer is easy, just subclass <em>SpecialConnection</em> and stub out the method.</p>
<pre><code>Class FakeSpecialConnection: SpecialConnection {
  Send_string(String s) {
    if (s != “expected value”)
    throw new Exception(…);
  }
}</code></pre>
<p>And the test code could be like this:</p>
<pre><code>SomeLegacyClass c = new SomeLegacyClass(new FakeSpecialConnection());
c.create_and_send_string();</code></pre>
<p>On the other hand, if <em>send_string</em> is not a virtual method we must do some refactoring (like extracting an interface from SpecialConnection) before we can do testing without a real connection. One could argue that the code in the example is poorly designed, and that we should refactor it anyway. That’s true, but a prerequisite for safe refactoring is thorough unit-testing, something we don’t have at this point, which is why we’re trying to get this piece of code into a testing harness in the first place; so that we could make safe refactorings.</p>
<p>When it comes to testing, virtual methods means more options, better options, safer options. That is the reason why I have converted, and now value that flexibility more than I fear possible regression.</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=mB4ynz"><img src="http://feeds.feedburner.com/~a/hans-eric?i=mB4ynz" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=Ze4xP4E"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Ze4xP4E" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=9IJaCke"><img src="http://feeds.feedburner.com/~f/hans-eric?i=9IJaCke" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=bVmRtxE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=bVmRtxE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=cZau62e"><img src="http://feeds.feedburner.com/~f/hans-eric?i=cZau62e" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=xqy0hme"><img src="http://feeds.feedburner.com/~f/hans-eric?i=xqy0hme" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=e3IegyE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=e3IegyE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=bPgjfie"><img src="http://feeds.feedburner.com/~f/hans-eric?i=bPgjfie" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=KW7fbGE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=KW7fbGE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=FDSuSqE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=FDSuSqE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/242865874" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/02/28/virtual-by-default-is-better/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/02/28/virtual-by-default-is-better/</feedburner:origLink></item>
		<item>
		<title>OT: Al Gore and “The Climate Crisis”</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/237484359/</link>
		<comments>http://www.hans-eric.com/2008/02/19/ot-al-gore-and-the-climate-crisis/#comments</comments>
		<pubDate>Tue, 19 Feb 2008 10:43:53 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[off-topic]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/19/ot-al-gore-and-the-climate-crisis/</guid>
		<description><![CDATA[Sorry for the off-topic.
I saw Al Gore on Swedish television last week. He had received the Gothenburg Sustainable Development Award and was holding a speech at the ceremony. As usual Al Gore was able to capture his audience with a mix of scaring facts and a call for action. This time he conveyed the new [...]]]></description>
			<content:encoded><![CDATA[<p>Sorry for the off-topic.</p>
<p>I saw Al Gore on Swedish television last week. He had <a href="http://www.ens-newswire.com/ens/sep2007/2007-09-11-097.asp" title="Gore Wins 2007 Gothenburg Sustainable Development Award">received the Gothenburg Sustainable Development Award</a> and was holding a speech at the ceremony. As usual Al Gore was able to capture his audience with a mix of scaring facts and a call for action. This time he conveyed the new prediction that <a href="http://www.telegraph.co.uk/earth/main.jhtml?xml=/earth/2007/12/12/eaice112.xml" title="Arctic ice 'could be gone in five years'">the arctic ice could be gone in as little as five years</a>. While that could very well be a grave exaggeration, we can’t deny that something is terribly wrong with our climate.</p>
<p>Where I live, a coast town in the middle of Sweden, the rising temperature has been particularly noticeable. The first sign came in the late 1980’s when I experienced my first non-white Christmas. Now, having no snow in December has become normal.</p>
<p>This year, the year of 2008 – a year I’ll never forget – we have witnessed something I thought was impossible. This year we had rain in January. Where I live January is <em>the</em> winter month. It’s supposed to be cold and the only thing coming down from the skies should be snow. In my life, and I’ve been on this planet for 37 years, I have never experienced rain in January before. <em>But this year it rained for ten whole days.</em></p>
<p>So what can we do? Well, Al Gore’s mantra is that “we <em>can</em> do something about it,” and I agree. There are definitely things I can do to reduce my share of released greenhouse gases. I can use my car much less (we have great public transportations here,) and I can, with little effort, save energy. Simple things would be a good place to start; like really turning things off when they&#8217;re not used (computers, the TV, lamps), turning heat down (human beings sleep best in 18 degree Celsius) or replacing old energy devouring machines (like our freezer from 1980).</p>
<p>My promise to you, my dear reader, and to the rest of the world, is that 2008 will be the year when I start to implement changes to become a more optimized human being. I will make sacrifices, my life will be less convenient, but I’ll do it happily for the sake of my children and for future generations.</p>
<p>My intentions are not entirely unselfish though, I expect the changes to have a significant and positive effect on my economy as well.</p>
<p>Cheers!</p>
<p>P.S. I can’t help wondering what the world would be like if the outcome of <a href="http://en.wikipedia.org/wiki/U.S._presidential_election,_2000">the election</a> had been different.</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=GYLBY8"><img src="http://feeds.feedburner.com/~a/hans-eric?i=GYLBY8" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=FKLQ8VE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=FKLQ8VE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=O5bw7Ae"><img src="http://feeds.feedburner.com/~f/hans-eric?i=O5bw7Ae" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=09fcxrE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=09fcxrE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=KigCXhe"><img src="http://feeds.feedburner.com/~f/hans-eric?i=KigCXhe" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=8rkWhbe"><img src="http://feeds.feedburner.com/~f/hans-eric?i=8rkWhbe" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=xw1mYjE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=xw1mYjE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=3sZCtce"><img src="http://feeds.feedburner.com/~f/hans-eric?i=3sZCtce" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=NI4eNKE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=NI4eNKE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=Bz5xnhE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=Bz5xnhE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/237484359" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/02/19/ot-al-gore-and-the-climate-crisis/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/02/19/ot-al-gore-and-the-climate-crisis/</feedburner:origLink></item>
		<item>
		<title>The Open-Closure-Close Idiom in D</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/234351859/</link>
		<comments>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 13:22:26 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[D Programming Language]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/</guid>
		<description><![CDATA[In a Reddit discussion following my last post on object lifetime management in D, bonzinip wondered why the D closures aren&#8217;t used with the open-closure-close idiom that is common, for instance, in Ruby.
bonzinip: languages with closures (Ruby, Smalltalk) use them to ensure that the file is closed when you get out of scope, and that [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://reddit.com/r/programming/info/67z6n/comments">Reddit discussion</a> following <a href="http://www.hans-eric.com/2008/02/07/managing-object-lifetimes-in-d/" title="Managing Object Lifetimes in D">my last post on object lifetime management in D</a>, <em>bonzinip</em> wondered why the D closures aren&#8217;t used with the open-closure-close idiom that is common, for instance, in Ruby.</p>
<blockquote><p>bonzinip: languages with closures (Ruby, Smalltalk) use them to ensure that the file is closed when you get out of scope, and that does <em>not</em> require new keywords and does <em>not</em> require to bypass GC and possibly get dangling pointers.</p>
<p>NovaProspekt: D actually has full closures</p>
<p>bonzinip: so why don&#8217;t they use them with a &#8220;try { open; run closure; } finally { close; }&#8221; idiom instead?</p></blockquote>
<p>Well, let&#8217;s take a look at how that could be accomplished in D.</p>
<p>To get an image of the open-closure-close idiom, we can look at Ruby&#8217;s File class, and particularly <a href="http://www.ruby-doc.org/core/classes/IO.html#M002264" title="IO::open">the open method</a>.</p>
<blockquote><p>IO.open(fd, mode_string=&#8221;r&#8221; )               =&gt; io<br />
IO.open(fd, mode_string=&#8221;r&#8221; ) {|io| block } =&gt; obj</p>
<p>With no associated block, open is a synonym for IO::new. If the optional code block is given, it will be passed <em>io</em> as an argument, and the IO object will automatically be closed when the block terminates. In this instance, <tt>IO::open</tt> returns the value of the block.</p></blockquote>
<p>What this means is that a File can be opened, either in the normal way with explicit closing (begin-ensure corresponds to try-finally in D)</p>
<pre><code>f = File.open("c:\\log.txt", "w")
begin
  f.puts "Log this"
ensure
  f.close
end
</code></pre>
<p>or with a code block (closure)</p>
<pre><code>File.open("c:\\log.txt", "w") do |f|
  f.puts "Log this"
end</code></pre>
<p>In this last example the file is both opened and closed by the open method, in between the method invokes the associated code block with the file object reference as a parameter (f). In essence, that is the open-closure-close idiom.</p>
<p>How could we do this in D? Well, <a href="http://www.hans-eric.com/2008/01/17/loop-abstractions-in-d/" title="Loop Abstractions in D">as I&#8217;ve written before</a>, D&#8217;s delegates in combination with function literals can be used to mimic the code blocks of Ruby.  So, a D version of the File::open method could look something like this:</p>
<pre><code>import std.stdio;
import std.stream;

void open_run_close(char[] fn, FileMode fm = FileMode.In,
  void delegate(Stream) closure)
{
  Stream f = new File(fn, fm);
  try {
    closure(f);
  } finally {
    f.close();
  }
}</code></pre>
<p>and be invoked like this:</p>
<pre><code>open_run_close("c:\\log.txt", FileMode.Out, (Stream f) {
  OutputStream os = f;
  os.writefln("Log this");
});</code></pre>
<p>To make it a little more like the original Ruby version, let&#8217;s make it support the non-closure variant as well.</p>
<pre><code>Stream open_run_close(char[] fn, FileMode fm = FileMode.In,
void delegate(Stream) closure = null)
{
  Stream f = new File(fn, fm);
<strong>  if (!closure) {
    return f;
  } else {
</strong>    try {
      closure(f);
<strong>      return null;</strong>
    } finally {
      f.close();
    }
<strong>  }</strong>
}

// Example usage
open(&#8221;c:\\log.txt&#8221;, FileMode.Out, (Stream f) {
  OutputStream os = f;
  os.writefln(&#8221;Log this&#8221;);
});

// Example traditional usage
OutputStream f = open(&#8221;c:\\log2.txt&#8221;, FileMode.Out);
try {
  f.writefln(&#8221;Do log this&#8221;);
} finally {
  f.close;
}</code></pre>
<p>The open-closure-close idiom is definitely doable in D. It&#8217;s not as pretty and natural as in Ruby, but not so far from it either. Whether this particular idiom will be embraced by the D community is yet to be seen.</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=3VPRzL"><img src="http://feeds.feedburner.com/~a/hans-eric?i=3VPRzL" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=TEzf3YE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=TEzf3YE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=TkIBChe"><img src="http://feeds.feedburner.com/~f/hans-eric?i=TkIBChe" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=dppcMJE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=dppcMJE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=6hGMWve"><img src="http://feeds.feedburner.com/~f/hans-eric?i=6hGMWve" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=WkvP4Ue"><img src="http://feeds.feedburner.com/~f/hans-eric?i=WkvP4Ue" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=zlnB8fE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=zlnB8fE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=GpeN52e"><img src="http://feeds.feedburner.com/~f/hans-eric?i=GpeN52e" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=VnW8GOE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=VnW8GOE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=KgHJ8kE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=KgHJ8kE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/234351859" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/02/13/the-open-closure-close-idiom-in-d/</feedburner:origLink></item>
		<item>
		<title>Managing Object Lifetimes in D</title>
		<link>http://feeds.feedburner.com/~r/hans-eric/~3/230994049/</link>
		<comments>http://www.hans-eric.com/2008/02/07/managing-object-lifetimes-in-d/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 13:53:33 +0000</pubDate>
		<dc:creator>Hans-Eric</dc:creator>
		
		<category><![CDATA[D Programming Language]]></category>

		<guid isPermaLink="false">http://www.hans-eric.com/2008/02/07/managing-object-lifetimes-in-d/</guid>
		<description><![CDATA[The D Programming Language is a modern version of C. It adds productivity features to the performance power of C, features like object oriented programming and garbage collection.
It may seem strange that a language with focus on performance utilizes automatic memory management. A GC equals overhead, right? Well, actually that is a common misconception. These [...]]]></description>
			<content:encoded><![CDATA[<p>The D Programming Language is a modern version of C. It adds productivity features to the performance power of C, features like object oriented programming and garbage collection.</p>
<p>It may seem strange that a language with focus on performance utilizes automatic memory management. A <abbr title="Garbage Collector">GC</abbr> equals overhead, right? Well, actually <a href="http://www.ibm.com/developerworks/java/library/j-jtp09275.html?S_TACT=105AGX02&amp;S_CMP=EDU" title="Urban performance legends, revisited">that is a common misconception</a>. These days implicitly memory managed code is generally faster than code where the programmer handles deallocations. One reason for this counter-intuitive fact is that a number of optimizations can be done by the GC, especially on short-lived objects.</p>
<p>But garbage collection isn’t a problem free feature. For one thing, it is indeterministic. Normally, an object that uses external resources acquires them in a constructor and releases them in the destructor.</p>
<pre><code>import std.stream;

class LogFile {
  File f;

  this() {
    f = new File("c:\\log.txt", FileMode.Out);
  }

  ~this() {
    f.close;
  }

  // Logging methods goes here
}</code></pre>
<p>But with a GC there is no way to know when or even if the destructor is run. This may be a problem if you’re dealing with scarce resources like window handles, or file locks. So how can we control object destructions in a GC capable language? One possibility is to trigger a GC sweep explicitly in your code. In D this is done with the fullCollect function.</p>
<pre><code>import std.gc;

fullCollect();</code></pre>
<p>Explicit trigging of garbage collection is usually a bad idea, for several reasons. For one thing, it&#8217;s like killing an ant with a bazooka, and still you risk missing the target. Therefore, the normal approach to deal with the problem of indeterminism is to use a dispose method.</p>
<pre><code>class LogFile {
  File f;

  this() {
    f = new File("c:\\log.txt", FileMode.Out);
  }

  ~this() {
    <strong>dispose();</strong>
  }

<strong>  void dispose() {
    if (f !is null) {
      f.close;
      f = null;
    }
  }
</strong>
  // Logging methods here
}

LogFile log = new LogFile();
try {
  // Do some logging
} finally {
  <strong>log.dispose;</strong>
}</code></pre>
<p>We don’t have to use the dispose pattern though because in D we have the luxury of choosing between implicit and explicit memory management. We can either free the object ourselves with the delete operator, or leave it for the GC to dispose later.</p>
<pre><code>LogFile log = new LogFile();
try {
  // Do some logging
} finally {
  delete log; // Explicit memory management
}</code></pre>
<p>D has another construct which is very convenient when you need to control the lifetime of an object. With the scope attribute, an object is automatically destroyed when the program leaves the scope in which the object was created.</p>
<pre><code>void function some_func() {
<strong>  scope </strong>LogFile log = new LogFile();
  :
  // log will be freed on exit
}</code></pre>
<p>The ability to mix explicit and implicit memory management is a simple, yet great feature. It is one of many examples where D provides us with the best of two worlds. Convenience and control, as well as productivity and performance, is blended in a way that has no equivalence in any other language I know.</p>
<p>Cheers!</p>

<p><a href="http://feeds.feedburner.com/~a/hans-eric?a=yqZlan"><img src="http://feeds.feedburner.com/~a/hans-eric?i=yqZlan" border="0"></img></a></p><div class="feedflare">
<a href="http://feeds.feedburner.com/~f/hans-eric?a=wNHcd0E"><img src="http://feeds.feedburner.com/~f/hans-eric?i=wNHcd0E" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=JMcJEYe"><img src="http://feeds.feedburner.com/~f/hans-eric?i=JMcJEYe" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=sn2DWIE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=sn2DWIE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=NBsN16e"><img src="http://feeds.feedburner.com/~f/hans-eric?i=NBsN16e" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=WhhwDXe"><img src="http://feeds.feedburner.com/~f/hans-eric?i=WhhwDXe" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=QO6zulE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=QO6zulE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=TWY5L7e"><img src="http://feeds.feedburner.com/~f/hans-eric?i=TWY5L7e" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=twBLKFE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=twBLKFE" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/hans-eric?a=TeiKBwE"><img src="http://feeds.feedburner.com/~f/hans-eric?i=TeiKBwE" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/hans-eric/~4/230994049" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.hans-eric.com/2008/02/07/managing-object-lifetimes-in-d/feed/</wfw:commentRss>
		<feedburner:origLink>http://www.hans-eric.com/2008/02/07/managing-object-lifetimes-in-d/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.684 seconds -->
