﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com/blog/</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2012 (c) 2013</copyright><ttl>60</ttl><item><title>Code crimes, because even the Law needs to be broken</title><description>&lt;p&gt;In 99.9% of the cases, if you see this, it is a mistake:&lt;/p&gt; &lt;p&gt;&lt;a href="http://ayende.com/blog/Images/Windows-Live-Writer/Code-crimes-because-even-the-Law-needs-t_D730/image_2.png"&gt;&lt;img style="background-image: none; border-bottom: 0px; border-left: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://ayende.com/blog/Images/Windows-Live-Writer/Code-crimes-because-even-the-Law-needs-t_D730/image_thumb.png" width="371" height="91"&gt;&lt;/a&gt;&lt;/p&gt; &lt;p&gt;But I recently came into a place where this is actually a viable solution to a problem. The issue occurs deep inside RavenDB. And it boils down to a managed application not really having any way of actually assessing how much memory it is using. &lt;/p&gt; &lt;p&gt;What I would &lt;em&gt;really&lt;/em&gt; like to be able to do is to specify a heap (using HeapCreate) and then say: “The following objects should be created on this heap”, which would allow to me to control exactly how much memory I am using for a particular task. In practice, that isn’t really possible (if you know how, please let me know).&lt;/p&gt; &lt;p&gt;What we do instead is to use as much memory as we can, based on the workload that we have. At certain point, we may hit an Out of Memory condition, which we take to mean, not that there is no more memory, but the system’s way of telling us to calm down.&lt;/p&gt; &lt;p&gt;By the time we reached the exception handler, we already lost all of the current workload, that means that now there is a LOT of garbage around for the GC. Before, when it tried to cleanup, we were actually holding to a lot of that memory, but not anymore.&lt;/p&gt; &lt;p&gt;Once an OOME happened, we can adjust our own behavior, to know that we are consuming too much memory and should be more conservative about our operations. We basically reset the clock back and become twice as conservative about using more memory. And if we get another OOME? We become twice as conservative again &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://ayende.com/blog/Images/Windows-Live-Writer/Code-crimes-because-even-the-Law-needs-t_D730/wlEmoticon-smile_2.png"&gt;, and so on.&lt;/p&gt; &lt;p&gt;Eventually, even under high workloads and small amount of memory, we complete the task, and we can be sure that we make effective use of the system’s resources available to us.&lt;/p&gt;</description><link>http://ayende.com/blog/156161/code-crimes-because-even-the-law-needs-to-be-broken?key=365d890a-41ec-49da-bb3b-54ae2c620163</link><guid>http://ayende.com/blog/156161/code-crimes-because-even-the-law-needs-to-be-broken?key=365d890a-41ec-49da-bb3b-54ae2c620163</guid><pubDate>Mon, 11 Jun 2012 09:00:00 GMT</pubDate></item><item><title>Beware of big Task Parallel Library Operations</title><description>&lt;p&gt;Take a look at the following code:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Program
{
    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()
    {
        var list = Enumerable.Range(0, 10 * 1000).ToList();

        var task = ProcessList(list, 0);


        Console.WriteLine(task.Result);

    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Task&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; ProcessList(List&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; list, &lt;span class="kwrd"&gt;int&lt;/span&gt; pos, &lt;span class="kwrd"&gt;int&lt;/span&gt; acc = 0)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (pos &amp;gt;= list.Count)
        {
            var tcs = &lt;span class="kwrd"&gt;new&lt;/span&gt; TaskCompletionSource&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
            tcs.TrySetResult(acc);
            &lt;span class="kwrd"&gt;return&lt;/span&gt; tcs.Task;
        }

        &lt;span class="kwrd"&gt;return&lt;/span&gt; Task.Factory.StartNew(() =&amp;gt; list[pos] + acc)
            .ContinueWith(task =&amp;gt; ProcessList(list, pos + 1, task.Result))
            .Unwrap();
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;This is a fairly standard piece of code, which does a “complex” async process and then move on. It is important in this case to do the operation in the order they were given, and the real code is actually doing something that need to be async (go and fetch some data from a remote server).&lt;/p&gt;
&lt;p&gt;It is probably easier to figure out what is going on when you look at the C# 5.0 code:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Program
{
    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()
    {
        var list = Enumerable.Range(0, 10 * 1000).ToList();

        var task = ProcessList(list, 0);

        Console.WriteLine(task.Result);

    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; async &lt;span class="kwrd"&gt;static&lt;/span&gt; Task&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; ProcessList(List&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; list, &lt;span class="kwrd"&gt;int&lt;/span&gt; pos, &lt;span class="kwrd"&gt;int&lt;/span&gt; acc = 0)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (pos &amp;gt;= list.Count)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt; acc;
        }

        var result = await Task.Factory.StartNew(() =&amp;gt; list[pos] + acc);

        &lt;span class="kwrd"&gt;return&lt;/span&gt; await ProcessList(list, pos + 1, result);
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;I played with user mode scheduling in .NET a few times in the past, and one of the things that I was never able to resolve properly was the issue of the stack depth. I hoped that the TPL would resolve it, but it appears that it didn’t. Both code samples here will throw StackOverFlowException when run.&lt;/p&gt;
&lt;p&gt;It sucks, quite frankly. I understand why this is done this way, but I am quite annoyed by this. I expected this to be solved somehow. Using C# 5.0, I know how to solve this:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; Program
{
    &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()
    {
        var list = Enumerable.Range(0, 10 * 1000).ToList();

        var task = ProcessList(list);

        Console.WriteLine(task.Result);

    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; async &lt;span class="kwrd"&gt;static&lt;/span&gt; Task&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; ProcessList(List&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; list)
    {
        var acc = 0;
        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var i &lt;span class="kwrd"&gt;in&lt;/span&gt; list)
        {
            var currentAcc = acc;
            acc += await Task.Factory.StartNew(() =&amp;gt; i + currentAcc);
        }
        &lt;span class="kwrd"&gt;return&lt;/span&gt; acc;
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;The major problem is that I am not sure how to translate this code to C# 4.0. Any ideas?&lt;/p&gt;</description><link>http://ayende.com/blog/156065/beware-of-big-task-parallel-library-operations?key=c83d50d2-df19-458c-b10e-22738c21a712</link><guid>http://ayende.com/blog/156065/beware-of-big-task-parallel-library-operations?key=c83d50d2-df19-458c-b10e-22738c21a712</guid><pubDate>Thu, 12 Apr 2012 09:54:00 GMT</pubDate></item><item><title>Memorable code</title><description>&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Program
{
    &lt;span class="kwrd"&gt;static&lt;/span&gt; List&amp;lt;Thread&amp;gt; list = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Thread&amp;gt;();
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
    {
        var lines = File.ReadAllLines(args[0]);

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var line &lt;span class="kwrd"&gt;in&lt;/span&gt; lines)
        {
            var t = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(Upsert)
            {
                Priority = ThreadPriority.Highest,
                IsBackground = &lt;span class="kwrd"&gt;true&lt;/span&gt;
            };
            list.Add(t);
            t.Start(line);
        }

        &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var thread &lt;span class="kwrd"&gt;in&lt;/span&gt; list)
        {
            thread.Join();
        }

    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Upsert(&lt;span class="kwrd"&gt;object&lt;/span&gt; o)
    {
        var args = o.ToString().Split(&lt;span class="str"&gt;','&lt;/span&gt;);
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;using&lt;/span&gt;(var con = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(Environment.CommandLine.Split(&lt;span class="str"&gt;' '&lt;/span&gt;)[1]))
            {
                var cmd = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlCommand
                {
                    Connection = con, 
                    CommandText = &lt;span class="str"&gt;"INSERT INTO Accounts VALUES(@p1, @p2, @p3, @p4,@p5)"&lt;/span&gt;
                };

                &lt;span class="kwrd"&gt;for&lt;/span&gt; (var index = 0; index &amp;lt; args.Length; index++)
                {
                    cmd.Parameters.AddWithValue(&lt;span class="str"&gt;@"@p"&lt;/span&gt; + (index + 1), args[index]);
                }

                &lt;span class="kwrd"&gt;try&lt;/span&gt;
                {
                    cmd.ExecuteNonQuery();
                }
                &lt;span class="kwrd"&gt;catch&lt;/span&gt; (SqlException e)
                {
                    &lt;span class="kwrd"&gt;if&lt;/span&gt;(e.Number == 2627 )
                    {
                        cmd.CommandText = &lt;span class="str"&gt;"UPDATE Accounts SET Name = @p2, Email = @p3, Active = @p4, Birthday = @p5 WHERE ID = @p1"&lt;/span&gt;;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
        }
        &lt;span class="kwrd"&gt;catch&lt;/span&gt; (SqlException e)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt;(e.Number == 1205)
            {
                var t = &lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(Upsert)
                {
                    Priority = ThreadPriority.Highest,
                    IsBackground = &lt;span class="kwrd"&gt;true&lt;/span&gt;
                };
                list.Add(t);
                t.Start(o);
            }
        }
    }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;</description><link>http://ayende.com/blog/131073/memorable-code?key=3ea6f5ec-8f2c-48b2-83f5-0b07c3dcbd66</link><guid>http://ayende.com/blog/131073/memorable-code?key=3ea6f5ec-8f2c-48b2-83f5-0b07c3dcbd66</guid><pubDate>Thu, 27 Oct 2011 10:00:00 GMT</pubDate></item><item><title>Negative hiring decisions, Part II</title><description>&lt;p&gt;&lt;img style="display: inline; float: right" align="right" src="http://ih3.redbubble.net/work.4446603.1.sticker,220x200-pad,220x200,f8f8f8.the-straw-that-broke-the-camels-back-v1.png"&gt;Another case of a candidate completing a task at home and sending it to me which resulted in a negative hiring decision is this:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Button1_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
{
    &lt;span class="kwrd"&gt;string&lt;/span&gt; connectionString = &lt;span class="str"&gt;@"Data Source=OFFICE7-PC\SQLEXPRESS;Integrated Security=True"&lt;/span&gt;;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; sqlQuery = &lt;span class="str"&gt;"Select UserName From  [Users].[dbo].[UsersInfo] Where UserName = ' "&lt;/span&gt; + TextBox1.Text + &lt;span class="str"&gt;"' and Password = ' "&lt;/span&gt; + TextBox2.Text+&lt;span class="str"&gt;"'"&lt;/span&gt;;
    
    &lt;span class="kwrd"&gt;using&lt;/span&gt; (SqlConnection connection = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlConnection(connectionString))
    {
        SqlCommand command = &lt;span class="kwrd"&gt;new&lt;/span&gt; SqlCommand(sqlQuery, connection);
        connection.Open();
        SqlDataReader reader = command.ExecuteReader();
        &lt;span class="kwrd"&gt;try&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;while&lt;/span&gt; (reader.Read())
            {
           
            }
        }
        &lt;span class="kwrd"&gt;finally&lt;/span&gt;
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (reader.HasRows)
            {
                reader.Close();
                Response.Redirect(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"&lt;font style="background-color: #ffff00"&gt;WebForm2&lt;/font&gt;.aspx?UserName={0}&amp;amp;Password={1}"&lt;/span&gt;, TextBox1.Text, TextBox2.Text));
            }
            &lt;span class="kwrd"&gt;else&lt;/span&gt;
            {
                reader.Close();
                Label1.Text = &lt;span class="str"&gt;"Wrong user or password"&lt;/span&gt;;
            }
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;The straw that really broke the camel’s back in this case was the naming of WebForm2. I could sort of figure out the rest, but not bothering to give a real name to the page was over the top.&lt;/p&gt;</description><link>http://ayende.com/blog/102402/negative-hiring-decisions-part-ii?key=1262a2ac-28b4-4a5d-9a6d-a72612340586</link><guid>http://ayende.com/blog/102402/negative-hiring-decisions-part-ii?key=1262a2ac-28b4-4a5d-9a6d-a72612340586</guid><pubDate>Mon, 10 Oct 2011 10:00:00 GMT</pubDate></item><item><title>Is Node.cs a cure for cancer?</title><description>&lt;p&gt;This is mainly a tongue in cheek post, in reply to &lt;a href="http://teddziuba.com/2011/10/node-js-is-cancer.html"&gt;this guy&lt;/a&gt;. I decided to take his scenario and try it using my &lt;a href="http://ayende.com/blog/72705/node-cs"&gt;Node.cs&lt;/a&gt; “framework”. Here is the code:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Fibonaci : AbstractAsyncHandler
{
    &lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; Task ProcessRequestAsync(HttpContext context)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; Task.Factory.StartNew(() =&amp;gt;
        {
            context.Response.ContentType = &lt;span class="str"&gt;"text/plain"&lt;/span&gt;;
            context.Response.Write(Fibonacci(40).ToString());
        });
    }

    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Fibonacci(&lt;span class="kwrd"&gt;int&lt;/span&gt; n)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (n &amp;lt; 2)
            &lt;span class="kwrd"&gt;return&lt;/span&gt; 1;
        
        &lt;span class="kwrd"&gt;return&lt;/span&gt; Fibonacci(n - 2) + Fibonacci(n - 1);
    }
}

&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;We start by just measuring how long it takes to serve a single request:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$ time curl &lt;a href="http://localhost/Fibonaci.ashx"&gt;http://localhost/Fibonaci.ashx&lt;/a&gt;&lt;br&gt;165580141&lt;br&gt;real&amp;nbsp;&amp;nbsp;&amp;nbsp; 0m2.763s&lt;br&gt;user&amp;nbsp;&amp;nbsp;&amp;nbsp; 0m0.000s&lt;br&gt;sys&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0m0.031s&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;That is 2.7 &lt;em&gt;seconds&lt;/em&gt; for a highly compute bound operation. Now, let us see what happens when we use Apache Benchmark to test things a little further:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;ab.exe -n 10 -c 5 &lt;a href="http://localhost/Fibonaci.ashx"&gt;http://localhost/Fibonaci.ashx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(Make a total of ten requests, maximum of 5 concurrent ones)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;And this gives us:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Requests per second:&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.91 [#/sec] (mean)&lt;br&gt;Time per request:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5502.314 [ms] (mean)&lt;br&gt;Time per request:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1100.463 [ms] (mean, across all concurrent requests)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Not bad, considering the best node.js (on a different machine and hardware configuration) was able to do was 0.17 requests per second.&lt;/p&gt;
&lt;p&gt;Just for fun, I decided to try it with&amp;nbsp; a hundred requests, with 25 of them concurrent. &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Requests per second:&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.97 [#/sec] (mean)&lt;br&gt;Time per request:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 25901.481 [ms] (mean)&lt;br&gt;Time per request:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1036.059 [ms] (mean, across all concurrent requests)&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Not bad at &lt;em&gt;all&lt;/em&gt;.&lt;/p&gt;</description><link>http://ayende.com/blog/114689/is-node-cs-a-cure-for-cancer?key=e8a8ce35-1db7-4430-8b93-03f084601c89</link><guid>http://ayende.com/blog/114689/is-node-cs-a-cure-for-cancer?key=e8a8ce35-1db7-4430-8b93-03f084601c89</guid><pubDate>Wed, 05 Oct 2011 10:00:00 GMT</pubDate></item><item><title>What is the cost of try/catch</title><description>&lt;p&gt;I recently got a question about the cost of try/catch, and whatever it was prohibitive enough to make you want to avoid using it.&lt;/p&gt; &lt;p&gt;That caused some head scratching on my part, until I got the following reply:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;But, I’m still confused about the try/catch block not generating an overhead on the server.&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt; &lt;p&gt;Are you sure about it?&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt; &lt;p&gt;&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt; &lt;p&gt;I learned that the try block pre-executes the code, and that’s why it causes a processing overhead.&lt;u&gt;&lt;/u&gt;&lt;u&gt;&lt;/u&gt; &lt;p&gt;Take a look here: &lt;a href="http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic2"&gt;http://msdn.microsoft.com/en-us/library/ms973839.aspx#dotnetperftips_topic2&lt;/a&gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Maybe there is something that I don’t know? It is always possible, so I went and checked and found this piece: &lt;blockquote&gt; &lt;p&gt;Finding and designing away exception-heavy code can result in a decent perf win. Bear in mind that this has nothing to do with try/catch blocks: &lt;i&gt;you only incur the cost when the actual exception is thrown. &lt;/i&gt;You can use as many try/catch blocks as you want. Using exceptions gratuitously is where you lose performance. For example, you should stay away from things like using exceptions for control flow.&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Note that the emphasis is in the original. There is &lt;em&gt;no cost to try/catch&lt;/em&gt; the only cost is when an exception is thrown, and that is regardless of whatever there is a try/catch around it or not. &lt;p&gt;Here is the proof: &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;var startNew = Stopwatch.StartNew();
var mightBePi = Enumerable.Range(0, 100000000).Aggregate(0d, (tot, next) =&amp;gt; tot + Math.Pow(-1d, next)/(2*next + 1)*4);
Console.WriteLine(startNew.ElapsedMilliseconds);
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Which results in: 6015 ms of execution.
&lt;p&gt;Wrapping the code in a try/catch resulted in:
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;var startNew = Stopwatch.StartNew();
&lt;span class="kwrd"&gt;double&lt;/span&gt; mightBePi = Double.NaN;
&lt;span class="kwrd"&gt;try&lt;/span&gt;
{
    mightBePi = Enumerable.Range(0, 100000000).Aggregate(0d, (tot, next) =&amp;gt; tot + Math.Pow(-1d, next)/(2*next + 1)*4);
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception e)
{
    Console.WriteLine(e);
}
Console.WriteLine(startNew.ElapsedMilliseconds);
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;And that run in 5999 ms.
&lt;p&gt;Please note that the perf difference is pretty much meaningless (only 0.26% difference) and is well within the range of derivations for tests runs.&lt;/p&gt;</description><link>http://ayende.com/blog/91137/what-is-the-cost-of-try-catch?key=092a30c0-2862-430a-a3fa-4ff7d7390afa</link><guid>http://ayende.com/blog/91137/what-is-the-cost-of-try-catch?key=092a30c0-2862-430a-a3fa-4ff7d7390afa</guid><pubDate>Wed, 14 Sep 2011 09:00:00 GMT</pubDate></item><item><title>A surprise TaskCancelledException</title><description>&lt;p&gt;All of a sudden, my code started getting a lot of TaskCancelledException. It took me a while to figure out what was going on. We can imagine that the code looked like this:&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;var unwrap = Task.Factory.StartNew(() =&amp;gt;
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (DateTime.Now.Month % 2 != 0)
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;

    &lt;span class="kwrd"&gt;return&lt;/span&gt; Task.Factory.StartNew(() =&amp;gt; Console.WriteLine(&lt;span class="str"&gt;"Test"&lt;/span&gt;));
}).Unwrap();

unwrap.Wait();
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;The key here is that when Unwrap is getting a null task, it will throw a TaskCancelledException, which was utterly confusing to me. It make sense, because if the task is null there isn’t anything that the Unwrap method can do about it. Although I do wish it would throw something like ArgumentNullException with a better error message.&lt;/p&gt;
&lt;p&gt;The correct way to write this code is to have:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;var unwrap = Task.Factory.StartNew(() =&amp;gt;
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (DateTime.Now.Month % 2 != 0)
    {
        var taskCompletionSource = &lt;span class="kwrd"&gt;new&lt;/span&gt; TaskCompletionSource&amp;lt;&lt;span class="kwrd"&gt;object&lt;/span&gt;&amp;gt;();
        taskCompletionSource.SetResult(&lt;span class="kwrd"&gt;null&lt;/span&gt;);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; taskCompletionSource.Task;
    }

    &lt;span class="kwrd"&gt;return&lt;/span&gt; Task.Factory.StartNew(() =&amp;gt; Console.WriteLine(&lt;span class="str"&gt;"Test"&lt;/span&gt;));
}).Unwrap();

unwrap.Wait();
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;Although I do wish that there was an easier way to create a completed task.&lt;/p&gt;</description><link>http://ayende.com/blog/88065/a-surprise-taskcancelledexception?key=845ebfc3-c574-4159-9071-532f1f4a0863</link><guid>http://ayende.com/blog/88065/a-surprise-taskcancelledexception?key=845ebfc3-c574-4159-9071-532f1f4a0863</guid><pubDate>Fri, 09 Sep 2011 09:00:00 GMT</pubDate></item><item><title>Concurrent Max</title><description>&lt;p&gt;Can you think of a better way to implement this code?&lt;/p&gt; &lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;volatile&lt;/span&gt; Guid lastEtag;
&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; lastEtagLocker = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;();&lt;/pre&gt;&lt;pre class="csharpcode"&gt;
&lt;span class="kwrd"&gt;internal&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; UpdateLastWrittenEtag(Guid? etag)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (etag == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        &lt;span class="kwrd"&gt;return&lt;/span&gt;;

    var newEtag = etag.Value.ToByteArray();

    &lt;span class="rem"&gt;// not the most recent etag&lt;/span&gt;
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (Buffers.Compare(lastEtag.ToByteArray(), newEtag) &amp;lt;= 0)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt;;
    }

    &lt;span class="kwrd"&gt;lock&lt;/span&gt; (lastEtagLocker)
    {
        &lt;span class="rem"&gt;// not the most recent etag&lt;/span&gt;
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Buffers.Compare(lastEtag.ToByteArray(), newEtag) &amp;lt;= 0)
        {
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }

        lastEtag = etag.Value;
    }
}
&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/blockquote&gt;
&lt;p&gt;We have multiple threads calling this function, and we need to ensure that lastEtag value is always the maximum value. This has the potential to be called often, so I want to make sure that I chose the best way to do this. Ideas?&lt;/p&gt;</description><link>http://ayende.com/blog/14337/concurrent-max?key=2c3cb183-cf99-497f-9386-c91ff1b8dc39</link><guid>http://ayende.com/blog/14337/concurrent-max?key=2c3cb183-cf99-497f-9386-c91ff1b8dc39</guid><pubDate>Sun, 12 Jun 2011 05:43:00 GMT</pubDate></item><item><title>ConcurrentDIctionary.GetOrAdd may call the valueFactory method more than once</title><description>&lt;blockquote&gt;Originally posted at 3/28/2011&lt;/blockquote&gt;&lt;p&gt;When you assume, you are making an ass out of yourself, you stupid moronic idiot with no sense whatsoever. The ass in question, if anyone cares to think about it, is yours truly.&lt;/p&gt;  &lt;p&gt;Let us take a look at the following code snippet:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;var concurentDictionary = &lt;span class="kwrd"&gt;new&lt;/span&gt; ConcurrentDictionary&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();
var w = &lt;span class="kwrd"&gt;new&lt;/span&gt; ManualResetEvent(&lt;span class="kwrd"&gt;false&lt;/span&gt;);
&lt;span class="kwrd"&gt;int&lt;/span&gt; timedCalled = 0;
var threads = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Thread&amp;gt;();
&lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; Environment.ProcessorCount; i++)
{
    threads.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Thread(() =&amp;gt;
    {
        w.WaitOne();
        concurentDictionary.GetOrAdd(1, i1 =&amp;gt;
        {
            Interlocked.Increment(&lt;span class="kwrd"&gt;ref&lt;/span&gt; timedCalled);
            &lt;span class="kwrd"&gt;return&lt;/span&gt; 1;
        });
    }));
    threads.Last().Start();
}

