<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Abstract AST</title>
	
	<link>http://abstractast.com</link>
	<description>ASTrein</description>
	<lastBuildDate>Mon, 13 Sep 2010 10:33:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/kabbash" /><feedburner:info uri="kabbash" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:copyright>© Copyright 2009, Moukarram Kabbash</media:copyright><item>
		<title>Extending NServiceBus</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/TC8OWNjwd_0/</link>
		<comments>http://abstractast.com/2010/09/extending-nservicebus/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 10:32:30 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[extensibility]]></category>
		<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://abstractast.com/2010/09/extending-nservicebus/</guid>
		<description><![CDATA[NServicecBus is a very popular enterprise service bus (ESB) for the .NET framework. In this article I will analyze the extensibility facility of NSB, what you can do with it and what you can’t. Suppose for now we have the a very simple application that sends messages from one endpoint to another. We want to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nservicebus.com/">NServicecBus</a> is a very popular enterprise service bus (ESB) for the .NET framework. In this article I will analyze the extensibility facility of NSB, what you can do with it and what you can’t. </p>
<p>Suppose for now we have the a very simple application that sends messages from one endpoint to another. We want to extend the NSB framework to do the following:</p>
<ul>
<li>Outgoing message should be checked for confidential information – like credit card numbers – and censored if necessary. </li>
<li>Messages of some specific kind should be augmented with copy right notices. </li>
<li>Some messages should be prevented from being send. As an alternative, a simple notice message should be sent instead. </li>
<li>The outgoing bytes should be compressed and encrypted. </li>
<li>The incoming bytes should be decrypted and decompress before dispatching to the message handlers. </li>
</ul>
<p>To achieve those requirements I started analyzing the UnicastBus class, which is responsible to taking the message processing them before sending them using the configured transport. </p>
<p>The first extensible point I found was the IMessageModule interface. Classes that implement this interfaces should implement three functions that represents the three different points in the lifecycle of a message handler. Those functions are executed before processing a message, afterwards and afterwards if a problem happened. The biggest short come of this approach&#160; is that the functions take no parameters. You don’t know which messages are being processed, you don’t have access to the bus to send messages on your own. If you know the <a href="http://msdn.microsoft.com/en-us/magazine/ff872394.aspx">Alexandria</a> application you will be very disappointed.&#160; Cool things like caching responses and sending them when a matched request is sent is not possible. I’m not sure when to use IMessageHanlder interface. The only usage I’m aware of is <a href="http://andreasohlund.blogspot.com/2010/02/nhibernate-session-management-in.html">managing NHibernate sessions</a>.&#160; The plus side of this interfaces is its easy to use. Just inject all implementations in your IoC Container of choice I you’re cool. NServiceBus will retrieve and call them for you. As I figured out, almost all extensibility points works in same way. Just implement an interface, inject the implementation in the container and you’re done.</p>
<p>The second interface that could be used to grant you access to&#160; message processing pipeline is the interface pair IMutateIncomingMessages and IMutateOutgoingMessages. </p>
<p>The IMutateOutgoingMessages interface has only one method:</p>
<pre class="brush: csharp;">IMessage MutateOutgoing(IMessage message);</pre>
<p>As you see you don’t just have write access to the message, you have to return the modified you. This can be used to return a wholly different message.</p>
<p>The following snippet shows how to watch sent messages and censor all messages containing the word “Visa”.</p>
<pre class="brush: csharp;">public IMessage MutateOutgoing(IMessage message)
{
    var msg = (message as EventMessage);
    if (msg == null)
        return message;

    if (msg.Text.ToLower().Contains(&quot;visa&quot;))
    {
        return new CensoredMessage
                   {
                       Text = &quot;Message has been censored!&quot;
                   };
    }
    return msg;
}</pre>
<p>Even though you couldn’t prevent sending the message, you can send a replacement message that do pretty nothing. If you have multiple mutators and you would like to execute them in defined order, just introduce them to the container in the same order. IoC containers usually return items in the same order they we configured in.</p>
<p>Accordingly&#160; IMutateIncopmingMessage do the same to the received messages. </p>
<p>&#160;</p>
<p>What we could not do with those interfaces is compressing the outgoing bytes to spare bandwidth.</p>
<p>To do this you have to use the IMapOutgoingTransportMessages interface. Having single method </p>
<pre class="brush: csharp;">void MapOutgoing(IMessage[] messages, TransportMessage transportMessage)</pre>
<p>it grants you access to original logic messages as well to the serialized bytes.TansportMessage give also an access to the message headers. Those headers could be used to set meta data that can be useful when decompressing the messages.</p>
<p>Using this method we could implement the following compression service</p>
<p>&#160;</p>
<pre class="brush: csharp;">void MapOutgoing(IMessage[] messages, TransportMessage transportMessage)
{

    if (!ShouldCompressMessage(transportMessage))
        return;

    transportMessage.Headers[&quot;zipped&quot;] = &quot;1&quot;;

    byte[] output;
    var inputData = transportMessage.Body;

    using (var inMemoryStream = new MemoryStream(inputData))
    using (var outMemoryStream = new MemoryStream())
    {
        using (var zipStream = new DeflateStream(outMemoryStream, CompressionMode.Compress,leaveOpen: true))
        {
            inMemoryStream.WriteTo(zipStream);
            zipStream.Flush();
        }
        output = outMemoryStream.ToArray();
    }
    transportMessage.Body = output;
}

private bool ShouldCompressMessage(TransportMessage transportMessage)
{
    return transportMessage.Body.Length &gt; 300;
}</pre>
<p>Now to the other side of communication. All we have to do to decompress the messages is implementing IMapIncomingTransportMessages, isn’t it? I was very surprised to discover that there is no such an interface. I can’t imagine why there is an IMapOutgoingTransportMessages&#160; interface but no IMapIncomingTransportMessages. I guess it must be on the way. Nevertheless NSB is open source and you can add this interface by your self. Simply by adding the interface and calling its implementations using the container in the right place I could undo the compressing and continue process the message, as if there were no compression at all. </p>
<pre class="brush: csharp;">void MapIncoming(TransportMessage transportMessage)
{
    if (!transportMessage.Headers.ContainsKey(&quot;zipped&quot;))
        return;

    byte[] output;
    using (var inMemoryStream = new MemoryStream(transportMessage.Body))
    using (var zipStream = new DeflateStream(inMemoryStream, CompressionMode.Decompress,leaveOpen: true))
    {
        using (var strea = new MemoryStream())
        {
            zipStream.CopyTo(strea);
            output = strea.ToArray();
        }
    }
    transportMessage.Body = output;
    transportMessage.Headers.Remove(&quot;zipped&quot;);
}</pre>
<p>That’s all, folks.&#160; Using those techniques you can hook your own processing pipeline to the default pipeline of NSB without (big) modifications to the NSB source code. </p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/TC8OWNjwd_0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2010/09/extending-nservicebus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://abstractast.com/2010/09/extending-nservicebus/</feedburner:origLink></item>
		<item>
		<title>Pro .NET 4 Parallel Programming in C#. Book Review.</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/I-z1KdUWYGA/</link>
		<comments>http://abstractast.com/2010/08/pro-net-4-parallel-programming-in-c-book-review/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 11:24:56 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://abstractast.com/2010/08/pro-net-4-parallel-programming-in-c-book-review/</guid>
		<description><![CDATA[Disclaimer: This is my first book review and I am definitely not a book critic.&#160; I don’t know which criteria should a good book satisfy or what makes a book better than another, at least from a formal point of view. All what I can tell you is how useful it was for me. &#160; [...]]]></description>
			<content:encoded><![CDATA[<p><em>Disclaimer</em>: This is my first book review and I am definitely not a book critic.&#160; I don’t know which criteria should a good book satisfy or what makes a book better than another, at least from a formal point of view. All what I can tell you is how useful it was for me.</p>
<p>&#160;</p>
<p><a href="http://apress.com/book/view/9781430229674">The Pro .NET 4 Parallel Programming</a> book is written by Adam Freeman and published by <a href="http://apress.com/">APress</a>.</p>
<p>&#160;</p>
<p>The book is divided by into 8 chapters:</p>
<p>The first chapter is, what a surprise, the introduction. It answers such questions like why should you care about concurrency and parallel programming.</p>
<p>The second chapter introduces the Task class of the Task Parallel Library (<a href="http://msdn.microsoft.com/de-de/library/dd460717.aspx">TPL</a>) and handles almost all aspects of using it; like staring , cancellation, coordination and handling exceptions of tasks. This chapter makes you love tasks and wish you have never worked with threads.</p>
<p>The third and fourth chapters are about sharing data and coordinating tasks in more details. Those two chapters are what make this book a book about real world problems. You see in this chapter how solve real problems with shared data and control flow. You don’t do solve just embarrassingly parallel problems. Free lunch is over! The subjects in those chapters include locking primitives, signaling other tasks /thread to do work. All of that in great details.</p>
<p>The second two chapters are about parallel loops and parallel Linq. It handles the specialties of those aspects like breaking from a parallel loop or managing order while using parallel Linq. </p>
<p>&#160;</p>
<p>The seventh chapter is about testing and debugging. It shows the new capabilities in Visual Studio 2010, its strengths and weaknesses and how to make use of them.</p>
<p>The last chapter is a great prologue. It shows how to use the TPL to implement well known algorithms like quick sort and MapReduce. </p>
<p>&#160;</p>
<p>After this small summary of the book I will show the things I liked and things I didn’t. </p>
<p>Lets start with the positive side of this parallel coin.</p>
<p>Pros:</p>
<ol>
<li>All mentioned aspects are handled in great details. If its tasks coordination, you will know how to wait for tasks, how to start a new task after another task finished successfully or with an exception and how to cancel scheduled tasks. Synchronization Primitives are handled in all details. How to use them, when to use the slim version of them, etc.</li>
<li>At the end of each chapter there is a section about common problems and their causes.&#160; You learn which conditions produce such pitfalls and how to avoid them. Actually I have never heard about some of them. I found this chapter to be invaluable. </li>
<li>The practical last chapter helps you solving the jigsaw and orchestrating the small parts of the previous chapters to build real world solutions.</li>
</ol>
<p>Cons</p>
<ol>
<li>I’m not sure if this behavior is intended, but this book is merely about the TPL. All introduces techniques, with exception of the Synchronization Primitives maybe, are from the TPL. Threads are mentioned only sparely as way to manage tasks scheduling. Did threads become useless (at least to work directly with)? Are ThreadPools obsolete?&#160; I don’t know.&#160; I wish the book mentioned that explicitly.</li>
<li>The Monitor class has only been mentioned in conjuction with locking objects, but you could use it for other things, like wait and pulsing. I’m not sure if you could simulate this behavior with [(a Manual)|(an Auto)]-ResetEvent. But this should have been mentioned. </li>
<li>The book has its own convention in naming namespaces, classes and private methods.&#160; The namespace Speculative_Cache and class name&#160; Use_Speculative_Cache do not conform to the established conventions. Starting private methods with small letter is also not very common in the .Net world. </li>
</ol>
<p>Summary</p>
<p>A great book about the TPL. If you are a .NET programmer&#160; then you should read it.&#160; If you think you don’t have to because you will not be needing parallel programming in your daily job then you are the most suitable audience for this book. Your programs will perform better if you learned how make independent small chunks&#160; run independently. </p>
<p>Happy reading!</p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/I-z1KdUWYGA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2010/08/pro-net-4-parallel-programming-in-c-book-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2010/08/pro-net-4-parallel-programming-in-c-book-review/</feedburner:origLink></item>
		<item>
		<title>Harmful Abstractions</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/KpDf57E6YSM/</link>
		<comments>http://abstractast.com/2010/08/harmful-abstractions/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 08:58:11 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://abstractast.com/?p=142</guid>
		<description><![CDATA[Abstraction is a key concept in computer science and math. Abstraction in computer science is the art of hiding details. It could be as simple as the getc() C function that return a single char from some source. That is, the user key strokes, a text file, etc, or a very complicated abstraction like the [...]]]></description>
			<content:encoded><![CDATA[<p>Abstraction is a key concept in computer science and math. Abstraction in computer science is the art of hiding details. It could be as simple as the getc() C function that return a single char from some source. That is, the user key strokes, a text file, etc, or a very complicated abstraction like the 7 layers of the ISO TCP protocol. When using the getc() function you are ignoring where the retrieved char come from. It also means that you have, usually, no way of knowing where it comes from. Hence, abstractions are not only ignoring and hiding details.</p>
<p>Modern software is build as a pyramid of abstraction layers. When writing a an application in C#, for instance, you are using an abstraction layer above&#160; the intermediate language (IL). The IL is an abstraction layer&#160; above the the native environment, which, in turn, is&#160; an abstraction layer above the von Neumann computation model. The von Neumann computation model, is an abstraction layer above the electronic gates, which hide the details of current and electrons.&#160; It your software uses the Internet you are very likely to use a framework that abstract the whole abstraction layers of TCP protocol (technically your application resides in the 7th layer &#8211; the application layer &#8211; of TCP layer. Nevertheless, you have multiple abstraction layer inside it).</p>
<p>It is safe to claim that, without those abstraction layer, writing modern software will be kind of self torturing.</p>
<p>Anyway, this article is not about how useful&#160; are abstractions. It’s about how harmful then can be, when used wrongly. The reason why abstracts could be dangerous lies in the fact, that they may hide important details. Such details could cause the system to stop behaving as expected.&#160; When ignoring details, you are saying “I don’t care about the details because my system will work the same, regardless of the actual detail. Actually this is a very important principle of the S.O.L.I.D priciples: the “Liskov substitution principle”.&#160; This principle states “<i>Let </i><i>q</i>(<i>x</i>) be a property provable about objects <i>x</i> of type <i>T</i>. Then <i>q</i>(<i>y</i>) should be true for objects <i>y</i> of type <i>S</i> where <i>S</i> is a subtype of <i>T</i>.”</p>
<p>In this definition T is an abstraction over S.&#160; Assuming S´is another subtype of T, this principle doesn’t say that q(x) &lt;=&gt; q(x’), for all instances x from S and s´from S´. To use other words, when defining an abstract you are defining the properties you want to have in all subtypes. Mixing defined with assumed common behavior leads to serious problems. A funny Poster about the LSP states: <a href="http://www.lostechies.com/blogs/derickbailey/archive/2009/02/11/solid-development-principles-in-motivational-pictures.aspx">If it looks like a duck, quacks like a duck, but have batteries – you have properly the wrong abstraction.</a></p>
<p>Is the rest of this post I will show some harmful abstraction that led/ could lead to dangerous behavior.</p>
<p>&#160;</p>
<h1>Databases are memory collections</h1>
<p>This abstract has been usually pushed by the raise of the Domain Driven Design (DDD) which encourage persistence&#160; ignorance (PI).&#160; The famous pattern of the PI is the repository pattern which hides the database access details behind a slick interface with few simple methods like : GettAll(), GetById(), etc. This pattern is really great for unit testing. Abstracting the data access layer enables&#160; to replace the database with an in-memory collection of the entities which results in a huge performance hit compared to the accessing the database and, more important, to predictable behavior. </p>
<p>&#160;</p>
<h2>Performance problems</h2>
<p>The problems start to appear usually after you have established the infra structure of you architecture, usually too late.The problem with this abstraction is that databases don’t work like memory. Navigation from an object to another in the database is not nearly the same as in memory. Round trips to database are far more time consuming than in memory.&#160; Getting too much object from the database is too expensive. All serious&#160; ORM provide lazy loading to load dependencies of some object on demand. To be mainstream conform I will demonstrate this behavior using the blog post with comments example. Loading the blog post from the database doesn’t mean you want to have all comments. This could be worst if the post has attachments in the database. Loading them&#160; is not only slow but could also&#160; be memory exhaustive. Such sub objects could be lazy loaded, i.e. on demand. Now assume you want show the blog post with all its comments. Lazy loading them is known as the select N+1 Problem. The ORM has to query the database N times, that is one time for each comment, and the first time to retrieve the blog post. </p>
<p>If you ignore this issue it bite you later. And it will bite hard!&#160; Not wanting ti discard your beautiful repository and the nice unit tests with the memory collections to try to solve this dilemma adding new specialized functions to the repository. For retrieving all post with comments you add:</p>
<p>GetAllWithComments()</p>
<p>The same problems happen again and again and each time you add a new method to the repository.&#160; The beautiful slick is ain’t slick and beautiful any more. It get bloated with many methods like:</p>
<p>GetAllWithCommentsPaged(); </p>
<p>GetAllWithCommntsAndAuthorsPaged();</p>
<p> Get ByTag(); </p>
<p>GetByTagWithComments(); </p>
<p>GetByTagWithCommentsPaged(); </p>
<p>You name it.</p>
<p>&#160;</p>
<h2>Context problems</h2>
<p>Many ORM embed the database context inside persisted object to keep the connection to the database to retrieve sub object and persist updated value. The context provides further context features like&#160; object lifecycle, transactions, etc.&#160; The consequence of this coupling between objects and content causes the persisted object to depend strongly on the the context. It is not enough for a service class to receive a list of blog posts to calculate the average comments count per one post. I has to assume that the comments are all loaded eagerly, or the context is not disposed. It means also that you can not keep the database object in the memory between requests if you wish you modify them later of navigate in the object graph.</p>
<p>&#160;</p>
<h1>Remote calls</h1>
<p>Remote calls are calls to a resource on a remote process, remote computer on the same network or a call over the internet. Such calls are afflicted&#160; with long latency.&#160; If you wish to avoid slowing down you application you can all them asynchronously, i.e. starting the call and registering a callback to be executed when the call has terminated. Problems start when&#160; you try to hide the distributed nature of your call. If all what you are doing is calling a webservice to get the weather data and show them on you home page your cool. You can hide the webservice call behind an IWeatherIno interface and nevermind how it works. Of course the latency of you site with get at least as big as the called webservice latency, but no problem. It works!</p>
<p>Now imagine a more complicated situation with many distributed processes.&#160; If a communication partner is waiting for few partners to answer its calls the system will get very slow. And that’s not all. It can get even worse. Deadlocks could render the system unusable.&#160; To demonstrate this situation let us consider the starbucks example. This example demonstrate how multiple process could communicate with each other over a long term to accomplish a business transaction.</p>
<p>A transaction at starbuck involves three actors: a customer, a barista and a cashier. The customer starts the transaction by ordering a drink from the barista. The barista starts making the drink an notify the cashier to bill it. The cashier asks the customer to pay for the drink. The customer pays for the drink. After receiving the payment the cashier notify the barista, which deliver the drink to the customer.</p>
<p>Executing this transaction in the same process yield no problems. The execution flows from object to other as method calls until the initial call of the customer to order a drink terminates.&#160; All needed is one thread.</p>
<p>Now trying to hide the distributed nature <strike>could</strike> will lead to the following deadlock:</p>
<p>The clients orders a drink and the thread blocks waiting for the asynchronous call to return. As described previously the cashier request the customer to pay. The customer cannot reply because its thread is blocked waiting to the ordering call to terminate, which in turn will not terminate until the payment is done. Every one is blocked waiting for some call to return.&#160; Of course you could assign a second thread to the customer. But what he is ordering two drinks simultaneously? This is a fairly simple example. In a real world&#160; distributed application you will have many of such service calling each other. Abstracting the asynchronous calls behind an interface would harm your system. </p>
<p>&#160;</p>
<h1>Hiding the stateless nature of the http protocol</h1>
<p>The http Protocol used for the&#160; web communication is stateless by nature. That is, each http connection is new connection that contains no information about previous connections. Classical ASP.NET tried to&#160; get rid of this limitation by using an abstraction layer over the protocol that enables stateful web control.&#160; preserving the state of web page by rendering a huge amount of redundant data the get exchanged each timer between the browser and server. </p>
<p>ASP.NET Also tried to abstract the html behind an object oriented, component based model which failed frequently. The hidden details about the true nature of html could not be ignored without losing of control over the feel and look of the rendered pages</p>
<p>&#160;</p>
<p>I’ve tried in this article to demonstrate how abstract could be harmful if used inappropriately. Consider you abstraction carefully and never assume. And remember if it looks like a duck, quacks like a duck, but have batteries – you have properly the wrong abstraction <img src='http://abstractast.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/KpDf57E6YSM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2010/08/harmful-abstractions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2010/08/harmful-abstractions/</feedburner:origLink></item>
		<item>
		<title>Solving the Countdown Numbers Problem with F#</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/-V0bS_v_SgQ/</link>
		<comments>http://abstractast.com/2010/02/solving-the-countdown-numbers-problem-with-f/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 11:12:40 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[combinatorics]]></category>
		<category><![CDATA[countdown]]></category>
		<category><![CDATA[f#]]></category>
		<category><![CDATA[permutation]]></category>

		<guid isPermaLink="false">http://abstractast.com/?p=135</guid>
		<description><![CDATA[Countdown Problem is a game from the UK TV described in the following link (PDF).&#160; Basically, giving a set of numbers&#160; and a single number, you have to use the arithmetic&#160; operation to build a expression of the given numbers (in any subset and order) , that evaluate to the specified number.&#160;&#160; I will call [...]]]></description>
			<content:encoded><![CDATA[<p>Countdown Problem is a game from the UK TV described in the following <a href="http://www.cs.nott.ac.uk/~gmh/countdown.pdf">link</a> (PDF).&#160; Basically, giving a set of numbers&#160; and a single number, you have to use the arithmetic&#160; operation to build a expression of the given numbers (in any subset and order) , that evaluate to the specified number.&#160;&#160; I will call this task in this article “The Countdown Problem”, since using the word “Problem” makes it sounds more as an academic (or as a homework , see the first comment on my <a href="http://stackoverflow.com/questions/1563271/3d-bin-packing-algorithm">question</a> on Stackoverflow).</p>
<p>&#160;</p>
<p>I came across this Problem after watching the &quot;Functional Programming Fundamentals” <a href="http://channel9.msdn.com/shows/Going+Deep/Lecture-Series-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-1/">series</a> on Channel9, with Erik Mejer. <a href="http://www.cs.nott.ac.uk/~gmh/">Graham Hutton</a> (the author of <a href="http://www.cs.nott.ac.uk/~gmh/book.html">Programming in Haskell</a>) guest-hosted the 11th episode and showed how to solve this problem using brute force with Haskell. As I’m learning F# currently I started to implement the program in F# as well. Despite being heavily based on the Haskell solution from that episode, this code is not an accurate translation of the Haskell code. It just uses the same ideas.</p>
<p>&#160;</p>
<p>At first let us make a structure to hold the possible operations:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:8134d21b-f087-411f-a68a-f8475133ca75" class="wlWriterEditableSmartContent">
<div style="font-family:consolas,lucida console,courier,monospace">
<span style="color:#008000"><b>type</b></span>&#160;<span style="color:#0000FF"><b>Op</b></span>&#160;<span style="color:#666666">=</span>&#160;<span style="color:#0000FF"><b>Add</b></span>&#160;<span style="color:#666666">|</span>&#160;<span style="color:#0000FF"><b>Sub</b></span>&#160;<span style="color:#666666">|</span>&#160;<span style="color:#0000FF"><b>Mul</b></span>&#160;<span style="color:#666666">|</span>&#160;<span style="color:#0000FF"><b>Div</b></span>
</div>
</div>
<p>This kind of types is called <a href="http://msdn.microsoft.com/en-us/library/dd233226(VS.100).aspx">discriminated unions</a> which means that an instance of this type is one of the named cases. An operation could be any of the following cases: Addition, Subtraction, multiplication or division.</p>
<p>The second type is an arithmetic expression, which may either be an integer or two expressions combined using an operation from the previous ones:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:fd51dbeb-f806-48d1-b9bc-ae122239b7d0" class="wlWriterEditableSmartContent">
<div style="font-family:consolas,lucida console,courier,monospace">
<span style="color:#008000"><b>type</b></span>&#160;<span style="color:#0000FF"><b>Expr</b></span>&#160;<span style="color:#666666">=</span>&#160;<span style="color:#0000FF"><b>Val</b></span>&#160;<span style="color:#008000"><b>of</b></span>&#160;<span style="color:#B00040">int</span>&#160;<br />
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<span style="color:#666666">|</span>&#160;&#160;<span style="color:#0000FF"><b>App</b></span>&#160;<span style="color:#008000"><b>of</b></span>&#160;<span style="color:#0000FF"><b>Op</b></span>&#160;<span style="color:#666666">*</span>&#160;<span style="color:#0000FF"><b>Expr</b></span>&#160;<span style="color:#666666">*</span>&#160;<span style="color:#0000FF"><b>Expr</b></span>
</div>
</div>
<p>Boy, I love discriminated unions <img src='http://abstractast.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>&#160;</p>
<p>Now we have the structures to hold the possible combinations, we still have to generate then in some way. For a set of numbers&#160; we have to generate all possible subsets, and for each of those subsets all permutations have to be generated. Its obvious that this task can be composed from two separate functions: building subsets and permutating them.</p>
<p>The first function generate all subsets of the set of numbers:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:d78262cc-7d71-4adc-8e55-2355970c4962" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace"><span style="color: #008000"><b>let</b></span>&#160;<span style="color: #008000"><b>rec</b></span> subSets items <span style="color: #666666">=</span>
<p>&#160;&#160;&#160; <span style="color: #008000"><b>match</b></span> items <span style="color: #008000"><b>with</b></span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span>&#160;<span style="color: #008000">[]</span>&#160;<span style="color: #666666">-&gt;</span> seq<span style="color: #666666">{</span>yield <span style="color: #008000">[]</span><span style="color: #666666">}</span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span> x<span style="color: #666666">::</span>xs <span style="color: #666666">-&gt;</span> seq<span style="color: #666666">{</span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>let</b></span> sub <span style="color: #666666">=</span> subSets xs</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; yield<span style="color: #666666">!</span> sub</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; yield<span style="color: #666666">!</span> sub <span style="color: #666666">|&gt;</span>&#160;<span style="color: #0000ff"><b>Seq</b></span>.map <span style="color: #666666">(</span><span style="color: #008000"><b>fun</b></span> l <span style="color: #666666">-&gt;</span> x<span style="color: #666666">::</span>l<span style="color: #666666">)</span>&#160;<span style="color: #666666">}</span></p>
</p></div>
</p></div>
<p>This exploits the simple idea that for each element of the set there are two almost identical categories of subsets;&#160; subsets that include this element, and the matching subsets that don’t. This could be exploited using an inductive approach to generate the subsets of small sets and then adding new elements successively to those sets.&#160; This function returns a sequence instead of an instance of Set because the number of subsets is exponential to the number of elements in the original set.&#160; Sequences are lazy evaluated, and thus consume less memory. There are 2<sup>n</sup> subsets of any set of n elements.</p>
<p>The Second function generates for a giving set&#160; alls possible permutations:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:dddd41bf-874d-4005-81c7-f6f8b0027f7d" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace"><span style="color: #008000"><b>let</b></span>&#160;<span style="color: #008000"><b>rec</b></span> permutations items <span style="color: #666666">=</span>
<p>&#160;&#160;&#160; <span style="color: #008000"><b>match</b></span> items <span style="color: #008000"><b>with</b></span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span>&#160;<span style="color: #008000">[]</span>&#160;<span style="color: #666666">-&gt;</span> seq<span style="color: #666666">{</span>yield <span style="color: #008000">[]</span><span style="color: #666666">}</span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span>&#160;<span style="color: #666666">_</span>&#160;<span style="color: #666666">-&gt;</span>&#160; seq<span style="color: #666666">{</span><span style="color: #008000"><b>for</b></span> x <span style="color: #008000"><b>in</b></span> items <span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>let</b></span> oth <span style="color: #666666">=</span>&#160;<span style="color: #666666">[</span><span style="color: #008000"><b>for</b></span> c <span style="color: #008000"><b>in</b></span> items <span style="color: #008000"><b>do</b></span>&#160;<span style="color: #008000"><b>if</b></span> c <span style="color: #666666">&lt;&gt;</span> x <span style="color: #008000"><b>then</b></span> yield c <span style="color: #666666">]</span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; yield<span style="color: #666666">!</span> permutations oth <span style="color: #666666">|&gt;</span>&#160;<span style="color: #0000ff"><b>Seq</b></span>.map <span style="color: #666666">(</span><span style="color: #008000"><b>fun</b></span> l <span style="color: #666666">-&gt;</span> x<span style="color: #666666">::</span>l<span style="color: #666666">)</span>&#160;<span style="color: #666666">}</span></p>
</p></div>
</p></div>
<p>This function returns n! different permutations for each set of n elements.</p>
<p>Now we can compose both methods to retrieve a method that generates all permutations of all subsets of a given set:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:f0580702-8ba5-460d-8379-64f917f81eda" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace"><span style="color: #008000"><b>let</b></span> choices items <span style="color: #666666">=</span>&#160;
<p>&#160;&#160;&#160; seq<span style="color: #666666">{</span><span style="color: #008000"><b>for</b></span> x <span style="color: #008000"><b>in</b></span> subSets items <span style="color: #008000"><b>do</b></span>&#160;&#160;&#160; </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; yield<span style="color: #666666">!</span> permutations x <span style="color: #666666">}</span></p>
</p></div>
</p></div>
<p>Given a set of n elements, this function returns n!.2<sup>n</sup> different choices, which is a huge number. For n=6 choices yields&#160; 46080&#160; elements.</p>
<p>After building all possible permutated subsets of the number set there is still many ways to combine them into an arithmetic expression.&#160; An arithmetic could be represented as a binary tree. Each node in this tree is an operation and the leaves are numbers. Building a binary tree could be done by splitting combining both binary trees into one with a single root node. This could be repeated recursively for all possible sub trees and possible splitting points to generate all binary trees:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:6160ad60-4275-456d-8259-5b6e79adf241" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace"><span style="color: #008000"><b>let</b></span>&#160;<span style="color: #008000"><b>rec</b></span> generateExpressions nums <span style="color: #666666">=</span>
<p>&#160;&#160;&#160; <span style="color: #008000"><b>match</b></span> nums <span style="color: #008000"><b>with</b></span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span><span style="color: #008000">[]</span>&#160;<span style="color: #666666">-&gt;</span>&#160;<span style="color: #0000ff"><b>Seq</b></span>.empty</p>
<p>&#160;&#160;&#160; <span style="color: #666666">|[</span>a<span style="color: #666666">]</span>&#160;<span style="color: #666666">-&gt;</span> seq<span style="color: #666666">{</span>yield <span style="color: #0000ff"><b>Val</b></span><span style="color: #666666">(</span>a<span style="color: #666666">)}</span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|_-&gt;</span>seq<span style="color: #666666">{</span><span style="color: #008000"><b>for</b></span> posnum <span style="color: #008000"><b>in</b></span> choices nums <span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>for</b></span>&#160;<span style="color: #666666">(</span>f<span style="color: #666666">,</span>s<span style="color: #666666">)</span>&#160;<span style="color: #008000"><b>in</b></span> split posnum <span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>for</b></span> first <span style="color: #008000"><b>in</b></span> generateExpressions f <span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>for</b></span> second <span style="color: #008000"><b>in</b></span> generateExpressions s <span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>for</b></span> op <span style="color: #008000"><b>in</b></span>&#160;<span style="color: #666666">[</span><span style="color: #0000ff"><b>Add</b></span><span style="color: #666666">;</span><span style="color: #0000ff"><b>Sub</b></span><span style="color: #666666">;</span><span style="color: #0000ff"><b>Mul</b></span><span style="color: #666666">;</span><span style="color: #0000ff"><b>Div</b></span><span style="color: #666666">]</span>&#160;<span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; yield <span style="color: #0000ff"><b>App</b></span><span style="color: #666666">(</span>op<span style="color: #666666">,</span>first<span style="color: #666666">,</span>second<span style="color: #666666">)}</span></p>
</p></div>
</p></div>
<p>This yields an enormous number of binary trees. For a fixed number of leaves n one could construct (2n)! /((n+a)!n!) different trees.&#160;&#160; We will see in a coming article how to reduce this number by avoiding redundant expressions because of the commutatively of adding and multiplication.&#160;&#160; “split” is the function that splits a list into two non trivial list without changing the order of elements.</p>
<p>&#160;</p>
<p>Now we move to the evaluating arithmetical expressions.&#160; The function “eval” takes an expression and returns an list of integers. This is a common technique when programming in Haskell to express Null. If the expression is valid the function will evaluate it and return a singleton listing containing the result otherwise it will return an empty list.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:3cf8654f-cc70-4b80-9145-95be8e71b910" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace"><span style="color: #008000"><b>let</b></span>&#160;<span style="color: #008000"><b>rec</b></span> eval expr <span style="color: #666666">=</span>
<p>&#160;&#160;&#160; <span style="color: #008000"><b>match</b></span> expr <span style="color: #008000"><b>with</b></span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span><span style="color: #0000ff"><b>Val</b></span><span style="color: #666666">(</span>n<span style="color: #666666">)</span>&#160;<span style="color: #666666">-&gt;</span>&#160;<span style="color: #666666">[</span>n<span style="color: #666666">]</span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span><span style="color: #0000ff"><b>App</b></span><span style="color: #666666">(</span>op<span style="color: #666666">,</span> left<span style="color: #666666">,</span> right<span style="color: #666666">)</span>&#160; <span style="color: #666666">-&gt;</span>&#160;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #666666">[</span><span style="color: #008000"><b>for</b></span> l <span style="color: #008000"><b>in</b></span> eval left <span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>for</b></span> r <span style="color: #008000"><b>in</b></span> eval right <span style="color: #008000"><b>do</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>if</b></span> valid op l r <span style="color: #008000"><b>then</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; yield apply op l r<span style="color: #666666">]</span></p>
</p></div>
</p></div>
<p>“valid” is a simple function that ensure that all intermediate results are natural numbers. If valid of sum expression returned false all tree containing the sub tree of this expression are invalid.:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:c721418c-3404-461c-8ff7-d125f99766c6" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace"><span style="color: #008000"><b>let</b></span> valid op f s&#160; <span style="color: #666666">=</span>&#160;
<p>&#160;&#160;&#160; <span style="color: #008000"><b>match</b></span> op <span style="color: #008000"><b>with</b></span></p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span><span style="color: #0000ff"><b>Add</b></span>&#160;<span style="color: #666666">-&gt;</span>&#160;<span style="color: #008000">true</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span><span style="color: #0000ff"><b>Sub</b></span>&#160;<span style="color: #666666">-&gt;</span> f <span style="color: #666666">&gt;=</span> s</p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span><span style="color: #0000ff"><b>Mul</b></span>&#160;<span style="color: #666666">-&gt;</span>&#160;<span style="color: #008000">true</span>&#160;&#160; </p>
<p>&#160;&#160;&#160; <span style="color: #666666">|</span><span style="color: #0000ff"><b>Div</b></span>&#160;<span style="color: #666666">-&gt;</span>&#160;<span style="color: #666666">(</span>s <span style="color: #666666">&lt;&gt;</span>&#160;<span style="color: #666666">0</span><span style="color: #666666">)</span>&#160;<span style="color: #666666">&amp;&amp;</span>&#160;<span style="color: #666666">(</span>f <span style="color: #666666">%</span> s <span style="color: #666666">=</span>&#160;<span style="color: #666666">0</span><span style="color: #666666">)</span>&#160;&#160; </p>
</p></div>
</p></div>
<p>Now we have all necessary tools to iterate thru all possible combinations and returning the&#160; ones which matching result:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:875c5af6-fb12-4320-aadf-b1c21562e7eb" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace"><span style="color: #008000"><b>let</b></span> solutions nums result <span style="color: #666666">=</span>
<p>&#160;&#160;&#160; seq <span style="color: #666666">{</span><span style="color: #008000"><b>for</b></span> ex <span style="color: #008000"><b>in</b></span> generateExpressions nums <span style="color: #008000"><b>do</b></span>&#160;</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #008000"><b>if</b></span>&#160;<span style="color: #666666">(</span>eval ex <span style="color: #666666">|&gt;</span>&#160;<span style="color: #0000ff"><b>Seq</b></span>.to_list<span style="color: #666666">)</span>&#160;<span style="color: #666666">=</span>&#160;<span style="color: #666666">[</span>result<span style="color: #666666">]</span>&#160;<span style="color: #008000"><b>then</b></span></p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; yield ex<span style="color: #666666">}</span></p>
</p></div>
</p></div>
<p>&#160;</p>
<p>Running this function on the same input as the one presented in the Haskell lecture of Hutton returns the same result:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:2EC9848E-067D-4e79-BAB7-06CA927DB962:75b8ba41-0232-4aa2-a175-b09cebf252ae" class="wlWriterSmartContent">
<div style="font-family: consolas,lucida console,courier,monospace">solutions <span style="color: #666666">[</span><span style="color: #666666">1</span><span style="color: #666666">;</span>&#160;<span style="color: #666666">3</span><span style="color: #666666">;</span>&#160;<span style="color: #666666">7</span><span style="color: #666666">;</span>&#160;<span style="color: #666666">10</span><span style="color: #666666">;</span>&#160;<span style="color: #666666">25</span><span style="color: #666666">;</span>&#160;<span style="color: #666666">50</span><span style="color: #666666">]</span>&#160;<span style="color: #666666">765</span>&#160;&#160;&#160;
<p>&#160;&#160;&#160; <span style="color: #666666">|&gt;</span>&#160;<span style="color: #0000ff"><b>Seq</b></span>.length</p>
</p></div>
</p></div>
<p>The only problem with this Algorithm is the runtime. It takes too much to calculate the result.</p>
<p>Finding one solution is relative fast, but finding all results takes for ever. In the coming article I will try to reduce the runtime by avoiding redundant arithmetic expressions.</p>
<p>The code exists on <a href="http://github.com/mouk/Countdown">http://github.com/mouk/Countdown</a> and will be updated to reflect the planed changes.</p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/-V0bS_v_SgQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2010/02/solving-the-countdown-numbers-problem-with-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<enclosure url="http://www.cs.nott.ac.uk/~gmh/countdown.pdf" length="107552" type="application/pdf" /><media:content url="http://www.cs.nott.ac.uk/~gmh/countdown.pdf" fileSize="107552" type="application/pdf" /><feedburner:origLink>http://abstractast.com/2010/02/solving-the-countdown-numbers-problem-with-f/</feedburner:origLink></item>
		<item>
		<title>A coupon for any Tekpub series to give away</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/Cld5LGeF_yk/</link>
		<comments>http://abstractast.com/2010/01/a-coupon-for-any-tekpub-series-to-give-away/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 20:17:41 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://abstractast.com/2010/01/a-coupon-for-any-tekpub-series-to-give-away/</guid>
		<description><![CDATA[Justin Etheredge announced in his post that I am one of the five winners of his LINQ challenge accompanying his Tekpub series on LINQ. Since I already have a yearly subscription to Tekpub and because tomorrow is my 26th birthday I’m willing to give my coupon away As I have been using A LOT of [...]]]></description>
			<content:encoded><![CDATA[<p>Justin Etheredge announced in his <a href="http://www.codethinked.com/post/2010/01/10/Winners-of-the-TekPub-LINQ-Challenge.aspx">post</a> that I am one of the five winners of his LINQ <a href="http://www.codethinked.com/post/2010/01/08/TekPubs-Mastering-LINQ-Challenge.aspx">challenge</a> accompanying his <a href="http://www.tekpub.com/">Tekpub</a> <a href="http://www.tekpub.com/view/linq/1">series on LINQ</a>.</p>
<p>Since I already have a yearly subscription to Tekpub and because tomorrow is my 26th birthday I’m willing to give my coupon away <img src='http://abstractast.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>As I have been using A LOT of open source projects lately and not participating with coding I want to give something back. If you are an active committer&#160; in any active open source .Net (or jQuery)&#160; project, just leave a comment with your OS project and wished series. I will get the coupon and forward it to you.&#160; Active OS projects are … note very unknown project, you know?</p>
<p>&#160;</p>
<p>== UPDTAE ==</p>
<p>A coupon of “Mastering NHibernate” has already been sent to Krzysztof Koźmic. Have fun with it, Krzysztof <img src='http://abstractast.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/Cld5LGeF_yk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2010/01/a-coupon-for-any-tekpub-series-to-give-away/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://abstractast.com/2010/01/a-coupon-for-any-tekpub-series-to-give-away/</feedburner:origLink></item>
		<item>
		<title>Mastering LINQ</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/17TqWP8olyk/</link>
		<comments>http://abstractast.com/2010/01/mastering-linq/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 00:39:58 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Challenge]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://abstractast.com/2010/01/mastering-linq/</guid>
		<description><![CDATA[Mastering LINQ is a new series on Tekpub.com, the Rob Conery site with, yet few, but very interesting screencast about new technologies. &#160; The host of Mastering LINQ, Justin Etheredge,&#160; posted a challenge on his site&#160; promising the first five people to code a LINQ&#160; query returning all primes of a sequence a single Tekpub [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.tekpub.com/preview/linq">Mastering LINQ</a> is a new series on Tekpub.com, the Rob Conery site with, yet few, but very interesting screencast about new technologies.</p>
<p>&#160;</p>
<p>The host of Mastering LINQ, Justin Etheredge,&#160; posted a challenge on his <a href="http://www.codethinked.com/post/2010/01/08/TekPubs-Mastering-LINQ-Challenge.aspx">site</a>&#160; promising the first five people to code a LINQ&#160; query returning all primes of a sequence a single Tekpub screencast of choice.</p>
<p>&#160;</p>
<p>I gave it a try! It is really easy:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d21be6a0-e3d1-48a3-a263-550ce944435f" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">var n = 100;
var primes = Enumerable.Range(1, n)
    .Where(i =&gt; i &gt; 1)
    .Where(i =&gt;
               {
                   for (int j = 2; j &lt;= Math.Sqrt(i); j++)
                   {
                       if (i%j == 0)
                           return false;
                   }
                   return true;
               }
    );</pre>
</div>
<p>&#160;</p>
<p>Having a yearly subscription of Tekpub I don’t really need the price. I will give it away to some co-worker probably.</p>
<p>UPDATE:</p>
<p>The closure inside the where function could also be formulated using the “Range” and “All” method of the (I)Enumerable:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:1a7cd1f3-bd26-4e03-b6b1-3974685c4bc7" class="wlWriterEditableSmartContent">
<pre name="code" class="c#">var primes2 = Enumerable.Range(1, n)
    .Where(i =&gt; i &gt; 1)
    .Where(i =&gt; Enumerable
                    .Range(2, (int) Math.Sqrt(i) - 1)
                    .All(mod =&gt; i%mod != 0)
    );</pre>
</div>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/17TqWP8olyk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2010/01/mastering-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2010/01/mastering-linq/</feedburner:origLink></item>
		<item>
		<title>Continuous Integration with TeamCity and MSBuild I</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/Hv5xnyAqkDE/</link>
		<comments>http://abstractast.com/2009/09/continuous-integration-with-teamcity-and-msbuild-i/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 06:29:00 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[TeamCity]]></category>

		<guid isPermaLink="false">http://abstractast.com/2009/09/continuous-integration-with-teamcity-and-msbuild-i/</guid>
		<description><![CDATA[‘To start this article let us cite the definition of Continuous Integration from Martin Fowler’s site: Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily &#8211; leading to multiple integrations per day. Each integration is verified by an automated build (including [...]]]></description>
			<content:encoded><![CDATA[<p>‘To start this article let us cite the definition of Continuous Integration from Martin Fowler’s site:</p>
<blockquote><p><i>Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily &#8211; leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly. This article is a quick overview of Continuous Integration summarizing the technique and its current usage.</i></p>
</blockquote>
<p>I advice you to read the whole article about <a href="http://martinfowler.com/articles/continuousIntegration.html">Continuous Integration</a> before you go on.</p>
<p>For the sake of CI you need the following tools:</p>
<h3>1 &#8211; A Build Server</h3>
<p><a href="http://www.jetbrains.com/teamcity/">TeamCity</a> is very popular CI server from <a href="http://www.jetbrains.com/">JetBrains</a>, the&#160; creator of <a href="http://www.jetbrains.com/resharper/">ReSharper</a>, IntelliJ, etc. I have had also used <a href="http://cruisecontrol.sourceforge.net">CruiseControl.NET</a>, a free CI server from <a href="http://www.thoughtworks.com/">ThoughtWorks</a>, but I liked TeamCity much more because of its friendly UI and distributed agents principle.</p>
<h3>2 &#8211; Build Tool</h3>
<p><a href="http://en.wikipedia.org/wiki/MSBuild">MSBuild</a> is an xml-based build platform from Microsoft that comes with the .NET framework. A build platform is some kind of DSL, that helps you to compile your code and do all other related stuff in one action. You could compile source code, execute tests, generate documentation, generate a deployable zip file, publish your web site to the server and almost everything else you may need to do with your code.</p>
<p>Technically, you could write a batch file as you your build script and I have no doubt it will work and do every thing you wish. It just won’t be that convenient.</p>
<p><a href="http://nant.sourceforge.net/">NAnt</a> is another popular build platform ported from Ant for the Java platform.</p>
<p>Recently I have heard a lot about using Rake, the Ruby build tool, in the .NET world. <a href="http://codebetter.com/blogs/james.kovacs/archive/2008/06/27/introducing-psake.aspx">Psake</a>&#160; is another build automation tool written in PowerShell . </p>
<p>&#160;</p>
<p>In this and few next posts I will configuring <a href="http://www.jetbrains.com/teamcity/">TeamCity</a> to do a nightly build for <a href="http://github.com/mouk/Stutali/tree">Stutali</a> , the task list generation tool, I introduced last in this <a href="http://abstractast.com/2009/09/tasklist-generator/">article</a>.The task list generation task will be also included in the nightly build to process its own code and generate the task list.</p>
<h3>Building the Build Script</h3>
<p>The first step in configuring the build server is to add a build script to the project.&#160; Because TeamCity supports sln files directly, a build script is technically not necessary if you just want to compile the project. Anyway if you want to perform some further building steps like processing&#160; source code or deployment you will need the script.</p>
<p>As already mentioned, MSBuild is the&#160; technology that will be used in this article. The first and most important task is the bare compilation. For this task MSBuild needs only to know&#160; where the sln file is.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:a3607ab5-e967-4385-aba8-a30a0f173305" class="wlWriterEditableSmartContent">
<pre name="code" class="xml">&lt;PropertyGroup&gt;
  &lt;Configuration Condition=" '$(Configuration)' == '' "&gt;Debug&lt;/Configuration&gt;
  &lt;ProjectDir&gt;src&lt;/ProjectDir&gt;
  &lt;ProjectName&gt;TasklistGenerator&lt;/ProjectName &gt;
  &lt;ProjectFile&gt;$(ProjectName).sln&lt;/ProjectFile &gt;
&lt;/PropertyGroup&gt;

&lt;Target Name="Build" DependsOnTargets="Clean"&gt;
    &lt;MSBuild Projects="$(ProjectFile)" Properties="Configuration=Debug" /&gt;
&lt;/Target&gt;
  </pre>
</div>
<p>The Property group section is the place where you define you constants. This could include the project name, tools path and every thing you may use at different places.</p>
<h3>TeamCity</h3>
<p>After testing the build script and pushing the code to the repository, we can start configuring TeamCity to do the CI work. At first we have to create a new project in the admin panel. This task is as easy as clicking through the wizard steps, filling out some text boxes and ready you are. TeamCity makes really pleasant. Out of the box is Git not supported. Anyway JetBrains has developed a plug-in to enable Git repositories. You have just to download this file from <a href="http://www.jetbrains.net/confluence/display/TW/Git">JetBrains</a> and it to the place described.</p>
<p>&#160;</p>
<p><a href="http://abstractast.com/wp-content/uploads/2009/09/configrunner.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TeamCity configuration runner msbuild" border="0" alt="TeamCity configuration runner msbuild" src="http://abstractast.com/wp-content/uploads/2009/09/configrunner_thumb.jpg" width="558" height="331" /></a> </p>
<p>For the source code repository you should have been able to choose Git from the list after getting the Git plugin installed properly. </p>
<p>In the build triggering section you can specify when you want the build process to be started. Plausible options are either when the repository changes, i.e. when you push modification, or scheduled on a regular base, usually in the nightly, the so called nightly build. </p>
<p><a href="http://abstractast.com/wp-content/uploads/2009/09/configtigger.jpg"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TeamCity configuration build triggering" border="0" alt="TeamCity configuration build triggering" src="http://abstractast.com/wp-content/uploads/2009/09/configtigger_thumb.jpg" width="558" height="331" /></a> </p>
<h3>&#160;</h3>
<h3>Artifacts</h3>
<p>Artifacts are any data items generated during the build process. Those could be binaries, documentation, reports, etc. Because of distributed nature of TeamCity, the actual compiling process doesn’t have to happen physically on the save machine as the TeamCity server. Thus, the artifacts you want to keep have to be specified explicitly, so that they be copied from the machine of the build agent and kept on the server.</p>
<p>Suppose for now the build script generates an html file containing the task list parsed from the source code and save it to CHECKOUT_FOLDER\<em>doc\tasklist.html</em>.&#160; If you want TeamCity to copy this file and make available for download in the artifacts tab of the build report, you have to specify it in the artifacts section</p>
<p><a href="http://abstractast.com/wp-content/uploads/2009/09/configartifacts.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TeamCity configuration artifacts" border="0" alt="TeamCity configuration artifacts" src="http://abstractast.com/wp-content/uploads/2009/09/configartifacts_thumb.png" width="558" height="329" /></a> </p>
<p>If you want to add an alias to the copied artifacts, just use the =&gt; syntax </p>
<p><em>doc\tasklist.html =&gt; tasks.html</em></p>
<p>You can also copy a whole folder of artifacts.</p>
<p>Now we are ready to go. Every thing is configured and we can trigger a test build. Just click the “run” that you see on almost every project page. If every thing went well you should see a new green line in the result page of the project.</p>
<p><a href="http://abstractast.com/wp-content/uploads/2009/09/teamcity_overview_atrifacts.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="TeamCity overview artifacts" border="0" alt="TeamCity overview artifacts" src="http://abstractast.com/wp-content/uploads/2009/09/teamcity_overview_atrifacts_thumb.png" width="558" height="330" /></a> </p>
<p>&#160;</p>
<h3>Outlook</h3>
<p>It was just the start. What you can do in the CI process is only limited by your imagination and time. You could generate code metric reports, what we will do in the next posts, generate release binaries, push them to the download server, generate documentation,&#160; push the new ASP.Net files to the server and precompile them, etc. </p>
<p>For the next posts, we will see how to integrate NDepend, NCover, FxCop and code documentation with the build process. </p>
<p>See you later!</p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/Hv5xnyAqkDE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/09/continuous-integration-with-teamcity-and-msbuild-i/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/09/continuous-integration-with-teamcity-and-msbuild-i/</feedburner:origLink></item>
		<item>
		<title>JsonToDynamic: Consuming Json Data as Dynamic Objects in C# 4.0</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/RjcQSykMIuY/</link>
		<comments>http://abstractast.com/2009/09/jsontodynamic-consuming-json-data-as-dynamic-objects-in-c-4-0/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 10:50:00 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dynamic]]></category>

		<guid isPermaLink="false">http://abstractast.com/2009/09/jsontodynamic-consuming-json-data-as-dynamic-objects-in-c-4-0/</guid>
		<description><![CDATA[About a month ago I was reading the early access edition of C# in Depth, Second Edition from Jon Skeet. In this book the auto demonstrates using dynamic objects and the dynamic keyword in C# using a wrapper around an xml document. Suppose you have a xml document containing a number of books &#60;book&#62; &#60;autor&#62;The [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago I was reading the early access edition of <a href="http://www.manning.com/skeet2/">C# in Depth, Second Edition</a> from <a href="http://msmvps.com/blogs/jon_skeet/default.aspx">Jon Skeet</a>. In this book the auto demonstrates using dynamic objects and the dynamic keyword in C# using a wrapper around an xml document. Suppose you have a xml document containing a number of books</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:e67611ae-da2f-4bf9-bb7a-29c9e351cdb8" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre class="xml">&lt;book&gt;
	&lt;autor&gt;The Autor&lt;/autor&gt;
&lt;/boo&gt;</pre>
</div>
<p>Now you can access the auto properties of each book in the following way:</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:5fd41805-8f2d-480c-af64-1092399590a2" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre class="c#">dynamic book = GetBookAsDynamic();
string autoName = book.autor</pre>
</div>
<p>Having been using Json intensively  the last few weeks and seeing how easy it is to consume Json in JavaScript, I thought dynamic object would be a fantastic way to make Json more natural in the .Net world. My favorite Json library is the <a href="http://james.newtonking.com/pages/json-net.aspx">Json.Net</a>. Since, I started to code a wrapper about it.</p>
<p>Suppose now you have such an object, that you have Json serialized:</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:06d6fa5c-d1ed-469e-aabb-7f9ca85895d5" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre class="c#">var obj = new
{
    Name = "mouk",
    FavoriteNames = new[] { "mouk", "dermouk", "mouk9000" },
    NestedValues = new { First = 1, Second = 3, Nums = new[] { 1, 2, 3 } },
    NestedArray = new object[]{ 1, 3, new[] { 100, 2, 3 } },
    Age = 25,
    Height = 180
};

var serializedObject = JsonConvert.SerializeObject(obj);</pre>
</div>
<p>After deserializing it back to a dynamic object you can access as easy as:</p>
<div id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:6f15e0d5-2847-4e9b-b646-f7d4395f7acf" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<pre class="c#">dynamic _deserializedObject = JsonDeserilizer.GetObjectFromString(serializedObject);

string name= _deserializedObject.Name;
int age = _deserializedObject.Age;

int nested = _deserializedObject.NestedArray[1];</pre>
</div>
<h3>Source Code</h3>
<p>The source code of this wrapper can be downloaded from <a title="http://github.com/mouk/JsonToDynamic/tree/master" href="http://github.com/mouk/JsonToDynamic/tree/master">http://github.com/mouk/JsonToDynamic/tree/master</a>:</p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/RjcQSykMIuY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/09/jsontodynamic-consuming-json-data-as-dynamic-objects-in-c-4-0/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/09/jsontodynamic-consuming-json-data-as-dynamic-objects-in-c-4-0/</feedburner:origLink></item>
		<item>
		<title>Task List Generator</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/WpgpNEjti5U/</link>
		<comments>http://abstractast.com/2009/09/tasklist-generator/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 13:12:00 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[Task]]></category>
		<category><![CDATA[TeamCity]]></category>
		<category><![CDATA[TODO]]></category>

		<guid isPermaLink="false">http://abstractast.com/?p=90</guid>
		<description><![CDATA[A Task list is the list, that VS generate for your code files including all special marker items like TODO, HACK, etc. Visual studio lists all those items in the tasks window in grid containing the description, file and line number.&#160; Clicking an items in the tasks windows cause the editor to jump to this [...]]]></description>
			<content:encoded><![CDATA[<p align="left">A Task list is the list, that VS generate for your code files including all special marker items like TODO, HACK, etc. Visual studio lists all those items in the tasks window in grid containing the description, file and line number.&#160; Clicking an items in the tasks windows cause the editor to jump to this line in the code.&#160; Unfortunately, visual studio show only tasks for opened file. Additionally, I thinks the number of task is a metric for code maturity and should be integrated in the continues integration process.</p>
<h3>The Project</h3>
<p align="left">After some googling with both Google and Bing I decided to do it myself. The only similar program I found, was the <a href="http://wiki.hudson-ci.org/display/HUDSON/Task+Scanner+Plugin">Task Scanner plug-in</a> from the Hudson project.&#160; Unfortunately, this plug-in is written in Java and I didn’t want to assume the presence of a Java runtime on the build server. Besides, I want to integrate this job as build task (MSBuild build for now but maybe also for NAnt, etc..). For all other purposes a command line interface is essential. All those requirements make the amount of code I could reuse very minimal. So I went for the own solution and started summarizing the requirements.</p>
<h3>Wish List</h3>
<p align="left">If you prefer the scrum terminology, you can call this wish list the product backlog. It contains all items that COULD be implemented.</p>
<p align="left">Important feature for me are:</p>
<ul>
<li>
<div align="left">Recognizing all lines including // TODO token</div>
</li>
<li>
<div align="left">Flexibility of defining pre configured and custom tasks</div>
</li>
<li>
<div align="left">Assigning priorities for the the different types of tasks</div>
</li>
<li>
<div align="left">Returning for each task a TaskItem object with the description, file and line number.</div>
</li>
<li>
<div align="left">Grouping the tasks by file name or&#160; priority.</div>
</li>
<li>
<div align="left">Integration with TeamCity</div>
</li>
<li>
<div align="left">Generating reports in both xml and html formats</div>
</li>
<li>
<div align="left">being able to define thresholds for the occurrence of the different type/priorities&#160; to consider a build failed</div>
</li>
</ul>
<h3>&#160;</h3>
<p>To generate a task list to you MSBuild script all you need the the following xml snippet:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:86c57aba-7adc-4695-ab8d-ca426bfa8fc4" class="wlWriterSmartContent">
<pre class="xml" name="code">&lt;UsingTask AssemblyFile=&quot;$(ToolPath)\TasklistGenerator\TasklistGenerator.dll&quot; TaskName=&quot;Tasklist&quot; /&gt;

&lt;Target Name=&quot;tasklist&quot; &gt;
	&lt;Message Text=&quot;==== Generate tas klist ===&quot; /&gt;
	&lt;CreateItem Include=&quot;src\**\*.cs&quot;&gt;
      &lt;Output TaskParameter=&quot;Include&quot; ItemName=&quot;Sourcefiles&quot; /&gt;
    &lt;/CreateItem&gt;
    &lt;Tasklist Files=&quot;@(Sourcefiles)&quot; OutputFile=&quot;doc\tasks.html&quot; /&gt;
&lt;/Target&gt;</pre>
</div>
<h3>&#160;</h3>
<h3>The Code</h3>
<p>Currently, still the project in the pre alpha phase of the CTP (PACTP as I call it since two minutes ago). It Uses a Regex to scan all specified cs files and generates a simple xml representation. A html reporting facility is also in pre stone age look and feel&#160; html (Did I mention I don’t do UI?)&#160; I will try to find out how does usually build tasks, like NUnit, integrate with build server. not sure if there is a common format. The only interface available currently is the MSBuild task.</p>
<p>You can download the most recent source code from GitHub&#160; at the following link <a title="http://github.com/mouk/Stutali/tree/master" href="http://github.com/mouk/Stutali/tree/master">http://github.com/mouk/Stutali/tree/master</a>.</p>
<p>Because I have never developed an integration task, I don’t know what are the requirements exactly such a thing. More than ever, every idea or notes will be highly appreciated.</p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/WpgpNEjti5U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/09/tasklist-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/09/tasklist-generator/</feedburner:origLink></item>
		<item>
		<title>Using IronPython to configure Castle Windsor III</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/j-Qjnrn2Bsg/</link>
		<comments>http://abstractast.com/2009/09/using-ironpython-to-configure-castle-windsor-iii/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 05:04:00 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[IronPython]]></category>
		<category><![CDATA[Windsor]]></category>

		<guid isPermaLink="false">http://abstractast.com/2009/09/using-ironpython-to-configure-castle-windsor-iii/</guid>
		<description><![CDATA[Pysor Series Using IronPython to configure Castle Windsor I : the basic functionality Using IronPython to configure Castle Windsor II : parameters and references Using IronPython to configure Castle Windsor III : arrays and lists In the first two articles I introduced Pysor, the Castle Windsor configuration tool using IronPython. Now I have added some [...]]]></description>
			<content:encoded><![CDATA[<div style="background-color: #e5e5e5; margin: 10px 40px">
<p style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid" align="center"><font color="#004080"><strong>Pysor Series</strong></font></p>
<ul>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor/">Using IronPython to configure Castle Windsor I</a> : the basic functionality</div>
</li>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor-ii/">Using IronPython to configure Castle Windsor II</a> : parameters and references</div>
</li>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/09/using-ironpython-to-configure-castle-windsor-iii/">Using IronPython to configure Castle Windsor III</a> : arrays and lists</div>
</li>
</ul>
</div>
<p>In the first two articles I introduced Pysor, the Castle Windsor configuration tool using IronPython. Now I have added some exciting functions to exploit the nice hash table and list syntax feature in IronPython.</p>
<p>Since the second part of this series is possible to add (named) parameters to component registration. It accepted only both literal and referential scalars. In the current revision you can exploit the nice list syntax of Python using the square brackets to add arrays and list parameters.</p>
<p>A parameter is a string literal or a reference to an already registered service. This value is supplied either to a constructor parameter with the same name or a property.</p>
<p>A example used in the last part was to provide AdditionalMessage property like this:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:61188c36-e49e-4b97-b748-09082e5f9f68" class="wlWriterSmartContent">
<pre name="code" class="py">add( "retriverWithParam", HtmlTitleRetriever, HtmlTitleRetriever,
	{'AdditionalMessage': "Test"})</pre>
</div>
<p>Now suppose that we have a class that accepts an array of strings in the constructor.&#160; We could provide them using the Python list syntax</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:6ce22de8-54ab-4eb9-834e-317534e9a2f8" class="wlWriterSmartContent">
<pre name="code" class="py">add( "MessageStorage" , MessageStorage, MessageStorage,
	{'messages':['first message', 'second message' ]})</pre>
</div>
<p>This syntax works not only for array but also for ILists.</p>
<p>Things get more interesting when you want to add an array of registered services. The method add returns a hook to the service. You can use this hook to reference the service in the parameters :</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ed959925-8214-46fb-a789-b9e3396b9842" class="wlWriterSmartContent">
<pre name="code" class="py">ftp = add( "ftp", FtpFileDownloader, FtpFileDownloader)

add( "MultipleDowloaderStorage", MultipleDowloaderStorage,
	MultipleDowloaderStorage, {'dowloaders' : [ ftp] })</pre>
</div>
<h3>&#160;</h3>
<h3>Comparison</h3>
<p>In this section I will compare the same configuration using traditional xml syntax and the Pysor syntax. I am sure not every body would prefer Pysor. I am pretty comfortable with xml, yet I don’t like it. I will choose Pysor anyway. In the next section I will make a small project and use both configuration mechanisms and let you find by yourself, which solution is more elegant and appropriate for you.</p>
<p>Not breaking the tradition of almost all IoC tutorials, we will need a logging service to be located dynamically. Additionally we have two implementations: ConsoleLog&#160; and FileLog. FileLog expect a file name in its constructor..</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:edee535f-32ec-4a79-8803-7835c8a31653" class="wlWriterSmartContent">
<pre name="code" class="c#">public interface ILog
{
    void Log(string message);
}

public class FileLog : ILog
{
    private readonly string _fileName;
    public FileLog(string fileName)
    {
        _fileName = fileName;
    }

    public void Log(string message)
    {
        Console.WriteLine(_fileName+ " -&gt; " + message);
    }
}

public class ConsoleLog : ILog
{
    public void Log(string message)
    {
        Console.WriteLine(message);
    }
}</pre>
</div>
<p>In additional we have an <em>IAlgorithm</em> interface with following members:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ba032607-ac95-4193-ab6f-ef6d7f70b391" class="wlWriterSmartContent">
<pre name="code" class="c#">public interface IAlgorithm
{
    event EventHandler OnOperationDone;
    void Run();
}</pre>
</div>
<p><em>Algorithm</em> is a class implementing this interface. <em>AlglorithmRunnner</em> is a class that takes an algorithm with an array of loggers, starts the algorithm and notify all loggers when an event is fired.</p>
<p>Configuring this setup of dependencies in App.config would look much like:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:e178480d-0ce9-42e4-9535-1794371d27d1" class="wlWriterSmartContent">
<pre name="code" class="xml">&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section name="castle" type=
"Castle.Windsor.Configuration.AppDomain.CastleSectionHandler, Castle.Windsor"/&gt;
  &lt;/configSections&gt;

  &lt;castle&gt;
    &lt;components&gt;
      &lt;component id="fileLog"
                 type="CastleComparison.FileLog, CastleComparison"
                 service="CastleComparison.ILog, CastleComparison"&gt;
        &lt;parameters&gt;
          &lt;fileName&gt;log.txt&lt;/fileName&gt;
        &lt;/parameters&gt;
      &lt;/component&gt;

      &lt;component id="consoleLog"
                 type="CastleComparison.ConsoleLog, CastleComparison"
                 service="CastleComparison.ILog, CastleComparison"&gt;
      &lt;/component&gt;

      &lt;component id="algorithm"
                 type="CastleComparison.Algorithm, CastleComparison"
                 service="CastleComparison.IAlgorithm, CastleComparison"&gt;
      &lt;/component&gt;

      &lt;component id="runner"
                 type="CastleComparison.AlgorithmRunner, CastleComparison"&gt;
        &lt;parameters&gt;
          &lt;loggers&gt;
            &lt;array&gt;
              &lt;item&gt;${consoleLog}&lt;/item&gt;
              &lt;item&gt;${fileLog}&lt;/item&gt;
            &lt;/array&gt;
          &lt;/loggers&gt;
        &lt;/parameters&gt;
      &lt;/component&gt;

    &lt;/components&gt;
  &lt;/castle&gt;
&lt;/configuration&gt;</pre>
</div>
<p>On the other hand, configuring it with Pysor is as simple as</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:47566c04-b019-483c-9930-789f78946a4a" class="wlWriterSmartContent">
<pre name="code" class="py">clr.AddReference("CastleComparison")
from CastleComparison import *

fileLog = add("fileLog", ILog, FileLog,
	{"fileName":"log.txt"})
consoleLog = add("consoleLog", ILog, ConsoleLog)

add("algorithm ", IAlgorithm , Algorithm )

add("runner", AlgorithmRunner, AlgorithmRunner,
	{"loggers": [consoleLog, fileLog]})</pre>
</div>
<p>Clearly, I will always choose the second configuration.</p>
<h3>To-do&#8217;s</h3>
<p>The updated to-do list is now</p>
<ul>
<li><span style="text-decoration: line-through">Adding a nicer API for referencing assemblies and importing namespaces</span> (I have now idea how to do it). </li>
<li><span style="text-decoration: line-through">Adding parameters to be passed to the constructor.</span> </li>
<li><span style="text-decoration: line-through">Passing parameters as lists or arrays.</span> </li>
<li>Dictionary based parameters </li>
<li><span style="text-decoration: line-through">Referencing already registered implementation inside the same configuration script.</span> </li>
<li>Documenting and signing the assembly </li>
<li>Lifestyle management </li>
<li>Considering turning Pysor into an Interpreter to be used as the built-in XmlInterpreter </li>
</ul>
<h3>Source Code</h3>
<p>Please don’t forget to download the code from <a href=" https://github.com/mouk/Pysor/ ">GitHub</a> and try it yourself.</p>
<p>All remarks , ideas, bug reports, etc. will be appreciated.</p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/j-Qjnrn2Bsg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/09/using-ironpython-to-configure-castle-windsor-iii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/09/using-ironpython-to-configure-castle-windsor-iii/</feedburner:origLink></item>
		<item>
		<title>xUnit.net and running multiple test assemblies</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/cyrMxkTDgFI/</link>
		<comments>http://abstractast.com/2009/09/xunit-net-and-running-multiple-test-assemblies/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 17:34:38 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Gallio]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[NCover]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[TeamCity]]></category>
		<category><![CDATA[Test]]></category>
		<category><![CDATA[unit]]></category>
		<category><![CDATA[xUnit]]></category>

		<guid isPermaLink="false">http://abstractast.com/2009/09/xunit-net-and-running-multiple-test-assemblies/</guid>
		<description><![CDATA[xUnit.net is a unit testing framework for the .Net platform designed with inspired by some nice ideas like reducing custom attributes, one instance per method , etc. The Internet is full of blog posts and articles about xUnit. In this link you can find a comparison of xUnit and other popular unit testing frameworks. For [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.codeplex.com/xunit">xUnit.net</a> is a unit testing framework for the .Net platform designed with inspired by some nice ideas like reducing custom attributes, one instance per method , etc. The Internet is full of blog posts and articles about xUnit. In this <a href="http://xunit.codeplex.com/Wiki/View.aspx?title=Comparisons&amp;referringTitle=Home">link</a> you can find a comparison of xUnit and other popular unit testing frameworks.</p>
<p>For the CI I use MSBuild script that compiles, runs test, generates documentations, etc.&#160; For test projects I have the habit of postfixing them with &quot;Tests”&#160; to simplify fetching all test dlls in MSBuild scripts using wild cards (Who dares to claim that Convention over Configuration is new in the .Net world? ). Running all NUnit tests in some project would look like :</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:fd8405d6-bdad-4cf5-a85c-c20227d95a22" class="wlWriterSmartContent">
<pre class="xml" name="code">&lt;CreateItem Include=&quot;tests\*\bin\Debug\*.Tests.dll&quot;&gt;
  &lt;Output TaskParameter=&quot;Include&quot; ItemName=&quot;TestAssembly&quot; /&gt;
&lt;/CreateItem&gt;
&lt;NUnit Assemblies=&quot;@(TestAssembly)&quot; ToolPath=&quot;$(NUnit-ToolPath)&quot; /&gt;</pre>
</div>
<p>Adding new test project will require me to add nothing to the build script. I have just to follow the convention.</p>
<p>Unfortunately this is not possible with xUnit task because it accepts only one assembly. Thus I have to specify each assembly separately. The xml result will be also split. <a href="http://twitter.com/bradwilson">@bradwilson</a> nicely wrote me via&#160; Twitter, that I can use a project file to specify multiple assembly.&#160; This, while solving the second problem, doesn’t enable you to use wild cards. You have to add each assembly manually to the project.</p>
<p>Gallio is a tool&#160; or, may better a framework, for running many test frameworks in the same way and provides as unique results format. It integrates also very well with some build servers.</p>
<p>To integrate Gallio in my MSBuild script I downloaded the bits from <a href="http://www.gallio.org/">here</a> and extracted them to the tools folder inside my project root folder.</p>
<p>Running the tests was as simple as</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:5707c53a-fbff-429b-86a7-a4ec182f9f52" class="wlWriterSmartContent">
<pre class="xml" name="code">&lt;UsingTask AssemblyFile=&quot;$(ToolPath)\gallio\Gallio.MSBuildTasks.dll&quot;
	TaskName=&quot;Gallio&quot; /&gt;

&lt;Target Name=&quot;Test&quot; DependsOnTargets=&quot;Build&quot;&gt;
	&lt;Message Text=&quot;==== Starting Gallio to run tests ===&quot; /&gt;

	&lt;CreateItem Include=&quot;tests\*\bin\Debug\*Tests.dll&quot;&gt;
      &lt;Output TaskParameter=&quot;Include&quot; ItemName=&quot;TestAssemblies&quot; /&gt;
    &lt;/CreateItem&gt;
    &lt;Gallio RunnerExtensions=&quot;TeamCityExtension,Gallio.TeamCityIntegration&quot;
        Assemblies=&quot;@(TestAssemblies)&quot;  /&gt;
&lt;/Target&gt;</pre>
</div>
<p><em>RunnerExtensions</em> is an extension for Gallio to provide TeamCity with status messages. Integrating Gallio with TeamCity will be discussed in a following post.</p>
<p>&#160;</p>
<h3>NUnit&#160;&#160; and running multiple assemblies from the console</h3>
<p>Even though NUnit MSBuild task supports multiple assemblies, if you want to use NCover with NUnit&#160; you have to do some manual work to enable NCover running NUnit console tool. The @() operator of MSBuild join all paths with a semicolon. On the other hand NUnit console runner expect all assemblies to be separated with a white space. Fortunately you can tell @() how it should concatenate the paths.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:cfcb8e85-8674-4b37-9ae8-0ae4a90f0d97" class="wlWriterSmartContent">
<pre class="xml" name="code">&lt;NCover ToolPath=&quot;$(NCoverPath)&quot;
        CommandLineExe=&quot;$(NUnit-ToolPath)\nunit-console.exe&quot;
        WorkingDirectory=&quot;.&quot;
        CommandLineArgs=&quot;@(TestDll-&gt;'%(Identity)', ' ')&quot;
        CoverageFile=&quot;$(CoverageFile)&quot;
        LogFile=&quot;$(CoveragePath)\Coverage.log&quot;
        AssemblyList=&quot;@(CoverageDll)&quot; /&gt;</pre>
</div>
<p>In the fourth line @ concatenate the relative path of each file using a white space. You may need to surround each path with a quote if it contains white spaces.</p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/cyrMxkTDgFI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/09/xunit-net-and-running-multiple-test-assemblies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/09/xunit-net-and-running-multiple-test-assemblies/</feedburner:origLink></item>
		<item>
		<title>Using IronPython to configure Castle Windsor II</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/7u4Xofq12-Y/</link>
		<comments>http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor-ii/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 22:36:38 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[IronPython]]></category>
		<category><![CDATA[Windsor]]></category>

		<guid isPermaLink="false">http://abstractast.com/?p=69</guid>
		<description><![CDATA[Pysor Series Using IronPython to configure Castle Windsor I : the basic functionality Using IronPython to configure Castle Windsor II : parameters and references Using IronPython to configure Castle Windsor III : arrays and lists In the last article I introduced a small Castle Windsor configuration tool using IronPython. This tool enabled us to add [...]]]></description>
			<content:encoded><![CDATA[<div style="background-color: #e5e5e5; margin: 10px 40px">
<p style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid" align="center"><font color="#004080"><strong>Pysor Series</strong></font></p>
<ul>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor/">Using IronPython to configure Castle Windsor I</a> : the basic functionality</div>
</li>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor-ii/">Using IronPython to configure Castle Windsor II</a> : parameters and references</div>
</li>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/09/using-ironpython-to-configure-castle-windsor-iii/">Using IronPython to configure Castle Windsor III</a> : arrays and lists</div>
</li>
</ul>
</div>
<p>In the last article I introduced a small Castle Windsor configuration tool using IronPython. This tool enabled us to add service implementation in an easer to read way. On the other hand advanced usages like optional and constructer parameters were not possible.</p>
<p>In this article I will continue developing Pysor (As I called it!) to accept parameters. Before introducing the new functionality I will&#160; show what are parameters and when and how would you want to use them. For the sake of demonstration I will borrow the demo application from the very good <a href="http://dotnetslackers.com/articles/designpatterns/InversionOfControlAndDependencyInjectionWithCastleWindsorContainerPart1.aspx">article</a> series from Simone Busoli about Castle Windsor. If you didn’t read it then go read it all and come back.</p>
<p>The developed application is an html title retriever. It downloads an html string and then extract the title tag from it.&#160; For downloading the the html document it uses an <em>I Downloader</em> service&#160; that accepts an Uri object and downloads it if it can handle the scheme. For Example we have an <em>HtmlDownloader</em>, <em>FileDownloader</em>, etc. The other needed service is <em>ITitleScraper</em> which extract the <em>&lt;title&gt;</em> tag contents.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f754ed02-33f7-417a-9f65-faf81edf2a0b" class="wlWriterSmartContent">
<pre class="c#" name="code">public interface IFileDownloader
{
    string Download(Uri file);
    bool SupportsUriScheme(Uri file);
}

public interface ITitleScraper
{
    string Scrape(string fileContents);
}</pre>
</div>
<p>For the purpose of accelerating the unit tests I changed the downloader to not really download the files but return a fake text instead.</p>
<p>Having the constructor :</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:5e84efd9-b0ca-4634-abcd-26071075727e" class="wlWriterSmartContent">
<pre class="c#" name="code">public HtmlTitleRetriever(IFileDownloader downloader, ITitleScraper scraper)
{
    AdditionalMessage = &quot;&quot;;
    Downloader = downloader;
    Scraper = scraper;
}</pre>
</div>
<p>with AdditionalMessage as a property indicates a short message, that will be concatenated with retrieved tile, we can now configure the container:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:0f5b62a6-3a79-475d-a2b6-96be6b23a659" class="wlWriterSmartContent">
<pre class="py" name="code">add( &quot;parsingScraper&quot; , ITitleScraper, StringParsingTitleScraper)

add( &quot;HttpFileDownloader&quot;, IFileDownloader, HttpFileDownloader)

add( &quot;retriver&quot;, HtmlTitleRetriever, HtmlTitleRetriever)</pre>
</div>
<p>And everything works like expected. Now suppose we want to set the <em>AdditionalMessage</em> for each initiated object. Using xml configuration this could be achieved using a parameters tag&#160; containing all parameters in a dictionary-like fashion.</p>
<p>The most appropriate data structure for this purpose in Python would be a hash which is equivalent to a <em>Dictionary</em> in the .Net&#160; world.</p>
<p>Because C# in the current version doesn’t support optional or named parameters and because I don’t&#160; know whether Python supports method overloading I added a Python method with supply the C# method with default value for missing arguments.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:a51ce9fe-6eef-495b-9b6f-eb51f6131871" class="wlWriterSmartContent">
<pre class="py" name="code">def add(name, service, impl, params={}):
	addComponent(name, service, impl, params)</pre>
</div>
<p>Using this new method you can now set the <em>AdditionalMessage</em> value for each object:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d3598f7b-8b81-42b0-9743-8a1b488e1c62" class="wlWriterSmartContent">
<pre class="py" name="code">add( &quot;retriverWithParam&quot;, HtmlTitleRetriever, HtmlTitleRetriever,
	{'AdditionalMessage': &quot;Test&quot;})</pre>
</div>
<p>We test it with</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d4bb3b25-65d1-4873-9339-7d71140eea40" class="wlWriterSmartContent">
<pre class="c#" name="code">[Test]
public void CanProvideOptionalParameters()
{
    var obj = container.Resolve&lt;HtmlTitleRetriever&gt;(&quot;retriverWithParam&quot;);
    Assert.AreNotEqual(&quot;&quot;, obj.AdditionalMessage);
}</pre>
</div>
<p>And of course it works.</p>
<p>Notice that in line 4 we specified the name of the configuration node to use because have added the service HtmlTitleRetriever twice.</p>
<p>The other use of parameters is to specify an implementation for some service to be used.&#160; If you have for example another <em>IDownloader</em> implementation, that retrieves files sing the ftp protocol and we want to use this implementation for the constructor.&#160; In xml we could do it using <em>${name}</em> to reference the name of an already registered service. In Pysor we can use this notation as well. But to make it more like a usual program I modified the <em>add</em> function to return a string to be used whenever you need to reference this implementation.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:ea561955-ec18-4dcf-a257-c094fd4bd558" class="wlWriterSmartContent">
<pre class="c#" name="code">Func&lt;string, Type, Type, IDictionary&lt;object, object&gt; , string&gt; action =
     (name, service, impl, parameters) =&gt;
         {
             var pairs = parameters.ToList();
             var reg = Component
                 .For(service)
                 .ImplementedBy(impl)
                 .Named(name);

             if (pairs.Count &gt; 0)
             {
                 var param = (from pair in pairs
                              select Parameter
                                 .ForKey(pair.Key.ToString())
                                 .Eq(pair.Value.ToString())
                             ).ToArray();
                 reg = reg.Parameters(param);
             }

             container.Register(reg);
             return &quot;${&quot; + name + &quot;}&quot;;
         };

 //Inject this function into IronPython runtime
scope.SetVariable(&quot;addComponent&quot;, action);</pre>
</div>
<p>And the Python wrapper function looks now like:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:2c18f072-fac9-4253-9887-cc45b50742d9" class="wlWriterSmartContent">
<pre class="py" name="code">def add(name, service, impl, params={}):
	return addComponent(name, service, impl, params)</pre>
</div>
<p>We are now ready to register a retriever that uses a concrete implementation:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:cf9a2113-c617-4c5a-9346-b9e6daf40952" class="wlWriterSmartContent">
<pre class="py" name="code">ftp = add( &quot;ftp&quot;, FtpFileDownloader, FtpFileDownloader)

add( &quot;ftpRetriver&quot;, HtmlTitleRetriever, HtmlTitleRetriever,
	{'downloader': ftp})</pre>
</div>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:53645658-3210-42d6-95fd-87aca0d47629" class="wlWriterSmartContent">
<pre class="c#" name="code">[Test]
public void CanProvideSpecificImplimentationParameters()
{
    var obj = container.Resolve&lt;HtmlTitleRetriever&gt;(&quot;ftpRetriver&quot;);
    Assert.IsInstanceOf&lt;FtpFileDownloader&gt;(obj.Downloader);
}</pre>
</div>
<p>We are finished for now.</p>
<h3>&#160;</h3>
<h3>To-do&#8217;s</h3>
<p>The updated to-do list is now</p>
<ul>
<li>Adding a nicer API for referencing assemblies and importing namespaces. </li>
<li><span style="text-decoration: line-through">Adding parameters to be passed to the constructor.</span> </li>
<li><span style="text-decoration: line-through">Referencing already registered implementation inside the same configuration script.</span> </li>
<li>Lifestyle management </li>
</ul>
<h3>Source Code</h3>
<p>The source code of Pysor is available to download from GitHub</p>
<p><a href="https://github.com/mouk/Pysor/">https://github.com/mouk/Pysor/</a></p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/7u4Xofq12-Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor-ii/</feedburner:origLink></item>
		<item>
		<title>Using IronPython to configure Castle Windsor I</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/MC7LCnT59hI/</link>
		<comments>http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 21:18:40 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Castle]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[IoC]]></category>
		<category><![CDATA[IronPython]]></category>
		<category><![CDATA[Windsor]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://abstractast.com/?p=50</guid>
		<description><![CDATA[Pysor Series Using IronPython to configure Castle Windsor I : the basic functionality Using IronPython to configure Castle Windsor II : parameters and references Using IronPython to configure Castle Windsor III : arrays and lists Castle Windsor is a very popular IoC container in the .Net world. Like almost all other containers it can be [...]]]></description>
			<content:encoded><![CDATA[</p>
<div style="background-color: #e5e5e5; margin: 10px 40px">
<p style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid" align="center"><font color="#004080"><strong>Pysor Series</strong></font></p>
<ul>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor/">Using IronPython to configure Castle Windsor I</a> : the basic functionality</div>
</li>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor-ii/">Using IronPython to configure Castle Windsor II</a> : parameters and references</div>
</li>
<li>
<div style="border-bottom-style: solid; border-right-style: solid; border-top-style: solid; border-left-style: solid"><a href="http://abstractast.com/2009/09/using-ironpython-to-configure-castle-windsor-iii/">Using IronPython to configure Castle Windsor III</a> : arrays and lists</div>
</li>
</ul></div>
<p>Castle Windsor is a very popular IoC container in the .Net world. Like almost all other containers it can be configured using either a fluent interface or an xml-based configuration file.</p>
<p>The fluent interface has the advantage of being strongly typed, what spares you a lot of errors caused by typos. On the other hand, it is hard coded and can’t be changed easily without recompiling (Actually you could use an IoC container to load you IoC container configuration dynamically but it give a rise to the question: “How do configure the container to load its own configuration?” <img src='http://abstractast.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />  )</p>
<p>The other option is to use an xml file. Despite being the most used solution in almost all containers it is really a very ugly solution. The configuration file can get very big and very complicated.</p>
<p>As I am reading <a href="http://www.manning.com/foord/">IronPython</a> in Action from Manning Publications, I thought I could configure Windsor using Python and a very tiny DSL. IronPython is an interpreted language for .Net framework. It combines the elegance of Python with the strength of .Net. Since it being interpreted it is a suitable solution for configuration.</p>
<p>For the beginning I will start with a simple solution, that can configure basic service without an enough for me to be able to configure just basic services without parameter zing. The syntax for configuring a simple implementation in Castle looks like:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:bf6ad6ce-079b-4a50-8af3-cca3a4651ffa" class="wlWriterSmartContent">
<pre class="c#" name="code">container.AddComponent(&quot;service.name&quot;
				typeof(IService&gt;),
				typeof(Implementation));</pre>
</div>
<p>Of course there is a whole bunch of other&#160; settings like lifestyle and parameters, but I will ignore that for now.</p>
<p>Analyzing this one line I realized that all I need is a function with three arguments: the name of the coupling, the service type and the implementation type. SoI coded thus a function in C#:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:1c24cf43-d9da-407e-8c96-debf6b628784" class="wlWriterSmartContent">
<pre class="c#" name="code">private static void ConfigureContainer(IWindsorContainer container, string scriptPath)
{
	var engine = Python.CreateEngine();
    var runtime = engine.Runtime;
    var scope = runtime.CreateScope();
    scope.SetVariable(&quot;__main__&quot;, &quot;__main__&quot;);
    Action&lt;string, Type, Type&gt; action =
			(name, service, impl)=&gt;
				container.AddComponent(name, service, impl);

	//Inject this function into IronPython runtime
    scope.SetVariable(&quot;add&quot;,action);
    var script = engine.CreateScriptSourceFromFile(scriptPath);
    var code = script.Compile();
    code.Execute(scope);
}</pre>
</div>
<p>To test this DSL I wrote a simple interface with a single implementation to bind them with Python.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:b71804f3-a8bc-46a3-900e-fd1c10257c62" class="wlWriterSmartContent">
<pre class="c#" name="code">namespace PythonConfig
{
    public interface IDependency
    {
        string Name
        { get; }
    }
    public class Dependency : IDependency
    {
        public string Name
        {
            get { return &quot;Default&quot;; }
        }
    }
}</pre>
</div>
<p>And the Python configuration is just as simple as</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d702a191-18a6-43c3-aca8-da8ea82ed00a" class="wlWriterSmartContent">
<pre class="py" name="code">import clr
clr.AddReference(&quot;PythonConfig&quot;)
from PythonConfig import *

add(&quot;name&quot; , IDependency, Dependency)</pre>
</div>
<p>Now everything is ready. You can configure the container using this file:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:cbe9c720-076b-4feb-aaf3-25a83b30b9cb" class="wlWriterSmartContent">
<pre class="c#" name="code">static void Main(string[] args)
{
    var container = new WindsorContainer();
    ConfigureContainer(container, &quot;script.py&quot;);

    var depend= container.Resolve&lt;IDependency&gt;();
    Console.WriteLine(depend.Name);
    Console.ReadLine();
}</pre>
</div>
<p>And … it works as expected!</p>
<h3>Todo’s</h3>
<p>I am very aware that this implementation is very limited and incomplete. It is just enough for my needs (That’s how DSL ought to be). Nevertheless, I will try to add some of the missing features. In particularly following&#160; functionalities will be considered very soon:</p>
<ul>
<li>Adding a nicer API for referencing assemblies and importing namespaces. </li>
<li>Adding parameters to be passed to the constructor. </li>
<li>Referencing&#160; already registered implementation inside the same configuration script. </li>
<li>Lifestyle management </li>
</ul>
<h3>Links</h3>
<ul>
<li><a href="http://ironpython.codeplex.com/">IronPython</a>’s page on Codeplex. </li>
<li><a href="http://www.amazon.com/IronPython-Action-Michael-Foord/dp/1933988339">IronPython in Action</a> an excellent (and <span style="text-decoration: line-through">currently the only</span> the first) IronPython book by <a href="http://www.voidspace.org.uk/">Michael Foord</a>. </li>
<li><a href="http://ayende.com/Blog/archive/2006/09/16/IntroductingBinsorTheBooDSLForWindsor.aspx">Binsor</a>: a <a href="http://boo.codehaus.org/">Boo</a> based DSL for Windsor by <a href="http://www.Ayende.com/Blog">Ayende</a>. </li>
</ul>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/MC7LCnT59hI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/08/using-ironpython-to-configure-castle-windsor/</feedburner:origLink></item>
		<item>
		<title>Comparison of some popular pastebins</title>
		<link>http://feedproxy.google.com/~r/kabbash/~3/x9WgoiNRAD4/</link>
		<comments>http://abstractast.com/2009/08/comparison-of-some-popular-pastebins/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 16:17:25 +0000</pubDate>
		<dc:creator>Moukarram Kabbash</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[codepaste]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[gist]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[paste]]></category>
		<category><![CDATA[paste-it]]></category>
		<category><![CDATA[pastebin]]></category>
		<category><![CDATA[pastie]]></category>

		<guid isPermaLink="false">http://abstractast.com/?p=33</guid>
		<description><![CDATA[Recently I have seen a lot of links, especially on twitter, to some pieces of code hosted on some online code sites. I really liked the idea and started to use those site. Later on I discovered that they are called pastebins&#160; and have been existing for a long time, mainly among the IRC community. [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have seen a lot of links, especially on twitter, to some pieces of code hosted on some online code sites. I really liked the idea and started to use those site. Later on I discovered that they are called <a href="http://en.wikipedia.org/wiki/Pastebin">pastebins</a>&#160; and have been existing for a long time, mainly among the IRC community. </p>
<p>Because each time I wanted to use this service, I wondered which one to use, I decided to do some comparison and&#160; outline the differences.&#160; Thus picked the ones I have most seen or used and compared them with each other. My chosen pastebins are:</p>
<ul>
<li><a href="http://paste-it.net">paste-it.net</a> </li>
<li><a href="http://pastie.org/">pastie.org</a> </li>
<li><a href="http://codepaste.net">codepaste.net</a> </li>
<li><a href="http://gist.github.com">gist.github.com</a> </li>
</ul>
<h2>&#160;</h2>
<h2>Paste-it.net</h2>
<p><a href="http://paste-it.net">Paste-it.net</a> supports a very large number of languages.&#160; Almost all popular languages can be chosen from the list. Just as an example : C#, VB.NET Ruby, Java, Django, xml, etc.&#160; There are even some languages I have ever heard of. I Didn’t know for example that vim is a language. </p>
<p>Beside the big number of supported languages I like ability to set an expiration date at most. If you need to send some co-workers a small piece of code of some internal project and don’t want it to be persisted this option helps you minimizing this risk.&#160; Paste some code and make it disappear after one day. </p>
<p><a href="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/pasteit.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="paste-it" border="0" alt="paste-it" src="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/pasteit_thumb.jpg" width="554" height="303" /></a> </p>
<p>The other interesting option is the hidden check box,&#160; with which you could hide your paste. I am not really sure how this works. You still can access this post without a password. I guess, it just will prevent you past from being listed.</p>
<p>When viewing a piece of code on paste-it.net you can change the language any time you wish. Beside this ability, you can’t change the theme.&#160; You have always the basic theme with a light background. For my this is almost always just fine. You could also view the raw code, download it as a text file of tweet it.</p>
<p>Right to the code you get a whole bunch of Google ads. All ads are in text format with no blinking or moving party, yet a really whole bunch of them.</p>
<h2>&#160;</h2>
<h2>Pastie.org</h2>
<p><a href="http://pastie.org">Pastie.org</a> is another simple and easy to use pastebin.&#160; The first thing took my attention was the absent of C#&#160; support (and actually all other .NET languages too) . I don’t thing adding support for C# will cause the developers any more effort. They could just the use theme of java for now.&#160; On the other hand, you can choose Pascal if you wish. Ruby, RoR, C++, etc. are some of the supported languages.</p>
<p><a href="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/pastie.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="pastie" border="0" alt="pastie" src="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/pastie_thumb.jpg" width="554" height="301" /></a> </p>
<p>Pastie allows you as well to hide you pastes. On the other hand, it not possible to make the pastes expire after some period of time.&#160; When making a paste private, it gets a very harder name to guess instead of the usual serial number.</p>
<p>In addition to posting a link to your paste you can also embed it in your html. Pastie gives you a small html snippet to a JavaScript file, that inject the code inside of the Dom. Oddly enough when&#160; you make a paste private you still get the snippet to embed, but it does nothing. It&#8217;s Pretty confusing the first time you see it. The public ones will work and display the code properly if you have a lot of horizontal space and don’t have complicated style sheets.&#160; For this blog it failed miserably.</p>
<p>Another nice feature is the ability to change the theme on the fly. Not very crucial for me, but it still yet nice feature to have.</p>
<p><a href="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/pastieembedded.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="pastie-embedded" border="0" alt="pastie-embedded" src="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/pastieembedded_thumb.jpg" width="554" height="296" /></a> </p>
<p>For making a bundle of code you Pastie provides you with the ability to define different sections inside your paste and giving each section a title.&#160; One limitation of this feature is that you cannot chose different language for each section. That means you cannot paste the controller code and the mark up of some mvc page.</p>
<p>One graphical ad is shown decently on the right bar. Nothing else.</p>
<h2>&#160;</h2>
<h2>Codepaste.net</h2>
<p><a href="http://Codepaste.net ">Codepaste.net</a> is a .Net oriented pastebin.&#160; It supports all major .Net languages with some other languages, that may be used during .Net development like JavaScript, Powershell, xml, etc. Support for C++ and Java is also available. </p>
<p>Because of it lack of hiding and expiration settings it is really easy to go. Just paste a snippet, give it a title, choose the language&#160; and push the button. Some other optional information like author name and tags can be provided. After posting the code I couldn’t see anyway to edit the paste. Anyway you can register and log in to manage your pastes. </p>
<p><a href="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/codepastenetscreeenshot.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="codepaste-net-screeenshot" border="0" alt="codepaste-net-screeenshot" src="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/codepastenetscreeenshot_thumb.jpg" width="554" height="302" /></a> </p>
<p>Beside “recent posts” codepaste.net provides also feed to pastes. I have no idea why anyone would like to subscribe to some bunch of non-related code snippets. </p>
<p>A very interesting feature is its API. It provides access to looking up, searching and posting.&#160; This may be very useful for integrating in other application like twitter clients. just like the URLs shorteners. </p>
<p>Unfortunately codepaste.net doesn’t provide a link to the raw source code, what makes copying some piece of the code a bit harder.</p>
<h2>&#160;</h2>
<h2>gist.github.com</h2>
<p><a href="http://gist.github.com">gist.github.com</a> is a service from Github, the popular project hosting service. When using gist you get all benefits of Github. Each snippet you post to gist become a Git repository with all the known capabilities like cloning, editing and pushing. Taking the embedding facility into consideration, gist.github.com is a very powerful way to post code into some html page and keeping it up to date.</p>
<p><a href="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/gist.github.screenshot.jpg"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="gist.github.screenshot" border="0" alt="gist.github.screenshot" src="http://abstractast.com/images/ComparisonofOnlineCodePastePlatforms_12FD4/gist.github.screenshot_thumb.jpg" width="554" height="303" /></a> </p>
<p>&#160;</p>
<h2>Links</h2>
<p>Wikipedia has also an <a href="http://en.wikipedia.org/wiki/Comparison_of_pastebins">article</a> comparing some other pastebins. </p>
<img src="http://feeds.feedburner.com/~r/kabbash/~4/x9WgoiNRAD4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://abstractast.com/2009/08/comparison-of-some-popular-pastebins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://abstractast.com/2009/08/comparison-of-some-popular-pastebins/</feedburner:origLink></item>
	<copyright>© Copyright 2009, Moukarram Kabbash</copyright><media:rating>nonadult</media:rating></channel>
</rss><!-- Dynamic page generated in 1.645 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-16 15:51:56 --><!-- Compression = gzip -->
