<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Challanges</title>
        <link>http://www.ayende.com/Blog/category/454.aspx</link>
        <description>Challanges</description>
        <language>en-US</language>
        <copyright>Ayende Rahien</copyright>
        <managingEditor>Ayende@ayende.com</managingEditor>
        <generator>Subtext Version 1.9.3.51</generator>
        <item>
            <title>Challenge: calling generics without the generic type</title>
            <link>http://ayende.com/Blog/archive/2008/04/13/Challenge-calling-generics-without-the-generic-type.aspx</link>
            <description>&lt;p&gt;Assume that I have the following interface:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IMessageHandler&amp;lt;T&amp;gt; where T : AbstractMessage
{
	&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Handle(T msg);
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;How would you write this method so dispatching a message doesn't require reflection every time:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispatch(AbstractMessage msg)
{
	IMessageHandler&amp;lt;msg.GetType()&amp;gt; handler = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MyHandler&amp;lt;msg.GetType()&amp;gt;();
	handler.Handle(msg);
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Note that you can use reflection the first time you encounter a message of a particular type, but not in any subsequent calls.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/10178.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/04/13/Challenge-calling-generics-without-the-generic-type.aspx</guid>
            <pubDate>Sat, 12 Apr 2008 23:39:09 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10178.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/04/13/Challenge-calling-generics-without-the-generic-type.aspx#feedback</comments>
            <slash:comments>49</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10178.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Challenge: The directory tree</title>
            <link>http://ayende.com/Blog/archive/2008/04/12/Challenge-The-directory-tree.aspx</link>
            <description>&lt;p&gt;Since people seems to really enjoy posts like this, here is another one. This time it is an interesting issue that I dealt with today.&lt;/p&gt;  &lt;p&gt;Given a set of versioned file, you need to cache them locally. Note that IPersistentCache semantics means that if you put a value in it, is is always going to remain there.&lt;/p&gt;  &lt;p&gt;Here is the skeleton:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IPersistentCache
{
	&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Set(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; key, &lt;span style="color: #0000ff"&gt;params&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] items);
	&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] Get(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; key);
}

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;enum&lt;/span&gt; Recursion
{
	None,
	OneLevel,
	Full
}

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; VersionedFile
{
	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Version;
	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Name;
}

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; FileSystemCache : IFileSystemCache 
{
	IPersistentCache cache;
	
	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; FileSystemCache(IPersistentCache cahce)
	{
		&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.cache = cache;
	}
	
	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Add(VersionedFile[] files)
	{
		&lt;span style="color: #008000"&gt;// to do&lt;/span&gt;
	}

	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;[] ListFilesAndFolders(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; root, &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; version, Recursion recursion)
	{
		&lt;span style="color: #008000"&gt;// to do&lt;/span&gt;
	}
	
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;How would you implement this? Note that your only allowed external dependency is the ICache interface. &lt;/p&gt;

&lt;p&gt;The usage is something like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre&gt;&lt;span style="color: #008000"&gt;// given &lt;/span&gt;
var fsc = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; FileSystemCache(cache);
fsc.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; []
{
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 1, Name = "&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;"},
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 1, Name = "&lt;span style="color: #8b0000"&gt;/foo&lt;/span&gt;"},
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 1, Name = "&lt;span style="color: #8b0000"&gt;/foo/bar&lt;/span&gt;"},
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 1, Name = "&lt;span style="color: #8b0000"&gt;/foo/bar/text.txt&lt;/span&gt;"},
});
fsc.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; []
{

      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 2, Name = "&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;"},
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 2, Name = "&lt;span style="color: #8b0000"&gt;/foo&lt;/span&gt;"},
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 2, Name = "&lt;span style="color: #8b0000"&gt;/foo/bar&lt;/span&gt;"},
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 2, Name = "&lt;span style="color: #8b0000"&gt;/foo/bar/text.txt&lt;/span&gt;"},
      &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; VersionFile{Version = 2, Name = "&lt;span style="color: #8b0000"&gt;/test.txt&lt;/span&gt;"},
});

&lt;span style="color: #008000"&gt;// then &lt;/span&gt;
fsc.ListFilesAndFolders("&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;", 1, Recursion.None) == { "&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;" } 

fsc.ListFilesAndFolders("&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;", 1, Recursion.OneLevel) == { "&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;/foo&lt;/span&gt;", } 

fsc.ListFilesAndFolders("&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;", 2, Recursion.OneLevel) == { "&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;/foo&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;test.txt&lt;/span&gt;" } 