w.Set();&lt;span class="rem"&gt;//release all threads to start at the same time&lt;/span&gt;
&lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var thread &lt;span class="kwrd"&gt;in&lt;/span&gt; threads)
{
    thread.Join();
}

Console.WriteLine(timedCalled);&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;What would you say would be the output of this code?&lt;/p&gt;

&lt;p&gt;Well, I assumes that it would behave in an atomic fashion, that the implementation is something like:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt;(TryGetValue(key, &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;))
   &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;

&lt;span class="kwrd"&gt;lock&lt;/span&gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;)
{
   &lt;span class="kwrd"&gt;if&lt;/span&gt;(TryGetValue(key, &lt;span class="kwrd"&gt;out&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;))
      &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;

   AddValue( key, valueFactory());
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;Of course, the whole &lt;em&gt;point &lt;/em&gt;of the ConcurentDictionary is that there are no locks. Well, that is nice, except that because I assumed that the call is only made once, I called that with a function that had side effects when called twice.&lt;/p&gt;

&lt;p&gt;That was a pure hell to figure out, because in my mind, &lt;em&gt;of course&lt;/em&gt; that there was no error with this function.&lt;/p&gt;</description><link>http://ayende.com/blog/4802/concurrentdictionary-getoradd-may-call-the-valuefactory-method-more-than-once?key=b6f403e5-0084-4537-8352-b3b8d6070125</link><guid>http://ayende.com/blog/4802/concurrentdictionary-getoradd-may-call-the-valuefactory-method-more-than-once?key=b6f403e5-0084-4537-8352-b3b8d6070125</guid><pubDate>Tue, 05 Apr 2011 09:00:00 GMT</pubDate></item><item><title>Synchronization primitives, MulticastAutoResetEvent</title><description>&lt;p&gt;I have a very interesting problem within RavenDB. I have a set of worker processes that all work on top of the same storage. Whenever a change happen in the storage, they wake up and start working on it. The problem is that this change may be happening while the worker process is busy doing something other than waiting for work, which means that using Monitor.PulseAll, which is what I was using, isn’t going to work.&lt;/p&gt;  &lt;p&gt;AutoResetEvent is what you are supposed to use in order to avoid losing updates on the lock, but in my scenario, I don’t have a single worker, but a set of workers. And I really wanted to be able to use PulseAll to release all of them at once. I started looking at holding arrays of AutoResetEvents, keeping tracking of all changes in memory, etc. But none of it really made sense to me.&lt;/p&gt;  &lt;p&gt;After thinking about it for  a while, I realized that we are actually looking at a problem of state. And we can solve that by having the client hold the state. This led me to write something like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MultiCastAutoResetEvent 
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt; waitForWork = &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;object&lt;/span&gt;();
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; workCounter = 0;
    
    
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; NotifyAboutWork()
    {
        Interlocked.Increment(&lt;span class="kwrd"&gt;ref&lt;/span&gt; workCounter);
        &lt;span class="kwrd"&gt;lock&lt;/span&gt; (waitForWork)
        {
            Monitor.PulseAll(waitForWork);
            Interlocked.Increment(&lt;span class="kwrd"&gt;ref&lt;/span&gt; workCounter);
        }
    }
    
    
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; WaitForWork(TimeSpan timeout, &lt;span class="kwrd"&gt;ref&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; workerWorkCounter)
    {
        var currentWorkCounter = Thread.VolatileRead(&lt;span class="kwrd"&gt;ref&lt;/span&gt; workCounter);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (currentWorkCounter != workerWorkCounter)
        {
            workerWorkCounter = currentWorkCounter;
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;
        }
        &lt;span class="kwrd"&gt;lock&lt;/span&gt; (waitForWork)
        {
            currentWorkCounter = Thread.VolatileRead(&lt;span class="kwrd"&gt;ref&lt;/span&gt; workCounter);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (currentWorkCounter != workerWorkCounter)
            {
                workerWorkCounter = currentWorkCounter;
                &lt;span class="kwrd"&gt;return&lt;/span&gt;;
            }
            Monitor.Wait(waitForWork, timeout);
        }
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;By forcing the client to pass us the most recently visible state, we can efficiently tell whatever they still have work to do or do they have to wait.&lt;/p&gt;</description><link>http://ayende.com/blog/4673/synchronization-primitives-multicastautoresetevent?key=66bdd416-9df5-46cb-9e8e-151bdc1fea6d</link><guid>http://ayende.com/blog/4673/synchronization-primitives-multicastautoresetevent?key=66bdd416-9df5-46cb-9e8e-151bdc1fea6d</guid><pubDate>Tue, 26 Oct 2010 10:00:00 GMT</pubDate></item><item><title>JAOO: The Go Programming Language</title><description>&lt;p&gt;Currently sitting in the &lt;a href="http://golang.com"&gt;Go language&lt;/a&gt; keynote in JAOO. &lt;/p&gt;  &lt;p&gt;Go was created to handle Google needs:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Compilation speed&lt;/li&gt;    &lt;li&gt;Efficient&lt;/li&gt;    &lt;li&gt;Fit for the current set of challenges we face&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Go is meant to be Simple, Orthogonal, Succinct. Use C syntax, but leave a lot of complexity behind. &lt;/p&gt;  &lt;p&gt;This make sense, because C/C++ is horrible for a lot of reasons, because of complexity added to it over the years. Actually, the major problem is that C/C++ mindset are literally designed for a different era. Take into account how &lt;em&gt;long&lt;/em&gt; it can take to build a C++ application (I have seen no too big apps that had half an hour build times!), and you can figure out why Google wanted to have a better model.&lt;/p&gt;  &lt;p&gt;Nice quotes:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Programming shouldn’t be a game of Simon’s Says&lt;/li&gt;    &lt;li&gt;Difference between seat belts &amp;amp; training wheels – I am going to use that a &lt;em&gt;lot.&lt;/em&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I find Go’s types annoying:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;[variable name] [variable type] vs. [variable type] [variable name]&lt;/li&gt;    &lt;li&gt;And []int vs. int[]&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I like the fact that is uses garage collection in native code, especially since if you reference a variable (including local) it will live as long as it has a reference to. Which is a common mistake in C.&lt;/p&gt;  &lt;p&gt;It also have the notion of deferring code. This is similar to how you can use RAII in C++, but much more explicit, which is good, because RAII is always tricky. It very cleanly deals with the need to dispose things.&lt;/p&gt;  &lt;p&gt;All methods looks like extension methods. Data is held in structures, not in classes. There is support for embedding structures inside one another, but Go isn’t an OO language. &lt;/p&gt;  &lt;p&gt;Interfaces work for all types, and interfaces are satisfied implicitly! Much easier to work, think about this like super dynamic interfaces, but strong typed. Implies that we can retrofit things afterward.&lt;/p&gt;  &lt;p&gt;Error handling is important, and one of the major reasons that I moved from C++ to .NET. Go have two modes, the first is error codes, which they use for most errors. This is especially nice since Go have multiple return values, so it is very simple to use. But it also have the notion of panics, which are similar to exceptions. Let us take a look at the following test code:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;package main

func test() {
  panic(&lt;span class="str"&gt;"ayende"&lt;/span&gt;)
}

func main() {
    test()
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;Which generate the following panic:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;panic: ayende

panic PC=0x2ab34dd47040
runtime.panic+0xb2 /sandbox/go/src/pkg/runtime/proc.c:1020
    runtime.panic(0x2ab300000000, 0x2ab34dd470a0)
main.test+0x47 /tmp/gosandbox-a9aaff6c_68e6b411_26fb5255_aa397bb1_6299a954/prog.go:5
    main.test()
main.main+0x18 /tmp/gosandbox-a9aaff6c_68e6b411_26fb5255_aa397bb1_6299a954/prog.go:8
    main.main()
mainstart+0xf /sandbox/go/src/pkg/runtime/amd64/asm.s:78
    mainstart()
goexit /sandbox/go/src/pkg/runtime/proc.c:145
    goexit()&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;I got my stack trace, so everything is good. Error handling is more tricky. There isn’t a notion of try/catch, because panics aren’t really exceptions, but you can recover from panics:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;package main
import ( 
   &lt;span class="str"&gt;"fmt"&lt;/span&gt;
)
func badCall() {
  panic(&lt;span class="str"&gt;"ayende"&lt;/span&gt;)
}

func test() {
   defer func() { 
    &lt;span class="kwrd"&gt;if&lt;/span&gt; e := recover(); e != nil {
       fmt.Printf(&lt;span class="str"&gt;"Panicing %s\r\n"&lt;/span&gt;, e);
    }
   
    }()
    badCall()
   fmt.Printf(&lt;span class="str"&gt;"After bad call\r\n"&lt;/span&gt;);
}

func main() {
   fmt.Printf(&lt;span class="str"&gt;"Calling test\r\n"&lt;/span&gt;);
   test()
   fmt.Printf(&lt;span class="str"&gt;"Test completed\r\n"&lt;/span&gt;);
 
 
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;Which will result in the following output:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre&gt;Calling test
Panicing ayende
Test completed&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;All in all, if I need to write native code, I’ll probably go with Go instead of C now. Especially since the ideas that it have about multi threading are so compelling. I just wish that the windows port would be completed soon.&lt;/p&gt;</description><link>http://ayende.com/blog/4651/jaoo-the-go-programming-language?key=81fa92f5-3fc4-4644-91d4-411b1ef33814</link><guid>http://ayende.com/blog/4651/jaoo-the-go-programming-language?key=81fa92f5-3fc4-4644-91d4-411b1ef33814</guid><pubDate>Wed, 06 Oct 2010 10:00:00 GMT</pubDate></item><item><title>It ain’t no simple feature, mister</title><description>&lt;p&gt;I recently got a bug report about NH Prof in a multi monitor environment. Now, I &lt;em&gt;know&lt;/em&gt; that &lt;a href="http://nhprof.com"&gt;NH Prof&lt;/a&gt; works well in multi monitor environment, because I frequently run in such an environment myself.&lt;/p&gt;  &lt;p&gt;The problem turned out to be not multi monitors in and of itself, but rather how NH Prof handles the &lt;em&gt;removal&lt;/em&gt; of a monitor. It turns out that NH Prof has a nice little feature that actually remembers the last position the window was at, and returns to it on start. When the monitor NH Prof was located on was removed, on start NH Prof would put itself beyond the screen position. &lt;/p&gt;  &lt;p&gt;That led to me having to figure out how to find the available monitor space, so I could detect if the saved positions were valid or not. What I found interesting in this is that what seemed to be a very trivial feature (save two numbers) turned out to be somewhat more complex, and I am pretty sure that there are other scenarios that I am missing (in the very same feature).&lt;/p&gt;</description><link>http://ayende.com/blog/4629/it-aint-no-simple-feature-mister?key=e269bb78-5778-4c46-8242-cc06ce66ac4e</link><guid>http://ayende.com/blog/4629/it-aint-no-simple-feature-mister?key=e269bb78-5778-4c46-8242-cc06ce66ac4e</guid><pubDate>Tue, 14 Sep 2010 10:00:00 GMT</pubDate></item><item><title>Implementing CreateSequentialUuid()</title><description>&lt;p&gt;We run into an annoying problem in Raven regarding the generation of sequential guids. Those are used internally to represent the etag of a document.&lt;/p&gt;  &lt;p&gt;For a while, we used the Win32 method CreateSequentialUuid() to generate that. But we run into a severe issue with that, it create sequential guids only as long as the machine is up. After a reboot, the guids are no longer sequential. That is bad, but it also means that two systems calling this API can get drastically different results (duh! that is the point, pretty much, isn’t it?). Which wouldn’t bother me, except that we use etags to calculate the freshness of an index, so we &lt;em&gt;have&lt;/em&gt; to have an always incrementing number.&lt;/p&gt;  &lt;p&gt;How would you implement this method?&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Guid CreateSequentialUuid()&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;blockquote /&gt;

&lt;p&gt;A few things to note:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;We really actually care about uniqueness here, but only inside a single process, not globally.&lt;/li&gt;

  &lt;li&gt;The results must always be incrementing.&lt;/li&gt;

  &lt;li&gt;The always incrementing must be consistent across machine restarts and between different machines.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Yes, I am fully aware of the NHibernate’s implementation of guid.comb that creates sequential guids. It isn't applicable here, since it doesn't create truly sequential guids, only guids that sort near one another.&lt;/strong&gt;&lt;/p&gt;
</description><link>http://ayende.com/blog/4628/implementing-createsequentialuuid?key=0210c71f-53a6-45ba-858c-4ad953fbc223</link><guid>http://ayende.com/blog/4628/implementing-createsequentialuuid?key=0210c71f-53a6-45ba-858c-4ad953fbc223</guid><pubDate>Mon, 13 Sep 2010 10:00:00 GMT</pubDate></item><item><title>LightSwitch: Initial thoughts</title><description>&lt;p&gt;As promised, I intend to spend some time today with LightSwitch, and see how it works. Expect a series of post on the topic. In order to make this a read scenario, I decided that that a simple app recording animals and their feed schedule is appropriately simple. &lt;/p&gt;  &lt;p&gt;I created the following table:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_16.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_thumb_7.png" width="798" height="287" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Note that it has a calculated field, which is computed using:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_18.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_thumb_8.png" width="514" height="125" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;There are several things to note here:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;ReSharper doesn’t work with LightSwitch, which is a &lt;em&gt;big&lt;/em&gt; minus to me.&lt;/li&gt;    &lt;li&gt;The decision to use partial methods had resulted in &lt;em&gt;really&lt;/em&gt; ugly code. &lt;/li&gt;    &lt;li&gt;Why is the class called Animals? I would expect to find an inflector at work here.&lt;/li&gt;    &lt;li&gt;Yes, the actual calculation is crap, I know.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;This error kept appearing at random:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_thumb_2.png" width="767" height="60" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;It appears to be a &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/219f42cf-5c99-4a72-9acb-249210c835e2"&gt;known issue&lt;/a&gt;, but it is incredibly annoying.&lt;/p&gt;  &lt;p&gt;This is actually really interesting:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_10.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_thumb_4.png" width="1035" height="128" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt;  &lt;p /&gt;  &lt;ul&gt;   &lt;li&gt;You can’t really work with the app unless you are running in debug mode. That isn’t the way I usually work, so it is a bit annoying.&lt;/li&gt;    &lt;li&gt;More importantly, it confirms that this is indeed KittyHawk, which was a secret project in 2008 MVP Summit that had some hilarious aspects.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;There is something that is really interesting, it takes roughly 5 – 10 &lt;em&gt;seconds &lt;/em&gt;to start a LS application. That is a &lt;em&gt;huge &lt;/em&gt;amount of time. I am guessing, but I would say that a lot of that is because the entire UI is built dynamically from the data source.&lt;/p&gt;  &lt;p&gt;That would be problematic, but acceptable, except that it takes seconds to load data even after the app has been running for a while. For example, take a look here:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_14.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_thumb_6.png" width="820" height="642" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p /&gt;  &lt;p&gt;This is running on a quad core, 8 GB machine, in 2 tiers mode. It takes about 1 – 2 seconds to load each screen. I was actually able to capture a screen half way loaded. Yes, it is beta, I know. Yes, perf probably isn’t a priority yet, but that is still worrying.&lt;/p&gt;  &lt;p&gt;Another issue is that while Visual Studio is &lt;em&gt;very&lt;/em&gt; slow, busy about 50% of the time. This is when the LS app is running or not. As an a side issue, it is hard to know if the problem is with LS or VS, because of all the problems that VS has &lt;em&gt;normally&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_20.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchInitialthoughts_76F9/image_thumb_9.png" width="228" height="151" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;As an example of that, this is me trying to open the UserCode, it took about 10 seconds to do so.&lt;/p&gt;  &lt;p&gt;What I like about LS is that getting to a working CRUD sample is very quick. But the problems there are pretty big, even at a cursory examination. More detailed posts touching each topic are coming shortly.&lt;/p&gt;</description><link>http://ayende.com/blog/4603/lightswitch-initial-thoughts?key=9895ec4d-51c1-4f89-a0a4-3d6df8fae79c</link><guid>http://ayende.com/blog/4603/lightswitch-initial-thoughts?key=9895ec4d-51c1-4f89-a0a4-3d6df8fae79c</guid><pubDate>Wed, 25 Aug 2010 04:52:00 GMT</pubDate></item><item><title>Runtime code compilation &amp; collectible assemblies are no go</title><description>&lt;p&gt;The problem is quite simple, I want to be able to support certain operation on &lt;a href="http://ravendb.net"&gt;Raven&lt;/a&gt;. In order to support those operations, the user need to be able to submit a linq query to the server. In order to allow this, we need to accept a string, compile it and run it.&lt;/p&gt;  &lt;p&gt;So far, it is pretty simple. The problem begins when you consider that assemblies can’t be unloaded. I was &lt;em&gt;very&lt;/em&gt; hopeful when I learned about &lt;a href="http://msdn.microsoft.com/en-us/library/dd554932.aspx"&gt;collectible assemblies&lt;/a&gt; in .NET 4.0, but they focus exclusively on assemblies generated from System.Reflection.Emit, while my scenario is compiling code on the fly (so I invoke the C# compiler to generate an assembly, then use that).&lt;/p&gt;  &lt;p&gt;Collectible assemblies doesn’t help in this case. &lt;em&gt;Maybe&lt;/em&gt;, in C# 5.0, the compiler will use SRE, which will help, but I don’t hold much hope there. I also checked out Mono.CSharp assembly, hoping that maybe it can do what I wanted it to do, but that suffer from the memory leak as well.&lt;/p&gt;  &lt;p&gt;So I turned to the one solution that I knew would work, generating those assemblies in another app domain, and unloading that when it became too full. I kept thinking that I can’t do that because of the slowdown with cross app domain communication, but then I figured that I am violating one of the first rules of performance: You don’t know until you measure it. So I set out to test it.&lt;/p&gt;  &lt;p&gt;I am only interested in testing the speed of cross app domain communication, not anything else, so here is my test case:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; RemoteTransformer : MarshalByRefObject
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; Transformer transfomer = &lt;span class="kwrd"&gt;new&lt;/span&gt; Transformer();

    &lt;span class="kwrd"&gt;public&lt;/span&gt; JObject Transform(JObject o)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; transfomer.Transform(o);
    }
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Transformer
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; JObject Transform(JObject o)
    {
        o[&lt;span class="str"&gt;"Modified"&lt;/span&gt;] = &lt;span class="kwrd"&gt;new&lt;/span&gt; JValue(&lt;span class="kwrd"&gt;true&lt;/span&gt;);
        &lt;span class="kwrd"&gt;return&lt;/span&gt; o;
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;Running things in the same app domain (base line):&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
{
    var t = &lt;span class="kwrd"&gt;new&lt;/span&gt; RemoteTransformer();
    
    var startNew = Stopwatch.StartNew();

    &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 100000; i++)
    {
        var jobj = &lt;span class="kwrd"&gt;new&lt;/span&gt; JObject(&lt;span class="kwrd"&gt;new&lt;/span&gt; JProperty(&lt;span class="str"&gt;"Hello"&lt;/span&gt;, &lt;span class="str"&gt;"There"&lt;/span&gt;));

        t.Transform(jobj);

    }

    Console.WriteLine(startNew.ElapsedMilliseconds);
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;This consistently gives results under 200 ms (185ms, 196ms, etc). In other words, we are talking about over 500 operations per &lt;em&gt;millisecond&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;What happen when we do this over AppDomain boundary? The first problem I run into was that the Json objects were serializable, but that was easy to fix. Here is the code:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main(&lt;span class="kwrd"&gt;string&lt;/span&gt;[] args)
 {
    var appDomain = AppDomain.CreateDomain(&lt;span class="str"&gt;"remote"&lt;/span&gt;);
    var t = (RemoteTransformer)appDomain.CreateInstanceAndUnwrap(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(RemoteTransformer).Assembly.FullName, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(RemoteTransformer).FullName);
    
    var startNew = Stopwatch.StartNew();
     
     &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 100000; i++)
     {
         var jobj = &lt;span class="kwrd"&gt;new&lt;/span&gt; JObject(&lt;span class="kwrd"&gt;new&lt;/span&gt; JProperty(&lt;span class="str"&gt;"Hello"&lt;/span&gt;, &lt;span class="str"&gt;"There"&lt;/span&gt;));

         t.Transform(jobj);

     }

     Console.WriteLine(startNew.ElapsedMilliseconds);
 }&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;And that run close to 8 seconds, (7871 ms). Or over &lt;em&gt;40 times slower, &lt;/em&gt;or just about 12 operations per millisecond.&lt;/p&gt;

&lt;p&gt;To give you some indication about the timing, this means that an operation over 1 million documents would spend about 1.3 minutes just serializing data across app domains.&lt;/p&gt;

&lt;p&gt;That is… &lt;em&gt;long&lt;/em&gt;, but it might be acceptable, I need to think about this more.&lt;/p&gt;</description><link>http://ayende.com/blog/4602/runtime-code-compilation-collectible-assemblies-are-no-go?key=20fc33d4-ecdb-410d-90eb-8907001a28b9</link><guid>http://ayende.com/blog/4602/runtime-code-compilation-collectible-assemblies-are-no-go?key=20fc33d4-ecdb-410d-90eb-8907001a28b9</guid><pubDate>Tue, 24 Aug 2010 09:00:00 GMT</pubDate></item><item><title>LightSwitch: The Return Of The Secretary</title><description>&lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchTheReturnOfTheSecretary_E83A/image_8.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchTheReturnOfTheSecretary_E83A/image_thumb_3.png" width="404" height="378" /&gt;&lt;/a&gt; &lt;a href="http://www.microsoft.com/visualstudio/en-us/lightswitch"&gt;Microsoft LightSwitch&lt;/a&gt; is a new 4GL tool from Microsoft, this is another in the series of “you don’t have to write &lt;em&gt;any&lt;/em&gt; code” tools that I have seen.&lt;/p&gt;  &lt;p&gt;Those are the tools that will give the secretary the ability to create applications and eliminate the need for coders. The industry has been chasing those tools since the 80s (does anyone remember the promises of the CASE tools?). We have seen many attempts at doing this, and all of them have run into a wall pretty quickly. &lt;/p&gt;  &lt;p&gt;Oh, you can build a tool that gives you UI on top of a data store pretty easily. And you can go pretty far with it, but eventually your ability to point &amp;amp; click hit the limit, and you have to write code. And that is things totally breaks down.&lt;/p&gt;  &lt;p&gt;LightSwitch is not yet publically available, so I have to rely on the presentation that Microsoft published. And I can tell you that I am filled with dread, based on what I have seen.&lt;/p&gt;  &lt;p&gt;First of all, I &lt;strong&gt;strongly&lt;/strong&gt; object to the following slide. Because I have the experience to know that working with a tool like that is akin to do back flips with a straightjacket on. &lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchTheReturnOfTheSecretary_E83A/image_6.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchTheReturnOfTheSecretary_E83A/image_thumb_2.png" width="331" height="241" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The capabilities of the tools that were shown in the presentation have strongly underwhelmed me in terms of newness, complexity or applicability. &lt;/p&gt;  &lt;p&gt;Yeah, a meta data driven UI. Yeah, it can do validation on a phone number automatically (really, what happen with &lt;em&gt;my&lt;/em&gt; Israeli based phone number?), etc. What is worse, even through the demo, I get the very strong feeling that the whole things is incredibly slow, you can see in the presentation &lt;em&gt;multi second&lt;/em&gt; delays between screen repaints. &lt;/p&gt;  &lt;p&gt;Then there are things like “it just works as a web app or windows app” which is another &lt;a href="http://en.wikipedia.org/wiki/Fallacies_of_Distributed_Computing"&gt;pipe dream&lt;/a&gt; that the industry has been chasing for a while. And the only piece of code that I have seen is this guy:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchTheReturnOfTheSecretary_E83A/image_4.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://ayende.com/Blog/images/ayende_com/Blog/WindowsLiveWriter/LightSwitchTheReturnOfTheSecretary_E83A/image_thumb_1.png" width="691" height="234" /&gt;&lt;/a&gt;  &lt;/p&gt;  &lt;p&gt;Which makes me want to break down and cry.&lt;/p&gt;  &lt;p&gt;Do you know why? Because this is going to be the &lt;em&gt;essence&lt;/em&gt; of a SELECT N+1 in any system, because this code is going to run once per each row in the grid. And when I can find bugs from watching a presentation, you know that there are going to be more issues.&lt;/p&gt;  &lt;p&gt;So, just for fun sake, since I don’t have the bits and I can rely only on the presentation, I decided to make a list of all the things that are likely to be wrong with LightSwitch.&lt;/p&gt;  &lt;p&gt;I’ll review it when it comes out, and if it does manage to do everything that it does and &lt;em&gt;still&lt;/em&gt; be a tool usable by developers, I’ll have to eat crow (well, Raven :-) ), but I am not overly worried.&lt;/p&gt;  &lt;p&gt;Here are a few areas where I am feeling certain things will not work right:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Source control – how do I diff two versions of the app to see what changes? Are all changes diffable? &lt;/li&gt;    &lt;li&gt;Programmatic modifications:&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;what happen when I want to write some code to do custom validation of property (for instance, calling a web service)?&lt;/li&gt;      &lt;li&gt;what happen when I want to put a custom control on the screen (for instance, a google maps widget)?&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Upsizing – when it gets to a 1,000 users and we need a full blown app, how hard it is to do?&lt;/li&gt;    &lt;li&gt;Performance – as I said, I think it is slow from the demo.&lt;/li&gt;    &lt;li&gt;Data access behavior – from what I have seen so far, I am willing to be that it hits its data store pretty heavily.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I fully recognize that there is a need for such a tool, make no mistake. And giving users the ability to do that is important. What I strongly object to is the notion that it would be useful for developers writing real apps, not forms over data. To put it simply, simple forms over data is a solved problem. There is a large number of tools out there to do that. From Access to Oracle Apex to FoxPro. Hell, most CRM solutions will give you just that.&lt;/p&gt;  &lt;p&gt;My concern is that there seems to be an emphasis on that being useful for developers as well, and I &lt;em&gt;strongly&lt;/em&gt; doubt that.&lt;/p&gt;</description><link>http://ayende.com/blog/4575/lightswitch-the-return-of-the-secretary?key=f6f25cb7-fcfc-4a97-a658-8eee075987ce</link><guid>http://ayende.com/blog/4575/lightswitch-the-return-of-the-secretary?key=f6f25cb7-fcfc-4a97-a658-8eee075987ce</guid><pubDate>Thu, 05 Aug 2010 10:00:00 GMT</pubDate></item><item><title>Package management for .NET: Nu</title><description>&lt;p&gt;Package management for .NET has long been an issue. I won’t &lt;a href="http://codebetter.com/blogs/dru.sellers/archive/2010/07/17/nu-and-the-oss-dependency-nightmare.aspx"&gt;rehash the story&lt;/a&gt;, but you can read about a &lt;a href="http://devlicio.us/blogs/rob_reynolds/archive/2010/07/26/the-future-of-net-open-source-software-delivery.aspx?utm_source=feedburner&amp;amp;utm_medium=feed&amp;amp;utm_campaign=Feed:+Devlicious+(Devlicio.us)&amp;amp;utm_content=Google+Reader"&gt;lot of the problems here&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;There has been several attempts to replicate the success of Gems in Ruby, but none has really taken hold. &lt;a href="http://codebetter.com/blogs/dru.sellers/"&gt;Dru Sellers&lt;/a&gt; &amp;amp; &lt;a href="http://devlicio.us/blogs/rob_reynolds/"&gt;Rob Reynolds&lt;/a&gt; had decided to take a slightly different approach. Instead of trying to &lt;em&gt;replicate&lt;/em&gt; Ruby’s gems, just &lt;em&gt;use&lt;/em&gt; them.&lt;/p&gt;  &lt;p&gt;That is how Nu was created (and I really want to know what that name was picked, I nearly titled this post Dr. No). Before you can use Nu, you need to install it, which means that you have to make the following one time steps:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://rubyinstaller.org/"&gt;Install Ruby&lt;/a&gt; (you can also use Iron Ruby, but the Ruby installer is just sweet &amp;amp; painless).&lt;/li&gt;    &lt;li&gt;gem install nu&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Once this is done, all you need to do to install a piece of software is just write:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;nu install rhino.mocks&lt;/li&gt;    &lt;li&gt;nu install nhibernate&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;And Nu will get the latest version (&lt;em&gt;&lt;strong&gt;including resolving dependencies&lt;/strong&gt;&lt;/em&gt;) and put them in your lib folder.&lt;/p&gt;  &lt;p&gt;After executing the two commands above, I have the following contents in my lib directory.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;castle.core&lt;/li&gt;    &lt;li&gt;castle.dynamicproxy2&lt;/li&gt;    &lt;li&gt;log4net&lt;/li&gt;    &lt;li&gt;nhibernate&lt;/li&gt;    &lt;li&gt;rhino.mocks&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I &lt;em&gt;like&lt;/em&gt; it, it is going to make things so much simpler!&lt;/p&gt;</description><link>http://ayende.com/blog/4569/package-management-for-net-nu?key=c9bf896d-9c6c-4d16-97a1-7d8d18c98962</link><guid>http://ayende.com/blog/4569/package-management-for-net-nu?key=c9bf896d-9c6c-4d16-97a1-7d8d18c98962</guid><pubDate>Sun, 01 Aug 2010 09:00:00 GMT</pubDate></item><item><title>A question of an untenable situation</title><description>&lt;p&gt;One of the most common issues that I run into in my work is getting all sort of questions which sound really strange. For example, I recently got a question that went something like this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;What is the impact of reflection on NHibernate’s performance?&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I started to answer that there isn’t one that you would notice, even beyond the major optimizations that NH had in that role, you are accessing a remote database, which is much more expensive. But then they told me that they profiled the application and found some stuff there about that.&lt;/p&gt;  &lt;p&gt;I asked them what their scenario was, and the exchange went like that:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Well, when we load a million rows…&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;And &lt;em&gt;that&lt;/em&gt; is your problem…&lt;/p&gt;  &lt;p&gt;To be fair, they actually had a reasonable reason to want to do that. I disagree with the solution that they had, but it was a reasonable approach to the problem at hand.&lt;/p&gt;</description><link>http://ayende.com/blog/4565/a-question-of-an-untenable-situation?key=6d2da3a7-6021-49c2-98ef-b5a751dbed48</link><guid>http://ayende.com/blog/4565/a-question-of-an-untenable-situation?key=6d2da3a7-6021-49c2-98ef-b5a751dbed48</guid><pubDate>Thu, 29 Jul 2010 09:00:00 GMT</pubDate></item><item><title>Buy vs. Build &amp; YAGNI</title><description>&lt;p&gt;I was recently at the Israeli ALT.Net tools night, and I had a very interesting discussion on installers. Installers are usually a very painful part of the release procedure. The installer format for Windows is MSI, which is… strange. It takes time to understand how MSI work, and even after you got that, it is still painful to work with. Wix is a great improvement when it comes to building MSI installations, but that doesn’t make it good. Other installer builders, such as InstallSheild and NSIS are just as awkward.&lt;/p&gt;  &lt;p&gt;The discussion that I had related to the complexity of building an installer on those technologies.&lt;/p&gt;  &lt;p&gt;My argument was that it simply made no sense to try to overcome the hurdles of the installer technologies, instead, we can write our own installer more easily than fussing about the existing ones. The installer already assumes the presence of the .NET framework, so that make things even easier.&lt;/p&gt;  &lt;p&gt;This is an application of a principle that I strongly believes in: Single purpose, specially built tools &amp;amp; components can be advantageous over more generic ones, &lt;em&gt;for your specific scenarios&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;Case in point, the installer. Installers are complicated beasts because they must support a lot of complex scenarios (upgrading from 5.3.2 to 6.2.1, for example), be transactional, support installation, etc. But for the installer in question, upgrade is always an uninstall of the previous version &amp;amp; install of the new one, and the only tasks it requires is copying files and modifying registry entries.&lt;/p&gt;  &lt;p&gt;Given that set of requirements, we can design the following installer framework:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IInstallerTask
{
     &lt;span class="kwrd"&gt;void&lt;/span&gt; Install();
     &lt;span class="kwrd"&gt;void&lt;/span&gt; Uninstall();
}

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; FileCopyTask : IInstallerTask
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Source { get;set; }
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Destination { get;set; }
    
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Install()
    {
        File.Copy(Source, Destination,overwrite:&lt;span class="kwrd"&gt;true&lt;/span&gt;);
    }
    
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Uninstall()
    {
        File.Delete(Destination);
    }
}&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;And building a particular installer would be:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;ExecuteInstaller(
    Directory.GetFiles(extractedTempLocation)
        .Select( file =&amp;gt;
            &lt;span class="kwrd"&gt;new&lt;/span&gt; FileCopyTask
            {
                Source = file,
                Destination = Path.Combine(destinationPath, file)
            }        
        ),
    &lt;span class="kwrd"&gt;new&lt;/span&gt; RegistryKeyTask
    {
        Key = &lt;span class="str"&gt;"HKLM/Windows/CurrentVersion..."&lt;/span&gt;,
        Value = 9
    }
);&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;This gives the ExecuteInstaller method a list of tasks to be executed, which can then be used to installer or uninstall everything.&lt;/p&gt;

&lt;p&gt;Yes, it is extremely simple, and yes, it wouldn’t fit many scenarios. &lt;em&gt;But&lt;/em&gt;, it is quick to do, match the current and projected requirements, doesn’t introduce any new technology to the mix and it &lt;em&gt;works&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Contrast that with having someone on the team that is the Installer expert (bad) or having to educate the entire team about installer (expensive).&lt;/p&gt;</description><link>http://ayende.com/blog/4555/buy-vs-build-yagni?key=342d9cca-ac42-4985-96f3-ff77ca034d84</link><guid>http://ayende.com/blog/4555/buy-vs-build-yagni?key=342d9cca-ac42-4985-96f3-ff77ca034d84</guid><pubDate>Fri, 16 Jul 2010 09:28:30 GMT</pubDate></item><item><title>The pitfalls of transparent security</title><description>&lt;p&gt;A long time ago, I needed to implement a security subsystem for an application. I figured that it was best to make the entire security subsystem transparent to the developer, under the assumption that if the infrastructure would take care of security, it would make a lot more sense than relying on the developer to remember to add the security calls.&lt;/p&gt;  &lt;p&gt;It took me a long while to realize how wrong that decision was. Security is certainly important, but security doesn’t apply to the system itself. In other words, while a specific user may not be allowed to read/write to the audit log, actions that the user made should be written to that log. That is probably the simplest case, but that are a lot of similar ones.&lt;/p&gt;  &lt;p&gt;Ever since then, I favored using an explicit approach:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;var books = session.CreateQuery(&lt;span class="str"&gt;"from Books"&lt;/span&gt;)
                       &lt;strong&gt; .ThatUserIsAllowedToRead(CurrentUser)&lt;/strong&gt;
                        .List&amp;lt;Book&amp;gt;();&lt;/pre&gt;
  &lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;&lt;/blockquote&gt;

&lt;p&gt;This also help you implement more interesting features, such as “on behalf of”. And yes, it does put the onus of security on the developer, but considering the alternative, that is a plus.&lt;/p&gt;</description><link>http://ayende.com/blog/4550/the-pitfalls-of-transparent-security?key=2883f878-4ac4-4b1a-bfb9-2c1d3bd31c99</link><guid>http://ayende.com/blog/4550/the-pitfalls-of-transparent-security?key=2883f878-4ac4-4b1a-bfb9-2c1d3bd31c99</guid><pubDate>Wed, 30 Jun 2010 07:42:00 GMT</pubDate></item></channel></rss>