<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><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:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Tore Vestues blogs</title>
	
	<link>http://tore.vestues.no</link>
	<description>On a quest for the silver bullet..</description>
	<lastBuildDate>Sun, 19 Jun 2011 19:34:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/ToreVestues" /><feedburner:info uri="torevestues" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Rethinking web architecture</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/PluvSWE8rD4/</link>
		<comments>http://tore.vestues.no/2011/06/19/rethinking-web-architecture/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 19:26:09 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=160</guid>
		<description><![CDATA[Last year I was a speaker at NDC for the first time, and I'm proud to again have been given the opportunity at this years NDC. The presentation this year is titled: “When less is more - Agile web architecture”, and I did together with Jonas Follesø.
]]></description>
			<content:encoded><![CDATA[<p>Last year I was a speaker at NDC for the first time, and I&#8217;m proud to again have been given the opportunity at this years NDC. The presentation this year is titled: “When less is more &#8211; Agile web architecture”, and I did together with <a href="http://jonas.follesoe.no/">Jonas Follesø</a>.</p>
<p><strong>Rethinking thinking</strong> </p>
<p>Rather than talking about rethinking web architecture, we are actually talking about rethinking our thinking and practices when designing web architecture. So, although we do give a concrete example, this is not <em>the one</em> new architecture. The main points we&#8217;re trying to convey is that you should keep it simple (often much simpler than we normally do) and that architecture should evolve (adding only when you have to, when you have to). The example shows one way of doing that.</p>
<p><strong>Growing architecture</strong></p>
<p>Letting software and architecture grow as we learn is for me simply being agile, but my experience tells me that although most of us consider ourselves agile, we have a hard time wrapping our heads around what that actually means when it comes to architecture. Being agile when it comes to architecture, and being able to grow good architecture takes a lot of skill and knowledge, and let it be clear that when we talk about simplicity we do not say throw away <em>everything</em>. We say reflect on every choice you make.</p>
<p><strong>Developer productivity</strong></p>
<p>Our presentation also take a critical look at the typical three layer architecture which, a bit to my surprise, was known and used by almost everyone in the audience. The critique is mostly about productivity, or rather the lack of it. Pushing data through such an architecture is often a pretty costly affair. An interesting point is also that with this architecture we violate the DRY principle at least ten times for every piece of information in the system (that is stored in the database). I spend a few minutes explaining that one. Have a look yourself.</p>
<p>Some of the feedback we got after the presentation suggests that this talk have sparked a few discussions. That is great!</p>
<p><a href="http://ndc2011.macsimum.no/SAL2/Onsdag/1500-1600.wmv">You can watch the presentation here</a>.</p>
<p><a href="http://ndc2011.no/">The NDC 2011 website is here</a>.</p>
<p>- Tore Vestues</p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/PluvSWE8rD4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2011/06/19/rethinking-web-architecture/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://ndc2011.macsimum.no/SAL2/Onsdag/1500-1600.wmv" length="424690686" type="video/x-ms-wmv" />
		<feedburner:origLink>http://tore.vestues.no/2011/06/19/rethinking-web-architecture/</feedburner:origLink></item>
		<item>
		<title>Glue 0.9 “Magic” Released</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/S3QPmQ7JHwE/</link>
		<comments>http://tore.vestues.no/2011/01/05/glue-0-9-magic-released/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 13:54:58 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Bits and bytes]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Glue]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=147</guid>
		<description><![CDATA[
My feelings on magic 
(Feel free to skip this section if you couldn&#8217;t care less about my thoughts on automagic)
I am not the biggest fan of automagical behavior. For that reason, up until now, Glue has not automatically created new objects when you map. You have to instantiate the object to map to (and all [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://vestues.no/tore/wp-content/211330471_0b84c297a3_m.jpg" alt="http://www.flickr.com/photos/grrrl/211330471/" title="http://www.flickr.com/photos/grrrl/211330471/" width="240" height="240" class="size-full wp-image-152" align="left"/></p>
<p><strong>My feelings on magic</strong> </p>
<p>(Feel free to skip this section if you couldn&#8217;t care less about my thoughts on automagic)</p>
<p>I am not the biggest fan of automagical behavior. For that reason, up until now, Glue has not automatically created new objects when you map. You have to instantiate the object to map to (and all nested objects within that object). The reason for this is that I want the developer to explicitly decide when it comes to how objects are to be created. Personally I like to be in control, so that problems do not arise at inconvenient times (like at runtime in a production environment). </p>
<p>In addition, I come from the OO school. I believe that objects should be, yes, objects, and not just data containers (a typical data container is a class containing only properties, and little or no logic). I believe objects should be relevant, individual, and contain logic. This often means that constructing them is not something you let a framework do (unless it is a framework specialized for that kind of job). Because constructing them often means making decisions, like what dependencies these objects should have.</p>
<p><strong>The &#8220;General purpose&#8221; mapping framework</strong></p>
<p>One of the driving forces for creating Glue was to create a <em>general purpose</em> mapping framework. Meaning it should support different scenarios, not just the ones I liked the most. In addition, using Glue extensively myself, I have found that there are (quite a lot of) times when having Glue create objects for me are both convenient, and low risk.</p>
<p><strong>Automagical and Strict mode</strong></p>
<p>So, with version 0.9 of Glue, I introduce the &#8220;Automagical&#8221; mode where Glue tries to instantiate objects whenever necessary. In addition, the existing behavior (making you create all the objects) is now named &#8220;Strict&#8221; mode. Choosing between the modes is simply done by choosing the right overload of the Mapper.Map-method. Intellisense will guide you.</p>
<p><strong>Examples</strong> can be found <a href="http://glue.codeplex.com/wikipage?title=Strict%20and%20Automagical%20Modes">here</a></p>
<p>(<a href="http://glue.codeplex.com/">What is Glue?</a>)</p>
<p><a href="http://glue.codeplex.com/releases/view/58617">Download Glue 0.9 binaries here</a></p>
<p>- Tore Vestues</p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/S3QPmQ7JHwE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2011/01/05/glue-0-9-magic-released/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2011/01/05/glue-0-9-magic-released/</feedburner:origLink></item>
		<item>
		<title>Speaking at Javazone 2010</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/mwRSJEqTgLQ/</link>
		<comments>http://tore.vestues.no/2010/08/19/speaking-at-javazone-2010/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 13:13:26 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=141</guid>
		<description><![CDATA[I&#8217;m looking forward to be speaking at Javazone 2010. It&#8217;s been a few years since I attended Javazone, so I am really looking forward to the conference. The agenda looks great!
This time my talk will be in Norwegian.
My talk &#8211; Javazone 2010  &#8211; Agenda
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m looking forward to be speaking at Javazone 2010. It&#8217;s been a few years since I attended Javazone, so I am really looking forward to the conference. The agenda looks great!</p>
<p>This time my talk will be in Norwegian.</p>
<p><a href="http://javazone.no/incogito10/events/JavaZone%202010/sessions#508535d1-5601-4076-aa05-e1899741863f">My talk</a> &#8211; <a href="http://jz10.java.no/">Javazone 2010</a>  &#8211; <a href="http://javazone.no/incogito10/events/JavaZone%202010/sessions">Agenda</a></p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/mwRSJEqTgLQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/08/19/speaking-at-javazone-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/08/19/speaking-at-javazone-2010/</feedburner:origLink></item>
		<item>
		<title>Law of Demeter: A real-world example</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/Vm6QS2oO-Cg/</link>
		<comments>http://tore.vestues.no/2010/08/05/law-of-demeter-a-real-world-example/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 20:05:50 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Coding principles]]></category>
		<category><![CDATA[Patterns]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=128</guid>
		<description><![CDATA[ The Law of Demeter (LOD) helps decouple objects, it makes mocking intensive tests much easier to write, and it offers a concrete set of rules that can make things clearer.
I recently ran into an example in Glue where I refactored towards LOD. I will share my thoughts on that here.
The problem
I am working on [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://vestues.no/tore/wp-content/2416461325_00321d3ec6_m.jpg" alt="Demeter - http://www.flickr.com/photos/zaqarbal/2416461325/" align="left" title="Demeter - http://www.flickr.com/photos/zaqarbal/2416461325/" width="135" height="240" class="size-full wp-image-137" /> <a href="http://en.wikipedia.org/wiki/Law_of_Demeter">The Law of Demeter</a> (LOD) helps decouple objects, it makes mocking intensive tests much easier to write, and it offers a concrete set of rules that can make things clearer.</p>
<p>I recently ran into an example in <a href="http://glue.codeplex.com">Glue</a> where I refactored towards LOD. I will share my thoughts on that here.</p>
<p><strong>The problem</strong></p>
<p>I am working on a new feature in Glue. In order to make room for that feature, I had to do some refactoring, to make it smoother to add that feature. What I found during the refactoring was this line (in the <em>Mapper</em>-class):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">mapping.<span style="color: #0000FF;">Relations</span>.<span style="color: #0000FF;">GetRelationsTowardsRight</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>I found it because I already had some trouble with the <em>Mapper</em> class&#8217; dependency on the <em>Mapping</em> class. I realized that I was exposing a lot of information, <em>Mapper</em> shouldn&#8217;t know about <em>Mapping</em>. This dependency made my refactoring job bigger. I strongly believe that objects should know as little as possible. </p>
<p>This is a good example of breaking LOD. I think breaking LOD isn&#8217;t always a big offense (Martin Fowler <a href="http://martinfowler.com/articles/mocksArentStubs.html">suggests</a> we rename it &#8220;<em>Suggestion</em> of Demeter&#8221;), and I don&#8217;t think doing it here is my largest mistake. But now a new feature had brought the need for some refactoring, and at this point applying LOD seemed like a good idea. So it&#8217;s not only a question of where to apply a pattern, but also when.</p>
<p><strong>The solution</strong></p>
<p>The <em>Mapping</em> class is a kind of <a href="http://en.wikipedia.org/wiki/Facade_pattern">facade</a> to the rest of the system. It is an attempt to make the API as simple as possible. That means it handles the creation of some objects. In our case this is how <em>Mapping</em> creates <em>Mapper</em> objects:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">var mapper <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Mapper<span style="color: #008000;">&lt;</span>LeftType, RightType<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>(Notice how <em>Mapping</em> passes itself in to <em>Mapper</em>). <em>Mapper</em> gets what it needs by calling:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">mapping.<span style="color: #0000FF;">Relations</span>.<span style="color: #0000FF;">GetRelationsTowardsRight</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><em>Mapper</em> gets a <em>RelationContainer </em>(the Relations property) from <em>Mapping</em>.</p>
<p>This breaks LOD. There is a simple fix in this case. The code passes a <em>Mapping</em> object, while what the <em>Mapper</em> wants is a <em>RelationContainer</em>.  We should only pass the object it needs (in the <em>Mapping</em> class):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">var mapper <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Mapper<span style="color: #008000;">&lt;</span>LeftType, RightType<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>Relations<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>The <em>Mapper</em> now gets what it needs by calling:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">relations.<span style="color: #0000FF;">GetRelationsTowardsRight</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>It&#8217;s fixed!</p>
<p>This way we have lowered the coupling, making <em>Mapper</em> unaware of <em>Mapping</em>, meaning that now it can access only what it needs, not a whole lot more. For me it is important that objects know as little as possible, and now it knows a whole lot less. It doesn&#8217;t care (or know) where the <em>RelationContainer</em> comes from. That isn&#8217;t its concern, and shouldn&#8217;t be either.</p>
<p>(The Law of Demeter is a rather academic specification of who is allowed to call who, specified <a href="http://en.wikipedia.org/wiki/Law_of_Demeter#In_object-oriented_programming">here</a>. Basically what it boils down to is that you shouldn&#8217;t ask for other objects from an object, and do an action on that. Or in other words, you should just use one dot per line.)</p>
<p><strong>Not the &#8220;standard&#8221; solution</strong></p>
<p>This solution is not how one normally is advised to resolve the breaking of LOD. Normally you&#8217;re supposed to hide the inner object. In this case it would mean that <em>Mapper</em> should be unaware of the fact that <em>Mapping</em> contains a <em>RelationContainer</em>, it should just ask <em>Mapping</em> to get the relations (a concept called encapsulation, it&#8217;s pretty standard object oriented thinking). Like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">mapping.<span style="color: #0000FF;">GetRelationsTowardsRight</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p>That&#8217;s a smart solution, if you&#8217;ve got the right problem. That solution enables <em>Mapper</em> to only know about <em>Mapping</em>, and none of its collaborators (hiding the <em>RelationContainer</em> in this example). </p>
<p>But the problem we have here is slightly different. What I found here was that <em>Mapper</em> should not know about <em>Mapping</em> at all. <em>Mapper</em> should only concern itself with the relations, and in this case <em>Mapper</em> should only receive the <em>RelationContainer</em> to work with. So the problem was that we depended on the wrong object altogether, not that we had the right object, and had to know about its collaborator. A subtle, but important difference. It&#8217;s important to be aware of what your problem is in order to find the right solution. It&#8217;s not always as easy as choosing the &#8220;standard&#8221; solution.</p>
<p><strong>Reflections on Law of Demeter</strong></p>
<p>LOD is just a concrete set of rules that aims to help writing less coupled code. You can do this without even knowing about LOD. In our case, focusing on separation of concerns  can yield the same effects. As can sound object oriented thinking, like hiding as much as possible (not exposing things through properties or getters), focusing on knowing as little as possible, applying <a href="http://tore.vestues.no/2009/08/16/tell-dont-ask/">&#8220;Tell, don&#8217;t ask&#8221;</a>, and so on.</p>
<p>The problem with concrete rules like LOD is that it works great if you understand the intention, but if you do not, you&#8217;re probably going to apply it wrong. And if you understand the intention, often you can get the effects without even thinking about LOD. </p>
<p>For me, I like the intention of LOD , but I do not think about it that often, as I use other guidelines to help me yield the same result. On the other hand, knowing the LOD principle have helped me on several occasions, as in this example, to see clearly what is going on.</p>
<p>Also, if you need to justify a style of programming that is heavy on mocking, LOD is an often used argument.</p>
<p>This refactoring is checked in as <a href="http://glue.codeplex.com/SourceControl/changeset/changes/52023">changeset 52023</a> in <a href="http://glue.codeplex.com/">Glue</a>. Compare that and the previous changeset to see what was done.</p>
<p>- Tore Vestues</p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/Vm6QS2oO-Cg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/08/05/law-of-demeter-a-real-world-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/08/05/law-of-demeter-a-real-world-example/</feedburner:origLink></item>
		<item>
		<title>Glue &amp; Nu: Glue is a RubyGem!</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/1rVMvjjhLTY/</link>
		<comments>http://tore.vestues.no/2010/08/02/glue-nu-glue-is-a-rubygem/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 18:30:02 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Bits and bytes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Glue]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=118</guid>
		<description><![CDATA[ No doubt, Ruby has an excellent package management system: Gems. Simply beautiful.
Also no doubt, we have not had such excellent package management system in the .Net-sphere. So why not just make RubyGems work for .Net as well? That&#8217;s exactly what Dru Sellers have done with Nu.
This is a great idea, so I decided right [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://vestues.no/tore/wp-content/135751440_2f59574661_m.jpg" title="http://www.flickr.com/photos/afternoon_sunlight/135751440/" width="240" height="227" class="size-full wp-image-119" align="right" /> No doubt, Ruby has an excellent package management system: <a href="http://rubygems.org/">Gems</a>. Simply beautiful.</p>
<p>Also no doubt, we have not had such excellent package management system in the .Net-sphere. So why not just make RubyGems work for .Net as well? That&#8217;s exactly what <a href="http://codebetter.com/blogs/dru.sellers/default.aspx">Dru Sellers</a> have done with <a href="http://codebetter.com/blogs/dru.sellers/archive/2010/07/17/nu.aspx">Nu</a>.</p>
<p>This is a great idea, so I decided right away to make a Gem out of <a href="http://glue.codeplex.com">Glue</a>.</p>
<p> To use it, start your favorite windows shell and type:</p>
<p><code>gem install gluemapping</code></p>
<p>Then go to your project directory (if you&#8217;re not already there) and type</p>
<p><code>nu install gluemapping</code></p>
<p>That&#8217;s it! The newest Glue-assemblies will be put in the lib-folder in your project directory.</p>
<p><strong>Requirements:</strong></p>
<p>1. You will need to install ruby. Download the latest <a href="http://rubyinstaller.org/downloads/">rubyinstaller</a>, and install it.<br />
2. Install Nu:<br />
<code><br />
gem update --system<br />
gem install nu<br />
</code></p>
<p>You can find more information on Nu <a href="http://codebetter.com/blogs/dru.sellers/archive/2010/07/17/nu.aspx">here</a>.</p>
<p>The Gem is hosted at RubyGems, you can find information about it <a href="http://rubygems.org/gems/gluemapping">here</a>.</p>
<p>- Tore Vestues</p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/1rVMvjjhLTY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/08/02/glue-nu-glue-is-a-rubygem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/08/02/glue-nu-glue-is-a-rubygem/</feedburner:origLink></item>
		<item>
		<title>The Microsoft MVP Award</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/F4hXuAGJr_M/</link>
		<comments>http://tore.vestues.no/2010/07/26/the-microsoft-mvp-award/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 12:20:35 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=113</guid>
		<description><![CDATA[I am proud to announce that I have received the Microsoft MVP Award in C#, for my &#8220;exceptional contributions and commitment to technical communities worldwide&#8221;.
That means I am a C# MVP, and I am very proud of it!
I feel it is important for me to contribute to, and learn from, the technical communities around the [...]]]></description>
			<content:encoded><![CDATA[<p>I am proud to announce that I have received the Microsoft MVP Award in C#, for my &#8220;exceptional contributions and commitment to technical communities worldwide&#8221;.</p>
<p>That means I am a C# MVP, and I am very proud of it!</p>
<p>I feel it is important for me to contribute to, and learn from, the technical communities around the world, and therefore I&#8217;m honored by receiving this award for my contributions. I will do my best to continue to contribute to the communities in the time to come, and I know I will learn a lot from them.</p>
<p>- Tore Vestues</p>
<p><img src="http://vestues.no/tore/wp-content/MVP_Horizontal_FullColor_resized_500x.png" alt="MVP" title="MVP" width="500" height="202" class="size-full wp-image-114" /></p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/F4hXuAGJr_M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/07/26/the-microsoft-mvp-award/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/07/26/the-microsoft-mvp-award/</feedburner:origLink></item>
		<item>
		<title>Reflection and performance</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/16nOSCbRdHU/</link>
		<comments>http://tore.vestues.no/2010/07/01/reflection-and-performance/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 11:07:45 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Bits and bytes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Frameworks]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=85</guid>
		<description><![CDATA[The open source framework Glue that I&#8217;ve created, use a lot of reflection to invoke members on objects. This has sparked my interest in exploring the use of reflection in respect to performance. A colleague of mine, Åsmund Eldhuset, and I set aside an evening for a geeknight to get to the bottom of this, [...]]]></description>
			<content:encoded><![CDATA[<p>The open source framework <a href="http://glue.codeplex.com">Glue</a> that I&#8217;ve created, use a lot of reflection to invoke members on objects. This has sparked my interest in exploring the use of reflection in respect to performance. A colleague of mine, <a href="http://no.linkedin.com/in/aasmundeldhuset">Åsmund Eldhuset</a>, and I set aside an evening for a geeknight to get to the bottom of this, and this is what we found out.</p>
<p>There are many ways to use reflection, and the performance on them vary a lot. What we did was to try out every method and timing them to measure performance. These are the methods we tested: Normal property access, normal reflection, compiling and invoking a compiled expression, using Emit to create, compile and run the statement.</p>
<p><strong>Normal property access</strong></p>
<p>To compare the other methods, we measured the performance on accessing a property the normal way:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">Run<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Normal property access&quot;</span>, <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> <span style="color: #000000;">&#123;</span> var city <span style="color: #008000;">=</span> address.<span style="color: #0000FF;">City</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>It was no surprise that this was the fastest method.</p>
<p><strong>Normal reflection (250 times slower than normal property access)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">var cityPropertyInfo <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span> <span style="color: #000000;">&#40;</span>Address<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetProperty</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;City&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Run<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;With reflection&quot;</span>, <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> cityPropertyInfo.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span>address, <span style="color: #008000;">new</span> <span style="color: #FF0000;">object</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>This is what most of us think about when talking about reflection. This is also the by far most common method of reflection used in Glue. Although about 250 times slower than normal property access, this method has very strong sides compared to the other methods.</p>
<p><strong>Invoking compiled expressions (twice as slow as normal property access)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">Expression<span style="color: #008000;">&lt;</span>Func<span style="color: #008000;">&lt;</span>Address, <span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;&gt;</span> expression <span style="color: #008000;">=</span> x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">City</span><span style="color: #008000;">;</span>
var func <span style="color: #008000;">=</span> expression.<span style="color: #0000FF;">Compile</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Run<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Invoke compiled expression&quot;</span>, <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> func.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span>address<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Using compiled expressions is another way of dynamically invoking members on objects. Due to the syntax exposed in the api in Glue, most mapping specifications enter Glue as (uncompiled) expressions. The fact that it is only about twice as slow than normal property access, is very promising. But there is a catch, a big one. In order to invoke this way, the expression must be compiled. It is not compiled when it enters Glue, so we have to include the time it takes to compile the expression as well.</p>
<p><strong>Compile Expression and invoke it (51700 times slower than normal property access)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">RunLong<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Compile Expression and invoke&quot;</span>, <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span>
             <span style="color: #000000;">&#123;</span>
                 var compiledFunction <span style="color: #008000;">=</span> expression.<span style="color: #0000FF;">Compile</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                 compiledFunction.<span style="color: #0000FF;">Invoke</span><span style="color: #000000;">&#40;</span>address<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
             <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Yes, if you have to compile an expression before invoking it, it takes about 200 times longer to do the operation than with normal reflection. Leaving this a unattractive method to use with Glue.</p>
<p><strong>Using Emit, invoking a compiled expression (4 times slower than normal property access)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">private</span> Func<span style="color: #008000;">&lt;</span>Address, <span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> GetEmitDelegate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    var dm <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> DynamicMethod<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;TestMethod&quot;</span>, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Address<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span>, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Address<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Module</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    MethodInfo getCity <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Address<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetProperty</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;City&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">GetGetMethod</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    ILGenerator il <span style="color: #008000;">=</span> dm.<span style="color: #0000FF;">GetILGenerator</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    il.<span style="color: #0000FF;">Emit</span><span style="color: #000000;">&#40;</span>OpCodes.<span style="color: #0000FF;">Ldarg_0</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    il.<span style="color: #0000FF;">EmitCall</span><span style="color: #000000;">&#40;</span>OpCodes.<span style="color: #0000FF;">Call</span>, getCity, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    il.<span style="color: #0000FF;">Emit</span><span style="color: #000000;">&#40;</span>OpCodes.<span style="color: #0000FF;">Ret</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">return</span> <span style="color: #000000;">&#40;</span>Func<span style="color: #008000;">&lt;</span>Address, <span style="color: #FF0000;">String</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#41;</span>dm.<span style="color: #0000FF;">CreateDelegate</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>Func<span style="color: #008000;">&lt;</span>Address, <span style="color: #FF0000;">String</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
var emitDelegate <span style="color: #008000;">=</span> GetEmitDelegate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
Run<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Emit: run compiled statement&quot;</span>, <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">=&gt;</span>emitDelegate<span style="color: #000000;">&#40;</span>address<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>My guess is that using Emit is not something you will be doing a lot. But, we had to try. Again, executing a compiled expression was fast. But as with expressions, the problem comes when you have to compile before running.</p>
<p><strong>Using Emit, create statement, compile it and run (39000 times slower than normal property access)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">RunLong<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Emit: Create statement, compile, run&quot;</span>,<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">=&gt;</span>Emit<span style="color: #000000;">&#40;</span>address<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>As we can see, this is also horribly slow.</p>
<p><strong>Conclusion</strong></p>
<p>Unless you can create an expression/emit statement and compile it and then run the compiled version more than 200 times, in the app&#8217;s lifetime, using normal reflection is by far the preferred way to go when you have to dynamically invoke members on objects.</p>
<p>- Tore Vestues</p>
<p>Thanks to <a href="http://no.linkedin.com/in/aasmundeldhuset">Åsmund Eldhuset</a>.</p>
<p><a href='http://tore.vestues.no/2010/07/01/reflection-and-performance/performancerunner/' rel='attachment wp-att-104'>Here&#8217;s the source</a></p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/16nOSCbRdHU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/07/01/reflection-and-performance/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/07/01/reflection-and-performance/</feedburner:origLink></item>
		<item>
		<title>My NDC2010 talk</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/8sgcVy_WQfk/</link>
		<comments>http://tore.vestues.no/2010/06/25/my-ndc2010-talk/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 18:07:33 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=99</guid>
		<description><![CDATA[I had a great time at NDC this year. Good talks, great people!
My talk titled &#8220;A Style of Programming&#8221;, was filmed and is already online.
You can find it here.
Most of the other talks from the conference can be found here.
- Tore Vestues
]]></description>
			<content:encoded><![CDATA[<p>I had a great time at NDC this year. Good talks, great people!</p>
<p>My talk titled &#8220;A Style of Programming&#8221;, was filmed and is already online.</p>
<p>You can find it <a href="http://streaming.ndc2010.no/tcs/?id=C21C13ED-8657-4D10-9A21-213BA1031F90">here</a>.</p>
<p>Most of the other talks from the conference can be found <a href="http://streaming.ndc2010.no/tcs/#page:conferenceList&#038;status:recorded&#038;pageNumber:4">here</a>.</p>
<p>- Tore Vestues</p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/8sgcVy_WQfk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/06/25/my-ndc2010-talk/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/06/25/my-ndc2010-talk/</feedburner:origLink></item>
		<item>
		<title>My Xp2010 lightning talk</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/Se9da9sotDc/</link>
		<comments>http://tore.vestues.no/2010/06/08/my-xp2010-lightning-talk/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 21:10:23 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Talks]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=96</guid>
		<description><![CDATA[I recently did a lightning talk on the Xp2010 conference, titled &#8220;Agile fails without craftsmanship&#8221;. It was filmed, and you can see it here. 
Xp2010 was a great event by the way, and you can find other talks here.
- Tore Vestues
]]></description>
			<content:encoded><![CDATA[<p>I recently did a lightning talk on the <a href="http://xp2010.org">Xp2010</a> conference, titled <a href="http://multimedie.adm.ntnu.no/mediasite/SilverlightPlayer/Default.aspx?peid=6a11ed3be82e48e1b018c330ccdbfa9b"><strong>&#8220;Agile fails without craftsmanship&#8221;</strong></a>. It was filmed, and you can see it <a href="http://multimedie.adm.ntnu.no/mediasite/SilverlightPlayer/Default.aspx?peid=6a11ed3be82e48e1b018c330ccdbfa9b"><strong>here</strong></a>. </p>
<p>Xp2010 was a great event by the way, and you can find other talks <a href="http://multimedie.adm.ntnu.no/mediasite/Catalog/pages/catalog.aspx?catalogId=741a4896-6bfc-4ca5-95fa-8865bcf58166">here</a>.</p>
<p>- Tore Vestues</p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/Se9da9sotDc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/06/08/my-xp2010-lightning-talk/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/06/08/my-xp2010-lightning-talk/</feedburner:origLink></item>
		<item>
		<title>Speaking at NDC 2010</title>
		<link>http://feedproxy.google.com/~r/ToreVestues/~3/ajKBzOdvtFA/</link>
		<comments>http://tore.vestues.no/2010/04/13/speaking-at-ndc-2010/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 12:41:57 +0000</pubDate>
		<dc:creator>Tore Vestues</dc:creator>
				<category><![CDATA[Coding principles]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://tore.vestues.no/?p=92</guid>
		<description><![CDATA[I&#8217;m very proud to announce that I will be speaking at the Norwegian Developers Conference 2010 (track 6, day 3, 16:20). 
My talk is named &#8220;A Style of programming&#8221;:
&#8220;This talk describes a set of coding principles that constitutes a style of programming that focuses on ease of coding, ease of changing the code, and ease [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_93" class="wp-caption alignright" style="width: 210px"><img src="http://vestues.no/tore/wp-content/ndc2010.png" alt="Ndc 2010" title="ndc2010" width="200" height="83" class="size-full wp-image-93" /><p class="wp-caption-text">Ndc 2010</p></div>
<p>I&#8217;m very proud to announce that I will be speaking at the <a href="http://www.ndc2010.no/">Norwegian Developers Conference 2010</a> (track 6, day 3, 16:20). </p>
<p>My talk is named &#8220;A Style of programming&#8221;:</p>
<p>&#8220;This talk describes a set of coding principles that constitutes a style of programming that focuses on ease of coding, ease of changing the code, and ease of testing the code. The presentation aims at helping programmers understand how the principles relate to actual code. Every principle is made concrete through examples. This style of programming is influenced by leading object oriented and agile developers, and it is perfect for applying on object oriented languages such as C#.&#8221;</p>
<p>Hope to see you there!</p>
<p>- Tore Vestues</p>
<img src="http://feeds.feedburner.com/~r/ToreVestues/~4/ajKBzOdvtFA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://tore.vestues.no/2010/04/13/speaking-at-ndc-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://tore.vestues.no/2010/04/13/speaking-at-ndc-2010/</feedburner:origLink></item>
	</channel>
</rss>