fsc.ListFilesAndFolders("&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;", 1, Recursion.Full) == { "&lt;span style="color: #8b0000"&gt;/&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;/foo&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;/foo/bar&lt;/span&gt;", "&lt;span style="color: #8b0000"&gt;/foo/bar/text.txt&lt;/span&gt;"}  &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can assume that all paths are '/' separated and they always starts with '/'.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/10172.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/04/12/Challenge-The-directory-tree.aspx</guid>
            <pubDate>Fri, 11 Apr 2008 23:41:26 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10172.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/04/12/Challenge-The-directory-tree.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10172.aspx</wfw:commentRss>
        </item>
        <item>
            <title>A challenge: Getting a list of products</title>
            <link>http://ayende.com/Blog/archive/2008/04/09/A-challenge-Getting-a-list-of-products.aspx</link>
            <description>&lt;p&gt;A few days ago I posted about &lt;a href="http://www.ayende.com/Blog/archive/2008/04/03/How-to-get-good-people-Two-phase-code-tests.aspx"&gt;two phase tests&lt;/a&gt;, I have been thinking about this lately, and decided that I have a good example for this, which also demonstrate some important design decisions.&lt;/p&gt;  &lt;p&gt;The task is listing the first 10 products that we can sell to a customer. The UI is console application, and the database design and data access method are whatever you want.&lt;/p&gt;  &lt;p&gt;That is pretty easy, right? &lt;/p&gt;  &lt;p&gt;Expected input is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;/dev/product_listing/bin&amp;gt; list_products&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Expected output is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Milk                  $1.0     &lt;br /&gt;Bread               $1.3      &lt;br /&gt;Sausage            $2.5      &lt;br /&gt;Horror Movie    $5.0&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Next requirement is that given the following input:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;/dev/product_listing/bin&amp;gt; list_products -pg13&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;The output is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Milk                  $1.0     &lt;br /&gt;Bread               $1.3      &lt;br /&gt;Sausage            $2.5&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Next requirement is that given the following input:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;/dev/product_listing/bin&amp;gt; list_products -vegetarian&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Expected output is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Milk                  $1.0     &lt;br /&gt;Bread               $1.3      &lt;br /&gt;Horror Movie    $5.0&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Additional requirements of this type will follow, and they can be combined. That is, we can also have:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;/dev/product_listing/bin&amp;gt; list_products -pg13 -vegetarian&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Expected output is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Milk                  $1.0     &lt;br /&gt;Bread               $1.3&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;How would you solve this?&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/10166.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/04/09/A-challenge-Getting-a-list-of-products.aspx</guid>
            <pubDate>Tue, 08 Apr 2008 22:18:40 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10166.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/04/09/A-challenge-Getting-a-list-of-products.aspx#feedback</comments>
            <slash:comments>35</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10166.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Deterministic Disposable</title>
            <link>http://ayende.com/Blog/archive/2008/04/02/Deterministic-Disposable.aspx</link>
            <description>&lt;p&gt;Here is a challenge, get this to work:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;&lt;span style="color: #808080"&gt;///&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #808080"&gt;/// Executes the given handler when the instance is disposed&lt;/span&gt;
&lt;span style="color: #808080"&gt;/// of using the Dispose(instance);&lt;/span&gt;
&lt;span style="color: #808080"&gt;/// Note: Doesn't cause memory leak&lt;/span&gt;
&lt;span style="color: #808080"&gt;///&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; OnDisposable(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; instance, Action&amp;lt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt;&amp;gt; action);

&lt;span style="color: #808080"&gt;///&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #808080"&gt;/// Executes the previously registered Action for this&lt;/span&gt;
&lt;span style="color: #808080"&gt;/// instance&lt;/span&gt;
&lt;span style="color: #808080"&gt;///&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Dispose(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; instance);&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;The key part here is to get this to work without causing a memory leak. Furthermore, assume that you need to handle this scenario as well without causing a leak:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre&gt;&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; instance = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt;();
OnDisposable(instance, &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;(&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; obj)
{
    Console.WriteLine("&lt;span style="color: #8b0000"&gt;Disposing of {0}&lt;/span&gt;", obj);
});&lt;/pre&gt;&lt;/blockquote&gt;&lt;img src="http://ayende.com/Blog/aggbug/10156.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/04/02/Deterministic-Disposable.aspx</guid>
            <pubDate>Wed, 02 Apr 2008 12:52:16 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10156.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/04/02/Deterministic-Disposable.aspx#feedback</comments>
            <slash:comments>28</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10156.aspx</wfw:commentRss>
        </item>
        <item>
            <title>What is wrong with this code? Answers</title>
            <link>http://ayende.com/Blog/archive/2008/04/02/What-is-wrong-with-this-code-Answers.aspx</link>
            <description>&lt;p&gt;Wow, &lt;a href="http://ayende.com/Blog/archive/2008/04/01/What-is-wrong-with-this-code.aspx"&gt;that&lt;/a&gt; was a popular topic, just take a look at the comment thread. I'll do more of those in the future.&lt;/p&gt;  &lt;p&gt;The code in question is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] DownloadBytes(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; url,
                            ICredentials credentials)
{
    WebRequest request = Util.SetupWebRequest(WebRequest.Create(url), credentials);

    &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (WebResponse response = request.GetResponse())
    {
        &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (Stream stream = GetResponseStream(response))
        {
            &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] buffer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[&lt;font color="#ff0000"&gt;&lt;strong&gt;response.ContentLength&lt;/strong&gt;&lt;/font&gt;];
            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; current = 0;
            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; read;
            &lt;span style="color: #0000ff"&gt;do&lt;/span&gt;
            {
                read = stream.Read(buffer, current, buffer.Length - current);
                current += read;
            } &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (read != 0);
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; buffer;
        }
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;The code as written will result in data corruption. Now, people have found a &lt;em&gt;lot&lt;/em&gt; of issues with this code. So many that I am considering doing a "production code" post about this.&lt;/p&gt;

&lt;p&gt;The problem that I had in mind, which El Guapo correctly pointed at, is that this code relies on response.ContentLength to be accurate. There are innumerous reasons for it to be &lt;em&gt;inaccruate &lt;/em&gt;(server not sending the header, chucking, etc).&lt;/p&gt;

&lt;p&gt;The main issue, however, is that ContentLegnth represent the size of the payload &lt;em&gt;on the wire&lt;/em&gt;. This is very important, because size_on_wire != actual_size. This happened to me when the server was using GZip compression to send files. The CLR Web API will automatically notify the server that they can accept gzip and deflate compressions, and they will decompress it behind the scene when it comes the time to read it. The result is that size on the wire is significantly smaller than the actual file size, but I blithely ignored everything else and read only the size on the wire.&lt;/p&gt;

&lt;p&gt;It took me a while to track that, because the code that had this issue was an async file reader, and I initially assume that I had a threading issue there.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/10151.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/04/02/What-is-wrong-with-this-code-Answers.aspx</guid>
            <pubDate>Tue, 01 Apr 2008 21:23:32 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10151.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/04/02/What-is-wrong-with-this-code-Answers.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10151.aspx</wfw:commentRss>
        </item>
        <item>
            <title>What is wrong with this code?</title>
            <link>http://ayende.com/Blog/archive/2008/04/01/What-is-wrong-with-this-code.aspx</link>
            <description>&lt;p&gt;&lt;/p&gt;  &lt;p&gt;There is a &lt;strong&gt;huge&lt;/strong&gt; bug in this code, resulting in data corruption. Can you spot what it is?&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] DownloadBytes(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; url,
                            ICredentials credentials)
{
    WebRequest request = Util.SetupWebRequest(WebRequest.Create(url), credentials);

    &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (WebResponse response = request.GetResponse())
    {
        &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (Stream stream = GetResponseStream(response))
        {
            &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[] buffer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; &lt;span style="color: #0000ff"&gt;byte&lt;/span&gt;[response.ContentLength];
            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; current = 0;
            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; read;
            &lt;span style="color: #0000ff"&gt;do&lt;/span&gt;
            {
                read = stream.Read(buffer, current, buffer.Length - current);
                current += read;
            } &lt;span style="color: #0000ff"&gt;while&lt;/span&gt; (read != 0);
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; buffer;
        }
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Hint, this has nothing to do with exception handling. Assumes that nothing goes wrong.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/10149.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/04/01/What-is-wrong-with-this-code.aspx</guid>
            <pubDate>Tue, 01 Apr 2008 18:46:03 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10149.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/04/01/What-is-wrong-with-this-code.aspx#feedback</comments>
            <slash:comments>46</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10149.aspx</wfw:commentRss>
        </item>
        <item>
            <title>The Illustrated Design Patterns Spotter Guide</title>
            <link>http://ayende.com/Blog/archive/2008/03/31/The-Illustrated-Design-Patterns-Spotter-Guide.aspx</link>
            <description>&lt;p&gt;What is the name of the pattern here?&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;QuoteGeneratorRule.Evaluate()&lt;/li&gt;    &lt;li&gt;RoutingBase.Route()&lt;/li&gt;    &lt;li&gt;AuthorizationRule.CheckAuthorization()&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://ayende.com/Blog/aggbug/10144.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/03/31/The-Illustrated-Design-Patterns-Spotter-Guide.aspx</guid>
            <pubDate>Sun, 30 Mar 2008 22:54:24 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10144.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/03/31/The-Illustrated-Design-Patterns-Spotter-Guide.aspx#feedback</comments>
            <slash:comments>16</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10144.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Find out the right directory</title>
            <link>http://ayende.com/Blog/archive/2008/03/28/Find-out-the-right-directory.aspx</link>
            <description>&lt;p&gt;Another interesting challenge. Given the following API:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IFileRepository
{
	&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Save(IFile file);

	IFile[] GetFiles(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; path, Recursion recursion);
}

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;enum&lt;/span&gt; Recursion
{
	None,
	OneLevel,
	Full
}&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;And assuming that you are saving to a relational database, how are you going to build the GetFiles method?&lt;/p&gt;

&lt;p&gt;Oh, and just to make things interesting, Save(IFile) may only perform a single SQL INSERT statement.&lt;/p&gt;&lt;img src="http://ayende.com/Blog/aggbug/10128.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/03/28/Find-out-the-right-directory.aspx</guid>
            <pubDate>Fri, 28 Mar 2008 01:44:14 GMT</pubDate>
            <wfw:comment>http://ayende.com/Blog/comments/10128.aspx</wfw:comment>
            <comments>http://ayende.com/Blog/archive/2008/03/28/Find-out-the-right-directory.aspx#feedback</comments>
            <slash:comments>20</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10128.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Challenge: Strongly typing weakly typed code</title>
            <link>http://ayende.com/Blog/archive/2008/01/21/Challenge-Strongly-typing-weakly-typed-code.aspx</link>
            <description>&lt;p&gt;How would you make the following code work?&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Security
{
	&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetDescription(Type entityType, Guid securityKey)
	{
		Guard.Against&amp;lt;ArgumentException&amp;gt;(securityKey == Guid.Empty, "&lt;span style="color: #8b0000"&gt;Security Key cannot be empty&lt;/span&gt;");
		IEntityInformationExtractor&amp;lt;TEntity&amp;gt; extractor = IoC.Resolve&amp;lt;IEntityInformationExtractor&amp;lt;TEntity&amp;gt;&amp;gt;();
		&lt;span style="color: #0000ff"&gt;return&lt;/span&gt; extractor.GetDescription(securityKey);
	}
}&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt;You can't change the entity type parameter to a generic parameter, because you only know about it at runtime. This is usually called with:&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;Security.GetDescription(Type.GetType(permission.EntityTypeName), permission.EntitySecurityKey.Value);&lt;/pre&gt;&lt;/blockquote&gt;&lt;img src="http://ayende.com/Blog/aggbug/10010.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/01/21/Challenge-Strongly-typing-weakly-typed-code.aspx</guid>
            <pubDate>Mon, 21 Jan 2008 08:44:22 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2008/01/21/Challenge-Strongly-typing-weakly-typed-code.aspx#feedback</comments>
            <slash:comments>18</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/10010.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Count the interfaces...</title>
            <link>http://ayende.com/Blog/archive/2008/01/10/Count-the-interfaces.aspx</link>
            <description>&lt;p&gt;Without running this code, what does this print?&lt;/p&gt; &lt;blockquote&gt;&lt;pre&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;interface&lt;/span&gt; IStartable : IDisposable
{
   &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Start();
}

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; Pipeline : IStartable
{ 
  &lt;span style="color: #008000"&gt;// ...&lt;/span&gt;
}

Console.WriteLine(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(Pipeline).GetInterfaces().Length);
&lt;/pre&gt;&lt;/blockquote&gt;&lt;img src="http://ayende.com/Blog/aggbug/9996.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Ayende Rahien</dc:creator>
            <guid>http://ayende.com/Blog/archive/2008/01/10/Count-the-interfaces.aspx</guid>
            <pubDate>Thu, 10 Jan 2008 20:25:04 GMT</pubDate>
            <comments>http://ayende.com/Blog/archive/2008/01/10/Count-the-interfaces.aspx#feedback</comments>
            <slash:comments>16</slash:comments>
            <wfw:commentRss>http://ayende.com/Blog/comments/commentRss/9996.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>