<?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>Software Development in a Dynamic Environment</title>
	<atom:link href="http://davidvcorbin.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidvcorbin.wordpress.com</link>
	<description>Lessons Learned - And the trials of learning them</description>
	<lastBuildDate>Wed, 04 May 2011 00:30:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='davidvcorbin.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Software Development in a Dynamic Environment</title>
		<link>http://davidvcorbin.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://davidvcorbin.wordpress.com/osd.xml" title="Software Development in a Dynamic Environment" />
	<atom:link rel='hub' href='http://davidvcorbin.wordpress.com/?pushpress=hub'/>
		<item>
		<title>An Examination of Software Testing Approaches</title>
		<link>http://davidvcorbin.wordpress.com/2011/05/03/an-examination-of-software-testing-approaches/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/05/03/an-examination-of-software-testing-approaches/#comments</comments>
		<pubDate>Tue, 03 May 2011 23:55:11 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[Application Lifecycle Management]]></category>

		<guid isPermaLink="false">https://davidvcorbin.wordpress.com/?p=122</guid>
		<description><![CDATA[Microsoft’s David Platt is known to say “Users don’t care about your program in and of itself. Never have, never will. Your mother might, because you wrote it and she loves you, and then again she might not; but no &#8230; <a href="http://davidvcorbin.wordpress.com/2011/05/03/an-examination-of-software-testing-approaches/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=122&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Microsoft’s David Platt is known to say “<em>Users don’t care about your program in and of itself. Never have, never will. Your mother might, because you wrote it and she loves you, and then again she might not; but no one else does. Users care only about their own productivity or their own pleasure</em>.” In this light; if software is “correct” if it can be shown to:</p>
<ul>
<li>Meet the users expectations and requirements</li>
<li>Deployable and supportable in a manner acceptable to the operations group</li>
<li>Maintainable in a manner acceptable to the development group</li>
</ul>
<p>The purpose of testing can be reduced to verifying these statements about the program are in fact true. In many ways these can be considered the Prime Directives of a testing approach.</p>
<p>&nbsp;<strong>“System Testing</strong>” is one type of testing that can be used to verify this. It is typically done in an environment that closely matches the production environment, and performed by people who will act as the eventual consumers (Users, Administrators, etc.). At this level, only the externally visible aspects of the program are considered, and the tests typically fall into one of three categories:</p>
<ul>
<li>Script based Manual Testing</li>
<li>Exploratory Manual Testing</li>
<li>Automated Testing</li>
</ul>
<p>This approach does have some limitations including:</p>
<ul>
<li>Testing cannot begin until the program is in a sufficiently mature state</li>
<li>Regression testing is time consuming and therefore costly</li>
<li>Setting up specific scenarios (especially error scenarios) can be very difficult</li>
</ul>
<p>As a result, other types of testing get introduced to minimize the impact of these limitations. But the question remains what types of testing are best for different scenarios. </p>
<p>“<strong>Functional Testing</strong>” breaks the system down to individual elements that map directly to the (wait for it….) Functional Specifications, or for Agile teams, User Stories.&nbsp; The primary advantage of this is that is correlates very well with the concepts of “<em>deliver working software</em>” without having to necessarily have the whole system (or even large parts of it) complete. With the judicious use of Mock objects we can easily address most of the limitations with system level testing. A large number of teams focus on this type of testing during each iteration (sprint) and use this as the primary methodology of determining with when something is “complete”;&nbsp; the completed items are regularly propagated into the Test/QA environment, where system type testing can be performed.</p>
<p>Before continuing, let us think about what “perfect” testing would be.&nbsp; I propose the following as a working definition: “Perfect testing would insure that any change made to the software, which would cause a violation of any of the Prime Directives, is caught by one or more failing tests”.&nbsp; However, we know that nothing is perfect, and that even if this is the goal, it can not be reached even with infinite resources dedicated to testing. What we are left with is a continuum. At one end, a minimal effort expended on testing with a high probability of issues which incur associated costs.&nbsp; At the other end,&nbsp; an extremely high investment in testing with the goal of minimizing the number and severity of any issues which slip past the tests.</p>
<p>The “sweet spot” is where we have minimized the sum of both the testing costs and “issues” costs. Of course, the type of system has a major impact on finding this spot. Some of the projects I work on are Industrial Automation, where serious injury or loss of life is a distinct possibility if certain types of malfunctions occur. Other systems such as banking and trading may incur millions of dollars in financial losses in the event of certain&nbsp; defects. What I have repeatedly found working in different domains (vertical markets), is that many of the methodologies in these demanding environments can be applied, with modification, to “normal” business systems where they are not usually considered; and that this can be done with a minimal cost, often resulting in overall savings.</p>
<p>I have come to the conclusion that while Functional Testing is nearly always a key component, it is not sufficient to minimize the chances of violating a Prime Directive by making a change to the code. This is because Functional testing only captures one of the 5 “W”’s:</p>
<ul>
<li>Who – Which piece of code is responsible for a given item</li>
<li>What – What does the code accomplish</li>
<li>When – When is the operation actually performed (Aggressive Loading, Lazy Evaluation, etc.)</li>
<li>Where – Where do the inputs come from?, where do the outputs go?, where are there side effects?</li>
<li>Why – What drove a specific approach? Why were others eliminated?</li>
</ul>
<p>It is important to remember the qualifier as “by making a change to the code”. Initially determining these items is definitely a human activity; and the best way to achieve this is through a solid design methodology with a strong emphasis on code-reviews (pair-programing can also be very helpful in many cases).&nbsp; What I am specifically addressing are the changes that occur to a piece of code, for any one of a number of reasons that “seem like a good idea”, but fail to take into account that (presumably) the code was developed the way it was for a specific reason.</p>
<p>As a specific example, I was recently on a project where there was a small (never more than 20 items) collection that had a huge number of replacements (one item being removed, a different item being added)&nbsp; occurring at a very high rate. There were also a fair number of places where the entire collection was iterated over, and a few places where an element was being accessed by its “key”. The original implementation was a .NET <font face="Courier New"><strong>List&lt;T&gt;</strong></font> so that locating an item for replacement and accessing an element by key were both done by a linear scan.&nbsp; One of the developers was working with code that interacted with the collection, and noticed&nbsp; the&nbsp; linear scans of the collection.&nbsp; It looked like a good idea to replace the <font face="Courier New"><strong>List&lt;T&gt; </strong></font>with a <font face="Courier New"><strong>Dictionary&lt;K,T</strong></font><font face="Calibri">&gt;, because of this change it was also necessary to add some synchronization (lock) code. </font> The code was reviewed, the change was made, the Functional tests all passed, and even the Application level Load/performance tests passed. </p>
<p>About two weeks after the code was deployed to production, there were various performance anomalies that were causing a multitude of problems. It took about two days to track the problem back to this change. The initial thought was that it was the locking that caused the problem, but that did not account for all of the issues. The original developer was contacted [he had moved to a different team], and after some time thinking about it remembered the reason he had chosen the <font face="Courier New"><strong>List&lt;T&gt;</strong></font> with the linear operations – the overhead of managing the index far outweighed the cost of the sequential scans.</p>
<p>Many will argue that the code should have been commented, or that the load testing should have been enhanced, and neither of these are incorrect. But, we all know that comments are often not read, or become out of date; and, in this particular case, setting up a load test for this specific condition at the application level would have been extremely difficult. Had there been a test at a lower level designed to detect the conditions that caused the original author to choose the specific implementation, this entire episode would have been virtually eliminated.</p>
<p>This is only one simple sample, but the general concept applies in many situations. In order to address these, I generally recommend the following types of tests be implemented (or at least considered):</p>
<p>“<strong>Granular Unit Testing</strong>” (which I often will refer to as GUT testing) These tests focus tightly on specific code elements at the lowest level practical, typically individual methods and properties of each class. Heavy use of Mock object, and even Reflection to setup the desired states is quite common. In many environments, this type of testing has fallen out of favor; being viewed as “testing the trivially obvious”; Yet, there is significant value in this type of testing. The ability to quickly execute a focused test can reduce the “cycle time” from minutes down to seconds for quick verification of the change. The tests themselves often provide useful information about the amount of work to setup a given item (often revealing tighter than intended coupling), and can also be useful as “sample use-cases” for new developers coming up to speed. In order to reduce the costs in developing these tests, some automation is helpful. Here are Dynamic Concepts Development Corp. we have developed a custom toolkit (hopefully to be released as a product later this year) that makes it very easy to setup the initial conditions and have a clean separation between the manually created elements and the generated code.</p>
<p>“<strong>Design Rule Check Testing</strong>” (commonly referred to as DRC tests) These tests have the greatest degree of separation from the “functional” aspects. The goal here is to minimize the risk that the code has deviated from the intended/desired design.&nbsp; Some “tests” can be accomplished by having a robust set of StyleCop/FxCop/etc. rules. Others may perform more detailed analysis on the code. Items that are often a good target focus (some specifically for .Net): Resource Utilization, Thread Safety Identification (even for applications that are currently single threaded), Complexity of Object Graphs (which may a bigger impact on Garbage collection than the number of temporary objects created!).</p>
<p>“<strong>Negative Testing</strong>”&nbsp; (i.e. testing things that don’t happen!) These tests seem to be the the rarest of them all, and typically need explanation. As a quick example consider a class that exposes 4 events. Changing a specific property should raise one of the events. Validating that this event is raised at the appropriate time is likely to be in the Functional tests and/or the GUT tests. But most of these tests will not catch a bug where the property change triggers other events in addition to the one that is specified.&nbsp; This can be very significant. At the low end of the impact spectrum it can create unnecessary processing overhead -especially if the handler[s] are heavy, or there are a large number of handlers registered. At the high end of the impact spectrum, it may reveal a significant defect in the logic of the code under test which might not be caught in other conditions. As with the GUT tests, it is very helpful to have a tool which can compare initial state with final state as well as register for events which should not fire.</p>
<p>When all of these are put together to form a multi-dimensional approach to testing, I have seen drops in defect rates of up to 60%. If you are currently engaged on a greenfield (initial development) project, I strongly recommend this approach. If you are currently on a brownfield (ongoing maintenance/upgrade) project, then an incremental adoption is typically the best bet. When one component is being updated, take the time to make sure that the testing for that component (not just the elements you are currently changing) have a solid set of tests before making the change, validate that the change will cause test failures to the existing tests, and also look for cases where the old code is capable of passing the relevant test suite. This last step goes a long way in ensuring that the changes you are making are thoroughly tested.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/122/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/122/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/122/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=122&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/05/03/an-examination-of-software-testing-approaches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>Method Invocation based on Runtime Type of Parameter (conclusion)</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/29/method-invocation-based-on-runtime-type-of-parameter-conclusion/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/29/method-invocation-based-on-runtime-type-of-parameter-conclusion/#comments</comments>
		<pubDate>Sat, 30 Apr 2011 01:40:54 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[.NET Architecture & Implementation]]></category>

		<guid isPermaLink="false">https://davidvcorbin.wordpress.com/2011/04/29/method-invocation-based-on-runtime-type-of-parameter-conclusion/</guid>
		<description><![CDATA[In the last two installments, we covered both a simple baseline implementation of the double dispatch pattern and a flexible method of passing additional parameters. This leaves us with one remaining objective – being able to invoke a specific method &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/29/method-invocation-based-on-runtime-type-of-parameter-conclusion/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=119&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the last two installments, we covered both a simple baseline implementation of<br />
the double dispatch pattern and a flexible method of passing additional parameters.<br />
This leaves us with one remaining objective – being able to invoke a specific method<br />
based on the runtime type of multiple parameters. To start off we make the observation<br />
that the following code:</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span class="style1" style="color:#0000ff;">void</span> Sample&lt;T1&gt;( <span style="color:#2b91af;">Thing </span>a, <span style="color:#2b91af;">Thing  </span>b, T1 data)</p>
<p> </p>
<p>can be logically transformed to and from</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#0000ff;">void </span>Sample&lt;T1&gt;( <span style="color:#2b91af;">Thing</span> b, <span style="color:#0000ff;">ref</span>  <span style="color:#2b91af;">T2</span>&lt; <span style="color:#2b91af;">Thing</span>,T1&gt; encapsulatedData)</p>
<p> </p>
<p>by simply creating a simple wrapper contain such as the one below:</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#0000ff;">class</span> <span style="color:#2b91af;">T2</span>&lt;TARGET, ARG2, DATA&gt;<br />
{<br />
    <span style="color:#0000ff;">public</span> T2(TARGET target, ARG2 arg2, DATA originalData)<br />
    {<br />
        Target = target;<br />
        Arg2 = arg2;<br />
        OriginalData = originalData;<br />
    }</p>
<p>  <span style="color:#0000ff;">internal </span>TARGET Target { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">private set</span>; }<br />
   <span style="color:#0000ff;">internal</span> ARG2 Arg2 { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">private set</span>; }<br />
   <span style="color:#0000ff;">internal</span> DATA OriginalData { <span style="color:#0000ff;">get</span>; <span style="color:#0000ff;">private set</span>; }<br />
}</p>
<p>class Helper&lt;X&gt; : IThingDispatchTarget&lt;T2&lt;X,MyData&gt;&gt; <span style="color:#0000ff;">where</span> X : Thing<br />
{<br />
   public <span style="color:#0000ff;">void</span> Dispatch( <span style="color:#2b91af;">Thing</span> b, <span style="color:#0000ff;">ref  </span><span style="color:#2b91af;">T2</span>&lt;X, <span style="color:#2b91af;">MyData</span>&gt; encapsulatedData) {…}<br />
}</p>
<p>We already know how to perform a a method invocation based on runtime type for a method with the signature of “EncapsulatedSample” so it would seem we are very close<br />
to our goal. In fact, if we were dealing with C++ templates rather than C# generics,  we would indeed by on the last steps of our journey. Unfortunately, even though our T2 helper class is specialized for a specific derived class, within the generic body, the type is still treated as if it were of the type specified in the where clause. Thus any usage of encapsulatedData.FirstParameter within our Dispatch(…) method [or indeed within the <span style="color:#2b91af;">Helper </span>class implementation] will be treaded as a <span style="color:#2b91af;">Thing </span>rather than a specific derived class such as: <span style="color:#2b91af;">Asteroid</span> or <span style="color:#2b91af;">Planet</span>. So much for being able to simply dispatch using the methodology we have been covering.</p>
<p>Alas, there is no way to accomplish our goal using purely “static” code while avoiding<br />
significant duplication, and/or runtime conditional code. This series would not be a useful “Power Programming” tip if it ended here, and it doesn’t. Compiled Expression Trees can come to our rescue! The following code will generate a delegate that will invoke the proper overload:</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#0000ff;">private</span> <span style="color:#0000ff;">static</span><span style="color:#2b91af;">Action</span>&lt;TARGET, ARG1, ARG2, DATA&gt; GetRealAction&lt;TARGET,ARG1, ARG2, DATA&gt;()<br />
{     <span style="color:#2b91af;"><br />
   MethodInfo</span> mi = <span style="color:#0000ff;">typeof</span>(TARGET).GetMethod(<br />
            <span style="color:#a31515;">&#8220;Execute&#8221;</span>, <br />
             <span style="color:#0000ff;">new</span>[] {<span style="color:#0000ff;">typeof</span>(ARG1),<span style="color:#0000ff;">typeof</span>(ARG2),<span style="color:#0000ff;">typeof</span>(DATA)});     <br />
<span style="color:#2b91af;">   ParameterExpression</span> target = <span style="color:#2b91af;">Expression</span>.Paramete(<span style="color:#0000ff;">typeof</span>(TARGET),<span style="color:#a31515;">target&#8221;</span>); </p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#2b91af;">   ParameterExpression</span> arg1 = <span style="color:#2b91af;">Expression</span>.Paramete(<span style="color:#0000ff;">typeof</span>(ARG1),<span style="color:#a31515;">&#8220;arg1&#8243;</span>);</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#2b91af;">   ParameterExpression</span> arg2 = <span style="color:#2b91af;">Expression</span>.Parameter( <span style="color:#0000ff;">typeof</span>(ARG2),<span style="color:#a31515;">&#8220;arg2&#8243;</span>);</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#2b91af;">   ParameterExpression</span> data = <span style="color:#2b91af;"> Expression</span>.Parameter( <span style="color:#0000ff;">typeof</span>(DATA),<span style="color:#a31515;">&#8220;data&#8221;</span>);    <span style="color:#2b91af;"> </span></p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#2b91af;">   MethodCallExpression</span> mce = <span style="color:#2b91af;">Expression</span>.Call(</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;">                                target, mi, arg1, arg2, data);    </p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#2b91af;">   Expression</span>&lt;<span style="color:#2b91af;">Action</span>&lt;TARGET, ARG1, ARG2, DATA&gt;&gt; lambda =<span style="color:#2b91af;">    </span></p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#2b91af;">              Expression</span>.Lambda&lt;<span style="color:#2b91af;">Action</span>&lt;TARGET, ARG1, ARG2, DATA&gt;&gt;</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;">             (mce, target, arg1, arg2, data);     <span style="color:#0000ff;"><br />
   return</span> lambda .Compile();<br />
}</p>
<p>With this helpful utility method, we can create all that we need as part of the<br />
type initialization of the <span style="color:#2b91af;">Helper </span>class:</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#0000ff;">static</span> Helper()</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;">{<br />
    sr_ThingAction = GetRealAction&lt;<span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Thing</span>,  <span style="color:#2b91af;">MyData</span>&gt;();</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;">  sr_SpaceshipAction = GetRealAction&lt; <span style="color:#2b91af;">RealClass</span>, X,  <span style="color:#2b91af;">Spaceship</span>, <span style="color:#2b91af;">MyData</span>&gt;();</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;">    sr_PlanetAction = GetRealAction&lt; <span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Planet</span>, <span style="color:#2b91af;">MyData</span>&gt;();    <br />
    sr_SunAction = GetRealAction&lt; <span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Sun</span>, <span style="color:#2b91af;">MyData</span>&gt;();<br />
    sr_AsteroidAction = GetRealAction&lt; <span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Asteroid</span>,<span style="color:#2b91af;">MyData</span>&gt;();<br />
}  <br />
<span style="color:#0000ff;">private </span><span style="color:#0000ff;">static </span><span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Thing</span>,<span style="color:#2b91af;">MyData</span>&gt; sr_ThingAction;</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#0000ff;">private </span><span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Spaceship</span>, <span style="color:#2b91af;">MyData</span>&gt; sr_SpaceshipAction; <span style="color:#0000ff;">private </span><span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly </span><span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Planet</span>, <span style="color:#2b91af;">MyData</span>&gt; sr_PlanetAction; <span style="color:#0000ff;">private </span><span style="color:#0000ff;">static</span> <span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Sun</span>, <span style="color:#2b91af;">MyData</span>&gt; sr_SunAction;</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"><span style="color:#0000ff;">private </span><span style="color:#0000ff;">static </span><span style="color:#0000ff;">readonly</span> <span style="color:#2b91af;">Action</span>&lt;<span style="color:#2b91af;">RealClass</span>, X, <span style="color:#2b91af;">Asteroid</span>, <span style="color:#2b91af;">MyData</span>&gt; sr_AsteroidAction;</p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"> </p>
<p>And complete our <span style="color:#2b91af;">Helper</span>class implementation with:</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">void </span>Dispatch( <span style="color:#2b91af;">Thing</span> b, <span style="color:#0000ff;">ref</span> <span style="color:#2b91af;">T2</span>&lt;<span style="color:#2b91af;">RealClass</span>, ARG1, <span style="color:#2b91af;">MyData</span>&gt; data)<br />
{ b.Dispatch( <span style="color:#0000ff;">this</span>,  <span style="color:#0000ff;">ref</span> data); }   <span style="color:#0000ff;"><br />
</span></p>
<p style="margin-left:20pt;margin-top:0;margin-bottom:0;font-family:'Courier New', Courier, monospace;font-weight:bold;font-size:small;"> </p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Thing</span> instance, <span style="color:#0000ff;">ref</span>  <span style="color:#2b91af;">T2</span>&lt;<span style="color:#2b91af;">RealClass</span>,ARG1,<span style="color:#2b91af;">MyData</span>&gt;data)</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;">{ sr_ThingAction(data.Target,data.Arg1, instance, data.OriginalData); }</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"> </p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Spaceship</span> instance, <span style="color:#0000ff;">ref</span> <span style="color:#2b91af;">T2</span>&lt;<span style="color:#2b91af;">RealClass</span>, ARG1, <span style="color:#2b91af;">MyData</span>&gt;data) { sr_SpaceshipAction(data.Target, data.Arg1,instance,data.OriginalData); }</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"> <span style="color:#0000ff;"><br />
public </span><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Planet</span> instance, <span style="color:#0000ff;">ref</span> <span style="color:#2b91af;">T2</span>&lt; <span style="color:#2b91af;">RealClass</span>, ARG1, <span style="color:#2b91af;">MyData</span>&gt;data)</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"> { sr_PlanetAction(data.Target, data.Arg1, instance, data.OriginalData); }</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">void</span> Execute( <span style="color:#2b91af;">Sun</span> instance, <span style="color:#0000ff;">ref</span> <span style="color:#2b91af;">T2</span>&lt; <span style="color:#2b91af;">RealClass</span>,ARG1, <span style="color:#2b91af;">MyData</span>&gt; data)<br />
{ sr_SunAction(data.Target, data.Arg1, instance, data.OriginalData); }  </p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"> </p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">void</span> Execute( <span style="color:#2b91af;">Asteroid </span>instance, <span style="color:#0000ff;">ref</span> <span style="color:#2b91af;">T2</span>&lt;<span style="color:#2b91af;">RealClass</span>, ARG1, <span style="color:#2b91af;">MyData</span>&gt; data) { sr_AsteroidAction(data.Target, data.Arg1, instance, data.OriginalData); }</p>
<p style="margin-top:0;font-family:'Courier New', Courier, monospace;margin-bottom:0;margin-left:20pt;font-size:small;font-weight:bold;"> </p>
<h2>Conclusion</h2>
<p>Well, it took a bit of work but we finally made it. The only remaining question is was the effort worth it. Running the above code where we have 1,000 elements (of equally distributed derived types) and running a loop that invokes a method for every combination (1,000,000 method invocations), gives the following numbers:</p>
<table style="width:628px;height:269px;" width="628" border="0" cellspacing="0" cellpadding="2">
<tbody>
<tr>
<td valign="top" width="731"><strong>Scenario</strong></td>
<td valign="top" width="111"><strong>Total Time (mSec)</strong></td>
<td valign="top" width="176"><strong>Methodology Overhead(mSec)</strong></td>
</tr>
<tr>
<td valign="top" width="731">Baseline loop directly calling a method which takes the base ( <span style="color:#2b91af;"><br />
Thing</span>) type as parameters</td>
<td style="text-align:right;" valign="top" width="111">738</td>
<td valign="top" width="176"> </td>
</tr>
<tr>
<td valign="top" width="731">Multi-Dispatch using the above architecture</td>
<td style="text-align:right;" valign="top" width="111">9510</td>
<td style="text-align:right;" valign="top" width="176">8772</td>
</tr>
<tr>
<td valign="top" width="731">Multi-Dispatch using the <span style="color:#0000ff;">dynamic</span> keyword</td>
<td style="text-align:right;" valign="top" width="111">18478</td>
<td style="text-align:right;" valign="top" width="176">17739</td>
</tr>
</tbody>
</table>
<p>The chart clearly shows that dispatching to specific methods based on runtime type<br />
of parameter is not “cheap”, but the timing difference is significant. Using <span style="color:#0000ff;"><strong>dynamic</strong></span> created double the overhead of out multi-dispatch implementation, and we reduced the loop time <em>from over 18.4  seconds to 9.5 seconds</em>. If this were a smaller collection (say 1000 invocations per iteration) this would translate to a difference in frame rates (assuming this  loop was the only calculation occurring) of 54 FPS and 105 FPS.</p>
<p>Additionally, although the use cases where this implementation is worth the effort may be small; we did uncover a very powerful technique for being able to tread generic arguments as their actual type rather than being constrained to the functionality exposed by the common base [i.e. the type specified in the where clause]. In the long run is is the discovery of these “gems” that are potentially applicable to a wide variety of use-cases that provides the biggest gains in exploring “Power Programming” techniques.</p>
<p>I hope you have all enjoyed this journey, and am looking forward to hearing your<br />
comments and feedback. The next series of posts will be focused back on ALM, but<br />
I am hoping to produce about one “Power Programming” series per month.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/119/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/119/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/119/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=119&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/29/method-invocation-based-on-runtime-type-of-parameter-conclusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>Method Invocation based on Runtime Type of Parameter (continued)</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/25/method-invocation-based-on-runtime-type-of-parameter-continued/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/25/method-invocation-based-on-runtime-type-of-parameter-continued/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 22:26:12 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[.NET Architecture & Implementation]]></category>

		<guid isPermaLink="false">https://davidvcorbin.wordpress.com/2011/04/25/method-invocation-based-on-runtime-type-of-parameter-continued/</guid>
		<description><![CDATA[In my last post post, we reviewed the basics of the Double Dispatch pattern, and provided a simple example implementation. Unfortunately, this implementation is rather limited because it only handles the case where the instance in question in the sole &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/25/method-invocation-based-on-runtime-type-of-parameter-continued/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=117&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my last post post, we reviewed the basics of the Double Dispatch pattern, and provided a simple example implementation. Unfortunately, this implementation is rather limited because it only handles the case where the instance in question in the sole parameter to the target method. Later, we will discuss ways to overcome this limitation, but first I want to expand on Peter Ritchie’s <a href="http://msmvps.com/blogs/peterritchie/archive/2010/05/24/using-the-dynamic-keyword-in-c-to-improve-object-orientation.aspx" target="_blank">post</a> on using the dynamic keyword that is available in .NET 4.0.</p>
<p>First, dynamic is a great tool and is an excellent choice for many situations where the goal is to have different methods execute based on the runtime type of a parameter. Slightly reworking his same to use our classes we have:</p>
<blockquote><p style="margin:0;" class="MsoNormal"><font face="Consolas"><font size="3"><span><font color="#0000ff">void</font></span><span> DynamicMethod(<span><font color="#0000ff">dynamic</font></span> thing)</span></font></font></p>
<p style="margin:0;" class="MsoNormal"><span><font size="3" face="Consolas">{</font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp;&nbsp; </span>SomeMethod(thing);</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font size="3" face="Consolas">}</font></span></p>
</blockquote>
<p><font size="3">Indeed, it is very “clean” to look at, no modifications were required to the class hierarchy, and in fact this approach will handle additional parameters and even dispatch based on multiple parameters with ease. Alas, as science fiction writer Robert Heinlein said (he did not originate the acronym but definitely popularized it, as did Larry Niven) TANSTAAFL&nbsp; &#8211; “<strong><em>There ain’t no such thing as a free lunch.</em></strong>”.&nbsp; There are in fact two side-effects of choosing to use <strong>dynamic:</strong></font></p>
<ul>
<li><strong>Security</strong> – As Peter pointed out, there does not even have to be a relationship between the instance. Provided a target can be resolved, it will be used. In our case, this risk is minimal; but in the example Peter used with deserialization the risk can be much higher. Lets look at a sample very similar (<em>but with significant difference</em>) to Peter’s:</li>
</ul>
<blockquote><p><font><span><font color="#2b91af" face="Consolas">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IFormatter</font></span></font><span><font><font face="Consolas">&nbsp; formatter = <span><font color="#0000ff">new</font></span></font></font><span><font><font face="Consolas">&nbsp; <span><font color="#2b91af">BinaryFormatter</font></span></font></font><span><font face="Consolas"> ();<br /></font></span></span></span><span><font color="#2b91af"><font><font face="Consolas"><font><span><font color="#0000ff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dynamic</font></span></font><span><font> </font></span></font></font></font></span><font face="Consolas"><span><font>shape = formatter.Deserialize(stream);<br /></font></span><font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; shape.<font>Execute(</font>);</font></font></p>
</blockquote>
<blockquote><p><font size="3">If someone can hijack the stream (perhaps it is reading from a disk file), then the the object type can be completely replaced by altering the stream. Providing the object type has an execute method that takes no parameters, the code will run. Now, imagine if the de-serialized object is of type SelfDestructSequence instead of a sub-class of Shape.</font></p>
</blockquote>
<ul>
<li><font size="3"><strong>Performance</strong> – Assuming we are constrained by a performance specification, the use of dynamic may have serious ramifications.&nbsp; Measurements I have performed (<em>using Stopwatch over 10 million executions and then averaging 10 runs after throwing out the fastest and slowest</em>) show that dynamic is typically twice as slow as the original sequence of casts and compares, and 15 times as slow as the double dispatch used in the last post.</font></li>
</ul>
<blockquote><p><font size="3">It is critical to put this performance measurement into context. If the overall operation is of significant time, or the number of calls through the dispatching mechanism is low, then the difference will be meaningless in the overall scheme of things. However, if the target method is very fast, and there are going to be large numbers of calls [such as in our later example where 10,000 instances are operated on in all possible combinations for a total of nearly 10 million calls] and there is a tight performance specification, then this must be taken into account.</font></p>
</blockquote>
<p><font size="3">With that out of the way, we can return to the original topics. First, lets look at scenarios where the target method requires one or more parameters in addition to the one that is being specially treated.&nbsp; This is relatively simple, just change the signatures of the “IDispatchTarget” interface, along with the dispatch methods within the class hierarchy. But what should the new signatures be???</font></p>
<p><font size="3">At first glance, it may appear easiest to modify the code to match the parameter types for the specific use-case. I recommend against this approach because it has a habit of growing out of control very quickly. If the parameters change, then the interface and class hierarchy will be impacted.&nbsp; it gets even worse if the same class hierarchy needs to be dispatched to different methods in different classes. Either there will have to be multiple different interfaces (with a “Dispatch” method for each, or there will be multiple methods in the interface for the same object type, which usually leads to forced implementation of “NotSupported” methods.</font></p>
<p><font size="3">Using generics helps the situation, but only a little. You still need different implementations for different numbers of parameters, and face the same issues as in the previous scenario.</font></p>
<p><font size="3">What I have found to be the best solution for the majority of cases, is to use a single generic parameter, and pass it as a <strong><font face="Courier New">ref</font></strong> parameter. This gives rise to the following:</font></p>
<blockquote><p style="margin:0;" class="MsoNormal"><font face="Consolas"><font size="3"><span><font color="#0000ff">interface</font></span><span> <span><font color="#2b91af">IThingDispatchTarget</font></span>&lt;T&gt;</span></font></font></p>
<p style="margin:0;" class="MsoNormal"><span><font size="3" face="Consolas">{</font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> Execute(<span><font color="#2b91af">Thing</font></span> instance, <span><font color="#0000ff">ref</font></span> T data);</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> Execute(<span><font color="#2b91af">Spaceship</font></span> instance, <span><font color="#0000ff">ref</font></span> T data);</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> Execute(<span><font color="#2b91af">Planet</font></span> instance, <span><font color="#0000ff">ref</font></span> T data);</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> Execute(<span><font color="#2b91af">Sun</font></span> instance, <span><font color="#0000ff">ref</font></span> T data);</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> Execute(<span><font color="#2b91af">Asteroid</font></span> instance, <span><font color="#0000ff">ref</font></span> T data);</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font size="3" face="Consolas">}</font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font size="3" face="Consolas">&nbsp;</font></span></p>
</blockquote>
<p><font size="3">The</font> reason for using pass by reference, is that it gives use the ability to efficiently package an transfer multiple items within the data parameter by using a <font face="Courier New"><strong>struct</strong></font><font size="3">, without the overhead of creating additional instances on the heap, or by copying the contents of the <font face="Courier New"><strong>struct</strong></font> as would be required if it was pass by value. To complete the code sample..</font></p>
<blockquote><p style="margin:0;" class="MsoNormal"><font face="Consolas"><font size="3"><span><font color="#0000ff">class</font></span><span> <span><font color="#2b91af">RealClass</font></span> : <span><font color="#2b91af">IThingDispatchTarget</font></span>&lt;<span><font color="#2b91af">MyData</font></span>&gt;</span></font></font></p>
<p style="margin:0;" class="MsoNormal"><span><font size="3" face="Consolas">{</font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp;&nbsp; </span><span><font color="#0000ff">public</font></span> <span><font color="#0000ff">void</font></span> SomeMethod(<span><font color="#2b91af">Thing</font></span> thing, <span><font color="#0000ff">ref</font></span> <span><font color="#2b91af">MyData</font></span> data)</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp;&nbsp; </span>{</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>thing.Dispatch(<span><font color="#0000ff">this</font></span>, <span><font color="#0000ff">ref</font></span> data);</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp;&nbsp; </span>}<br /></font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span><font color="#0000ff">&nbsp;&nbsp; void</font></span> <span><font color="#2b91af">IThingDispatchTarget</font></span>&lt;<span><font color="#2b91af">MyData</font></span>&gt;.Execute(<span><font color="#2b91af">Thing</font></span> instance, <span><font color="#0000ff">ref</font></span> <span><font color="#2b91af">MyData</font></span> data) { }</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> <span><font color="#2b91af">IThingDispatchTarget</font></span>&lt;<span><font color="#2b91af">MyData</font></span>&gt;.Execute(<span><font color="#2b91af">Spaceship</font></span> instance, <span><font color="#0000ff">ref</font></span> <span><font color="#2b91af">MyData</font></span> data) { }</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> <span><font color="#2b91af">IThingDispatchTarget</font></span>&lt;<span><font color="#2b91af">MyData</font></span>&gt;.Execute(<span><font color="#2b91af">Planet</font></span> instance, <span><font color="#0000ff">ref</font></span> <span><font color="#2b91af">MyData</font></span> data) { }</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> <span><font color="#2b91af">IThingDispatchTarget</font></span>&lt;<span><font color="#2b91af">MyData</font></span>&gt;.Execute(<span><font color="#2b91af">Sun</font></span> instance, <span><font color="#0000ff">ref</font></span> <span><font color="#2b91af">MyData</font></span> data) { }</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font face="Consolas"><font size="3"><span>&nbsp;&nbsp; </span><span><font color="#0000ff">void</font></span> <span><font color="#2b91af">IThingDispatchTarget</font></span>&lt;<span><font color="#2b91af">MyData</font></span>&gt;.Execute(<span><font color="#2b91af">Asteroid</font></span> instance, <span><font color="#0000ff">ref</font></span> <span><font color="#2b91af">MyData</font></span> data) { }</font></font></span></p>
<p style="margin:0;" class="MsoNormal"><span><font size="3" face="Consolas">}</font></span></p>
</blockquote>
<p><font size="3">That wraps up handling additional parameters, leaving use with the topic of being able to dispatch based on the runtime type of multiple parameters. Since this post is getting a little on the long side, we will continue with it next time…</font></p>
<p><font size="3"></font></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/117/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/117/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/117/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=117&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/25/method-invocation-based-on-runtime-type-of-parameter-continued/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>C# Power Programming #101&#8211;Method Invocation based on Runtime Type of Parameter</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/23/c-power-programming-101method-invocation-based-on-runtime-type-of-parameter/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/23/c-power-programming-101method-invocation-based-on-runtime-type-of-parameter/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 16:49:27 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">https://davidvcorbin.wordpress.com/?p=57</guid>
		<description><![CDATA[Virtual methods make it easy to invoke a specific method on an object based on the runtime type of the instance. However, invoking specific methods based on the runtime type of a parameter is not so easy. For this post &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/23/c-power-programming-101method-invocation-based-on-runtime-type-of-parameter/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=57&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Virtual methods make it easy to invoke a specific method on an object based on the runtime type of the instance. However, invoking specific methods based on the runtime type of a parameter is not so easy. For this post we will use the following class hierarchy:</p>
<div style="padding-left:25pt;padding-bottom:12pt;"><span style="color:blue;">class</span> <span style="color:#2b91af;">Thing</span>{}<br />
<span style="color:blue;">class</span> <span style="color:#2b91af;">Spaceship</span> : <span style="color:#2b91af;">Thing</span> {}<br />
<span style="color:blue;">class</span> <span style="color:#2b91af;">Planet</span> : <span style="color:#2b91af;">Thing</span> {}<br />
<span style="color:blue;">class</span> <span style="color:#2b91af;">Sun</span> : <span style="color:#2b91af;">Thing</span> {}<br />
<span style="color:blue;">class</span> <span style="color:#2b91af;">Asteroid</span> : <span style="color:#2b91af;">Thing</span> {}</div>
<p>The following code illustrates a trivial case of the issue:</p>
<div style="padding-left:25pt;padding-bottom:12pt;"><span style="color:#0000ff;">void</span> SomeMethod(<span style="color:#2b91af;">Spaceship</span> spaceship) {}<br />
<span style="color:#0000ff;">void</span> SomeMethod(<span style="color:#2b91af;">Thing</span> thing) {}</p>
<p><span style="color:#2b91af;">Thing</span> sample1 = <span style="color:#0000ff;">new</span> <span style="color:#2b91af;">Spaceship</span>();<br />
SomeMethod(sample1);</div>
<p>The above code will always call the overload that takes a <span style="color:#2b91af;">Thing</span> because that is the declared type of sample1, even though it is obvious that the instance is a <span style="color:#2b91af;">Spaceship</span>. Of course this trivial example could easily be modified to declare sample1 as a <span style="color:#2b91af;">Spaceship</span>, but that would be cheating. Since the overload that takes a <span style="color:#2b91af;">Thing</span> will always be called, many developers resort to variations on the following pattern:&lt;/p.</p>
<div style="padding-left:25pt;padding-bottom:12pt;margin:0;">
<span style="padding-left:0;"><span style="color:#0000ff;">void</span> SomeMethod(<span style="color:#2b91af;">Thing</span> thing)</span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;"><span style="color:blue;">if</span> (thing <span style="color:blue;">is</span> <span style="color:#2b91af;">Spaceship</span>)</span><br />
<span style="padding-left:20pt;">{</span><br />
<span style="padding-left:40pt;"><span style="color:#2b91af;">Spaceship</span> spaceship = (<span style="color:#2b91af;">Spaceship</span>) thing;</span><br />
<span style="padding-left:40pt;">SomeMethod(spaceship);</span><br />
<span style="padding-left:20pt;">}</span><br />
<span style="padding-left:20pt;"><span style="color:blue;">else</span> <span style="color:blue;">if</span> (thing <span style="color:blue;">is</span> <span style="color:#2b91af;">Planet</span>)</span><br />
<span style="padding-left:20pt;">{</span><br />
<span style="padding-left:40pt;"><span style="color:#2b91af;">Planet</span> planet = (<span style="color:#2b91af;">Planet</span>)thing;</span><br />
<span style="padding-left:40pt;">SomeMethod(planet);</span><br />
<span style="padding-left:20pt;">}</span><br />
<span style="padding-left:20pt;"><span style="color:green;">// Repeat for each possible type&#8230;</span>;&#8221;&gt;}</span><br />
<span style="padding-left:0;">}</span>
</div>
<p>This code smells bad in so many ways. There are more lines of code for plumbing than there are for actual work. There are many redundant casts. If a new derived class is created, this code must be manually tracked down and altered. There is a better was and it is known as Double Dispatch. This pattern has been known for at least 20 years, and there is documentation on it readily available on the web. The classic implementation is to create an interface to the code that has the method in question add one virtual method to the base class of the hierarchy which is overridden in each of the derived classes. The result will look something like the following:</p>
<div style="padding-left:25pt;padding-bottom:12pt;">
<span style="color:#0000ff;">interface</span> <span style="color:#2b91af;">IThingDispatchTarget</span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Thing</span> instance);</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Spaceship</span> instance);</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Planet</span> instance);</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Sun</span> instance);</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">void</span> Execute(<span style="color:#2b91af;">Asteroid</span> instance);</span><br />
<span style="padding-left:0;">}</span><br />
<br />
<span style="padding-left:0;"><span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Thing</span></span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">virtual </span><span style="color:#0000ff;">void </span> Dispatch(<span style="color:#2b91af;">IThingDispatchTarget</span> target)</span><br />
<span style="padding-left:150pt;">{ target.Execute(<span style="color:#0000ff;">this</span>); }</span><br />
<span style="padding-left:0;">}</span><br />
<br />
<span style="padding-left:0;"><span style="color:#0000ff;">class <span style="color:#2b91af;">Spaceship</span> : <span style="color:#2b91af;">Thing</span></span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">virtual </span><span style="color:#0000ff;">void </span> Dispatch(<span style="color:#2b91af;">IThingDispatchTarget</span> target)</span><br />
<span style="padding-left:150pt;">{ target.Execute(<span style="color:#0000ff;">this</span>); }</span><br />
<span style="padding-left:0;">}</span><br />
<br />
<span style="padding-left:0;"><span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Planet</span> : <span style="color:#2b91af;">Thing</span></span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">virtual </span><span style="color:#0000ff;">void </span> Dispatch(<span style="color:#2b91af;">IThingDispatchTarget</span> target)</span><br />
<span style="padding-left:150pt;">{ target.Execute(<span style="color:#0000ff;">this</span>); }</span><br />
<span style="padding-left:0;">}</span><br />
<br />
<span style="padding-left:0;"><span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Sun</span> : <span style="color:#2b91af;">Thing</span></span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">public </span><span style="color:#0000ff;">virtual </span><span style="color:#0000ff;">void </span> Dispatch(<span style="color:#2b91af;">IThingDispatchTarget</span> target)</span><br />
<span style="padding-left:150pt;">{ target.Execute(<span style="color:#0000ff;">this</span>); }</span><br />
<span style="padding-left:0;">}</span><br />
<br />
<span style="padding-left:0;"><span style="color:#0000ff;">class</span> <span style="color:#2b91af;">Asteroid</span> : <span style="color:#2b91af;">Thing  </span> </span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">override</span> <span style="color:#0000ff;">void</span> Dispatch(<span style="color:#2b91af;">IThingDispatchTarget</span> target)</span><br />
<span style="padding-left:100pt;">{ target.Execute(<span style="color:#0000ff;">this</span>); }</span><br />
<span style="padding-left:0;">}</span><br />
<br />
<span style="padding-left:0;"><span style="color:#0000ff;">public</span> <span style="color:#0000ff;">void</span> SomeMethod(<span style="color:#2b91af;">Thing</span> thing)</span><br />
<span style="padding-left:0;">{</span><br />
<span style="padding-left:20pt;">thing.Dispatch(<span style="color:#0000ff;">this</span>);</span><br />
<span style="padding-left:0;">}</span><br />
<br />
<span style="padding-left:0;"><span style="color:#0000ff;">void</span> <span style="color:#2b91af;">IThingDispatchTarget</span>.Execute(<span style="color:#2b91af;">Thing</span> instance) { }</span><br />
<span style="padding-left:0;"><span style="color:#0000ff;">void</span> <span style="color:#2b91af;">IThingDispatchTarget</span>.Execute(<span style="color:#2b91af;">Spaceship</span> instance) { }</span><br />
<span style="padding-left:0;"><span style="color:#0000ff;">void</span> <span style="color:#2b91af;">IThingDispatchTarget</span>.Execute(<span style="color:#2b91af;">Planet</span> instance) { }</span><br />
<span style="padding-left:0;"><span style="color:#0000ff;">void</span> <span style="color:#2b91af;">IThingDispatchTarget</span>.Execute(<span style="color:#2b91af;">Sun</span> instance) { }</span><br />
<span style="padding-left:0;"><span style="color:#0000ff;">void</span> <span style="color:#2b91af;">IThingDispatchTarget</span>.Execute(<span style="color:#2b91af;">Asteroid</span> instance) { }</span>
</div>
<p>Ah, the sweet smell of success. We only need to create the interface and add the methods to the hierarchy once, regardless of how many places in the application there is the need to perform different processing based on the runtime type of the parameter. There are no casts anywhere in the code. There is no conditional plumbing in the class(es) that do the work. The code is also faster. Timing tests run on the above show that double dispatch has only 12.8% the overhead of the nested if; furthermore, the overhead of double dispatch is fixed regardless of the number of classes in the hierarchy, while the nested if with cases grows linearly with the number of types.</p>
<p><strong>Conclusion</strong></p>
<p>I can almost hear readers saying “<em>This is a good technique, but it has been known for a long time….is it really worthy of the title Power Programming?</em>”. The answer to that is no! This post is just setting the stage for discussing some of the limitations with this simple implementation. When we continue, we will cover some topics that I have rarely found published:</p>
<ul>
<li><strong><em>How do we extend this when there are additional parameters involved that must be passed?</em></strong></li>
<li><strong><em>How do we extend this when we want to dispatch to different targets based upon multiple parameters?</em></strong></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/57/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/57/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/57/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=57&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/23/c-power-programming-101method-invocation-based-on-runtime-type-of-parameter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>Introducing:  The Power Programming Tips Series</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/22/introducing-the-power-programming-tips-series/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/22/introducing-the-power-programming-tips-series/#comments</comments>
		<pubDate>Sat, 23 Apr 2011 02:35:16 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[.NET Architecture & Implementation]]></category>

		<guid isPermaLink="false">https://davidvcorbin.wordpress.com/2011/04/22/introducing-the-power-programming-tips-series/</guid>
		<description><![CDATA[Although this blog is going to primarily focus on ALM [Application Lifecycle Management] topics, the reality is that without an application that is well designed and implemented, all of the “management” in the world is not going to yield a &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/22/introducing-the-power-programming-tips-series/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=55&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p> Although this blog is going to primarily focus on ALM [Application Lifecycle Management] topics, the reality is that without an application that is well designed and implemented, all of the “management” in the world is not going to yield a successful outcome.</p>
<p>This series will focus on specific techniques that address recurring issues that are found in certain classes of applications. Many of these will be performance related, so examining the adage “<strong><em>Premature Optimization is the Root of all evil</em></strong>”&nbsp; is&nbsp; very relevant.</p>
<p>The actual statement written by Donald Knuth was:</p>
<p>“<em>Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts of their programs, and these attempts at efficiency actually have a strong negative impact when debugging and maintenance are considered. We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%</em>.&#8221;&nbsp; &#8211; Computing Surveys, Vol. 6, No 4, December 1974 </p>
<p> I had started writing software just over two years before just over two years before this was written (I did not actually encounter the article until nearly three years after it was written) on a DEC PDP-8 with 16 K (that is 0.0000152587890625 Gig for modernists) of real (ferromagnetic) core memory. Even with this limited amount of memory it was responsible for administrative tasks of a 6,000 student school district. Combined with a clock speed that was less than 1MHz, writing the smallest, fastest possible code was a requirement. These days, most of my actual coding work is on projects that are extremely demanding in some fashion, often in terms of raw performance and I consistently find myself dealing with “our opportunities in that critical 3%”.</p>
<p>The first step in looking at performance is to have a specification. Without a documented specification it is impossible to say that something is “too slow” and therefore a candidate for performance optimization. The second step is to perform detailed measurements of items that fail (or are dangerously close to) these specifications. In many cases, a focusing on a very small part of the operation under consideration will yield the desired benefits. In other cases, a redesign may be necessary in order to have a robust, maintainable codebase that meets the specification.</p>
<p>As an example of the former case; Last year my firm was contracted by a major financial company who were having problems with application performance. Historically they had programmed in C++, but had recently moved to C#.&nbsp; The codebase was well designed with SOLID principles applied throughout, the algorithm implementation was straight forward, and although there were some general issues with the code, the “killer” problem was the performance of this one algorithm.</p>
<p>When I first arrived, the team was nearly evenly divided into three camps:</p>
<ul>
<li>“We told you .Net is too slow…we have to go back to native code”</li>
<li>“The algorithm has to be redesigned or at least re-implemented”</li>
<li>“We have to abandon OO principles and had write the code in an optimized fashion”</li>
</ul>
<p>I asked them if they had profiled the code, and they answered yes. I then asked to see how they profiled the code and they showed my the following:</p>
<blockquote><p><font face="Courier New">Stopwatch sw = new Stopwatch();<br />sw.Start();<br />CallProblematicAlgorithm();<br />sw.Stop();<br />int measurement = sw.ElapsedMilliseconds;</font></p>
</blockquote>
<p>They had not done ANY actual profiling of where the time was being spend within the various parts of the code. I fired up my favorite profiler (Red-Gate ANTs 6.0), and within a few minutes identified that replacing elements in a generic Dictionary&lt;K,V&gt; collection was responsible for a large amount of the time. I then did some research (aka I asked questions) and found out that the collection was indeed highly volatile, elements were frequently referenced by their key (although there were actually more Add/Removes’ than Keyed retrieval), but most importantly, the design constrained the collection to never have more than than about 20 entries in the collection!!!!</p>
<p>Because of the size of the collection, and the overhead in maintaining an indexed collection, I made one simple change…to a plain old generic List&lt;T&gt;, with a simple iteration to find the proper element when “keyed access” was required. Not surprisingly the time required to add or replace an element went down dramatically, the times to remove an element went down slightly, and the indexed access was just about the same. </p>
<p>This one simple change, was sufficient to reduce the overall time so that it met the performance specification with a good safety margin. [I only wish some of the other issues on that project were so easily resolved].</p>
<p>The key takeaway is that it really was a small part of the code that was critical, and that their original views on the subject were significantly off-the mark [I am being kind], and had they adopted any of them, they would have been in rather poor shape.</p>
<p><strong>Conclusion</strong></p>
<p>If you have done your due diligence, and determined that there are real performance issues and that specific code is a leading contributor to the problem,&nbsp; then hopefully the techniques I will be posting here will be of help. It is unlikely that any of them will be directly adoptable in their presented form, but my goal is to provide the background so that they can be evaluated and even used as the basis for power programming techniques of your own.</p>
<p>As always, I am looking forward to comments on these items, and suggestions for ways to address specific issues that you are encountering.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=55&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/22/introducing-the-power-programming-tips-series/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>Getting Started with ALM is Easy, using Microsoft TFS 2010!</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/21/getting-started-with-alm-is-easy-using-microsoft-tfs-2010/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/21/getting-started-with-alm-is-easy-using-microsoft-tfs-2010/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 17:37:36 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">https://davidvcorbin.wordpress.com/2011/04/22/getting-started-with-alm-is-easy-using-microsoft-tfs-2010/</guid>
		<description><![CDATA[In previous posts, I started laying out some of the background in ALM – What is it and Why Do I Care? and took a quick look at the 9 key areas in ALM &#38; an expanded approach to being &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/21/getting-started-with-alm-is-easy-using-microsoft-tfs-2010/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=51&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In previous posts, I started laying out some of the background in <a href="http://davidvcorbin.wordpress.com/2011/04/18/alm-what-is-it-and-why-do-i-care/">ALM – What is it and Why Do I Care?</a> and took a quick look at the 9 key areas in <a href="http://davidvcorbin.wordpress.com/2011/04/19/alm-an-expanded-approach-to-being-test-driven-part-1/">ALM &amp; an expanded approach to being Test Driven</a>. When I discuss this material with software development teams, the most common reaction I get is <em><strong>&#8220;I really want the goodness, but getting started is overwhelming</strong></em>&#8220;.
<p>For teams using Microsoft Visual Studio 2010 (or previous versions), there is great news. Microsoft <a href="http://msdn.microsoft.com/en-us/vstudio/ff637362">Team Foundation Server 2010</a> is incredibly easy to get up and running, the default configuration is usable by a great many teams, customization can be approached incrementally, and perhaps best of all, the is a <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=3660cacf-f077-44d3-a9d9-97e801da2035&amp;displaylang=en">free trial available for download</a>. Once the ISO is downloaded, it typically takes well under an hour (and can be as short as 15-20 minutes) to get a fully functional environment up and running.
<p>For those who experienced either the 2005 or 2008 installation process, you are in for a major pleasant surprise. Not only is the process much faster, but in many cases you can simply step through the wizard driven installation and accept the defaults as they are presented.
<p>The second most common thing I hear is &#8220;<em>I&#8217;ve installed it, it looks good, but <strong>how do I now learn how to use the tools effectively</strong>?</em>&#8220;. Once again, there is good news.
<p>For people who want a detailed walkthroughs, I highly recommend <strong><a href="http://www.wrox.com/WileyCDA/WroxTitle/Professional-Application-Lifecycle-Management-with-Visual-Studio-2010.productCd-0470484268.html">Professional Application Lifecycle management with Visual Studio</a> </strong>[ISBN :978-0-470-48426-5]. Written my Mickey Gousset, Brian Keller, Ajoy Krishnamoorthy and martin Woodword and published by Wiley Publishing (under the Wrox name), this book contains a wealth of information. It is the only book on the topic that I have brought into clients and said &#8220;<em>Here is our starting point, as we adopt the material in this book, we will make customizations as required, but in general they should be minor and driven by unique requirements</em>&#8220;.
<p>Other people will instead (or in conjunction) want material that is focused on specific items. The <a href="http://msdn.microsoft.com/en-us/vstudio/ee358786.aspx">Visual Studio ALM Rangers</a> are a group approximately 70&nbsp; Microsoft Employees and selected other individuals who “<strong>deliver practical out of band solutions for missing features or guidance on Visual Studio 2010</strong>”. [<em>I am proud to be a member of this group, and my personal profile can be found </em><a href="http://blogs.msdn.com/b/willy-peter_schaub/archive/2010/08/05/introducing-the-visual-studio-alm-rangers-david-v-corbin.aspx" target="_blank"><em>here</em></a>]. The following list highlights some of the guides that have been published.</p>
<ul>
<li>&nbsp;<a href="http://vs2010quickref.codeplex.com/" target="_blank">Visual Studio 2010 Quick Reference Guidance</a> &#8211; Compact guidance for the field to cover Team System and TFS capabilities
<li><a href="http://tfsbranchingguideiii.codeplex.com/" target="_blank">Team Foundation Server 2010 Branching Guide</a> &#8211; Guide includes discussions around branching concepts, strategies, and also focuses on practical hands-on labs.
<li><a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=97ca3b31-3653-4d60-bdad-3f2017febdc3&amp;displaylang=en" target="_blank">Team Foundation Server 2010 Monitoring Management Pack</a> &#8211; Delivers the capabilities for professional monitoring and management of Team Foundation Server 2010 infrastructure components
<li><a href="http://vsarchitectureguide.codeplex.com/" target="_blank">Visual Studio 2010 Architecture Tooling Guidance</a>- Guide is focused on practical ways of effectively using Visual Studio 2010 Ultimate and other tools to create a new or revised design.
<li><a href="http://vsdatabaseguide.codeplex.com/" target="_blank">Visual Studio 2010 Database Guide</a> &#8211; Guide includes practical guidance for Visual Studio 2010 database projects. </li>
</ul>
<p>Many of these guides include Hands on Labs [HOL] so that the material can be walked through interactively, and videos that provide visual impact.</p>
<p>In addition to the work by the Rangers, there are also a number o offerings by the <a href="http://msdn.microsoft.com/en-us/practices/bb190332" target="_blank">Patterns &amp; Practices</a> group at Microsoft that directly relate to TFS. While many of them were written based on earlier versions of TFS, the majority of the material is applicable to TFS 2010. Finally there are Microsoft <a href="http://social.msdn.microsoft.com/Forums/en-us/categories/" target="_blank">forums</a> dedicated to TFS, Groups on Linked In, and many other public sources of useful information.</p>
<p>As part of this blog, it is my intention to regularly publish [I am planning on once a month, but open to more frequent updates if enough readers want them] summaries and links that I have found to be useful and relevant.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=51&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/21/getting-started-with-alm-is-easy-using-microsoft-tfs-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>ALM &amp; an expanded approach to being Test Driven (Part 2)</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/20/alm-an-expanded-approach-to-being-test-driven-part-2/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/20/alm-an-expanded-approach-to-being-test-driven-part-2/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 20:32:14 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://davidvcorbin.wordpress.com/?p=39</guid>
		<description><![CDATA[In my last post, we identified 9 key areas of an Applications Lifecycle, and also set the ground rules for developing tests that can quantify both correctness and quality. In this segment, we will se how this groundwork can be &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/20/alm-an-expanded-approach-to-being-test-driven-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=39&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my last post, we identified 9 key areas of an Applications Lifecycle, and also set the ground rules for developing tests that can quantify both correctness and quality. In this segment, we will se how this groundwork can be applied to each of the 9 areas.</p>
<p><strong>Requirements Gathering (User Story Development)</strong></p>
<p>At first glance, it may not seem that there is anything to test at this point in time. However ensuring that the documented requirements accurately match the user requirements and are also consistent among themselves is extremely critical. If there is an undetected problem at this phase, it can easily cause significant impact on all of the other areas.</p>
<p>I have found that there are indeed a few activities that can be used to &#8220;test&#8221; this area.</p>
<ol>
<li>Use light weight mockups to provide a visual walk-through. A large number of issues are often identified when &#8220;Seeing pictures&#8221; that do not surface by reading words. The most effective methods are using tools like SketchFlow or even PowerPoint. At early stages, mockups written in code often present more problems in the long run than they solve.</li>
<li>Record each item as a distinct artifact that is under revision control and provide links between related artifacts. TFS work items are the preferred way when using the Microsoft ALM tools.</li>
<li>Develop Test Plans and Specific Test Steps as each Requirement/Story is being formalized. This provides additional information about the expectations. I have found many instances where thinking about how the requirement is going to be tested as provided immediate refinement to the requirement itself.</li>
</ol>
<p><strong>Architecture/Design/Implementation</strong></p>
<p>I have grouped these three items together because test driven approaches in these areas are typically the best understood. In a future post, I will be covering these areas in greater detail.</p>
<p><strong>Quality Assurance</strong></p>
<p>If Test Plans and Test Steps have been being developed since the beginning (<em>see above</em>) then ter is already a good start on determining the Acceptance Criteria that the QA team will be targeting. Careful thought should also be given to the types of tests that will be performed, with the three major catefories being:</p>
<ul>
<li>Scripted Manual Testing</li>
<li>Automated [Coded UI] Testing</li>
<li>Exploratory Testing</li>
</ul>
<p>While most QA teams have a good handle on Scripted Manual Testing, the latter two categories are often overlooked or misunderstood. With Visual Studio 2010, it is simple to record actions while &#8220;driving&#8221; the application, and identifying the specific elements that are being examined along with their required values. These tests can then be repeated in an automated fashon to rapidly re-test many aspects of the system without the time consuming (therefore expensive) manual interactions. Having the tests run in a 100% repeatable manner also provides consistancy.</p>
<p>Formal Exploratory Testing is almost an oxymoron. By its very nature, it involves (a person) &#8220;wandering&#8221; through the application in a semi-structured or even random manner, looking for potential defects. Since there is no script or other definition of the testing activity, it can be hard to imagine this being formalized. However tooling such as Visual Studio 2010 once again provides some very helpful capabilities. The iteractions with the system can be recorded as a video that can be played back to see the exact steps to arrive at a specific point. IntelliTrace (background recording of internal state as the application runs) allows for the capture of elements such as stack traces, exceptions, state in the event that a potential defect is discovered. These features make it much simpler for the developer team to analyze reports that originate from QA.</p>
<p>When these activities are recorded into a central repository, there exists the capability to analyze the QA activities, and find out what testing methods are effective, what could be improved (in some cases, the improvement is a reduction in certain types of testing in favor of other types). Effectively we have reached the point where we can &#8220;test the testers&#8221; and reach a more harminic relationship between the development and test teams.</p>
<p><strong>Maintenance/</strong><strong>Defect Management/</strong><strong>Deployment/</strong><strong>Operations</strong></p>
<p>Application lifecycle management does not end with the release of a version to production. For most application, the journey is just beginning as the time from initial release to final decommissioning can be orders of magnitude longer than the time from concept to initial release.</p>
<p>If solid practices and processed have been established during the initial development phase, there is a good deal of &#8220;metadata&#8221; about the project, including significant informantion about HOW the application reached the current state, and WHY decisions were made. Unfortunately too many companies treat the release milestone as &#8220;throwing the project over a wall&#8221;.  Customer (User) Support starts to use their own &#8220;issue tracking&#8221; system and Operations keeps their own internal records. Things begin to drift back into &#8220;islands of information&#8221; rather than a unified/comprehensive view.</p>
<p>To the suprise of many, these issues can be mitigated simple by &#8220;testing&#8221; the relationships between the various parties. Before the first &#8220;real&#8221; deployment, there should be mock deployments that are treated as any other development activity, with requirements, tasks, issues and bugs being recorded. This will provide helpful informtion to the deployment team. As the &#8220;real&#8221; deployments occur, these activities should also be tracked back in the same manner. Similar trials and integration with whatever system is being used for tracking customer issues should be applied.</p>
<p><strong><span style="font-size:x-large;">Conclusion</span></strong><strong></strong></p>
<p>Hopefully these two posts have provided some insight regarding integrating all of the various areas into a unified environment. The outcome is a consistent approach to capturing information in a form that can be analyzed, review by all parties (<strong><em>testing</em></strong>) at or near the time it is recording, being able to see relationships between items and validating (<strong><em>testing</em></strong>) that they are consistent, having easy access to reference and update the information as work progresses ensuring (<strong><em>testing</em></strong>) the current tasks align the the requirements and test plan, and finally having retrospectives on completed items with the focus on evaluating (<strong><em>testing</em></strong>) if the process/workflow can be improved.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=39&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/20/alm-an-expanded-approach-to-being-test-driven-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>ALM &amp; an expanded approach to being Test Driven (Part 1)</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/19/alm-an-expanded-approach-to-being-test-driven-part-1/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/19/alm-an-expanded-approach-to-being-test-driven-part-1/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 21:07:28 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[Application Lifecycle Management]]></category>

		<guid isPermaLink="false">http://davidvcorbin.wordpress.com/?p=34</guid>
		<description><![CDATA[Since the dawn of the computer age, various methodologies have been introduced to improve quality and reduce cost. In recent years Test Driven Development has gained popularity as a means of verifying code functions properly [or that defects/limitations are identified &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/19/alm-an-expanded-approach-to-being-test-driven-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=34&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Since the dawn of the computer age, various methodologies have been introduced to improve quality and reduce cost. In recent years Test Driven Development has gained popularity as a means of verifying code functions properly [or that defects/limitations are identified by failing tests] at all times. When one is adopting a comprehensive approach to ALM, the principles of TDD as applied to code can, and should, be applied to other areas of the overall process.</p>
<p>To start off let&#8217;s quickly review the various activities that are part of the Application LifeCycle. These are going to be presented in a Waterfall style for simplicity, but each item also occurs within Iterative methodologies such as Agile/Scrum. the key ones here are:</p>
<ul>
<li>Requirements Gathering</li>
<li>Architecture</li>
<li>Design</li>
<li>Implementation</li>
<li>Quality Assurance</li>
<li>Maintenance</li>
<li>Defect Management</li>
<li>Deployment</li>
<li>Operations</li>
</ul>
<p>Can each of these items be subjected to a process which establishes quantified metrics  that reflect both the quality and correctness of each item? It should be clear that conventional Unit Tests do not apply to all of these items; at best they can verify that a local aspect (e.g. a Class/Method) of implementation matches the (test writers perspective of) the appropriate design document. So what can we do?</p>
<p>For each of area, the goal is to create tests that are quantifiable and durable. The ability to quantify the measurements (beyond a simple pass/fail) is critical to tracking progress(eventually measuring the level of success that has been achieved) and for providing clear information on what items need to be addressed (along with the appropriate time to address them &#8211; in varying levels of detail) . Durability is important so that the test can be reapplied (ideally in an automated fashion) over the entire cycle.</p>
<p>There are many places where &#8221;testing&#8221; is used outside of software development. Consider the (conventional) education process that most of us grew up on. The focus was to get the best grades as measured by different tests. Many of these tests measured rote memorization and not understanding of the subject matter. The result of this that many people graduated with high scores but without &#8220;quality and correctness&#8221; in their ability to utilize the subject matter (of course, the flip side is true where certain people DID understand the material but were not very good at taking this type of test).</p>
<p>One must also be careful of how the tests are organized and how the measurements are taken. If a test is in a multiple choice format, there is a significant statistical probability that a correct answer might be the result of a random guess. Also, in many situations, having the student simply provide a final answer can obscure many important elements. For example, on a math test, having the student simply provide a numeric answer (rather than showing the methodology) may result in a complete mismatch between the process and the result. It is hard to determine which is worse: The student who makes a simple arithmetric error at one step of a long process (resulting in a wrong answer) or The student who (without providing the &#8220;workflow&#8221;) uses a completely invalid approach, yet still comes up with the right number.</p>
<p>The &#8220;Wrong Process&#8221;/&#8221;Right Answer&#8221; is probably the single biggest problem in creating quality tests. Even very simple items can suffer from this. As an example consider the following code for a &#8220;straight line&#8221; calculation&#8230;.Is it correct? (for Integral Points)</p>
<p>int Solve(int m, int b, int x) { return m * x + b; }</p>
<p>Most people would respond &#8220;Yes&#8221;. But let&#8217;s take the question one step further&#8230; Is it correct for all possible values of m,b,x??? Without additional information regarding constrains on &#8220;the possible values of m,b,x&#8221; the answer must be NO, there is the risk of overflow/wraparound that will produce an incorrect result!</p>
<p>To properly answer this question (i.e. Test the Code), one MUST be able to backtrack from the implementation through the design, and architecture all the way back to the requirements. And the requirement itself must be tested against the stakeholder(s). It is only when the bounding conditions are defined that it is possible to determine if the code is &#8220;Correct&#8221; and has &#8220;Quality&#8221;.</p>
<p>Yet, how many of us (myself included) have written such code without even thinking about it. In many canses we (think we) &#8220;know&#8221; what the bounds are, and that the code will be correct. As we all know, requirements change, &#8220;code reuse&#8221; causes implementations to be applied to different scenarios, etc. This leads directly to the types of system failures that plague so many projects.</p>
<p>This approach to TDD is much more holistic than ones which start by focusing on the details. The fundamental concepts still apply:</p>
<ul>
<li>Each item should be tested.</li>
<li>The test should be defined/implemented before (or concurrent with) the definition/implementation of the actual item.</li>
</ul>
<p>We also add concepts that expand the scope and alter the style by recognizing:</p>
<ul>
<li>There are many things beside &#8220;lines of code&#8221; that benefit from testing (measuring/evaluating in a formal way)</li>
<li>Correctness and Quality can not be solely measured by &#8220;correct results&#8221;</li>
</ul>
<p>Next time we will dig deeper into the 9 ALM areas listed at the beginning of this post and evaluate how each can be tested.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/34/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/34/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/34/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=34&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/19/alm-an-expanded-approach-to-being-test-driven-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>ALM &#8211; What is it and Why Do I Care?</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/18/alm-what-is-it-and-why-do-i-care/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/18/alm-what-is-it-and-why-do-i-care/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 22:00:58 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[Application Lifecycle Management]]></category>

		<guid isPermaLink="false">http://davidvcorbin.wordpress.com/?p=23</guid>
		<description><![CDATA[For those not familiar with ALM, it can be simplified down to &#8220;A comprehensive view of all of the ideas, requirements, activities and artifacts that impact an application over the course of its lifecycle, from concept until decommissioning&#8221;. Obviously, this &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/18/alm-what-is-it-and-why-do-i-care/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=23&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>For those not familiar with ALM, it can be simplified down to &#8220;A comprehensive view of all of the ideas, requirements, activities and artifacts that impact an application over the course of its lifecycle, from concept until decommissioning&#8221;. Obviously, this encompasses a large number of different areas even for relatively small and medium-sized projects. In recent years, many teams have adapted methodologies which address individual aspects of this; but the majority of this adoption has resulted in &#8220;islands of improvement&#8221; rather than the desired comprehensive outcome&#8230;Until now!</p>
<p>Last year Microsoft released Team Foundation Server 2010 along with Visual Studio 2010 Ultimate Edition, and with these two in combination the situation has drastically changed. At last there is a single environment that is capable of handling all aspects of ALM, and is also capable of dealing with migration and integration with existing systems to make the transition to a single solution much easier.</p>
<p>The possibilities (and practicalities) are nothing short of amazing, Architecture thru Testing integration? YES. Being able to correlate specific requirement items (and their history) to actual code (and code history)? YES. Identification of which tests will be potentially impacted by a given code change? YES. Resiliant Automated Testing of User Interfaces? YES. Automatic Deployment Management? YES. Integraton Level testing as part of (designated) Builds? YES.</p>
<p>I could easily double or triple the above list, but these items should be enough to get you thinking about the &#8220;pain points&#8221; your team and organization currently face and the fact that there IS a way to relieve the pain.</p>
<p>When teams are first introduced to these capabilities, there are a couple of common reactions.  Many can be grouped under the heading of &#8220;That&#8217;s Great! What do I have to do in order to experience this goodness?&#8221;), but a fair number fall into one or more of the following groups:</p>
<ul>
<li>We don&#8217;t need any of that. We are doing just fine editing our code, compiling it locally, testing it locally, and doing manual deployment.</li>
<li>We already accomplish that (or at least the important parts) using a suite of [often OpenSource/Free] tools.</li>
<li>That will make our jobs more difficult / take longer, and decrease efficiency.</li>
</ul>
<p>If you are a member of the first two groups you are likely to be comfortable with the status quo and do not see the need for change. I recommend either a simple pilot project or a co-development effort (using both the existing methodology and an ALM approach in parallel) to identify and quantify specific areas for improvement. Trial versions of all of the tools are readily available, so this can be done without any capital expenditure.</p>
<p>If you are a member of the last group, it is likely that you have had a negative experience with adopting a formal comphrehensive process in the past. Unfortunately this is common, and my best suggestion is to keep an open mind, learn as much as possible about the capabilities, and (if possible) get an opportunity to work with a person or team who has successfully adopted ALM</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=23&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/18/alm-what-is-it-and-why-do-i-care/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
		<item>
		<title>Lets get started&#8230;.</title>
		<link>http://davidvcorbin.wordpress.com/2011/04/17/lets-get-started/</link>
		<comments>http://davidvcorbin.wordpress.com/2011/04/17/lets-get-started/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 21:12:49 +0000</pubDate>
		<dc:creator>David V. Corbin</dc:creator>
				<category><![CDATA[General Interest]]></category>

		<guid isPermaLink="false">http://davidvcorbin.wordpress.com/?p=7</guid>
		<description><![CDATA[&#8220;Software Development&#8221; is a vast topic. It is doubtful that there is anyone in the world who is knowledgable about the entire domain. It is certain that I do not possess such knowledge. This means that a context for this blog &#8230; <a href="http://davidvcorbin.wordpress.com/2011/04/17/lets-get-started/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=7&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&#8220;Software Development&#8221; is a vast topic. It is doubtful that there is anyone in the world who is knowledgable about the entire domain. It is certain that I do not possess such knowledge.</p>
<p>This means that a context for this blog must be established which places some bounds on the mega-topic of Software Development. While here may be exceptions in certain posts, the following is the environment that will typically be considered:</p>
<ul>
<li><strong>Microsoft Languages, Tools, and Platforms</strong>. Unless there are specific reasons: Code will be in C# 4.0, developed using Visual Studio 2010 Ultimate Edition.</li>
<li><strong>Small (&lt;=5) to Medium (&gt;5, &lt;=20) Teams</strong>. Much of what will be written involves the recording and sharing of knowledge and this most commonly occurs when multiple people are involved. This is not meant to exclude the individual developer, who also needs to record this information if only for easly at reliable recall at a latter date.  Finally, since most large development efforts are broken down into smaller team effort, even the biggest teams will be able to leverage the information.</li>
<li><strong>Moderate to High Project Complexity</strong>. This is not really a &#8220;requirement&#8221;, but as project complexity increases the return on investment in processes and practices become much more obvious. Simple systems (so called &#8220;jelly bean&#8221; or &#8220;cookie cutter&#8221;) can definately benefit also, but getting tangible metrics on the value may be more difficult.</li>
</ul>
<p>Within this scope are some key topic areas which will be categorized for easy of reference. <strong></strong></p>
<ul>
<li><strong>Application Lifecycle Management</strong>[ALM] will be the the primary focus as this covers all aspects of the effort from the gathering of initial requirements/ideas, through development and deployment, and only finishes when the system is finally decommissioned.</li>
<li><strong>.NET Architecture &amp; Implementation</strong>will cover specific design choices that have been adopted within Dynamic Concepts Development Corp. and have been proven to have applicability to other scenarios.</li>
<li><strong>Tales from the Trenches</strong>will cover specific situations that I have encountered that turned into key learning issues.</li>
</ul>
<p>Next Up: <a href="http://davidvcorbin.wordpress.com/2011/04/18/alm-what-is-it-and-why-do-i-care/">ALM &#8211; What is it and Why Do I Care?</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidvcorbin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidvcorbin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidvcorbin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidvcorbin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidvcorbin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidvcorbin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidvcorbin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidvcorbin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidvcorbin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidvcorbin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidvcorbin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidvcorbin.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidvcorbin.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidvcorbin.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidvcorbin.wordpress.com&amp;blog=19877164&amp;post=7&amp;subd=davidvcorbin&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidvcorbin.wordpress.com/2011/04/17/lets-get-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/62761167acb2764dfa3456e57b187d43?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidvcorbin</media:title>
		</media:content>
	</item>
	</channel>
</rss>
