<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Visions of Software</title>
	<atom:link href="http://visionsofsoftware.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://visionsofsoftware.com</link>
	<description>Exploring software&#039;s vast horizons</description>
	<lastBuildDate>Fri, 24 Sep 2010 09:56:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='visionsofsoftware.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Visions of Software</title>
		<link>http://visionsofsoftware.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://visionsofsoftware.com/osd.xml" title="Visions of Software" />
	<atom:link rel='hub' href='http://visionsofsoftware.com/?pushpress=hub'/>
		<item>
		<title>Asynchronous methods in C# using generics</title>
		<link>http://visionsofsoftware.com/2010/09/24/asynchronous-methods-in-c-using-generics/</link>
		<comments>http://visionsofsoftware.com/2010/09/24/asynchronous-methods-in-c-using-generics/#comments</comments>
		<pubDate>Fri, 24 Sep 2010 09:56:36 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[generic]]></category>
		<category><![CDATA[parallel]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=310</guid>
		<description><![CDATA[Asynchronous methods provide a means to execute long running operations in parallel. One strategy for implementing these is to define generic methods to handle the asynchronous actions and pass the methods to be called asynchronously as parameters. A simple example follows. The generic support methods A class is created with static methods to support start [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=310&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Asynchronous methods provide a means to execute long running operations in parallel.  One strategy for implementing these is to define generic methods to handle the asynchronous actions and pass the methods to be called asynchronously as parameters.  A simple example follows.</p>
<p><strong>The generic support methods</strong></p>
<p>A class is created with static methods to support start and completion of asynchronous methods.  The support methods for a single parameter with return type are shown.  Other methods can be added to handle other delegate signature requirements.</p>
<pre style="background:#e0e0e0;color:#000000;">    // Parameter and return type async method helper
    public static IAsyncResult BeginAsync&lt;T1, TResult&gt;(Func&lt;T1, TResult&gt; method,
                                                       T1 parameter)
    {
        var methodCopy = method;
        if (methodCopy == null)
            throw new ArgumentNullException();

        // Start the asynchronous operation
        // No callback or state object
        return methodCopy.BeginInvoke(parameter, null, null);
    }

    // Parameter and return type async method helper - async done
    public static TResult EndAsync&lt;T1, TResult&gt;(IAsyncResult aResult)
    {
        Func&lt;T1, TResult&gt; method =
            (Func&lt;T1, TResult&gt;) ((AsyncResult) aResult).AsyncDelegate;

        // Retrieve the result
        return method.EndInvoke(aResult);
    }</pre>
<p><strong>Asynchronous running</strong></p>
<p>With these methods in place it becomes a simple process to use the asynchronous operations in code.  Each operation calls the appropriate generic method to invoke the function, and a generic method to retrieve the result.  A blocking strategy is shown here (so not applicable for use in a UI thread) but the example can easily be modified to use callbacks on completion.</p>
<pre style="background:#e0e0e0;color:#000000;">    private int LongComputation(String data)
    {
        // Some long operation
        Thread.Sleep(10000);

        return data.Length;
    }

    private int MultiComputation()
    {
        IAsyncResult aRes1 =
            AsyncMethods.BeginAsync&lt;String, int&gt;(LongComputation, "Visions");
        IAsyncResult aRes2 =
            AsyncMethods.BeginAsync&lt;String, int&gt;(LongComputation, "of");
        IAsyncResult aRes3 =
            AsyncMethods.BeginAsync&lt;String, int&gt;(LongComputation, "Software");

        // Blocks for async call completion - not for use on UI thread
        int result = AsyncMethods.EndAsync&lt;String, int&gt;(aRes1);
        result += AsyncMethods.EndAsync&lt;String, int&gt;(aRes2);
        result += AsyncMethods.EndAsync&lt;String, int&gt;(aRes3);

        return result;
    }</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/310/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=310&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/09/24/asynchronous-methods-in-c-using-generics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF servers and clients without configuration files</title>
		<link>http://visionsofsoftware.com/2010/09/17/wcf-servers-and-clients-without-configuration-files/</link>
		<comments>http://visionsofsoftware.com/2010/09/17/wcf-servers-and-clients-without-configuration-files/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 08:20:59 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=290</guid>
		<description><![CDATA[WCF servers and clients can be set up using a declarative mechanism in web.config and app.config files. It is also possible to set up WCF servers and clients without using config files. A simple example follows. For these examples the WCF server and client will be hosted in simple WPF applications. WCF Server A reference [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=290&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>WCF servers and clients can be set up using a declarative mechanism in web.config and app.config files.  It is also possible to set up WCF servers and clients without using config files.  A simple example follows.</p>
<p>For these examples the WCF server and client will be hosted in simple WPF applications.</p>
<p><strong>WCF Server</strong></p>
<p>A reference to the System.ServiceModel assembly / dll is added to link the associated namespaces.  Then a ServiceContract is defined:</p>
<pre style="background:#e0e0e0;color:#000000;">using System.ServiceModel;

...

[ServiceContract]
public interface IWCFContract
{
    [OperationContract]
    int Add(int value1, int value2);

    [OperationContract]
    int Multiply(int value1, int value2);
}</pre>
<p>Next a concrete implementation of the service contract needs to be defined:</p>
<pre style="background:#e0e0e0;color:#000000;">public class WCFConcrete : IWCFContract
{
    public int Add(int value1, int value2)
    {
        return (value1 + value2);
    }

    public int Multiply(int value1, int value2)
    {
        return (value1 * value2);
    }
}</pre>
<p>Then the service host is programmatically created and the metadata is exposed and endpoints added:</p>
<pre style="background:#e0e0e0;color:#000000;">using System.ServiceModel;
using System.ServiceModel.Description;

...

public ServiceHost CreateAndOpenHost()
{
    ServiceHost newHost =
        new ServiceHost(typeof(WCFConcrete),
                        new Uri("http://localhost:8002/SimpleService"));

    // Configure publication of service metadata
    ServiceMetadataBehavior behaviour = new ServiceMetadataBehavior();
    behaviour.HttpGetEnabled = true;
    behaviour.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
    newHost.Description.Behaviors.Add(behaviour);

    // Add a MEX (metadata exchange) endpoint
    newHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName,
                               MetadataExchangeBindings.CreateMexHttpBinding(),
                               "mex");

    // Add an application endpoint using a WSHttpBinding
    newHost.AddServiceEndpoint(typeof(IWCFContract), new WSHttpBinding(), "");

    // Open the service host
    newHost.Open();

    return newHost;
}</pre>
<p>Appropriate permissions will need to be given to the user running the application.  This can be achieved by running the following in an elevated / administrator command window:</p>
<pre style="background:#e0e0e0;color:#000000;">netsh http add urlacl url=http://+:8002/SimpleService user=DOMAIN\username</pre>
<p>This service can now be run.  The running service can be verified by browsing to the service in Internet Explorer:</p>
<pre style="background:#e0e0e0;color:#000000;">http://localhost:8002/SimpleService</pre>
<p><strong>WCF Client</strong></p>
<p>To create the client class run the svcutil.exe (located at C:\Program Files\Microsoft SDKs\Windows\{version}\Bin) on the wsdl for the service (while the service is running):</p>
<pre style="background:#e0e0e0;color:#000000;">svcutil.exe http://localhost:8002/SimpleService?wsdl</pre>
<p>This will create a WCFConcrete.cs (along with a config file which is not needed for this example.)  This class file is added to the client project.  Again a reference to the System.ServiceModel assembly will need to be added to the client project.</p>
<p>The ChannelFactory is then used to create a client to the service:</p>
<pre style="background:#e0e0e0;color:#000000;">using System.ServiceModel;

...

public static IWCFContract CreateWCFClient(String endpointAddress)
{
    IWCFContract result = null;

    // Set up the binding and endpoint.
    WSHttpBinding binding = new WSHttpBinding();
    EndpointAddress endpoint = new EndpointAddress(endpointAddress);

    // Create a channel factory.
    ChannelFactory&lt;IWCFContract&gt; channelFactory =
                  new ChannelFactory&lt;IWCFContract&gt;(binding, endpoint);

    // Create a channel.
    result = channelFactory.CreateChannel();

    return result;
}</pre>
<p>With this in place a client can simply be created and used to access the service (when it is running):</p>
<pre style="background:#e0e0e0;color:#000000;">...

IWCFContract client = CreateWCFClient("http://localhost:8002/SimpleService");

int addResult = client.Add(2, 3);
int multiplyResult = client.Multiply(2, 3);</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/290/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=290&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/09/17/wcf-servers-and-clients-without-configuration-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>The adapter pattern and presenter-first UIs</title>
		<link>http://visionsofsoftware.com/2010/08/23/the-adapter-pattern-and-presenter-first-uis/</link>
		<comments>http://visionsofsoftware.com/2010/08/23/the-adapter-pattern-and-presenter-first-uis/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 09:56:05 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[adapter]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[presenter first]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=260</guid>
		<description><![CDATA[The adapter pattern provides a technique to bind together the presenter logic and the UI screens of a presenter-first model (and other loosely coupled models) of user interface implementation. An example follows. An application to double an integer requires a presenter function to perform the doubling on request: public class Presenter { public IInput Input [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=260&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The adapter pattern provides a technique to bind together the presenter logic and the UI screens of a presenter-first model (and other loosely coupled models) of user interface implementation. An example follows.</p>
<p>An application to double an integer requires a presenter function to perform the doubling on request:</p>
<pre style="background:#e0e0e0;color:#000000;">public class Presenter
{
    public IInput Input { get; set; }
    public IOutput Output { get; set; }

    public void PerformDoubling()
    {
        int inputValue = Input.GetValue();
        int result = inputValue * 2;
        Output.SetValue(result);
    }
}</pre>
<p>The presenter is using interfaces to access the user interface &#8211; which allows presenter unit tests to be built via mocks independent to the development of the UI:</p>
<pre style="background:#e0e0e0;color:#000000;">public interface IInput
{
    int GetValue();
}

public interface IOutput
{
    void SetValue(int newValue);
}</pre>
<p>Binding the interfaces to a deployed UI can then take the form of UI-specific adapters to the IInput and IOutput interfaces. I.e. for a Window1 class containing input and output accessors (implemented using explicit marshalling as described in <a href="http://visionsofsoftware.com/2010/06/25/use-explicit-marshalling-to-update-a-wpf-ui-from-a-non-ui-thread/">this blog entry</a>):</p>
<pre style="background:#e0e0e0;color:#000000;">public partial class Window1 : Window
{
    ...

    public String ThreadSafeGetInputValue() ...
    public void ThreadSafeSetOutputValue(String newValue) ...
}</pre>
<p>The following two adapters can be used to convert the UI to match the required interface without the need to modify the UI code. (Null and error checking has been excluded below to reduce code footprint:)</p>
<pre style="background:#e0e0e0;color:#000000;">public class AdapterIInputWindow1 : IInput
{
    private Window1 Window1 { get; set; }

    public AdapterIInputWindow1(Window1 wrappedWindow)
    {
        Window1 = wrappedWindow;
    }

    // IInput implementation - excluding error checking
    public int GetValue()
    {
        int result = Convert.ToInt32(Window1.ThreadSafeGetInputValue());
        return result;
    }
}

public class AdapterIOutputWindow1 : IOutput
{
    private Window1 Window1 { get; set; }

    public AdapterIOutputWindow1(Window1 wrappedWindow)
    {
        Window1 = wrappedWindow;
    }

    // IOutput implementation - excluding error checking
    public void SetValue(int newValue)
    {
        Window1.ThreadSafeSetOutputValue(newValue.ToString());
    }
}</pre>
<p>Finally the UI can initialize its presenter and set the IInput and IOutput interfaces to the appropriate adapters:</p>
<pre style="background:#e0e0e0;color:#000000;">public partial class Window1 : Window
{
    private Presenter Presenter { get; set; }

    public Window1()
    {
        InitializeComponent();

        Presenter = new Presenter();
        Presenter.Input = new AdapterIInputWindow1(this);
        Presenter.Output = new AdapterIOutputWindow1(this);
    }

    public void XamlAction(object sender, EventArgs args)
    {
        Presenter.PerformDoubling();
    }
    ...
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/260/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/260/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/260/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/260/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/260/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/260/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/260/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/260/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/260/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/260/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/260/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/260/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/260/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/260/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=260&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/08/23/the-adapter-pattern-and-presenter-first-uis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>Adapting agile techniques to open source and personal projects</title>
		<link>http://visionsofsoftware.com/2010/07/16/adapting-agile-techniques-to-open-source-and-personal-projects/</link>
		<comments>http://visionsofsoftware.com/2010/07/16/adapting-agile-techniques-to-open-source-and-personal-projects/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 10:28:24 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[methodology]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=182</guid>
		<description><![CDATA[Agile techniques are a great way to build applications in a flexible manner &#8211; allowing requirements to change during the lifetime of a project and delivering frequent working releases. Most agile methods are geared towards corporate development environments &#8211; where all contributors are available for face-to-face or instant messaging-based communication and each can guarantee a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=182&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Agile techniques are a great way to build applications in a flexible manner &#8211; allowing requirements to change during the lifetime of a project and delivering frequent working releases. Most agile methods are geared towards corporate development environments &#8211; where all contributors are available for face-to-face or instant messaging-based communication and each can guarantee a consistent and high level of contribution.</p>
<p>I&#8217;ve recently been looking at how agile techniques can be adapted to the benefit of both open source collaborations and personal projects.</p>
<p>Some key benefits of agile are:<br />
<UL><LI><B>Sustained engagement of the stakeholders</B> &#8211; by allow the stakeholders both visibility into the project, frequent working releases and the ability to change things if requirements change.<br />
<LI><B>Frequently available working releases</B> &#8211; by time-boxing activities and test-driven development methods.<br />
<LI><B>A high level of confidence in the delivered software</B> &#8211; by test-driven development methods, a large set of automated unit tests and pair programming.<br />
<LI><B>An engaged, productive development team</B> &#8211; by frequent short meetings, pair programming and repeated complete delivery cycles.</UL></p>
<p>There are a number of obstacles that open source and personal projects put in the way of using pure corporate agile techniques:<br />
<UL><LI><B>A highly distributed team</B> &#8211; it is unlikely to be able to get people together in person, or even online at a scheduled time.<br />
<LI><B>Lumpy time commitments</B> &#8211; these projects are typically background work for the contributors who cannot commit a specific amount of time during any given period.<br />
<LI><B>Contributor churn</B> &#8211; existing contributors may disappear from the project at any given point, and new contributors may join.<br />
<LI><B>A variable level / patchwork coverage of skills</B> &#8211; dependent on the team of contributors, the areas that require effort may have no skills coverage or a variable level of skills coverage.<br />
<LI><B>Loose or non-existent chain of command</B> &#8211; due to the community nature of open source projects and potential churn of original project members there may be no formal day-to-day direction of the project.</UL></p>
<p><B>Using collaborations and interactions</B></p>
<p>The distributed nature of the contributors to an open source project means that in most cases it is not feasible to have the frequent face-to-face meetings of standard agile implementations.</p>
<p>An adaptation of the methodology is needed and one option is to use online collaborations (shared documents / spreadsheets / etc.) and interactions to connect contributors.</p>
<p>The methodology is focused on scope-boxing the changes to the project (rather than time-boxing where a consistent level of effort can be sustained.) This means that each contributor should ensure that the project remains in a releasable state (does not degrade) with every contribution. Automated unit-tests (preferably integrated with the IDE build environment) should be created for each contribution to enable future contributors to ensure the same.</p>
<p>The methodology also aims to be as lightweight as possible &#8211; so that contributors can focus on progressing the project.</p>
<p><B>Collaborations</B><br />
<UL><LI><B>The project backlog</B> &#8211; Mimicking the product backlog of Scrum, the project backlog contains the set of stories that define the future modifications considered or targeted for the project. Stories can include: <B>user stories</B> &#8211; the raw features and interactions for end users, <B>design stories</B> &#8211; object model creation, code-internal refactorings and migration of code to use a given pattern, <B>bug stories</B> &#8211; the tracking list of bugs in the project.<br />
Any contributor can add any type of story to the project backlog. The priority of each story is maintained in the backlog and can be set either by those directing the effort or by a summation of contributor votes.<br />
<LI><B>Personal treadmills</B> &#8211; Each contributor maintains a community-visible personal treadmill &#8211; which contains the current story they are working on along with the history of stories they have previously completed. When the user claims a story and puts it on their treadmill the fact that it has been claimed is registered within the project backlog.<br />
<LI><B>The delivery log</B> &#8211; As each story is completed and submitted to the code repository it is removed from the project backlog and added to the appropriate section of the delivery log. This contains the set of features and changes that have occurred on the project. Sections within the delivery log include features (for user stories), designs (for design stories) and fixes (for bug stories.)</UL></p>
<p><B>Interactions</B><br />
<UL><LI><B>Adding a story</B> &#8211; Any contributor can add a story to the project backlog. The story is tagged with the type of story it is (user, design, etc.) and contains a description of the desired state of the application once the story is completed. Stories should be as atomic as possible such that they lead to treadmill work with a short duration.<br />
<LI><B>Prioritizing stories</B> &#8211; A community-wide method of prioritizing stories is to allow each contributor a number of movable votes (e.g. 5) which they can then apply to separate outstanding stories in the project backlog. The stories are then prioritized by the count of votes for each story. As stories get completed contributor votes get freed up to be applied to other outstanding stories in the backlog.<br />
<LI><B>Contribution</B> &#8211; A contributor claims an outstanding story and adds it to their treadmill. The story is marked as claimed in the project backlog and tagged with the date for the claim. Each contribution should be delivered such that a releasable project is available at the end of the contribution. The use of test-driven techniques strongly supports the continual verification of existing functionality as contributors add stories.<br />
<LI><B>Release phase lockout</B> &#8211; If needed a release phase lockout can be performed on the project backlog. In the run up to a release a line can be drawn under the set of user stories targeted for the release. Only bug stories are allowed to be added above the line. Contributors working on the release branch should focus on completing stories above the line.<br />
<LI><B>Exceptions</B> &#8211; Any stories that have been claimed by a contributor who has subsequently become inactive will be available for claim by other contributors. An appropriate timescale is agreed by the community (e.g. a week) before a story can be claimed by another contributor. Any stories on the backlog that are persistently being left unclaimed can have their priority increased. </UL></p>
<p>The same methodology easily scales down to personal projects.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=182&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/07/16/adapting-agile-techniques-to-open-source-and-personal-projects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>Use explicit marshalling to update a WPF UI from a non-UI thread</title>
		<link>http://visionsofsoftware.com/2010/06/25/use-explicit-marshalling-to-update-a-wpf-ui-from-a-non-ui-thread/</link>
		<comments>http://visionsofsoftware.com/2010/06/25/use-explicit-marshalling-to-update-a-wpf-ui-from-a-non-ui-thread/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 11:34:42 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[marshalling]]></category>
		<category><![CDATA[thread]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=127</guid>
		<description><![CDATA[One option for updating a WPF UI from a non-UI thread (including a background worker) is to perform explicit marshalling using the dispatcher. A simple example follows. A separate blog entry details how to update a UI using a background worker&#8217;s implicit marshalling. Lets assume there is a C# window mediator class that has a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=127&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One option for updating a WPF UI from a non-UI thread (including a background worker) is to perform explicit marshalling using the dispatcher.  A simple example follows.</p>
<p>A separate blog entry details how to update a UI using a background worker&#8217;s <a href="http://visionsofsoftware.com/2010/05/14/update-ui-from-background-worker-thread-without-explicit-marshalling/">implicit marshalling</a>.</p>
<p>Lets assume there is a C# window mediator class that has a reference to a pair of WPF controls &#8211; one for user input and one for user reporting.  The WPF window constructs the mediator and sets the two control properties during its construction.  Two functions provide access to the data and may be called from any thread:</p>
<pre style="background:#e0e0e0;color:#000000;">public partial class MainWindow : Window
{
    private WindowMediator m_mediator = null;

    public MainWindow()
    {
        InitializeComponent();

        m_mediator = new WindowMediator();

        // Controls declared in the window's XAML
        m_mediator.IncomingDataControl = m_xamlTextBox;
        m_mediator.ReportDataControl = m_xamlTextBlock;
        ...
    }
    ...
}

public class WindowMediator
{
    // Controls.  A TextBox to retrieve data and a TextBlock to report data
    public TextBox IncomingDataControl { private get; set; }
    public TextBlock ReportDataControl { private get; set; }

    // Access functions to retrieve and set data (also see below)
    public String GetIncomingData(bool reformat) { ... }
    public void SetReportData(String newReport) { ... }
}</pre>
<p>When updating the values of a WPF control, the code needs to be executed on the UI thread &#8211; i.e. the thread that owns the WPF control.  The control&#8217;s dispatcher provides a function <b>CheckAccess</b> (which is the equivalent of the Windows Forms property InvokeRequired) to determine whether the call is currently executing on the UI thread.</p>
<p>If not &#8211; the <b>Invoke</b> method of the dispatcher can be used to execute a delegate on the appropriate thread.  The <b>Action</b> framework class can be used to generate a Delegate from the current method (or from an anonymous method) and pass the parameters across:</p>
<pre style="background:#e0e0e0;color:#000000;">public void SetReportData(String newReport)
{
    if (!ReportDataControl.Dispatcher.CheckAccess())
    {
       // Switch threads and recurse
       ReportDataControl.Dispatcher.Invoke(
          System.Windows.Threading.DispatcherPriority.Normal,
          new Action&lt;String&gt;(SetReportData), newReport);
    }
    else
    {
        ReportDataControl.Text = newReport;
    }
}</pre>
<p>A similar method can be used to retrieve data from a WPF control.  The generic framework class <b>Func</b> can be used to add a return type:</p>
<pre style="background:#e0e0e0;color:#000000;">public String GetIncomingData(bool reformat)
{
    String result = "";

    if (!IncomingDataControl.Dispatcher.CheckAccess())
    {
       // Switch threads and recurse
       result = (String) IncomingDataControl.Dispatcher.Invoke(
          System.Windows.Threading.DispatcherPriority.Normal,
          new Func&lt;bool, String&gt;(GetIncomingData), reformat);
    }
    else
    {
        if (reformat)
        {
             result = "--" + IncomingDataControl.Text;
        }
        else
        {
             result = IncomingDataControl.Text;
        }
    }

    return result;
}</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/127/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/127/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/127/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=127&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/06/25/use-explicit-marshalling-to-update-a-wpf-ui-from-a-non-ui-thread/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>Garbage collection, generations and the large object heap</title>
		<link>http://visionsofsoftware.com/2010/06/18/garbage-collection-generations-and-the-large-object-heap/</link>
		<comments>http://visionsofsoftware.com/2010/06/18/garbage-collection-generations-and-the-large-object-heap/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 08:51:40 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[common language runtime]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[large object heap]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=135</guid>
		<description><![CDATA[The .Net CLR maintains a managed heap used to dynamically allocate and garbage collect objects. This heap is divided into two address spaces &#8211; one used by a generational garbage collector for small objects and a second used for large objects. The three generations The first address space (sometimes called the small object heap &#8211; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=135&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The .Net CLR maintains a managed heap used to dynamically allocate and garbage collect objects.  This heap is divided into two address spaces &#8211; one used by a generational garbage collector for small objects and a second used for large objects. </p>
<p><b>The three generations</b></p>
<p>The first address space (sometimes called the small object heap &#8211; SOH) holds the three GC generations (0, 1 and 2) and is used for small objects (less than 85,000 bytes in size.)  Each generation has a memory budget which can change over the lifetime of the application and is used to trigger collection of that generation.</p>
<p>The garbage collector will collect objects in generation 0 when its memory budget is exceeded.  Any survivors of a GC on generation 0 are promoted to generation 1 (any non-survivors have their memory reclaimed.)  Each generation is a contiguous address space &#8211; so promotion to generation 1 includes moving the objects into the address space allocated to generation 1 &#8211; compacting the memory used.</p>
<p>The GC will continue collecting generation 0 until the memory budget for generation 1 also gets exceeded.  Once this occurs both generation 0 and generation 1 are collected.  Any survivors of the generation 1 collection are promoted to generation 2.  Generation 2 contains the oldest / longest lived objects.  Again promotion includes compacting the memory by moving the objects into the address space allocated for generation 2.</p>
<p>This process continues with frequent collections of generation 0, less frequent collections of generation 1 and infrequent collections of generation 2.  As the garbage collector performs each collection it also adapts to the memory usage patterns of the application &#8211; changing the memory budget allocations for each generation to optimise performance.</p>
<p><b>The large object heap</b></p>
<p>The second address space contains the large object heap (LOH) and is used for large objects (85,000 bytes and larger.)</p>
<p>Objects on the LOH are considered part of generation 2 and collected with this generation.  This means that short-lived large objects will only be collected either when the generational GC collects generation 2, the LOH exceeds its memory budget or the user programmatically invokes a collection of generation 2.</p>
<p>Due to the cost of moving large objects, the CLR does not compact the memory space for the LOH.  Large objects will remain where they were originally allocated.  This is an implementation artefact of the CLR GC &#8211; as such it may be changed in the future.  The size boundary of objects considered large may also change so if you require a static memory location for an object you will need to pin it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/135/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/135/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/135/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=135&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/06/18/garbage-collection-generations-and-the-large-object-heap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>Covariance and contravariance in C# 4.0</title>
		<link>http://visionsofsoftware.com/2010/06/11/covariance-and-contravariance-in-c-4-0/</link>
		<comments>http://visionsofsoftware.com/2010/06/11/covariance-and-contravariance-in-c-4-0/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 07:55:45 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c#4.0]]></category>
		<category><![CDATA[contravariance]]></category>
		<category><![CDATA[covariance]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[generic]]></category>
		<category><![CDATA[interface]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=85</guid>
		<description><![CDATA[C# 4.0 introduces covariance and contravariance (together variance) for generic type parameters. These two concepts are similar and allow the use of derived or base classes in a class hierarchy. An easy way to understand the difference between the two concepts is to consider the activity of the user of the variables passed to / [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=85&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>C# 4.0 introduces covariance and contravariance (together variance) for generic type parameters.  These two concepts are similar and allow the use of derived or base classes in a class hierarchy.</p>
<p>An easy way to understand the difference between the two concepts is to consider the activity of the user of the variables passed to / from the generic method (interface or delegate.)</p>
<p><b>Contravariance</b></p>
<p>If the method implementation is only using variables passed with the parameter for <b>read</b> activity &#8211; then the generic parameter is a candidate for contravariance.  The &#8216;read only&#8217; role of the parameter type can be formalised by marking it with the <b>in</b> keyword &#8211; i.e. it is an input to the implementation.</p>
<p>Any generic type parameter marked with the <b>in</b> keyword will be able to match to types that are derived from the named type.  In this case the implementation is the user of the variables.  It makes sense to allow derived classes as any read activities that are available on the base class will also be available on any derived class.</p>
<pre style="background:#e0e0e0;color:#000000;">// C# 3.0 does not recognise the in keyword for parameterized types
public delegate void TypeReporter&lt;in T&gt;(T input);

public void DoSomeGenericContravariance(RoutedEventArgs args)
{
    TypeReporter&lt;EventArgs&gt; ReportMethod
                  = new TypeReporter&lt;EventArgs&gt;(this.SimpleReportMethod);

    // C# 3.0 and earlier will not compile the following
    TypeReporter&lt;RoutedEventArgs&gt; RoutedReportMethod = ReportMethod;

    RoutedReportMethod(args);
}

public void SimpleReportMethod(EventArgs args)
{
    Console.WriteLine(args.GetType().ToString());
}</pre>
<p><b>Covariance</b></p>
<p>Similarly &#8211; if a method implementation is only using variables passed with the parameter for <b>write</b> activity &#8211; then the generic parameter is a candidate for covariance.  The &#8216;write only&#8217; role of the parameter type can be formalised by marking it with the <b>out</b> keyword &#8211; i.e. it is an output from the implementation.</p>
<p>Any generic type parameter marked with the <b>out</b> keyword will be able to match to types that are base classes of the named type.  In this case the calling / client code can be considered the user of the variables &#8211; so again it makes sense.  Any operation (read or write) that is available on the base class that the client code has requested will also be available on the actual (derived) type that the implementation instantiates / sends as output.</p>
<pre style="background:#e0e0e0;color:#000000;">public void DoSomeGenericCovariance()
{
    // The generic IEnumerable interface is defined with the out keyword
    // on the parameter type:
    //
    // public interface IEnumerable&lt;out T&gt; : IEnumerable

    List&lt;String&gt; strings = new List&lt;String&gt; { "one", "two" };
    IEnumerable&lt;String&gt; myStrings = strings.AsEnumerable();

    // C#3.0 and earlier will not compile the following
    IEnumerable&lt;object&gt; myObjects = myStrings;

    foreach (object myObject in myObjects)
    {
        Console.WriteLine(myObject.ToString());
    }
}</pre>
<p><b>Issues to consider</b></p>
<p>Once type parameters have been marked with the in or out keyword the compiler will validate the interface / delegate compliance with the assigned variance.  E.g. if the first example is changed to return the parameter passed, then the compiler will report an error &#8211; as the parameter is not being used for input only.</p>
<pre style="background:#e0e0e0;color:#000000;">// Compiler will report a variance validation error
public delegate T TypeReporter&lt;in T&gt;(T input);</pre>
<p>Variance uses reference type conversion &#8211; so it will not work with value types.  Even though within the type system int inherits from object, the following will not compile.</p>
<pre style="background:#e0e0e0;color:#000000;">List&lt;int&gt; ints = new List&lt;int&gt; { 1, 2 };
IEnumerable&lt;int&gt; myInts = ints.AsEnumerable();

// Reference type conversion not available
IEnumerable&lt;object&gt; myIntObjects = myInts;</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/85/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/85/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/85/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=85&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/06/11/covariance-and-contravariance-in-c-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>C# and NUnit &#8211; testing interface implementations</title>
		<link>http://visionsofsoftware.com/2010/06/04/c-and-nunit-testing-interface-implementations/</link>
		<comments>http://visionsofsoftware.com/2010/06/04/c-and-nunit-testing-interface-implementations/#comments</comments>
		<pubDate>Fri, 04 Jun 2010 08:36:04 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[nunit]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=68</guid>
		<description><![CDATA[A common development strategy is to generate interface definitions and then code against these &#8211; allowing the implementations to be varied easily. When writing NUnit test cases for interfaces and implementing classes &#8211; it is possible to generate a set of test cases for the interface and then apply these test cases to each concrete [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=68&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A common development strategy is to generate interface definitions and then code against these &#8211; allowing the implementations to be varied easily.</p>
<p>When writing NUnit test cases for interfaces and implementing classes &#8211; it is possible to generate a set of test cases for the interface and then apply these test cases to each concrete implementation.  A strategy is outlined below.</p>
<p>Within the class library containing the test cases generate a test fixture for the interface itself.  A class member, <b>m_fileManager</b> in this case, is used to hold the interface instance to test and a second member <b>m_runTests</b> is used to track whether the fixture holds an interface realisation.</p>
<p>A virtual function <b>CreateConcrete</b> is defined to create the concrete interface implementation &#8211;  it is called in the SetUp method.</p>
<p>Add the interface test cases to this class &#8211; checking whether tests should by run using the m_runTests member.</p>
<pre style="background:#e0e0e0;color:#000000;">[TestFixture]
public class Test_IFileManager
{

    /// Interface to use for testing
    protected IFileManager m_fileManager;

    /// Indicator that we are in a realisation test fixture
    protected bool m_runTests = false;

    /// Create a concrete instance
    virtual public void CreateConcrete()
    {
    }

    [SetUp]
    /// Test set up
    public void Setup()
    {
        CreateConcrete();
    }

    [TearDown]
    /// Test tear down
    public void TearDown()
    {
        m_fileManager = null;
        m_runTests = false;
    }

    [Test]
    /// A simple test
    public void NonExistentDirectoryThrowsException()
    {
        if (m_runTests)
        {
            Console.WriteLine("Running test: NonExistentDirectoryThrowsException");

            Assert.Throws&lt;DirectoryNotFoundException&gt;
                ( delegate
                  {
                    m_fileManager.GetFreeFileName(@"ZZ:\BadDrive\", "stem", "txt");
                  });
        }
    }
}</pre>
<p>To attach the set of test cases to a concrete implementation, generate a class that inherits this base interface testing class.  Override the CreateConcrete method to assign the interface instance and to indicate that the tests should be run.</p>
<pre style="background:#e0e0e0;color:#000000;">[TestFixture]
public class Test_IFileManager_SimpleFileManager : Test_IFileManager
{

    /// Create a concrete instance
    override public void CreateConcrete()
    {
        // Using static method
        m_fileManager = (IFileManager) SimpleFileManager.GetFileManager();
        m_runTests = true;
    }

}</pre>
<p>Each implementing class can be tested by creating a separate concrete implementation testing class.  When NUnit runs it finds all of the interface tests and runs them for each concrete implementation.</p>
<p>If any implementation-specific test cases exist, then they can be added to the concrete testing class.  If a class implements multiple interfaces, then each interface can be tested in a similar manner by generating a concrete implementation testing class for each interface / implementer pair.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/68/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/68/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/68/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=68&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/06/04/c-and-nunit-testing-interface-implementations/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>Software companies listed in the UK</title>
		<link>http://visionsofsoftware.com/2010/05/28/software-companies-listed-in-the-uk/</link>
		<comments>http://visionsofsoftware.com/2010/05/28/software-companies-listed-in-the-uk/#comments</comments>
		<pubDate>Fri, 28 May 2010 08:08:32 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[company]]></category>
		<category><![CDATA[finance]]></category>
		<category><![CDATA[uk]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=49</guid>
		<description><![CDATA[With the news that Apple (AAPL) has overtaken Microsoft (MSFT) to become the largest software company in the world by market capitalisation it seems like a good time to have a look at the software companies listed in the UK. Below are the details for the largest UK pure-play (almost) software companies. Limited to FTSE [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=49&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>With the news that Apple (AAPL) has overtaken Microsoft (MSFT) to become the largest software company in the world by market capitalisation it seems like a good time to have a look at the software companies listed in the UK.</p>
<p>Below are the details for the largest UK pure-play (almost) software companies.  Limited to FTSE 350 components the sector has it&#8217;s own tracking index NMX9530.L</p>
<p>With a combined market capitalisation of approximately £18.3 b ($26.7 b) the whole sector is dwarfed by Apple at $231 b.</p>
<p>£4.18 b &#8211; Autonomy (AU.L) <a href="http://www.autonomy.com/">http://www.autonomy.com/</a><br />
£3.11 b &#8211; Sage Group (SGE.L) <a href="http://www.sage.com/">http://www.sage.com/</a><br />
£2.25 b &#8211; Invensys (ISYS.L) <a href="http://www.invensys.com/">http://www.invensys.com/</a><br />
£2.01 b &#8211; Logica (LOG.L) <a href="http://www.logica.com/">http://www.logica.com/</a><br />
£1.69 b &#8211; Dimension Data (DDT.L) <a href="http://www.dimensiondata.com/">http://www.dimensiondata.com/</a><br />
£1.22 b &#8211; Misys (MSY.L) <a href="http://www.misys.co.uk/">http://www.misys.co.uk/</a><br />
£987 m &#8211; Micro Focus (MCRO.L) <a href="http://www.microfocus.com/">http://www.microfocus.com/</a><br />
£781 m &#8211; Aveva (AVV.L) <a href="http://www.aveva.com/">http://www.aveva.com/</a><br />
£753 m &#8211; Telecity Group (TCY.L) <a href="http://www.telecitygroup.com/">http://www.telecitygroup.com/</a><br />
£488 m &#8211; Computacenter (CCC.L) <a href="http://www.computacenter.com/">http://www.computacenter.com/</a><br />
£483 m &#8211; Fidessa Group (FDSA.L) <a href="http://www.fidessa.com/">http://www.fidessa.com/</a><br />
£358 m &#8211; SDL (SDL.L) <a href="http://www.sdl.com/">http://www.sdl.com/</a></p>
<p>Prices at close of 27 May 2010 from Yahoo Finance (<a href="http://uk.finance.yahoo.com/">http://uk.finance.yahoo.com/</a>)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/49/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/49/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/49/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=49&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/05/28/software-companies-listed-in-the-uk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
		<item>
		<title>Optional parameters and named parameters in C#4.0</title>
		<link>http://visionsofsoftware.com/2010/05/21/optional-parameters-and-named-parameters-in-c4-0/</link>
		<comments>http://visionsofsoftware.com/2010/05/21/optional-parameters-and-named-parameters-in-c4-0/#comments</comments>
		<pubDate>Fri, 21 May 2010 09:23:56 +0000</pubDate>
		<dc:creator>sjhunt</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c#4.0]]></category>

		<guid isPermaLink="false">http://visionsofsoftware.com/?p=30</guid>
		<description><![CDATA[If you are familiar with C++ or VB then you will already be familiar with optional parameters. They are parameters that are assigned a default value at compile time and that can be omitted when calling a method. public void LayoutElements(IList&#60;Element&#62; elements, int xOrig = 0, int yOrig = 0) { ... } ... layoutTool.LayoutElements(elementList); [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=30&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are familiar with C++ or VB then you will already be familiar with optional parameters.  They are parameters that are assigned a default value at compile time and that can be omitted when calling a method.</p>
<pre style="background:#e0e0e0;color:#000000;">  public void LayoutElements(IList&lt;Element&gt; elements, int xOrig = 0, int yOrig = 0)
  {
    ...
  }

    ...

    layoutTool.LayoutElements(elementList);         // Will layout at 0, 0
    layoutTool.LayoutElements(elementList, 25, 25)  // Will layout at 25, 25</pre>
<p>C#4.0 adds the ability to define optional parameters for methods, constructors and indexers.</p>
<p>An obvious area of use is constructors.  Optional parameters remove the need to define multiple overloaded constructors with a variety of parameters all calling into a single constructor which does the work.</p>
<p>Any optional parameters must be declared after all non-optional parameters.  You can overload a method to have two versions &#8211; one with an optional parameter and one without.  In this case the compiler will resolve to the method without the optional parameter (following the principal of least surprise.)</p>
<pre style="background:#e0e0e0;color:#000000;">
  public void LayoutElements(IList&lt;Element&gt; elements)
  {
     LayoutElements(elements, 5, 5);
     ...
  }

  public void LayoutElements(IList&lt;Element&gt; elements, int xOrig = 0, int yOrig = 0)
  {
    ...
  }

    ...

    // Resolves to first method - will layout at 5, 5
    layoutTool.LayoutElements(elementList);</pre>
<p>Another addition, named parameters, helps when calling a method, constructor or indexer.  Similar in function to named parameters used with attributes.</p>
<p>You use the name of the variable to fill the parameter &#8211; using a colon to specify the value.</p>
<pre style="background:#e0e0e0;color:#000000;">  // Will layout at 0, 10
  layoutTool.LayoutElements(elementList, yOrig: 10);</pre>
<p>Named parameters can be used for both optional and positional parameters.  When making the function call all named parameters must occur after any positional parameters.  The named parameters do not have to appear in the order of the parameters in the method declaration.</p>
<pre style="background:#e0e0e0;color:#000000;">  // Will layout at 15, 10
  layoutTool.LayoutElements(yOrig: 10, xOrig: 15, elements: elementList);</pre>
<p>If you use partial methods, then for both optional and named parameters the declaration in the definition is used at compile time.</p>
<pre style="background:#e0e0e0;color:#000000;">  partial void LayoutElements(IList&lt;Element&gt; elements, int xOrig = 0, int yOrig = 0);

   ...

  partial void LayoutElements(IList&lt;Element&gt; elements, int x = 5, int y = 5)
  {
    ...
  }

    ...

//    layoutTool.LayoutElements(elementList, y : 10);    // Will not compile
    layoutTool.LayoutElements(elementList, yOrig : 10);  // Will layout at 0, 10</pre>
<p>Be aware that if you rename parameters in a method that is called elsewhere with the named parameter syntax, then the names will no longer match and the calling code will not compile.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/visionsofsoftware.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/visionsofsoftware.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/visionsofsoftware.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/visionsofsoftware.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/visionsofsoftware.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/visionsofsoftware.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/visionsofsoftware.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/visionsofsoftware.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/visionsofsoftware.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/visionsofsoftware.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/visionsofsoftware.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/visionsofsoftware.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/visionsofsoftware.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/visionsofsoftware.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=visionsofsoftware.com&amp;blog=13137346&amp;post=30&amp;subd=visionsofsoftware&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://visionsofsoftware.com/2010/05/21/optional-parameters-and-named-parameters-in-c4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e2725545b321553a6ee0ae89cc46ad39?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">sjhunt</media:title>
		</media:content>
	</item>
	</channel>
</rss>
