<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><!-- generator="wordpress/2.1" --><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/" version="2.0">

<channel>
	<title>Paul Stovell says...</title>
	<link>http://www.paulstovell.com/blog</link>
	<description>Learning Out Loud</description>
	<pubDate>Mon, 06 Oct 2008 14:16:01 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1</generator>
	<language>en</language>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/paulstovell" type="application/rss+xml" /><item>
		<title>Projects: The TODO List</title>
		<link>http://www.paulstovell.com/blog/projects-the-todo-list-help</link>
		<comments>http://www.paulstovell.com/blog/projects-the-todo-list-help#comments</comments>
		<pubDate>Mon, 06 Oct 2008 14:12:16 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Projects]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/projects-the-todo-list-help</guid>
		<description><![CDATA[I have a list of open source/community code I&#8217;d like to finish off and publish, but not enough time coming up:

Updated Validation library for WPF/Silverlight. A long time ago I wrote an article on WPF Validation, including a custom ErrorProvider. There are a number of issues and limitations with the inbuilt WPF validation, even in [...]]]></description>
			<content:encoded><![CDATA[<p>I have a list of open source/community code I&#8217;d like to finish off and publish, but not enough time coming up:</p>
<ol>
<li><strong>Updated Validation library for WPF/Silverlight</strong>. A long time ago I wrote an article on <a href="http://www.codeproject.com/KB/WPF/wpfvalidation.aspx">WPF Validation, including a custom ErrorProvider</a>. There are a number of issues and limitations with the inbuilt WPF validation, even in the latest incarnation of the framework, and so I&#8217;ve updated the ErrorProvider control and done significant performance tuning to really take it to the next level. Features include error summaries, hints, support for many validation sources (IDataErrorInfo, Validation Application Block, your own system via a plugin), and control over when validation takes place (automatic, explicit, or only when a control has had focus). I just have to document it and publish it somewhere. </li>
<li><strong>A WPF/Silverlight SiteMap library</strong>. I tried to capture many common features of site map systems, like support for dynamic/static site maps and changes to the site map structure (via Bindable LINQ, of course :-)) but I would probably approach this as more of a CodeProject guide rather than a CodePlex library. </li>
<li><strong>Next version of Bindable LINQ</strong>. I&#8217;ve been working on the documentation here for a while and making a few improvements here and there, and I&#8217;d like to get it to a &quot;1.0&quot; status and freeze the API a little better. </li>
<li><strong>WPF/Silverlight Forms library</strong>. A library of useful abstractions over common tasks such as building input forms. Code is written, just need to publish it and build some samples. </li>
</ol>
<p>I&#8217;m thinking of combining them all (except Bindable LINQ, of course) into one Codeplex library. </p>
<p>Which of these would you like to see first? And are you interested in helping to get them over the line? </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=zWtUM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=zWtUM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=C6XbM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=C6XbM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=9emhm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=9emhm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=nsSRm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=nsSRm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/projects-the-todo-list-help/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DHH: The Great Surplus</title>
		<link>http://www.paulstovell.com/blog/dhh-the-great-surplus</link>
		<comments>http://www.paulstovell.com/blog/dhh-the-great-surplus#comments</comments>
		<pubDate>Sun, 05 Oct 2008 16:59:52 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Commentary]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/dhh-the-great-surplus</guid>
		<description><![CDATA[There&#8217;s a great recording of a David Heinemeier Hansson talk (the Rails guy) on ITConversations. I think he&#8217;d make a great keynote speaker, though I&#8217;m not expecting to see him at the Tech.ED 2009 keynote. The talk is titled the Great Surplus, and although the talk description paints it as a heavy Rails talk, it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a great <a href="http://itc.conversationsnetwork.org/shows/detail3762.html">recording of a David Heinemeier Hansson talk</a> (the Rails guy) on ITConversations. I think he&#8217;d make a great keynote speaker, though I&#8217;m not expecting to see him at the Tech.ED 2009 keynote. The talk is titled the Great Surplus, and although the talk description paints it as a heavy Rails talk, it&#8217;s a very interesting talk on framework design in general, and more importantly, about reinvesting the savings you make in picking good technology by investing in yourself. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=uVfzM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=uVfzM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=4eNoM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=4eNoM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=JmXum"><img src="http://feeds.feedburner.com/~f/paulstovell?i=JmXum" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=r14xm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=r14xm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/dhh-the-great-surplus/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bindable LINQ: Getting Started</title>
		<link>http://www.paulstovell.com/blog/bindable-linq-getting-started</link>
		<comments>http://www.paulstovell.com/blog/bindable-linq-getting-started#comments</comments>
		<pubDate>Fri, 03 Oct 2008 03:24:43 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Bindable LINQ]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/bindable-linq-getting-started</guid>
		<description><![CDATA[Continuing the documentation theme, this is the &#34;getting started&#34; page from the CHM. Please note that some of the links are broken; they&#8217;re designed to link to different pages within the CHM which I haven&#8217;t written yet. Question: should I include a VB.NET version of the guide (on a different page)? 
This step-by-step guide will [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing the documentation theme, this is the &quot;getting started&quot; page from the CHM. Please note that some of the links are broken; they&#8217;re designed to link to different pages within the CHM which I haven&#8217;t written yet. Question: should I include a VB.NET version of the guide (on a different page)? </p>
<p>This step-by-step guide will walk you through setting up your first project using Bindable LINQ. </p>
<h2>Scenario</h2>
<p>In this walkthrough you will create a new Windows Presentation Foundation project which uses Bindable LINQ to filter an array of strings as a user types. </p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/window1.jpg"><img height="124" alt="Window1" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/window1-thumb.jpg" width="325" border="0" /></a> </p>
<h2>Requirements</h2>
<p>Bindable LINQ is compatible with the .NET Framework version 3.5 and above. To follow this guide, you will need to install Microsoft Visual Studio 2008 Standard edition, or you can install the free editions of <a href="http://www.microsoft.com/express/vcsharp/">Microsoft Visual C#/VB.NET 2008 Express</a>.</p>
<h2>Steps</h2>
<ol>
<li><strong>Download Bindable LINQ</strong>      <br />You can either download the latest stable release from the Codeplex <a href="http://www.codeplex.com/bindablelinq/Release/ProjectReleases.aspx" target="_blank">releases page</a>, or download the latest source code and build it yourself. To compile the project yourself, read the section &quot;<a href="PTMFOG0000000044">Building Bindable LINQ</a>&quot;. </li>
<li><strong>Create a new WPF Application project</strong>      <br />Using any edition of Visual Studio 2008 which supports WPF, create a new WPF Application project using either C# or VB.NET.      <br /><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/newproject.jpg"><img height="141" alt="NewProject" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/newproject-thumb.jpg" width="430" border="0" /></a> </li>
<li><strong>Add a reference to Bindable LINQ</strong>      <br />Extract the downloaded archive of Bindable LINQ to a folder of your choosing, or if you built it yourself, locate the build outputs folder (see the <a href="PTMFOG0000000044">Building Bindable LINQ</a> page for details). From Visual Studio, select <em>Add Reference&#8230;</em>      <br /><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/addproject.png"><img height="112" alt="AddProject" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/addproject-thumb.png" width="291" border="0" /></a>      <br />From the Browse tab, navigate to the Bindable LINQ directory and add a reference to <strong>Bindable.LINQ.dll</strong>. This is the only reference you will need.      <br /><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/addreference2.png"><img height="192" alt="AddReference2" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/addreference2-thumb.png" width="319" border="0" /></a></li>
<li><strong>Build the GUI</strong>      <br />You will need a ListBox to show the list of names, and a TextBox to filter them.      <br /> 
<pre>&lt;DockPanel&gt;
    &lt;TextBox x:Name=&quot;_textBox1&quot; DockPanel.Dock=&quot;Top&quot; /&gt;
    &lt;ListBox x:Name=&quot;_listBox1&quot; /&gt;
&lt;/DockPanel&gt;</pre>
</li>
<li><strong>Add a using directive for the core Bindable LINQ namespace</strong>
<p>In order to use Bindable LINQ, you will need to add a &quot;using&quot; entry for the Bindable.Linq namespace:</p>
<p></p>
<pre>using Bindable.Linq;</pre>
</li>
<li><strong>Initialize a list of names and write the query&#160; </strong>
<p>Create an array of first names, and then use a Bindable LINQ query to filter and order them.</p>
<p></p>
<pre>public Window1()
{
    InitializeComponent();

    var names = new [] { &quot;Paul&quot;, &quot;Michael&quot;, &quot;Sally&quot;, &quot;Sally&quot;, &quot;Mary&quot; };
    _listBox1.ItemsSource = from n in names.AsBindable()
                            where n.StartsWith(
                                _textBox1.Text,
                                StringComparison.CurrentCultureIgnoreCase
                                )
                            orderby n
                            select n;
}</pre>
</li>
<li><strong>Run!</strong>
<p>The application should compile and run at this point. As you type in the TextBox, Bindable LINQ will detect changes to the TextBox (since you called it from your &quot;where&quot; query), and will re-evaluate the items in the collection. </li>
</ol>
<p>It&#8217;s that easy. To see the experience of using standard LINQ to Objects, remove the &quot;AsBindable&quot; call and run the query again.</p>
<p>To see more ways to use Bindable LINQ, see the <a href="PTMFOG0000000038">Examples</a>, <a href="PTMFOG0000000040">Sample Applications</a>, or <a href="PTMFOG0000000072">Bindable LINQ Patterns</a> pages. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=mrUFM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=mrUFM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=4jqNM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=4jqNM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=Sazwm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=Sazwm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=evLvm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=evLvm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/bindable-linq-getting-started/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bindable LINQ: F# is Overhyped</title>
		<link>http://www.paulstovell.com/blog/bindable-linq-f-is-overhyped</link>
		<comments>http://www.paulstovell.com/blog/bindable-linq-f-is-overhyped#comments</comments>
		<pubDate>Wed, 01 Oct 2008 15:14:29 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Bindable LINQ]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/bindable-linq-f-is-overhyped</guid>
		<description><![CDATA[You can&#8217;t walk down the street these days without being told that F# is the next big thing. It&#8217;s easy to be taken in by the pomp and pageantry surrounding the functional programming paradigm, and in many ways it&#8217;s a bit of an emperor&#8217;s new clothes dilemma: most people can see functional programming is, for [...]]]></description>
			<content:encoded><![CDATA[<p>You can&#8217;t walk down the street these days without being told that F# is the next big thing. It&#8217;s easy to be taken in by the pomp and pageantry surrounding the functional programming paradigm, and in many ways it&#8217;s a bit of an <a href="http://en.wikipedia.org/wiki/The_Emperor%27s_New_Clothes">emperor&#8217;s new clothes dilemma</a>: most people can see functional programming is, for the most part, <strong>useless</strong>, but no one wants to admit it <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>What some people (mostly people on the CLR and C# language team) forget, is that there are alternatives to console applications. Here&#8217;s the typical User Experience of an F# program:</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/image1.png"><img height="99" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/image-thumb1.png" width="699" border="0" /></a> </p>
<p>There&#8217;s only one thing that&#8217;s constant in our world: change. Inputs change, assumptions change. So why is everyone so enthralled with a programming paradigm that has such abysmal support for handling change? </p>
<p>Your highly concurrent, lambda powered, currying pattern-matching data analysis algorithm, running over 87 threads and 8 cores, is a pretty good effort. But once it&#8217;s analysed the 3,000,000 visits to your web site and told you what products to put on discount, what happens to the 3,000,001&#8242;th visitor? Well, once your functional code arrived at a result, it kinda forgot how it got there. So you have to run the whole thing again for a minor change in the inputs. </p>
<p>Wouldn&#8217;t it be great if you could write code in a functional programming language, but which automatically detected changes and re-evaluated itself? A kind of <a href="http://www.addsimplicity.com/adding_simplicity_an_engi/2008/09/are-data-wareho.html">event stream processor</a>. As visits come in your algorithm is being constantly evaluated, quickly, and the results updated. It&#8217;s the difference between being able to react in real-time, and having to wait for the hourly report to be generated. </p>
<p>As it turns out, there&#8217;s a paradigm for that: it&#8217;s called <em><a href="http://en.wikipedia.org/wiki/Functional_reactive_programming">functional <strong>reactive </strong>programming</a></em>. And unlike normal functional programming, it actually has uses outside of console applications <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>F# developers go gaga over pattern matching:</p>
<pre>let getWarningMessageAboutTooManyToppings toppings =
  match toppings with
  | 0 -&gt; &quot;You didn't select any toppings&quot;
  | 1 -&gt; &quot;You should have more toppings&quot;
  | _ when toppings &lt; 5 -&gt; &quot;That's a healthy number of toppings&quot;
  | _ -&gt; &quot;Too many toppings on your pizza, fatboy&quot; </pre>
<p>Now that&#8217;s great, but what happens when I select a new topping? I guess that&#8217;s what &quot;Refresh&quot; buttons are for. </p>
<p>Here&#8217;s a functional reactive version of pattern matching, supported via Bindable LINQ&#8217;s Switch operator (you&#8217;ll find this in the PizzaLinq sample application in the Bindable LINQ code). </p>
<pre>_healthWarningMessage = _selectedToppings.Count().Switch(
    Case.When&lt;int, string&gt;(toppings =&gt; toppings &lt; 1,
        &quot;Surely you would like more toppings?&quot;
        ),
    Case.When&lt;int, string&gt;(toppings =&gt; toppings &gt;= 3,
        &quot;You have too many toppings!&quot;
        ),
    Case.Default&lt;int, string&gt;(
        &quot;Just right!&quot;
        )
    );</pre>
<p>In Bindable LINQ, when I select a topping on the UI the result of the Count() call will change, which will re-evaluate the Switch operator and return me a different message. There&#8217;s no Refresh buttons and no code to wire it up. It&#8217;s functional, but it&#8217;s also useful. </p>
<p>If you could get enough programmers working on a reactive .NET language, it&#8217;s conceivable that you could combine the implicit parallelism of functional languages with reactive languages in order to process changes and have a result that&#8217;s continually updated from multiple threads. Unfortunately, all the smart developers are focused right now on a paradigm that&#8217;s severely limited to back-end or discreet, point-in-time operations, rather than a more wide-ranging paradigm like that of functional reactive programming. </p>
<p>If you&#8217;re a language wonk and you&#8217;re considering learning F# and functional programming for fun, consider reactive programming instead. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=68KgM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=68KgM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=KDSBM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=KDSBM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=GPLXm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=GPLXm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=BQctm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=BQctm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/bindable-linq-f-is-overhyped/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bindable LINQ: What is Bindable LINQ?</title>
		<link>http://www.paulstovell.com/blog/bindable-linq-what-is-bindable-linq</link>
		<comments>http://www.paulstovell.com/blog/bindable-linq-what-is-bindable-linq#comments</comments>
		<pubDate>Wed, 01 Oct 2008 14:03:14 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Bindable LINQ]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/bindable-linq-what-is-bindable-linq</guid>
		<description><![CDATA[I am writing a set of documentation for Bindable LINQ which will be available via the web or as a downloadable CHM. I&#8217;ll blog each part as I go for feedback. Here&#8217;s an outline:
 
Below is the &#34;Bindable LINQ/Background&#34; page, which describes what Bindable LINQ is. What do you think? 
Overview
Bindable LINQ bridges the object-oriented [...]]]></description>
			<content:encoded><![CDATA[<p>I am writing a set of documentation for Bindable LINQ which will be available via the web or as a downloadable CHM. I&#8217;ll blog each part as I go for feedback. Here&#8217;s an outline:</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/image.png"><img height="384" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/10/image-thumb.png" width="257" border="0" /></a> </p>
<p>Below is the &quot;Bindable LINQ/Background&quot; page, which describes what Bindable LINQ is. What do you think? </p>
<h2>Overview</h2>
<p>Bindable LINQ bridges the object-oriented world of .NET, and the paradigm of reactive programming. While the procedural, object oriented or functional programming paradigms focus on <em>discreet evaluation</em> of code, the reactive programming paradigm instead focuses on <em>continuous evaluation,</em> and <em>propagation of change</em>. Bindable LINQ leverages the syntax of LINQ and the platform support of Data Binding to enable advanced scenarios that would otherwise require reams of code.</p>
<p>Bindable LINQ is <strong>not</strong> a library for querying databases or web services. For more information on where Bindable LINQ fits into your application architecture, see the section on <a href="PTMFOG0000000072">Bindable LINQ patterns</a>.</p>
<h2>Reactive Programming</h2>
<p>To understand the difference between discreet and continuous evaluation, consider the following C# code:</p>
<pre>decimal total = 0;
IList&lt;LineItem&gt; lineItems = ...;
foreach (var item in lineItems)
{
    total += item.Quantity * item.Price;
}</pre>
<p>The value of the <strong>total</strong> is <em>derived</em> from the <strong>lineItems</strong> collection. But in this case, once the <em>foreach</em> loop has completed and the total variable assigned, this relationship is lost. If the lineItems collection, from which the total was derived from, changes, the total will not change. You can think think of this code as representing a &quot;point-in-time&quot; snapshot of the total.</p>
<p>In a reactive programming language, the relationship between the source - lineItems - and the destination - total - should be maintained at all times, and changes to the source should be propagated.</p>
<p>Bindable LINQ allows you to use the familiar syntax of LINQ queries in a reactive programming way. For example, the order totaling code above could be written in Bindable LINQ as:</p>
<pre>ObservableCollection&lt;LineItem&gt; lineItems = ...;
IBindable&lt;decimal&gt; total = lineItems.AsBindable().Sum(li =&gt; li.Quantity * li.Price);</pre>
<h2>LINQ</h2>
<p>LINQ to Objects is an implementation of LINQ that ships with the .NET Framework and allows querying over in-memory collections such as generic Lists or Arrays. However, once the query has been evaluated and the results have been yielded, subsequent changes to the source collection are not propagated. LINQ to Objects is a purely discreet evaluation and assignment construct.</p>
<p>Bindable LINQ follows the same rules as other LINQ providers and works in-memory, just like LINQ to Objects, except the relationship to the source collection is changed. When the source collection raises events indicating that something has changed, Bindable LINQ will propagate the changes throughout the LINQ query, evaluate the changes, and any derived values will be updated.</p>
<h2>Data Binding</h2>
<p>Data Binding is a UI platform technology that allows properties of UI controls to be synchronized with properties of objects. To facilitate propagation of change, these objects can implement a number of interfaces, primarily <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx">INotifyPropertyChanged</a>, <a href="http://msdn.microsoft.com/en-us/library/system.componentmodel.ibindinglist.aspx">IBindingList</a> and <a href="http://msdn.microsoft.com/en-us/library/system.collections.specialized.inotifycollectionchanged.aspx">INotifyCollectionChanged</a>.</p>
<p>Bindable LINQ queries implement these data binding interfaces so that UI controls can be connected and kept in-sync with Bindable LINQ queries automatically. This leverages the platform&#8217;s support for data binding, while removing the limitation of data binding patterns as a UI-control level only concept.</p>
<h2>Summary</h2>
<p>Bindable LINQ leverages the familiar syntax of LINQ and the platform&#8217;s support for data binding to bring reactive programming to the .NET Framework. You express what you need, and Bindable LINQ takes care of wiring up event handlers, detecting changes and the complexities of propagating those changes. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=YQSTM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=YQSTM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=vReiM"><img src="http://feeds.feedburner.com/~f/paulstovell?i=vReiM" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=PmIvm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=PmIvm" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=XyXYm"><img src="http://feeds.feedburner.com/~f/paulstovell?i=XyXYm" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/bindable-linq-what-is-bindable-linq/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WPF: Colour Blindness Shader Effect</title>
		<link>http://www.paulstovell.com/blog/wpf-colour-blindness-shader-effect</link>
		<comments>http://www.paulstovell.com/blog/wpf-colour-blindness-shader-effect#comments</comments>
		<pubDate>Mon, 22 Sep 2008 23:05:41 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/wpf-colour-blindness-shader-effect</guid>
		<description><![CDATA[How does your application look to people with colour blindness? 
Joseph Cooney launched a community project last week to create a repository of useful pixel shader effects for WPF. It&#8217;s already got a number of effects, including a very cool radial blur effect. Rather than just blogging a link, I wanted to contribute to the [...]]]></description>
			<content:encoded><![CDATA[<p>How does your application look to people with colour blindness? </p>
<p><a href="http://www.jcooney.net">Joseph Cooney</a> launched a community project last week to create a <a href="http://learnwpf.com/">repository of useful pixel shader effects for WPF</a>. It&#8217;s already got a number of effects, including a very cool radial blur effect. Rather than just blogging a link, I wanted to contribute to the library and build a shader that I&#8217;ve been thinking about for a while. </p>
<p><a href="http://blogs.news.com.au/news/yoursay/index.php/news/comments/are_you_colour_blind/">Twelve percent of Australian men, and 0.5% of women</a> have some degree of <a href="http://en.wikipedia.org/wiki/Color_blindness">colour vision deficiency</a>, which makes up a significant segment of the audience for many applications. To aid in testing, the <a href="http://www.codeplex.com/fx/SourceControl/ListDownloadableCommits.aspx">ColorBlindnessEffect</a> allows you to simulate how your WPF application will look under various classifications of colour vision deficiencies. Here are some images of Joseph&#8217;s sample application running with Normal, Protanopia (loss in the red-yellow-green spectrum) and Tritanopia (loss in the blue-yellow spectrum):</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/clip-image001.jpg"><img height="162" alt="clip_image001" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/clip-image001-thumb.jpg" width="240" border="0" /></a><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/clip-image0015.jpg"><img height="172" alt="clip_image001[5]" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/clip-image0015-thumb.jpg" width="240" border="0" /></a><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/clip-image0017.jpg"><img height="168" alt="clip_image001[7]" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/clip-image0017-thumb.jpg" width="240" border="0" /></a></p>
<p>The effect provides eight filters:</p>
<ol>
<li>Protanopia </li>
<li>Protanomaly </li>
<li>Deuteranopia </li>
<li>Deuteranomaly </li>
<li>Tritanopia </li>
<li>Tritanomaly </li>
<li>Archromatopsia </li>
<li>Archromatomaly </li>
</ol>
<p>You can learn more about <a href="http://en.wikipedia.org/wiki/Color_blindness">colour blindness</a> on Wikipedia. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=5rjoL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=5rjoL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=ebUcL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=ebUcL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=gTStl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=gTStl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=8Pmkl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=8Pmkl" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/wpf-colour-blindness-shader-effect/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bindable LINQ: Threading</title>
		<link>http://www.paulstovell.com/blog/bindable-linq-threading</link>
		<comments>http://www.paulstovell.com/blog/bindable-linq-threading#comments</comments>
		<pubDate>Mon, 15 Sep 2008 15:52:10 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Bindable LINQ]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/bindable-linq-threading</guid>
		<description><![CDATA[This weekend I checked in a pretty large set of changes to Bindable LINQ, the main goals being a focus on removing all multi-threading capabilities, and general simplification. 
What I liked most about this commit is that the code was reduced. Before the changes, the Bindable LINQ solution was 20,829 lines of code; now it [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I checked in a pretty large set of changes to Bindable LINQ, the main goals being a focus on removing all multi-threading capabilities, and general simplification. </p>
<p>What I liked most about this commit is that the code was reduced. Before the changes, the Bindable LINQ solution was 20,829 lines of code; now it is down to 18,882 lines. Needless to say, this has led to a few breaking changes, and some of the tests don&#8217;t pass (yet), but it <em>seems </em>to work <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Threading: Before</h3>
<p>When I originally thought up Bindable LINQ, I had the idea of an <strong>Asynchronous</strong> operation. The idea was that you could setup a query over another data source, and Bindable LINQ would simply return an empty collection, then kick off a background thread, and as items are yielded, they&#8217;d be added to the Bindable LINQ result set and the UI automatically updated. I described it in my first video here:</p>
<p> <embed src="http://www.youtube.com/v/BI0lQ_Ps7Dw&amp;hl=en&amp;fs=1" width="425" height="344" type="application/x-shockwave-flash" allowfullscreen="true" />
<p>The Asynchronous operation could also be applied last, so other Bindable LINQ operations could be done as part of the background thread. This meant that every Bindable LINQ class had to be aware of multiple threads. </p>
<p>Threading has it&#8217;s tricks, but it isn&#8217;t that hard. After some early trial and error and plenty of time debugging deadlocks, I settled on some key principals:</p>
<ol>
<li><strong>Never hold a lock while calling code you didn&#8217;t write</strong>       <br />It might try to take a lock, while another thread holds that lock but wants to call your code. Deadlock.
<ul>
<li>This includes when raising events </li>
<li>This includes iterating over external items. I took snapshots of any external collection passed into Bindable LINQ, unless it was already a <code>List&lt;T&gt;</code>. </li>
</ul>
</li>
<li><strong>Take snapshots of IEnumerables</strong>.       <br />I explained this in my post <a href="http://www.paulstovell.com/blog/bindable-linq-snapshot-enumerators">Snapshot Enumerators</a>, which I still believe is the correct approach in the multi-thread aware scenario. You just can&#8217;t rely on Window 1 not to be looping through your collection while the user is clicking &quot;Delete&quot; in Window 2 (assuming they used different threads). </li>
<li><strong>Use locks when doing stuff to edit the collection</strong>       <br />Of course, since editing is meant to raise events, I created a &quot;Transaction&quot; system whereby only one thread could be performing a transaction at once, and once released, any events from changes made would be raised. It was complicated, but fun <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ol>
<p>As you can imagine, these principals caused a lot of overhead in the code, but <strong>I was absolutely convinced </strong>the multi-threading support was worth the cost. Then I changed my mind <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The reason for my backflip came when, having used Bindable LINQ in a couple of projects, I realised that in all asynchronous related scenarios, the Asynchronous operator didn&#8217;t go far enough, or didn&#8217;t let me take all of the advantages of threading (it couldn&#8217;t use PLINQ, for example). </p>
<p>Instead, I found myself just doing a regular Bindable LINQ query over an <code>ObservableCollection&lt;T&gt;</code> which was empty, and managing the background tasks myself, and using the Dispatcher to route the new items to the <code>ObservableCollection&lt;T&gt;</code>. It was actually a simpler approach, and I realised the Asynchronous iterator wasn&#8217;t that useful. </p>
<h3>Threading: After</h3>
<p>Like WPF UI elements, Bindable LINQ queries are now bound to a Dispatcher. If updates come from source collections on the wrong thread, they&#8217;ll be routed to the right thread before processing. Most operations in Bindable LINQ, such as <code>GetEnumerator()</code> or <code>Refresh()</code>, require that they are called on the dispatcher thread. It might sound like a limitation, compared to the previous approach, but it made all of the queries a lot easier. </p>
<p>What this meant is I was able to cut out some of the problematic areas:</p>
<ol>
<li><strong>All that code to avoid locks while making external code        <br /></strong>Many methods went from dozens of lines to two or three. </li>
<li><strong>Snapshots</strong>       <br />Since only one thread can be enumerating the collection at any one time, snapshots just aren&#8217;t needed. </li>
<li><strong>Locking </strong>      <br />When you ensure the object can only be touched from one thread, you generally don&#8217;t need to lock. </li>
</ol>
<p>I think this can best be summed up by &quot;YAGNI&quot;. </p>
<h3>Dispatchers and Testing</h3>
<p>A brief aside, but some issues can come up when combining the use of Dispatchers with unit tests. Here&#8217;s how I approach them in Bindable LINQ. </p>
<p>As I&#8217;m sure you know, components like the <code>Background Worker</code> or the <code>Dispatcher</code> work by sending messages from the current (background) thread to the message queue of the owning UI thread, which pulls them off the queue (just like a Button Click message) and processes them. This works great when you have a UI running, but not so great when you don&#8217;t, because <strong>there&#8217;s no message queue to read the messages from</strong>. </p>
<p>As a solution to this, I create the following components:</p>
<ul>
<li><strong><code>IDispatcher</code></strong>, an interface with methods like:
<ul>
<li><code>bool DispatchRequired();</code> </li>
<li><code>void Dispatch(Action action);</code> </li>
<li><code>void Dispatch&lt;TResult&gt;(Func&lt;TResult&gt; function);</code> </li>
</ul>
</li>
<li><strong><code>WpfDispatcher</code></strong>, which adapts the WPF Dispatcher object to the <code>IDispatcher</code> interface. </li>
<li><strong><code>SilverlightDispatcher</code></strong>, same as above, except for Silverlight. Since Silverlight doesn&#8217;t support synchronous invokes (you have to use <code>BeginInvoke</code>), I create a <code>AutoResetEvent</code>, and set it after the action has been processed, to effectively enable synchronous invokes. </li>
<li><strong><code>TestDispatcher</code></strong>, which provides a simulator for the dispatcher. </li>
</ul>
<p>It might sound like the simulated dispatcher is tricky, but in reality it turned out to be pretty simple. Instead of dispatching onto an owning thread, I just create a new thread each time - easy! </p>
<p>Suppose thread &quot;A&quot; is your UI thread, and thread &quot;B&quot; is your background thread. Here&#8217;s how it would work with a normal WPF dispatcher:</p>
<ol>
<li>Your UI is running on thread A </li>
<li>You dispatch an operation from thread B </li>
<li>It puts a message in the message queue for thread A </li>
<li>Thread B waits (if it&#8217;s a synchronous <code>Invoke</code>) or continues (if it&#8217;s an asynchronous <code>BeginInvoke</code>) </li>
<li>Thread A picks it up and processes it </li>
</ol>
<p>In your tests, there are usually a couple of things you want to do:</p>
<ul>
<li>Test that the thing you&#8217;re doing in the background is actually called on thread B </li>
<li>Test that any events you are raising are getting called on your foreground thread </li>
</ul>
<p>So, our <strong>Test Dispatcher</strong> enables this:</p>
<ol>
<li>Your test is running on thread A </li>
<li>You dispatch an operation from thread B </li>
<li>It creates a new thread, and calls the operation on the new thread (thread C) </li>
<li>Thread B waits (if it&#8217;s a synchronous <code>Invoke</code>) or continues (if it&#8217;s an asynchronous <code>BeginInvoke</code>) </li>
<li>Thread C does the action. </li>
<li>You test that the action happened on thread C </li>
</ol>
<p>Since your tests won&#8217;t know about Thread C, the <code>IDispatcher</code> manages this. Recall that <code>IDispatcher</code> supports a <code>DispatchRequired</code> method, which returns true if it is called on a thread which is not the UI thread. </p>
<p>In our test dispatcher, we pretend that each of the subsequent threads we create (thread C, thread D, thread E), is also the owner thread. So in <code>DispatchRequired</code>, we check for the owner thread (A), or any of the threads we&#8217;ve used as fake Dispatcher threads. Pretty easy <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>That&#8217;s my general approach to testing multi-threaded components that rely on a dispatcher of some description. If you&#8217;d like to see the code, here&#8217;s some direct links:</p>
<ul>
<li><a href="http://www.codeplex.com/bindablelinq/SourceControl/FileView.aspx?itemId=293215&amp;changeSetId=24348">IDispatcher.cs</a> </li>
<li><a href="http://www.codeplex.com/bindablelinq/SourceControl/FileView.aspx?itemId=293212&amp;changeSetId=24348">SilverlightDispatcher.cs</a> </li>
<li><a href="http://www.codeplex.com/bindablelinq/SourceControl/FileView.aspx?itemId=293214&amp;changeSetId=24348">WpfDispatcher.cs</a> </li>
<li><a href="http://www.codeplex.com/bindablelinq/SourceControl/FileView.aspx?itemId=299606&amp;changeSetId=24348">TestDispatcher.cs</a> </li>
</ul>
<p>Let me know what you think. To get the count of lines of code, I use a little utility I wrote some time ago <a href="http://www.projectdistributor.net/Projects/Project.aspx?projectId=139">here</a>. Tomorrow night I&#8217;ll blog about some other changes I made in the name of simplification, as well as the new <a href="http://www.codeplex.com/bindablelinq/SourceControl/FileView.aspx?itemId=248143&amp;changeSetId=24348">Switch</a> operator <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=m5dvL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=m5dvL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=krRPL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=krRPL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=ac5jl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=ac5jl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=gvhIl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=gvhIl" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/bindable-linq-threading/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Maslow’s Hierarchy of Project Manager’s Needs</title>
		<link>http://www.paulstovell.com/blog/maslows-hierarchy-of-project-managers-needs</link>
		<comments>http://www.paulstovell.com/blog/maslows-hierarchy-of-project-managers-needs#comments</comments>
		<pubDate>Sun, 14 Sep 2008 22:36:54 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Funny]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/maslows-hierarchy-of-project-managers-needs</guid>
		<description><![CDATA[ 
Central to this is the theory that the items higher up the pyramid tend to get thrown out when the lower ones are under threat. 
]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image10.png"><img height="533" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb10.png" width="768" border="0" /></a> </p>
<p>Central to this is the theory that the items higher up the pyramid tend to get thrown out when the lower ones are under threat. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=jgPsL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=jgPsL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=EfjEL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=EfjEL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=n1dSl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=n1dSl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=TRjBl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=TRjBl" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/maslows-hierarchy-of-project-managers-needs/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Expression Framework versus Composite WPF</title>
		<link>http://www.paulstovell.com/blog/expression-framework-versus-composite-wpf</link>
		<comments>http://www.paulstovell.com/blog/expression-framework-versus-composite-wpf#comments</comments>
		<pubDate>Sat, 13 Sep 2008 10:09:28 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[Architecture]]></category>

		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/expression-framework-versus-composite-wpf</guid>
		<description><![CDATA[Blend 2.5 has an Add-In model that let&#8217;s you write plug-ins for Blend. Even if you aren&#8217;t interested in Blend add-ins, if you have an interest in good application design, I&#8217;d heartily recommend taking some time to browse the Expression Blend object model in Reflector. You might not expect it, but Blend has many of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://hackingsilverlight.blogspot.com/2008/07/hacking-expression-blend.html">Blend 2.5 has an Add-In model</a> that let&#8217;s you write plug-ins for Blend. Even if you aren&#8217;t interested in Blend add-ins, if you have an interest in good application design, I&#8217;d heartily recommend taking some time to browse the Expression Blend object model in Reflector. You might not expect it, but Blend has many of the characteristics of a traditional composite application. </p>
<p>The Composite WPF project ships with a reference implementation that demonstrates how to apply the Composite WPF libraries. By contrast, Expression Blend is a good example of how to <em>apply</em> composite WPF techniques to a specific problem, without using any of the libraries. For this reason, I thought it would be interesting to compare the two. </p>
<p><em>Disclaimer: I draw all conclusions about the Expression Blend code from Reflector alone and inferring what the components do, rather than actually having read any documentation on the topic. I may be completely wrong in some aspects <img src='http://www.paulstovell.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </em></p>
<h3>Expression Framework overview</h3>
<p>Expression Blend has a few assemblies, the most interesting one being the <code>Microsoft.Expression.Framework</code> DLL. This provides the foundation classes that the various Expression products use in their architecture. The top-level Expression Framework design is decoupled, like Composite WPF applications, but it has also been simplified in interesting ways. </p>
<p>To implement an Add-In, you implement an <code>IAddIn</code> interface, and you are given access to an <code>IApplicationService</code> object. This service provides a set of application-level properties, for example:</p>
<ul>
<li><code>AddInService</code> : <code>IAddInService</code>, which lets you register more Add-Ins into the Application </li>
<li>CommandBarService : <code>ICommandBarService</code>, which give the ability to register commands on the toolbar </li>
<li><code>Packages</code> : <code>IPackageCollection</code>, which contains all of the &quot;packages&quot; (modules) loaded into the application. Examples are a Code Editing package, a Design Surface package, etc. </li>
<li><code>ViewService</code> : <code>IViewService</code>, for opening and closing views. </li>
<li><code>MessageDisplayService</code> : <code>IMessageDisplayService</code>, for message boxes and dialogs </li>
<li><code>MessageLoggingService</code> : <code>IMessageLoggingService</code>, for writing to the output window </li>
</ul>
<p>What this leads to is a hierarchy of logical components that make up any Expression application:</p>
<ul>
<li>An Expression Application (<code>IApplicationService</code>) is made up of:
<ul>
<li>Application-level services like menus, logging, messaging and scheduling </li>
<li>Add-Ins (implementing <code>IAddIn</code>) </li>
<li>Packages (<code>IPackage</code>) for specific bits of functionality, which tend to get their own DLL&#8217;s, such as:
<ul>
<li><code>CodePackage</code>, which allows for editing code, by providing:
<ul>
<li><code>CodeEditor</code>, which is a control for editing source code </li>
<li><code>CodeViews</code>, which host the editor and implements IView </li>
<li><code>CodeDocument</code>, which represents a source file being edited </li>
</ul>
</li>
<li><code>DesignerPackage</code>, which allows for designing documents </li>
<li><code>ProjectPackage</code>, for support for various Visual Studio project types </li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Now let&#8217;s look at some of those components, and consider how they would be approached in Composite WPF. </p>
<h3>Composition: Modules vs. Packages</h3>
<p>In contrast to monolithic applications, composite applications are about allowing distinct areas of functionality to be implemented separately, and then be &quot;composed&quot; together into an application. Composite WPF is based around <em>modules</em>, which are conceptually the equivalent to Packages in Expression Framework. When a Composite WPF application starts up, all Modules are located, and are told to initialise. A Composite WPF module is given an <code>IUnityContainer</code>, which it uses to register and consume services that can be used in other modules in the application. </p>
<pre>public class NewsModule : IModule
{
    private IUnityContainer _container;

    public NewsModule(IUnityContainer container)
    {
        _container = container;
    }

    protected void RegisterViewsAndServices()
    {
        _container.RegisterType&lt;INewsFeedService, NewsFeedService&gt;(new ContainerControlledLifetimeManager());
        _container.RegisterType&lt;INewsController, NewsController&gt;(new ContainerControlledLifetimeManager());
        _container.RegisterType&lt;IArticleView, ArticleView&gt;();
        _container.RegisterType&lt;IArticlePresentationModel, ArticlePresentationModel&gt;();
        _container.RegisterType&lt;INewsReaderView, NewsReader&gt;();
        _container.RegisterType&lt;INewsReaderPresenter, NewsReaderPresenter&gt;();
    }

    public void Initialize()
    {
        RegisterViewsAndServices();

        INewsController controller = _container.Resolve&lt;INewsController&gt;();
        controller.Run();
    }
}</pre>
<p>In the Stock Trader reference implementation, each module gets it&#8217;s own assembly, but it&#8217;s also possible to put many modules in one assembly, or to use many assemblies to compose and decouple a single module. </p>
<p>In the Expression Framework, modules are known as Packages. A Package provide a distinct area of functionality to an Expression application, like code editing or designer features. Each one tends to live in its own DLL. Here&#8217;s what an Expression Package looks like:</p>
<pre>public sealed class CodePackage : IPackage
{
    public CodePackage();
    public void Load(IApplicationService applicationService);
    public void Unload();
}</pre>
<p>The <code>IApplicationService</code> provides a set of properties that indicate what application-level services are available, and the Package can use them to access all of the areas of functionality it needs when it loads up. Conceptually, it acts like the <code>IUnityContainer</code> used in the Composite WPF reference implementation. </p>
<p><strong>Key takeaway: </strong>The Package API makes it clear that a Package is clearly loaded into <em>the context of an application</em>. A Composite WPF module is just loaded into <em>something</em>. The Expression approach seems to lend itself well to exploration - &quot;I&#8217;ll write a package that shows a message box. What&#8217;s this IApplicationService&#8230; oh, the <code>MessageDisplayService</code> property - that sounds like it could be what I want&quot;. </p>
<p>In the Composite WPF reference implementation, using just the <code>IUnityContainer</code>, you have to already know which services are available - it&#8217;s not so obvious. I think it would be nice to wrap the <code>IUnityContainer</code> as an <code>IApplicationService</code>, and expose application-level services as properties, and still use the container internally. There&#8217;s nothing in Composite WPF that would prevent that. </p>
<p><strong>Key takeaway: </strong>As a semantic thing, I like the choice of name for a &quot;package&quot;, because it is domain-specific. If I was building an insurance modelling application, which was made up of a lot of different modelling suites, even using Composite WPF, I&#8217;d consider renaming <code>IModule</code> to <code>IModellingPackage</code>. Names tell you a lot about what something is and help relate the product you&#8217;re building to the implementation. </p>
<h3>Dependencies and Services: IUnityContainer vs. IApplicationService</h3>
<p>In Composite WPF, when a module is created, it registers all of the services it provides into the IOC container, and they are available to other modules. It&#8217;s a nice, generic solution, and it leads to a lot of consistency. </p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image8.png"><img height="245" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb8.png" width="444" border="0" /></a> </p>
<p>The rules in the Expression Framework are fairly similar. The <code>IApplicationService</code> implements <code>IServiceProvider</code> and provides <code>AddService()</code> and <code>GetService()</code> methods, and so functions similarly to an IOC container, albeit with a lot less features. When a Package loads, it can ask the <code>IApplicationService</code> for a service provided by another module. </p>
<p>What both solutions appear to be missing is good support for cyclic dependencies. When a module is registered, you specify the other modules it relies on, and Composite WPF makes sure to load them in the correct order according to their dependencies. </p>
<pre>protected override IModuleEnumerator GetModuleEnumerator()
{
    return new StaticModuleEnumerator()
        .AddModule(typeof(NewsModule))
        .AddModule(typeof(MarketModule))
        .AddModule(typeof(WatchModule), &quot;MarketModule&quot;)
        .AddModule(typeof(PositionModule), &quot;MarketModule&quot;, &quot;NewsModule&quot;);
}</pre>
<p>When a module is initialised, it registers all of its services and then resolves any objects that rely on other modules, all in the one call. As the modules are loaded, it would happen in this order:</p>
<ol>
<li>News module registers all services </li>
<li>News module creates and shows some views </li>
<li>Market module registers all services (it has no views) </li>
<li>Watch module registers all services </li>
<li>Watch module creates some views (using services provided by Market) </li>
<li>Position module registers all services </li>
<li>Position module creates some views (using services provided by Watch and Market) </li>
</ol>
<p>Because each module is loaded in turn, you&#8217;ll get exceptions if you have cyclic dependencies between modules, which might be limiting. </p>
<p>Instead, I like to use a two-phase initialisation process, which would make each module look like this:</p>
<pre>public class NewsModule : IModule
{
    private IUnityContainer _container;

    public NewsModule(IUnityContainer container)
    {
        _container = container;
    }

    protected override void <strong>RegisterSharedServicesOverride</strong>()
    {
        base.RegisterSharedServicesOverride();

        _container.RegisterType&lt;INewsFeedService, NewsFeedService&gt;(new ContainerControlledLifetimeManager());
        _container.RegisterType&lt;INewsController, NewsController&gt;(new ContainerControlledLifetimeManager());
        _container.RegisterType&lt;IArticleView, ArticleView&gt;();
        _container.RegisterType&lt;IArticlePresentationModel, ArticlePresentationModel&gt;();
        _container.RegisterType&lt;INewsReaderView, NewsReader&gt;();
        _container.RegisterType&lt;INewsReaderPresenter, NewsReaderPresenter&gt;();
    }

    protected override void <strong>ConsumeSharedServicesOverride</strong>()
    {
        base.ConsumeSharedServicesOverride();

        INewsController controller = _container.Resolve&lt;INewsController&gt;();
        controller.Run();
    }
}</pre>
<p>And would thus be run the following order:</p>
<ol>
<li>Phase 1: Register Shared Services
<ol>
<li>News module registers all service </li>
<li>Market module registers all service </li>
<li>Watch module registers all services </li>
<li>Position module registers all services </li>
</ol>
</li>
<li>Phase 2: Consume Shared Services
<ol>
<li>Watch module creates some views (using services provided by Market) </li>
<li>Position module creates some views (using services provided by Watch and Market) </li>
<li>News module creates and shows some views </li>
</ol>
</li>
</ol>
<p>This allows modules to have cyclic dependencies (though of course, not cyclic DLL references, so you&#8217;d have to split the interfaces out into satellite or shared assemblies), since all modules get a chance to register before they consume. </p>
<p><strong>Key takeaway: </strong>It&#8217;s interesting that the Expression team chose not to use an IOC container, and instead use not much more than a <code>Hashable</code>. That said, I would still choose a full IOC container like <a href="http://www.castleproject.org/container/index.html">Castle Windsor</a> any day. I do however like the way application-level services (as opposed to module specific services) are exposed much more clearly. </p>
<p><strong>Key takeaway:</strong> Cyclic dependencies between modules may not come up, and there often are workarounds, but if you do, this is probably an area you&#8217;ll have to make a few tweaks to. </p>
<h3>UI Composition: Regions vs. Views</h3>
<p>In Composite WPF, when you want to show something on screen, you can ask the IOC container for an <code>IRegionManager</code>. The region manager provides a set of named <code>IRegions</code>, which you can get a reference to, and add UI elements to them. </p>
<pre>IRegionManager regionManager = Container.Resolve&lt;IRegionManager&gt;();
IRegion detailsRegion = regionManager.Regions[&quot;DetailsRegion&quot;];
detailsRegion.Add(view);</pre>
<p>Regions are quite generic. Panels on a form can be regions, as can toolbars and menus. The library comes with a set of adapters that allow specific WPF UI elements to act as regions - out of the box adapters include <code>ItemsControlRegionAdapter</code> (for a region with multiple controls) and <code>ContentControlRegionAdapter</code> (for regions with only one view). If you want to adapt to other, more complicated elements, you can write your own adapter pretty easily. </p>
<p>In Expression, the <code>IApplicationService</code> is a little more specific about what &quot;regions&quot; are available. You can get a <code>CommandBar</code> service, <code>ViewService</code> (for views on the main window), or <code>WindowService</code> (for popping up new Windows), each of which have a specific API according to what they are doing. </p>
<p>Here&#8217;s how adding a command to the Expression <code>CommandBar</code> would look (I gather, from the API). As you can see, it&#8217;s more explicit about which options are available:</p>
<pre>var commandBar = applicationService.CommandBarService.CommandBars[&quot;CommandBarName&quot;];
var button = commandBar.Items.AddButton(&quot;MyButton&quot;);</pre>
<p><strong>Key takeaway</strong>: I think the Region model is a nice idea, but perhaps a bit too limiting. The assumption is that all Regions just contain a list of Views, and should all conform to the same API, makes it a bit more clunky to code against and isn&#8217;t as intuitive as the Expression Framework approach. I like that the Expression Framework defines specific API&#8217;s for the various types of views. </p>
<p>The Expression Framework approach to regions is certainly possible to do using Composite WPF, and there&#8217;s no reason you can&#8217;t mix the models - using Regions for most panel-like regions, and more specific interfaces for menus or command bars. Expression shows that it is possible to be more specific while still being loosely coupled.&#160; </p>
<h3>Eventing: Services vs. Event Aggregator</h3>
<p>The final thing I was interested in is how services in modules communicate with each other, primarily around reacting to events. </p>
<p>In Composite WPF, services in a module can consume other services from other modules by getting them from the IOC container. Those services could then expose events, which the dependent modules/controllers could subscribe to.&#160; </p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image9.png"><img height="221" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb9.png" width="573" border="0" /></a></p>
<p>The Expression Framework works this way as well. When packages load, they can resolve services from the <code>IApplicationService</code>, and subscribe to events (such as the <code>ActiveViewChanged</code> event on the <code>IViewService</code>). I like this approach to eventing because it is consistent with all other forms of collaboration between services in modules. </p>
<p>However, Composite WPF also provides an alternative model. Instead of subscribing to events on individual services, you can obtain a reference to an <code>IEventAggregator</code> from the IOC container. You can then setup a subscription to the event, and events can be published from anywhere, with the <code>IEventAggregator</code> acting as a messaging hub. The <code>IEventAggregator</code> approach has a few noteworthy advantages:</p>
<ul>
<li>Event subscriptions are weak references by default. This is hugely important, because in the alternative approach outlined above, you need to make sure to unsubscribe from any events when the view is unloaded or else the service will keep your view alive indefinitely. </li>
<li>You can pass a <code>ThreadOption</code> to tell the event aggregator which thread to call you back on, such as always on the UI thread, or always on a background thread. </li>
<li>Multiple publishers can publish an event. In the first approach, only the service can raise the event, and you&#8217;d have to build your own layer to allow notifications from many places. </li>
</ul>
<p>I am actually in two minds about this. On the one hand, the advantages of the event aggregator approach are hard to ignore. However, if I&#8217;m going to call methods on services in a different module one way, I&#8217;d like to subscribe to events in much the same way. The Event Aggregator is a bit of an anomaly considering the rest of the guidance is so focused on IOC. </p>
<p><strong>Key takeaway</strong>: I would prefer to approach eventing as I would approach any other collaboration service, using the IOC container. I think the benefits of the Event Aggregator, including automatic threading and weak referencing, could be done nicely using Castle Windsor <a href="http://www.castleproject.org/container/documentation/trunk/usersguide/interceptors.html">Interceptors</a> instead. </p>
<h3>Conclusions</h3>
<p>My interest in this comparison was to see how the Expression Framework approached certain problems which Composite WPF provides an alternative approach for. Since <a href="http://www.paulstovell.com/blog/prism-review-part-i">my first review on Composite WPF</a> (then &quot;Prism&quot;), I&#8217;ve been a big fan, and I&#8217;ve recommended it as a base for a number of client engagements. But as I wrote in my first review, I think these projects should always be used as guidance, not gospel, and not as DLL&#8217;s you blindly reference and patterns you blindly follow. Expression Blend shows that there are many ways to skin a modular cat, and that rolling your own isn&#8217;t such a bad idea. </p>
<p>Something this reinforced is that it&#8217;s common to see architects on a team that spend all of their time evaluating patterns and frameworks. It is like an orchestra conductor who spends all his time evaluating which instruments the musicians should play, and not conducting the music. The result is a group where everyone is playing to a different tune, because there&#8217;s no shared vision of what they&#8217;re playing. </p>
<p>The Expression Framework enables loosely coupled, modular, composite applications, without strictly following all of the patterns or tools we spend so much time arguing about. It demonstrates how important it is to have a clear, cohesive vision of what you&#8217;re actually building, and how unimportant specific tools and libraries are. I get the feeling that someone on that team has a very clear vision of what they&#8217;re producing; a conductor that focuses on the music and not the instruments. Those are the architects I&#8217;d like to work with. </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=sV5NL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=sV5NL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=aN7DL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=aN7DL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=JTf0l"><img src="http://feeds.feedburner.com/~f/paulstovell?i=JTf0l" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=yhXdl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=yhXdl" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/expression-framework-versus-composite-wpf/feed/</wfw:commentRss>
		</item>
		<item>
		<title>WPF: Leverage</title>
		<link>http://www.paulstovell.com/blog/wpf-leverage</link>
		<comments>http://www.paulstovell.com/blog/wpf-leverage#comments</comments>
		<pubDate>Thu, 11 Sep 2008 14:54:18 +0000</pubDate>
		<dc:creator>Paul Stovell</dc:creator>
		
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.paulstovell.com/blog/wpf-leverage</guid>
		<description><![CDATA[There&#8217;s a myth that Windows Forms developers are more productive than WPF developers, and that WPF is only &#34;worth it&#34; if you&#8217;re worried about &#34;look and feel&#34;. Windows Forms has &#34;the RAD factor&#34;. I dispute that myth; I think a developer with enough experience in WPF can be more productive than the typical Windows Forms [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a myth that Windows Forms developers are more productive than WPF developers, and that WPF is only &quot;worth it&quot; if you&#8217;re worried about &quot;look and feel&quot;. Windows Forms has &quot;the RAD factor&quot;. I dispute that myth; I think a developer with enough experience in WPF can be more productive than the typical Windows Forms developer in most situations; the secret is <strong>leverage</strong>. </p>
<p>Windows Forms has a nice designer that let&#8217;s us drag and drop controls on the form, spend a bit of time with the margins and alignments, positioning stuff, and compiling it. It allows you to get something functional quite quickly. It&#8217;s where the &quot;RAD&quot; myth started. </p>
<p>However, <strong>Expression Blend</strong> supports nearly all of those features. We get snapping and alignment and all the other goodies:</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image1.png"><img height="244" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb1.png" width="387" border="0" /></a>&#160;</p>
<h3>Resources</h3>
<p>So in terms of raw &quot;banging out a UI&quot; ability, there&#8217;s not much difference. But using WPF enables a lot of <strong>extra</strong> options. For example, the <a href="http://msdn.microsoft.com/en-us/library/aa511279.aspx">Windows Vista user experience guidelines</a> give us some standards that we should follow when it comes to margins between controls: </p>
<ul>
<li>Margin between related controls: 7px </li>
<li>Margin between unrelated controls: 11px </li>
</ul>
<p>Using WPF we can translate that into a pair of resources:</p>
<pre>&lt;Application.Resources&gt;
    &lt;Thickness x:Key=&quot;Layout_StandardMarginBetweenRelatedControls&quot;&gt;0,3.5,0,3.5&lt;/Thickness&gt;
    &lt;Thickness x:Key=&quot;Layout_StandardMarginBetweenUnrelatedControls&quot;&gt;0,7.5,0,3.5&lt;/Thickness&gt;
&lt;/Application.Resources&gt;</pre>
<p>If I have a bunch of controls, the &quot;StandardMarginBetweenControls&quot; will put a 3.5px margin around each one, or 7 between two controls. If I need to break up the list with a control that is not related, I apply the &quot;StandardMarginBetweenUnrelatedControls&quot; to the next control, which will put 3.5 + 7.5 = 11 between the two controls. </p>
<p>Using these resources from Blend couldn&#8217;t be easier. I select my group of related controls, and apply the resource to the Margin property:</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image2.png"><img height="166" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb2.png" width="444" border="0" /></a>&#160;</p>
<p>If we now change our mind, we can update the resource from the one place, and it will apply to every place we&#8217;ve used it. We&#8217;re able to leverage our investment in resources later to make the application faster to maintain. By contrast, if I decide to change my Windows Forms layout, I need to manually fix each Form, since reusing something as simple as a margin in Windows Forms is actually quite difficult.&#160; </p>
<p>Here&#8217;s some other useful things you can turn into styles or resources:</p>
<ul>
<li>The font settings to apply to all labels </li>
<li>The standard margin around the border of the Window </li>
<li>The standard width and height of buttons </li>
<li>The standard horizontal alignment of labels (left-aligned labels versus right-aligned labels - Vista UX guidelines say Left) </li>
</ul>
<p>And those are the simple ones. We can take this leveraging power further by <strong>abstracting</strong> the problem we&#8217;re trying to solve. </p>
<h3>Abstraction</h3>
<p>Let&#8217;s think about what a Form is. Your typical Form window has a header, body, and footer with some buttons. The body contains a set of Fields, which have a label, an optional description, and one or more editable controls. We can take these concepts and turn them into some simple stub classes that we can style up. </p>
<p>First, I built some classes to represent the object model of an input form. After I stubbed out the classes, here&#8217;s what the markup looked like:</p>
<pre>&lt;Forms:Form Style=&quot;{DynamicResource Form_SimpleFormStyle}&quot;&gt;
    &lt;Forms:FormHeader
        Icon=&quot;ResourcesImagesUserNew32x32.png&quot;
        Title=&quot;Create an account&quot;
        /&gt;

    &lt;Forms:FormFooter&gt;
        &lt;Forms:FormButtonBar&gt;
            &lt;Button Content=&quot;Save&quot;/&gt;
            &lt;Button Content=&quot;Cancel&quot;/&gt;
        &lt;/Forms:FormButtonBar&gt;
    &lt;/Forms:FormFooter&gt;

    &lt;Forms:FormBody&gt;
        &lt;Forms:FormField Header=&quot;First name:&quot; IsRequired=&quot;True&quot;&gt;
            &lt;TextBox Text=&quot;&quot; TextWrapping=&quot;Wrap&quot; Width=&quot;300&quot;/&gt;
        &lt;/Forms:FormField&gt;
        &lt;Forms:FormField Header=&quot;Last name:&quot; IsRequired=&quot;True&quot;&gt;
            &lt;TextBox Text=&quot;&quot; TextWrapping=&quot;Wrap&quot; Width=&quot;300&quot;/&gt;
        &lt;/Forms:FormField&gt;
        &lt;Forms:FormField Header=&quot;Email address:&quot; Description=&quot;Your email address will not be shared with anyone.&quot; IsRequired=&quot;True&quot;&gt;
            &lt;TextBox Text=&quot;&quot; TextWrapping=&quot;Wrap&quot; Width=&quot;300&quot;/&gt;
        &lt;/Forms:FormField&gt;

        &lt;!-- Continued --&gt;
    &lt;/Forms:FormBody&gt;
&lt;/Forms:Form&gt;</pre>
<p>The intent was to capture what a form &quot;is&quot;, and separate it from what it &quot;looks like&quot;. I spent 10 minutes defining some very simple styles and templates to lay out the contents of each object, and then switched back to define the half-dozen forms I was building:</p>
</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image3.png"><img height="235" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb3.png" width="232" border="0" /></a> </p>
<p>Then I put on my designer hat. Since I&#8217;d pushed all of the layout information into the styles and templates, I was able to alter the look of all of the forms quite heavily without actually changing any of them:</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image4.png"><img height="275" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb4.png" width="420" border="0" /></a>&#160;</p>
<p>In total, the resource dictionary for the complete set of styles came out to 271 lines of XAML - most of which was done in the designer using Blend. I even put some design-time specific styles in to make the design experience nicer:</p>
<p><a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image5.png"><img height="183" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb5.png" width="166" border="0" /></a>&#160;<a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image6.png"><img height="182" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb6.png" width="227" border="0" /></a> <a href="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image7.png"><img height="180" alt="image" src="http://www.paulstovell.com/blog/wp-content/uploads/2008/09/image-thumb7.png" width="240" border="0" /></a> </p>
<p>The time consuming part was creating the classes and styles. But with them in place, building a single dialog is more productive than in Windows Forms, since I don&#8217;t have to think about layout at all. It&#8217;s all about leverage. </p>
<p><strong>In summary:</strong></p>
<ul>
<li>The WPF + Blend solution allows your design team to design the form <strong>layout </strong>separately to the implementation of the specific form.</li>
<li>The WPF + Blend solution allows you to enforce consistency by taking layout concerns away from the developer and giving them to the designer.</li>
<li>By abstracting the layout markup to add more structure, we make the markup and design experience for the controls much simpler.</li>
<li>By using WPF&#8217;s leveraging capabilities - styles, resources, templates, and most importantly, separating form from function - we are more productive in the long term.</li>
</ul>
<p>This is the stuff Windows Forms is meant to be superior at. We haven&#8217;t even looked at WPF&#8217;s extra features, like <a href="http://www.codeproject.com/KB/WPF/SmartRoutedCommandsInWPF.aspx">Commands</a>, <a href="http://www.paulstovell.com/blog/inductive-uis-with-wpf-navigation-applications">Navigation</a>, or the far superior <a href="http://msdn2.microsoft.com/en-us/library/ms752347.aspx">Binding</a>. The only downside is the learning curve. </p>
<p>I&#8217;ll be posting these resource dictionaries and controls sometime soon as part of a wider library of assets for rapid WPF development. In the mean time if you&#8217;re interested in seeing the markup, drop me an email (<a href="mailto:paul@paulstovell.com">paul@paulstovell.com</a>). </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~f/paulstovell?a=wakVL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=wakVL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=N9vJL"><img src="http://feeds.feedburner.com/~f/paulstovell?i=N9vJL" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=h3VFl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=h3VFl" border="0"></img></a> <a href="http://feeds.feedburner.com/~f/paulstovell?a=7sbvl"><img src="http://feeds.feedburner.com/~f/paulstovell?i=7sbvl" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.paulstovell.com/blog/wpf-leverage/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
