<?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/"
	>

<channel>
	<title>James Wiseman</title>
	<atom:link href="http://www.jameswiseman.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jameswiseman.com/blog</link>
	<description>My Programming Notebook and Other Things</description>
	<lastBuildDate>Wed, 05 Jun 2013 08:23:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Time-Saving JavaScript Browser Bookmarks</title>
		<link>http://www.jameswiseman.com/blog/2013/05/29/time-saving-javascript-browser-bookmarks/</link>
		<comments>http://www.jameswiseman.com/blog/2013/05/29/time-saving-javascript-browser-bookmarks/#comments</comments>
		<pubDate>Wed, 29 May 2013 13:57:41 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Bookmarks]]></category>
		<category><![CDATA[Browser]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Time-Saving]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4357</guid>
		<description><![CDATA[Today I was sent an email with the above title. which contained some JavaScript that was similar to the following: javascript:(function(){$('#UserName').val('a_user');$('#Password').val('their_password');$('form').submit();})(); As it turns out, the JavaScript was actually intended to be a browser bookmark that, when clicked, autofilled fields on the page and submitted it. Let&#8217;s look at it more carefully. If we assume [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Today I was sent an email with the above title. which contained some JavaScript that was similar to the following:</p>
<pre name="code" class="javascript">javascript:(function(){$('#UserName').val('a_user');$('#Password').val('their_password');$('form').submit();})();</pre>
<p>As it turns out, the JavaScript was actually intended to be a browser bookmark that, when clicked, autofilled fields on the page and submitted it.</p>
<p>Let&#8217;s look at it more carefully. If we assume that the page has a:</p>
<ul>
<li>Textbox with ID ‘UserName’.</li>
<li>Textbox with ID ‘Password’.</li>
<li>Form submit button.</li>
</ul>
<p>When the above JavaScript is added as a browser bookmark (i.e. is set as the bookmark URL) you can click on it to autofill the boxes on the form and then have it submit it for you.</p>
<p>So, when I click on the browser bookmark, the script will:</p>
<ul>
<li>Populate ‘UserName’ control with &#8216;a_user&#8217;.</li>
<li>Populate ‘Password’ control with ‘their_password’.</li>
<li>Submit the form.</li>
</ul>
<p>If you find yourself having to repeatedly enter the same details on a form, simply create some JavaScript to populate it automatically, and add it as a bookmark. The example above is simple, but when you have dozens of fields then this can be a handy time-saving activity.</p>
<p>As an esteemed colleague quite rightly pointed out, the code makes two important assumptions:</p>
<ol>
<li><span style="line-height: 13px;">You are using jQuery</span></li>
<li>The fields have IDs</li>
</ol>
<p>If you&#8217;re not using jQuery, then simply using <strong>document.getElementById</strong> will suffice. There are also ways of getting elements without IDs, but if you do have control over the HTML then I would suggest adding them in anyway.</p>
<div class="shr-publisher-4357"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/05/29/time-saving-javascript-browser-bookmarks/' data-shr_title='Time-Saving+JavaScript+Browser+Bookmarks'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/05/29/time-saving-javascript-browser-bookmarks/' data-shr_title='Time-Saving+JavaScript+Browser+Bookmarks'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/05/29/time-saving-javascript-browser-bookmarks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notes on C# Performance Counters</title>
		<link>http://www.jameswiseman.com/blog/2013/05/17/notes-on-c-performance-counters/</link>
		<comments>http://www.jameswiseman.com/blog/2013/05/17/notes-on-c-performance-counters/#comments</comments>
		<pubDate>Fri, 17 May 2013 12:34:11 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Performance-Counters]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4090</guid>
		<description><![CDATA[What&#8217;s Going On Here? I&#8217;m currently reading up on Performance Counters in .NET, and have been taking notes on the topic, so I can refer back later. These are a series of links and facts that I found helped me understand the topic. Most of the information was available on MSDN, so the relevant links [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><h3>What&#8217;s Going On Here?</h3>
<p>I&#8217;m currently reading up on Performance Counters in .NET, and have been taking notes on the topic, so I can refer back later.</p>
<p>These are a series of links and facts that I found helped me understand the topic. Most of the information was available on MSDN, so the relevant links are included.</p>
<h3>Some Links</h3>
<p><strong>Performance counters front page:</strong> <a href="http://msdn.microsoft.com/en-us/library/w8f5kw2e.aspx">http://msdn.microsoft.com/en-us/library/w8f5kw2e.aspx</a></p>
<p><strong>Runtime Profiling:</strong> <a href="http://msdn.microsoft.com/en-gb/library/w4bz2147(v=vs.110).aspx">http://msdn.microsoft.com/en-gb/library/w4bz2147(v=vs.110).aspx</a></p>
<h3>Overview</h3>
<p>Performance counter can be used for both for reading and writing pre-defined or custom performance counters.</p>
<p><strong>Reading an Existing or Pre-Defined System Counter</strong></p>
<p>To use, simply instantiate an object, set CategoryName, CounterName, and, optionally, InstanceName and MachineName. and then call NextValue().</p>
<p>The following will get us some simple perf stats:</p>
<pre name="code" class="c#">PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "Private Bytes";
PC.InstanceName = "Explorer";
Console.WriteLine(PC.NextValue().ToString());</pre>
<p><strong>Creating a Custom Counter.</strong></p>
<p>You might want to create a custom performance counter, for example, you may choose to instrument the number of records returned from a query over time. We could expose this through a performance counter, and monitor it through <a title="How To: Use Perfmon in Windows 7" href="http://blogs.msdn.com/b/securitytools/archive/2009/11/04/how-to-use-perfmon-in-windows-7.aspx" target="_blank">Perfmon</a>.</p>
<p>To write to a custom performance counter:</p>
<ol>
<li>Create a new <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.countercreationdata.aspx">CounterCreationData</a> class. We need:
<ul>
<li>Counter Name</li>
<li>Counter Help Text</li>
<li>Item from <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecountertype.aspx">PerformanceCounterType</a> enumeration</li>
</ul>
</li>
<li>Create a <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.countercreationdatacollection.aspx">CounterCreationDataCollection</a> and add the CounterCreationData class to it.</li>
<li><span style="line-height: 13px;">Create a custom <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecountercategory.aspx">PerformanceCounterCategory</a> counter using <a href="http://msdn.microsoft.com/en-gb/library/system.diagnostics.performancecountercategory.create.aspx">PerformanceCounterCategory.Create</a></span>
<ul>
<li>Category Name</li>
<li>Category HelpText</li>
<li>Item from <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecountercategorytype.aspx">PerformanceCounterCategoryType</a> enumeration</li>
<li>Our CounterCreationDataCollection intance</li>
</ul>
</li>
<li>Create an instance of the <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter.aspx">PerformanceCounter</a> class.</li>
<li>Make the PerformanceCounter instance writeable by setting the <strong>ReadOnly</strong> property to <strong>false</strong></li>
<li>Assign CategoryName, CounterName. (Optionally we can set InstanceName and MachineName also).</li>
<li>Call, IncrementBy, Increment, Decrement or set RawValue (note, RawValue does not use Interlocked for multithreading)</li>
</ol>
<p>These bullet points are reflected in the code below:</p>
<pre name="code" class="c#">// 1. Create a new CounterCreationData instance 
CounterCreationData ccd = new CounterCreationData(
    "AAAACounter1", // Counter name
    "AAA Counter Help",  //Counter help text
    PerformanceCounterType.NumberOfItems32); //Counter type

// 2. Create a CounterCreationDataCollection
CounterCreationDataCollection ccds = new CounterCreationDataCollection();
ccds.Add(ccd);

// Code to demonstrate how to delete a category if we need to.
// PerformanceCounterCategory.Delete("AAAA");

// Check to see if our performance counter category if we need to
if (!PerformanceCounterCategory.Exists("AAAA"))
{
    // 3. Create the PerformanceCounterCategory
    PerformanceCounterCategory.Create(
        "AAAA",
        "AAAA Category Help",
        PerformanceCounterCategoryType.SingleInstance,
        ccds);
}

// 4. Create an instance of the PerformanceCounter class
PerformanceCounter PC = new PerformanceCounter();

// 5. Make the counter writable by setting the .ReadOnly property to false
PC.ReadOnly = false;

// 6. Assign the Category name and Counter Name.
PC.CategoryName = "AAAA";
PC.CounterName = "AAAACounter1";

// 7. Set the counter RawValue and increment
PC.RawValue = 0;
for (int x = 0; x &lt; 100000000; x++)
{
    PC.Increment();
    if (x % 100 == 0)
    {
        Console.WriteLine(x);
    }
}</pre>
<p>You may get a security exception when you execute the code. This is because the account under which you&#8217;re running the code does not have appropriate permissions on you operating system.</p>
<p>In which case, you&#8217;ll need to add the following to the application manifest:</p>
<pre name="code" class="xml">&lt;trustInfo xmlns="urn:schemas-microsoft-com:asm.v2"&gt;
  &lt;security&gt;
    &lt;requestedPrivileges&gt;
      &lt;requestedExecutionLevel level="requireAdministrator" uiAccess="false" /&gt;
    &lt;/requestedPrivileges&gt;
  &lt;/security&gt;
&lt;/trustInfo&gt;</pre>
<p>This gets you around the problem, but may not be the best approach. For more info, consult: <a title="Stackoverflow: Performance counter throws SecurityException" href="http://stackoverflow.com/a/9039706/144491" target="_blank">What do if you get a  SecurityException</a>. I&#8217;d recommend reading it, as there&#8217;s more useful info on this with regard to alternative approaches.</p>
<p>Also note that this ensures the application requests privileges when it is run. This doesn&#8217;t help us help us when attempting to debug the application. For that, we need to run Visual Studio as an administrator. When I tried it with VS2012 on Windows 8, the application  prompted me about this, and then upon confirmation restarted automatically.</p>
<p>We can now view the new counter in <a title="How To: Use Perfmon in Windows 7" href="http://blogs.msdn.com/b/securitytools/archive/2009/11/04/how-to-use-perfmon-in-windows-7.aspx" target="_blank">Perfmon</a>. Note, that all the counter and category information is loaded into Perfmon once when you start it up. To pick up any new or modified counters or counter categories, you&#8217;ll need to restart the application if  it&#8217;s already open.</p>
<h3>Different Sorts of Pre-Defined Performance Counters</h3>
<p>Out-of-the box</p>
<ul>
<li>Exception</li>
<li>Interop</li>
<li>JIT</li>
<li>Loading</li>
<li>Lock and Thread</li>
<li>Memory</li>
<li>Networking</li>
<li>Security</li>
</ul>
<h3><strong>Performance Counter Types</strong></h3>
<p>There are a large number of performance counter types. They are as follows (refer to MSDN for more information)</p>
<ul>
<li><span style="line-height: 13px;">NumberOfItems32/64, NumberOfItemsHEX32/64.<br />
</span></li>
<li>RateOfCountsPerSecond32/64</li>
<li>CountPerTimeInterval32/64</li>
<li>RawFraction</li>
<li>RawBase</li>
<li>AverageTimer32</li>
<li>AverageBase</li>
<li>AverageCount64</li>
<li>SampleFraction</li>
<li>SampleCounter</li>
<li>SampleBase</li>
<li>CounterTimer</li>
<li>CounterTimerInverse</li>
<li>Timer100Ns</li>
<li>Timer100NsInverse</li>
<li>ElapsedTime</li>
<li>CounterMultiTimer</li>
<li>CounterMultiTimerInverse</li>
<li>CounterMultiTimer100Ns</li>
<li>CounterMultiTimer100NsInverse</li>
<li>CounterMultiBase</li>
<li>CounterDelta32/64</li>
</ul>
<p>In general, we can break these counters down to five specific types:</p>
<ol>
<li><strong>Average:</strong> Measure a value over time and display the average of the last two measurements. Needs a base counter.</li>
<li><strong>Difference:</strong> Subtract the last measurement from the previous one and display the difference</li>
<li><strong>Instantaneous:</strong> Display the most recent measurement.:</li>
<li><strong>Percentage:</strong> Display calculated values as a percentage.</li>
<li><strong>Rate: </strong>Change in values ovwer time divided by the time period.</li>
</ol>
<p>Some counters require a base counter. Base counters must be included immediately after the desired counter in the ConterCreationData structure.</p>
<p>There are four base counter types: <strong>AverageBase</strong>, <strong>CounterMultiBase, RawBase, SampleBase. </strong>Timers that require a base timer will start with the same text as those timers. For example: <strong>AverageTimer32</strong> will require <strong>AverageBase</strong>.</p>
<h3><strong>Performance Counter Category Types</strong></h3>
<p>There are three types: Unknown, Single and Multi.</p>
<p>A counter is a single instance upon first creation. When other instances are created it becomes a multi-instance.</p>
<p>&nbsp;</p>
<div class="shr-publisher-4090"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/05/17/notes-on-c-performance-counters/' data-shr_title='Notes+on+C%23+Performance+Counters+'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/05/17/notes-on-c-performance-counters/' data-shr_title='Notes+on+C%23+Performance+Counters+'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/05/17/notes-on-c-performance-counters/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RuntimeBinderException &#8211; &#8220;does not contain a definition for&#8221;</title>
		<link>http://www.jameswiseman.com/blog/2013/05/14/runtimebinderexception-does-not-contain-a-definition-for/</link>
		<comments>http://www.jameswiseman.com/blog/2013/05/14/runtimebinderexception-does-not-contain-a-definition-for/#comments</comments>
		<pubDate>Tue, 14 May 2013 21:26:01 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[exceptions]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4302</guid>
		<description><![CDATA[I thought I&#8217;d share an issue that I encountered recently with dynamic binding in C#, quite simply because I couldn&#8217;t easily find a solution out there on the net. In the end, it took the technical genius of a colleague of mine to identify the issue, and provide the solution. The problem manifested itself when [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I thought I&#8217;d share an issue that I encountered recently with dynamic binding in C#, quite simply because I couldn&#8217;t easily find a solution out there on the net. In the end, it took the technical genius of a colleague of mine to identify the issue, and provide the solution.</p>
<p>The problem manifested itself when a <strong>test project</strong> was attempting to test a property on the Class Under Test of type <em>object</em>. At runtime this type was populated with an anonymous type by the Class Under Test.</p>
<p>At this point, it is probably more instructive to conjure a contrived example.</p>
<p>Consider a simple class library:</p>
<pre name="code" class="c#">public class ClassUnderTest
{
    public object GetAnon()
    {
        return new { hint = 1 };
    }
}</pre>
<p>Note that we return an anonymous type from the method, implicitly upcasting it to <em>object</em>. The anonymous type is declared within the method within the class, and so is treated by the compiler as <strong>internal</strong> to the class.</p>
<p>Now let&#8217;s consider a simple console application that attempts to access it.</p>
<pre name="code" class="c#">private static void Main(string[] args)
{
    ClassUnderTest c = new ClassUnderTest();
    dynamic d = c.GetAnon();
    Console.WriteLine(d.member.hint);
}</pre>
<p>The method <strong>GetAnon</strong><strong>()</strong> of <strong>ClassUnderTest</strong> returns an object, thus denying us access to the members of the anonymous type. At this point we can access the properties via reflection, or if we&#8217;re being lazy (and naughty) set up an identical anonymous type and compare hash codes. (This is not to be encouraged: Principally because different types may generate the same hash, but there are other reasons which are outlined here on StackOverflow: <a href="http://stackoverflow.com/questions/16517392/is-it-safe-to-use-gethashcode-to-compare-identical-anonymous-types">http://stackoverflow.com/questions/16517392/is-it-safe-to-use-gethashcode-to-compare-identical-anonymous-types</a>)</p>
<p>As it is, the solution above uses dynamic typing to achieve this effect. However, when you run it, the program throws a RuntimeBinder Exception:</p>
<blockquote><p>&#8216;object&#8217; does not contain a definition for &#8216;member&#8217;</p></blockquote>
<p>This is not a very helpful error message, and gives little clue as to the potential solution.</p>
<p>The problem is that because the anonymous type is internal to the declaring assembly, our client assembly cannot actually access this. To solve this, we have to make the assembly internal visible to the client application, which in this case is the unit test project.</p>
<p>We can emulate this in our sample solution by modifying <strong>AssemblyInfo.cs </strong>within <strong>ClassUnderTest</strong>  to contain the following:</p>
<pre name="code" class="c#">[assembly: InternalsVisibleTo("ConsoleApplication1")]</pre>
<p>In our real-world project we have to make internal of the Class Under Test visible to the test project.</p>
<div class="shr-publisher-4302"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/05/14/runtimebinderexception-does-not-contain-a-definition-for/' data-shr_title='RuntimeBinderException+-+%22does+not+contain+a+definition+for%22'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/05/14/runtimebinderexception-does-not-contain-a-definition-for/' data-shr_title='RuntimeBinderException+-+%22does+not+contain+a+definition+for%22'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/05/14/runtimebinderexception-does-not-contain-a-definition-for/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XslCompiledTransform Memory Leak</title>
		<link>http://www.jameswiseman.com/blog/2013/04/30/xslcompiledtransform-memory-leak/</link>
		<comments>http://www.jameswiseman.com/blog/2013/04/30/xslcompiledtransform-memory-leak/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 11:11:52 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[memory-leak]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xsl]]></category>
		<category><![CDATA[XslCompiledTransform]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4205</guid>
		<description><![CDATA[Just recently, after deploying a web application to a testing environment, I was  approached by one of the testers complaining of an &#8220;Out of Memory&#8221; exception. The application in question was a port of a legacy system (written in JSP and C++) from an unsupported Windows 2000 server to a more future-resistant .NET solution on a [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Just recently, after deploying a web application to a testing environment, I was  approached by one of the testers complaining of an &#8220;Out of Memory&#8221; exception.</p>
<p>The application in question was a port of a legacy system (written in JSP and C++) from an unsupported Windows 2000 server to a more future-resistant .NET solution on a later, supported, version of Windows Server. Much of the original functionality was to be retained, and this was facilitated by the ability to copy/paste a large chunk of the original code (particularly the client-side JavaScript and static HTML).</p>
<p>However, some areas required developing from the ground up. One of these areas was the code that XML-formatted the data, and performed the XSLT transforms upon it. A particular headache was to get the whitespace recognition and treatment on the .NET platform to work the same as the older JSP system. After hours of trying different settings, in the end I was forced to reformat the underlying XSLT file just to get the screens looking the same. However, I digress&#8230;</p>
<p>With most of the major hurdles out-of-the-way, and the application delivered to testing, it was quite a disappointment to find a memory leak as the cause of the &#8220;Out of Memory&#8221; exception, especially at the scale I was noticing (50K+ per web page post).</p>
<p>I was pretty sure I had cleaned up unmanaged resources as required, but set about my code with a fine tooth comb to see if there was anything I missed. Eventually I fired up <strong>perfmon</strong> and stepped through the code line-by-line, looking for where significant memory consumption occurred.</p>
<p><a href="http://i0.wp.com/www.jameswiseman.com/blog/wp-content/uploads/2013/04/perfmon_xsl.png"><img class="alignnone size-medium wp-image-4250" alt="perfmon_xsl" src="http://i2.wp.com/www.jameswiseman.com/blog/wp-content/uploads/2013/05/perfmon_xsl.png?resize=300%2C214" data-recalc-dims="1" /></a></p>
<p>I happened to notice significant memory consumption when stepping over the code that loaded the XSLT and performed the transformation (the equivalent to lines 5 and 10 in the sample below)</p>
<pre name="code" class="c#">var xslCompiledDoc = new XslCompiledTransform(true);
//....
//....get myXSLDoc from some XSL file
//....
xslCompiledDoc.Load(myXSLDoc);
//....
//....get xmlSource and instantitate an XmlWriter
//....
//Memory leak on this line!!!
xslCompiledDoc.Transform(xmlSource, xmlWriter)</pre>
<p>This restored my ego a little. It looked like the problem might be some side-effect of <a title="MSDN - XslCompiledTransform" href="http://msdn.microsoft.com/en-us/library/system.xml.xsl.xslcompiledtransform.aspx" target="_blank">XslCompiledTransform<strong></strong></a>, and not the result of overly crap code. It also meant that I had pinpointed where exactly the problem lay, even if I didn&#8217;t know how to solve it.</p>
<p>As it turned out, no one solution solved the problem, but it did lay bare an interesting problem with the <strong>System.Xml.Xsl.XslCompiledTransform</strong> .NET class. When executed, this class will take the XSLT that is passed to it, and compile it down to IL. The problem was that when the client application was run in <strong>debug</strong> mode, both the <b>load </b>and <strong>transformation</strong> leaked memory.</p>
<p>So here are the steps that I took to seal the leak:</p>
<h3>1. XMLWriter Cleanup</h3>
<p>Although the leak wasn&#8217;t all my fault, I may have been partially responsible. My first action was to correctly ensure that the <a title="MSDN - XmlWriter" href="http://msdn.microsoft.com/en-GB/library/system.xml.xmlwriter.aspx" target="_blank">XmlWriter</a> unmanaged resource wrapper was cleaned up correctly:</p>
<pre name="code" class="c#">using (XmlWriter xmlWriter = XmlWriter.Create(xmlStringBuilder, xmlWriterSettings))
{
    xslCompiledDoc.Transform(xmlSource, xmlWriter);
}</pre>
<p>Using <strong>using </strong>in this context is considered all-round good practice for any class that wraps managed resources and implements <a title="MSDN - IDisposable" href="http://msdn.microsoft.com/en-us/library/system.idisposable.aspx" target="_blank">IDisposable</a>.</p>
<h3>2. Debug Option Off</h3>
<p><a title="MSDN - XslCompiledTransform Constructor (Boolean)" href="http://msdn.microsoft.com/en-us/library/ms163418.aspx" target="_blank">The first overload of the XslCompiledTransform constructor</a> accepts a boolean parameter indicating whether or not to enable debug information, and therefore be able to debug the stylesheet itself.</p>
<p>You&#8217;ll note from my original code that I had this option set to <strong>true</strong>, which caused the <strong>load</strong> and <strong>transform</strong> to leak memory. The fix was to pass <strong>false</strong> explicitly, although I could have used the default parameterless constructor instead.</p>
<h3>3. Caching in Session</h3>
<p>The XslCompiledTransform class was designed to be initialised once (i.e. one call to the <strong>load </strong>function), and for that instance used for the duration of the application.When you think about it, there is little point in performing a compilation of XSLT to IL every occasion, unless the XSLT content itself is variable.</p>
<p>My code contained two static XSLT files, so I chose to cache these stylesheets in session once initialised. Technically, they could have been stored at application level once and their one instance re-utilised for every user. I must confess that this is not an option I considered at the time, but is something I can always revisit if needs be.</p>
<h3>4. Release Mode DLL</h3>
<p>The new version of the application was to be hosted within existing application infrastructure. Essentially, the port of the old application was to be a new web page within an existing website.</p>
<p>This existing website had been deployed in debug mode. Changing every module of a large website to release mode was not an option, so I moved all the supporting code out into a dedicated DLL that itself could be deployed in release mode on its own.</p>
<h3>5. Precompiling XSL</h3>
<p>After doing all this however, I was still observing a significant memory leak upon each page post (between 10K and 13K). The memory  leak was now reserved to the transform, but it was still occurring.</p>
<p>The last step, which eventually fixed the issue was to follow the advice set out at the end of this article:</p>
<p><a href="http://blogs.msdn.com/b/xmlteam/archive/2011/09/26/effective-xml-part-5-something-went-really-wrong-outofmemoryexception-and-stackoverflowexception-thrown-when-using-xslcompiledtransform.aspx" target="_blank">http://blogs.msdn.com/b/xmlteam/archive/2011/09/26/effective-xml-part-5-something-went-really-wrong-outofmemoryexception-and-stackoverflowexception-thrown-when-using-xslcompiledtransform.aspx</a></p>
<blockquote><p>Another way to resolve the problem is to compile the stylesheet “offline” (i.e. not at runtime) with the xsltc (xslt compiler, more details in MSDN <a href="http://msdn.microsoft.com/en-us/library/bb399405.aspx" target="_blank">http://msdn.microsoft.com/en-us/library/bb399405.aspx</a>). This tool will create “regular” assemblies (.dll files) for the Xslt stylesheet and the embedded scripts. To be able to use them in your app you just need to add references. The memory leak problem is resolved – there is no compilation going on at runtime so no temporary assemblies are created.</p></blockquote>
<p>At the time of writing this was required to be a manual build step. The actions that I tool specifically were to compile each of my XSLT files (input.xsl and output.xsl) into DLLs with equivalent names (InputXSL.dll and OutputXSL.dll) and internal class names (InputXSL and OutputXSL). This was done with the following syntax:</p>
<pre>xsltc.exe /class:InputXSL /out:InputXSL.dll input.xsl</pre>
<p>Note: the <strong>xsltc.exe</strong> executable took some finding. The one I needed was located in <strong>C:/Program Files/Microsoft SDKs/Windowsv7.0A/bin</strong>, however this will be dependent on the .NET framework version you are using. If you don&#8217;t have the framework SDK installed then you will need to do so.</p>
<p>Once the DLLs were compiled, I referenced them from the new component I created in step 4 above. This gave the code access to the internal class names just stipulated.</p>
<p>Finally, I updated the code itself to pass the respective stylesheet class to the XsltCompiledTransform <strong>load()</strong> function:</p>
<pre name="code" class="c#">xslCompiledDoc.Load(typeof(InputXSL));</pre>
<p>When this last step was completed, the memory profile of the application remained constant, and there were no observable memory leaks.</p>
<p>&nbsp;</p>
<div class="shr-publisher-4205"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/04/30/xslcompiledtransform-memory-leak/' data-shr_title='XslCompiledTransform+Memory+Leak'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/04/30/xslcompiledtransform-memory-leak/' data-shr_title='XslCompiledTransform+Memory+Leak'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/04/30/xslcompiledtransform-memory-leak/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The 100 Keywords of C#</title>
		<link>http://www.jameswiseman.com/blog/2013/04/23/the-100-keywords-of-c/</link>
		<comments>http://www.jameswiseman.com/blog/2013/04/23/the-100-keywords-of-c/#comments</comments>
		<pubDate>Tue, 23 Apr 2013 11:30:58 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Revision Notes]]></category>
		<category><![CDATA[70-483]]></category>
		<category><![CDATA[70-483-Revision-Notes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[keywords]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4187</guid>
		<description><![CDATA[Previously I wrote about the The 10 Type Members of C#, and how it would be useful to list and understand each. In this article, I&#8217;ll take it a step further and refer to the identifiers and keywords of C# in the same context. At the time of writing, According to MSDN, there are 77 Reserved Identifiers. These [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Previously I wrote about the <a title="Delegates, Events and The 10 Type Members of C#" href="http://www.jameswiseman.com/blog/2013/03/18/delegates-events-and-the-10-type-members-of-c/">The 10 Type Members of C#</a>, and how it would be useful to list and understand each. In this article, I&#8217;ll take it a step further and refer to the identifiers and keywords of C# in the same context.</p>
<p>At the time of writing, <a title="C# Keywords" href="http://msdn.microsoft.com/en-gb/library/x53a06bb(v=vs.110).aspx" target="_blank">According to MSDN</a>, there are 77<strong> Reserved Identifiers</strong>. These have a special meaning to the and cannot be used as a custom identifier unless they are prefixed with @. For completeness, they are:</p>
<table style="font-weight: bold;">
<colgroup>
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" /></colgroup>
<tbody>
<tr>
<td>abstract</td>
<td>as</td>
<td>base</td>
<td>bool</td>
<td>break</td>
<td>byte</td>
<td>case</td>
</tr>
<tr>
<td>catch</td>
<td>char</td>
<td>checked</td>
<td>class</td>
<td>const</td>
<td>continue</td>
<td>decimal</td>
</tr>
<tr>
<td>default</td>
<td>delegate</td>
<td>do</td>
<td>double</td>
<td>else</td>
<td>enum</td>
<td>event</td>
</tr>
<tr>
<td>explicit</td>
<td>extern</td>
<td>false</td>
<td>finally</td>
<td>fixed</td>
<td>float</td>
<td>for</td>
</tr>
<tr>
<td>foreach</td>
<td>goto</td>
<td>if</td>
<td>implicit</td>
<td>in</td>
<td>int</td>
<td>interface</td>
</tr>
<tr>
<td>internal</td>
<td>is</td>
<td>lock</td>
<td>long</td>
<td>namespace</td>
<td>new</td>
<td>null</td>
</tr>
<tr>
<td>object</td>
<td>operator</td>
<td>out</td>
<td>override</td>
<td>params</td>
<td>private</td>
<td>protected</td>
</tr>
<tr>
<td>public</td>
<td>readonly</td>
<td>ref</td>
<td>return</td>
<td>sbyte</td>
<td>sealed</td>
<td>short</td>
</tr>
<tr>
<td>sizeof</td>
<td>stackalloc</td>
<td>static</td>
<td>string</td>
<td>struct</td>
<td>switch</td>
<td>this</td>
</tr>
<tr>
<td>throw</td>
<td>true</td>
<td>try</td>
<td>typeof</td>
<td>uint</td>
<td>ulong</td>
<td>unchecked</td>
</tr>
<tr>
<td>unsafe</td>
<td>ushort</td>
<td>using</td>
<td>virtual</td>
<td>void</td>
<td>volatile</td>
<td>while</td>
</tr>
</tbody>
</table>
<p>Some of these have different meaning depending on the context, for example:</p>
<ul>
<li>using</li>
<li>in</li>
<li>out</li>
</ul>
<p>MSDN also lists 23 <strong>Contextual Keywords</strong>. You can use these words as custom identifiers:</p>
<table style="font-weight: bold;">
<colgroup>
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" />
<col width="100" /></colgroup>
<tbody>
<tr>
<td>add</td>
<td>alias</td>
<td>ascending</td>
<td>async</td>
<td>await</td>
<td>dynamic</td>
<td>from</td>
</tr>
<tr>
<td>get</td>
<td>global</td>
<td>group</td>
<td>into</td>
<td>join</td>
<td>let</td>
<td>orderby</td>
</tr>
<tr>
<td>partial</td>
<td>remove</td>
<td>select</td>
<td>set</td>
<td>value</td>
<td>var</td>
<td>where</td>
</tr>
<tr>
<td>yield</td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>Again, some of these have an overloaded usage, for example:</p>
<ul>
<li><span style="line-height: 13px;">partial</span></li>
<li>where</li>
</ul>
<p>In contrast to my suggestion in the aforementioned article <strong>10 Type Members of C#</strong>, I wouldn&#8217;t suggest that you be able to list them all off the top of your head. However, from a study perspective, I think this list is a good checkpoint of one&#8217;s understanding of the C# core. Understanding each one, even if you rarely or never use it, is useful thing.</p>
<div class="shr-publisher-4187"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/04/23/the-100-keywords-of-c/' data-shr_title='The+100+Keywords+of+C%23'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/04/23/the-100-keywords-of-c/' data-shr_title='The+100+Keywords+of+C%23'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/04/23/the-100-keywords-of-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Hidden Costs of Slow Computers</title>
		<link>http://www.jameswiseman.com/blog/2013/04/18/the-hidden-costs-of-slow-computers/</link>
		<comments>http://www.jameswiseman.com/blog/2013/04/18/the-hidden-costs-of-slow-computers/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 07:30:52 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Non-Programming]]></category>
		<category><![CDATA[computers]]></category>
		<category><![CDATA[costs]]></category>
		<category><![CDATA[office]]></category>
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4134</guid>
		<description><![CDATA[Do you use a computer at work? If so read on. When a company buys a clutch of machines for its employees, it&#8217;s quite often perceived as one of the largest single outlays it will have, and because of this, there will be a temptation to cut costs. What I hope to show in this article [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Do you use a computer at work? If so read on.</p>
<p>When a company buys a clutch of machines for its employees, it&#8217;s quite often <em>perceived</em> as one of the largest single outlays it will have, and because of this, there will be a temptation to cut costs. What I hope to show in this article is the futility of doing this, and highlight the return on investment that buying top quality equipment will bring.</p>
<p>This idea started years ago at a previous employer, who made me write a justification the purchase for £30 worth of RAM. I spent an hour doing this. It probably cost the company more to pay me to write the justification than it did to buy the memory (which they did in the end).</p>
<p>So, let&#8217;s dive straight into some figures. Let’s take a look at a standard employee who:</p>
<p><strong>Earns:</strong> £30000 a year</p>
<p><strong>Works for</strong> 46 weeks (52 minus 6 weeks holiday), or 230 days a year.</p>
<p><strong>Daily rate:</strong> £130 .</p>
<p>Let’s assume that a slow machine costs this employee just <strong>1 minute</strong> of productivity <strong>per day</strong>.</p>
<p><strong>Minutes Lost Per Year:</strong> 230.</p>
<p><strong>Yearly Cost of Lost Minutes:</strong> £73.72 .</p>
<p>This sets the scene. I&#8217;m now going to make two more assumptions:</p>
<p><span style="line-height: 13px;"><strong>Machine Lifespan:</strong> 5 years</span></p>
<p><strong>Daily Minutes Lost:</strong> 10 minutes</p>
<p>I base the first assumption on personal experience and observation. The second is a substantial <em>understatement</em> based on straw polls I&#8217;ve conducted around my colleagues.</p>
<p>So, based on our machine that wastes <strong>10 minutes</strong> a day for <strong>5 years</strong> for an employee earning £30,000:</p>
<h1 style="text-align: center;"><span style="color: #ff0000;">£3700 Per Employee</span></h1>
<p>Think of the kit you could get for £3700! Or even half that.</p>
<p>Let&#8217;s start scaling across all employees. An organisation with 100 employees, wasting 10 minutes per day per employee for 5 years racks up a cost of nearly £370,000.</p>
<p>And 100 employees isn&#8217;t even that big. I work for a company with roughly 2000 employees which given the above might translate to £7.4 million.</p>
<p>JUST BECAUSE OF SLOW MACHINES!</p>
<p>But that&#8217;s not all. We&#8217;re just measuring <em>interrupted</em> time. We&#8217;re assuming that a worker is at full-pelt either side of the interruption. In reality, there will be a time to &#8220;get back up to speed&#8221; after the interruption, which will vary by employee, role, and task.</p>
<p>There is a somewhat clichéd analogy that says that likens computers to cars, and staff to racing drivers. The argument goes along the lines of &#8220;If you want your driver [employee] to perform their best then give them the best car [machine].&#8221; Although one could pick substantial holes in this, the broad tenet of the idea holds true.</p>
<p>Enough? Well, no. An employee earning £30000 a year will actually cost more to the company. Consider:</p>
<ul>
<li>Employer National Insurance contributions</li>
<li>Employer pension contributions (soon to be mandatory for every employer in the UK),</li>
<li>Benefits,</li>
<li>Office space costs,</li>
<li>Utility bills,</li>
<li>Network traffic,</li>
<li>HR overhead.</li>
</ul>
<p>In reality, the costs may be double the headline figures.</p>
<p>Aside from the costs of the individual employee, what about the costs associated with their role? Employees involved in a customer-facing role will want to be able to process customer requests quickly, to (1) aid customer satisfaction, and (2) get onto the next customer quickly. Substandard equipment can detract from the customer experience, as they take longer to be served and could spend more time in a call centre queue. A company investment in equipment could be a boast:  &#8221;We equip our staff with the finest equipment, and this pays dividends.&#8221;</p>
<p>In addition to this, people are often excited about tech. That&#8217;s why we love our i[Device Name Here], or our 99&#8243; 3D televisions, or our high-spec uber-powered games consoles. A decent bit of tech on their desk will often enthuse employees to come to work and use it.</p>
<p>Consider also, that workstations are part of the office environment, high quality of equipment contributes to a high quality environment. Why spend a quarter of a million of your favourite currency revamping an office space only to fill it with substandard equipment? A company spending money creating a productive environment must also consider this.</p>
<p>The largest cost for a company is hosting an employee in the building and paying their salary. Most company costs are directly related to employing staff and providing the environment for them to work. The cost of a high-powered machine is negligible &#8211; a pittance, and will provide the highest tangible and intangible return on investment that any company could possibly make.</p>
<p>So if this resonates, please share it. I firmly believe that each unit of currency invested in equipment (up to a sensible threshold) will yield triple-figure percentage returns. Do the math yourself, based on your organisation and show it to someone who pays the bills.</p>
<div class="shr-publisher-4134"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/04/18/the-hidden-costs-of-slow-computers/' data-shr_title='The+Hidden+Costs+of+Slow+Computers'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/04/18/the-hidden-costs-of-slow-computers/' data-shr_title='The+Hidden+Costs+of+Slow+Computers'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/04/18/the-hidden-costs-of-slow-computers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Type Filtering and Method Invocation with Reflection and LINQ – Part 4</title>
		<link>http://www.jameswiseman.com/blog/2013/03/28/type-filtering-and-method-invocation-with-reflection-and-linq-part-4/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/28/type-filtering-and-method-invocation-with-reflection-and-linq-part-4/#comments</comments>
		<pubDate>Thu, 28 Mar 2013 13:02:38 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[EduAttrDiscover]]></category>
		<category><![CDATA[late-binding]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[selectmany]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4086</guid>
		<description><![CDATA[Continuing on from the last post where we define some custom attributes, let&#8217;s look at setting up a class AttributeUsers that will use these attributes. Add a new class library to the main solution. This library will need to reference the custom attributes assembly. Here&#8217;s the code: namespace AttributeUsers { [CustomClassLevel] public class AttributeUser { public [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Continuing on from the <a title="Type Filtering and Method Invocation with Reflection and LINQ – Part 3" href="http://www.jameswiseman.com/blog/2013/03/27/type-filtering-and-method-invocation-with-reflection-and-linq-part-3/">last post</a> where we define some custom attributes, let&#8217;s look at setting up a class <strong>AttributeUsers </strong>that will use these attributes.</p>
<p>Add a new class library to the main solution. This library will need to reference the custom attributes assembly.</p>
<p>Here&#8217;s the code:</p>
<pre name="code" class="c#">namespace AttributeUsers
{
    [CustomClassLevel]
    public class AttributeUser
    {
        public void Setup() { /* setup actions */ }
        public void Teardown() { /* teardown actions */}

        [CustomMethodLevel]
        public void Message1()
        {
            Console.WriteLine("Message 1 Called");
        }

        [CustomMethodLevel]
        public void Message2()
        {
            Console.WriteLine("Message 2 Called");
        }
    }
}</pre>
<p>Again, there&#8217;s nothing truly groundbreaking here, however let&#8217;s note a few points:</p>
<ul>
<li><span style="line-height: 13px;">The class is decorated with <strong>[CustomClassLevel]</strong>. </span></li>
<li>The class is decorated with <strong>[CustomMethodLevel]</strong>.</li>
<li>As it&#8217;s an attribute, the &#8216;Attribute&#8217; is implied at the end of the name. We could have said <strong>[CustomClassLevelAttribute] </strong>instead and got an identical result.</li>
<li>The methods emit a message to the console. Our goal will be to invoke these dynamically. They are parameterless for simplicity, however later we&#8217;ll look at passing data that is specified on the attribute.</li>
</ul>
<p>You&#8217;ll also note the <strong>Setup</strong> and <strong>Teardown</strong> methods. Really, this is just a nod to the unit testing framework that we are trying to mimic, and serves no functional purpose. Later on, we&#8217;ll see that it&#8217;s not enough just to include a library in an assembly &#8211; we actually have to use something within it, otherwise the compiler omits it. When searching for assemblies that include attributes, we therefore must have used something in it in order for the Attribute Discovery algorithm to work.</p>
<p>Next up in part 5, we get the nuts and bolts of the attribute discovery, and how we leverage the reflection capabilities to do this.</p>
<p>&nbsp;</p>
<div class="shr-publisher-4086"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/28/type-filtering-and-method-invocation-with-reflection-and-linq-part-4/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+%E2%80%93+Part+4'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/28/type-filtering-and-method-invocation-with-reflection-and-linq-part-4/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+%E2%80%93+Part+4'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/28/type-filtering-and-method-invocation-with-reflection-and-linq-part-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Type Filtering and Method Invocation with Reflection and LINQ – Part 3</title>
		<link>http://www.jameswiseman.com/blog/2013/03/27/type-filtering-and-method-invocation-with-reflection-and-linq-part-3/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/27/type-filtering-and-method-invocation-with-reflection-and-linq-part-3/#comments</comments>
		<pubDate>Wed, 27 Mar 2013 23:10:51 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[EduAttrDiscover]]></category>
		<category><![CDATA[late-binding]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[selectmany]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4081</guid>
		<description><![CDATA[So, in part 2 we looked at setting up a Visual Studio solution to host the project. We split it up into four parts: Attribute Discovery Custom Attributes Attribute User Host executable In this part we&#8217;ll look at our Custom Attributes project. So, if you haven&#8217;t already created a solution project then do so now. Create [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>So, in <a title="Type Filtering and Method Invocation with Reflection and LINQ – Part 2" href="http://www.jameswiseman.com/blog/2013/03/26/type-filtering-and-method-invocation-with-reflection-and-linq-part-2/">part 2 </a>we looked at setting up a Visual Studio solution to host the project. We split it up into four parts:</p>
<ul>
<li><span style="line-height: 13px;">Attribute Discovery</span></li>
<li>Custom Attributes</li>
<li>Attribute User</li>
<li>Host executable</li>
</ul>
<p>In this part we&#8217;ll look at our <strong>Custom Attributes </strong>project. So, if you haven&#8217;t already created a solution project then do so now. Create a new <strong>Blank Solution</strong> under &#8216;Other Project Types -&gt; Visual Studio Solutions&#8217;. When created, add a new C# Class Library to the solution. I&#8217;ve called mine <strong>JamesWisemanAttributes,</strong> but you can name yours in any way you want.</p>
<p>Let&#8217;s dive straight into the code:</p>
<pre name="code" class="c#">namespace JamesWisemanAttributes
{
    [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
    public sealed class CustomClassLevelAttribute : Attribute
    {
        public CustomClassLevelAttribute() {}
    }

    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public sealed class CustomMethodLevelAttribute : Attribute
    {
        public CustomMethodLevelAttribute() {}
    }
}</pre>
<p>We should observe the following things about our code:</p>
<ul>
<li><span style="line-height: 13px;">They are simple classes derived from <strong>System.Attribute</strong></span></li>
<li>The constructor actually does nothing at the moment so could be omitted. (Later it will do something, which is why it&#8217;s included here)</li>
<li>They are themselves decorated with attributes denoting their usage. The class attribute has a <strong>Class</strong> <strong>AttributeTarget</strong> and the method&#8217;s attribute denotes that it&#8217;s for a method only. We could combine these with an or &#8216;|&#8217; operator.</li>
</ul>
<p>And that&#8217;s really it. There&#8217;s nothing groundbreaking about this &#8211; we&#8217;re just setting up our projects and setting the scene.</p>
<p>Next up, we look at <strong>AttributeUser</strong>, the class that will use our attribute.</p>
<div class="shr-publisher-4081"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/27/type-filtering-and-method-invocation-with-reflection-and-linq-part-3/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+%E2%80%93+Part+3'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/27/type-filtering-and-method-invocation-with-reflection-and-linq-part-3/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+%E2%80%93+Part+3'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/27/type-filtering-and-method-invocation-with-reflection-and-linq-part-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Type Filtering and Method Invocation with Reflection and LINQ – Part 2</title>
		<link>http://www.jameswiseman.com/blog/2013/03/26/type-filtering-and-method-invocation-with-reflection-and-linq-part-2/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/26/type-filtering-and-method-invocation-with-reflection-and-linq-part-2/#comments</comments>
		<pubDate>Tue, 26 Mar 2013 19:34:47 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[EduAttrDiscover]]></category>
		<category><![CDATA[late-binding]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[selectmany]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4057</guid>
		<description><![CDATA[In this post we&#8217;ll start looking at the structure of the solution for the problem posed in Part 1. Recall from the previous post that we were wanting to create a library that could iterate over an assembly looking for types with the attribute [MyClassAttribute] and then invoke methods within that class with the attribute [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>In this post we&#8217;ll start looking at the structure of the solution for the problem posed in <a title="Type filtering and Method Invocation with Reflection and LINQ – Part 1" href="http://www.jameswiseman.com/blog/2013/03/25/type-filtering-and-method-invocation-with-reflection-and-linq-part-1/">Part 1</a>.</p>
<p>Recall from the previous post that we were wanting to create a library that could iterate over an assembly looking for types with the attribute <strong>[MyClassAttribute]</strong> and then invoke methods within that class with the attribute <strong>[MyMethodAttribute]</strong>.</p>
<p>Here&#8217;s an example of what this class might look like:</p>
<pre name="code" class="c#">[MyClassAttribute]
public class MyTestClass
{
    [MyMethodAttribute]
    public void MyTestMethod()
    {
        Console.Writeline("MyTestMethod Called");
    }
}</pre>
<p>Our end goal is to invoke <strong>MyTestMethod</strong> dynamically, and see the resulting &#8220;MyTestMethod Called&#8221; rendered to the console window.</p>
<p>So let&#8217;s start by looking at a solution that can support this. I&#8217;m using Visual Studio 2012:</p>
<p><a href="http://i2.wp.com/www.jameswiseman.com/blog/wp-content/uploads/2013/03/AttributeDiscovery1.png"><img class="alignnone size-full wp-image-4069" alt="AttributeDiscovery" src="http://i1.wp.com/www.jameswiseman.com/blog/wp-content/uploads/2013/03/AttributeDiscovery1.png?resize=212%2C170" data-recalc-dims="1" /></a></p>
<p>Technically, we could host all of the code under one project, but I&#8217;ve chosen to split it up into the following<sup>[1]</sup>:</p>
<ul>
<li><strong>AttributeDiscovery</strong> contains the code that will walk our assembly/class/method walker.</li>
<li>The rather narcissistically named <strong>JamesWisemanAttribute</strong> contains code that declares our custom attributes.</li>
<li><strong>AttributeUser</strong> is the class that will use the custom attribute, and as such should be picked up by the attribute discoverer.</li>
<li><strong>HostConsoleApp</strong> is the container app for all of this.</li>
</ul>
<p><strong>HostConsoleApp</strong> will reference all three other assemblies. <strong>AttributeUser </strong>will reference <strong>JamesWisemanAttribute</strong>. The other projects will reference nothing other than the Microsoft assemblies required for their execution (such as <strong>System.Reflection</strong>).</p>
<p>It is of particular importance that <strong>AttributeDiscovery</strong> references nothing. By doing this we are ensuring that it is loosely bound, and not dependent on any particular attribute or code library. That way we can point it at any assembly searching for any attribute.</p>
<p>Now we&#8217;ve defined the structure, in <a title="Type Filtering and Method Invocation with Reflection and LINQ – Part 3" href="http://www.jameswiseman.com/blog/2013/03/27/type-filtering-and-method-invocation-with-reflection-and-linq-part-3/">Part 3</a> we&#8217;ll start defining some code for our projects&#8230;</p>
<hr />
<p><sup>[1]</sup> Yes, there&#8217;s no unit test project. Unit tests are important, and any production-grade code should have a suite of them. This is just a demo, and unit tests would not add to the discussion.</p>
<div class="shr-publisher-4057"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/26/type-filtering-and-method-invocation-with-reflection-and-linq-part-2/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+%E2%80%93+Part+2'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/26/type-filtering-and-method-invocation-with-reflection-and-linq-part-2/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+%E2%80%93+Part+2'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/26/type-filtering-and-method-invocation-with-reflection-and-linq-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Type Filtering and Method Invocation with Reflection and LINQ &#8211; Part 1</title>
		<link>http://www.jameswiseman.com/blog/2013/03/25/type-filtering-and-method-invocation-with-reflection-and-linq-part-1/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/25/type-filtering-and-method-invocation-with-reflection-and-linq-part-1/#comments</comments>
		<pubDate>Mon, 25 Mar 2013 12:34:17 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[EduAttrDiscover]]></category>
		<category><![CDATA[late-binding]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[reflection]]></category>
		<category><![CDATA[selectmany]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4029</guid>
		<description><![CDATA[I&#8217;m currently studying for Microsoft 70-483 Programming in C# exam, and a strategy I&#8217;m trying to adopt when researching for a topic is to combine aspects of other topics that I&#8217;m unfamiliar, then writing about them. This post combines aspects of reflection and LINQ that I&#8217;m currently looking at. Assembly and Type Discovery Late-Binding and [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>I&#8217;m currently studying for <a title="Microsoft 70-483 Programming in C#" href="http://www.microsoft.com/learning/en/us/exam.aspx?id=70-483" target="_blank">Microsoft 70-483 Programming in C#</a> exam, and a strategy I&#8217;m trying to adopt when researching for a topic is to combine aspects of other topics that I&#8217;m unfamiliar, then writing about them.</p>
<p>This post combines aspects of reflection and LINQ that I&#8217;m currently looking at.</p>
<ul>
<li>Assembly and Type Discovery</li>
<li>Late-Binding and Invocation</li>
<li>LINQ SelectMany and nested selects</li>
</ul>
<p>I was wanting to write a little &#8216;attribute discovery&#8217; library that could invoke methods that had been decorated with an attribute <strong>[MyMethodAttribute]</strong>. The methods themselves would be declared within a class that would also be decorated with an attribute, a different one named <strong>[MyClassAttribute]</strong>.</p>
<p>So, when I include my <strong>&#8220;Attribute Discovery&#8221;</strong> library in an executing module, the code should  search though all the assemblies referenced by the module for classes decorated with the attribute <strong>[MyClassAttribute]</strong>. For any that are found, the code should then search these types for methods decorated with  <strong>[MyMethodAttribute]</strong>.</p>
<p>This might sound familiar.  In fact, we encounter this pattern of attribute usage within unit test projects. Consider a simple test class:</p>
<pre name="code" class="c#">[TestClass]
public class MyTestClass
{
    [TestMethod]
    public void MyTestMethod()
    {
    }
}</pre>
<p>How does the framework run this? Well, without delving in and disassembling the code manually, I can&#8217;t say for sure, but I can speculate that some sort of process similar to that outlined above is used.</p>
<p>So, how might we achieve this ourselves? Well, that&#8217;s what we&#8217;re going to delve into in this series of articles, all under the tag <a title="EduAttrDiscover Tag" href="http://www.jameswiseman.com/blog/tag/eduattrdiscover/">EduAttrDiscover</a>.</p>
<p><a title="Type Filtering and Method Invocation with Reflection and LINQ – Part 2" href="http://www.jameswiseman.com/blog/2013/03/26/type-filtering-and-method-invocation-with-reflection-and-linq-part-2/">Up next, we setup our reference project&#8230;</a></p>
<div class="shr-publisher-4029"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/25/type-filtering-and-method-invocation-with-reflection-and-linq-part-1/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+-+Part+1'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/25/type-filtering-and-method-invocation-with-reflection-and-linq-part-1/' data-shr_title='Type+Filtering+and+Method+Invocation+with+Reflection+and+LINQ+-+Part+1'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/25/type-filtering-and-method-invocation-with-reflection-and-linq-part-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Learn to Read Binary and Hex Values</title>
		<link>http://www.jameswiseman.com/blog/2013/03/21/learn-to-read-binary-and-hex-values/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/21/learn-to-read-binary-and-hex-values/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 13:17:45 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[decimal]]></category>
		<category><![CDATA[dexadecimal]]></category>
		<category><![CDATA[hex]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=4037</guid>
		<description><![CDATA[When you see the following numeric characters written down what do you think? 1234 One thousand two hundred and thirty-four. Right? Probably, yes, the context is likely to be base-10, but what if it was hex? 0&#215;1234 What is that value? In decimal it&#8217;s 4660. The first four years of my career involved a lot [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>When you see the following numeric characters written down what do you think?</p>
<p><strong>1234</strong></p>
<p>One thousand two hundred and thirty-four. Right?</p>
<p>Probably, yes, the context is likely to be base-10, but what if it was hex?</p>
<p><strong>0&#215;1234</strong></p>
<p>What is that value? In decimal it&#8217;s 4660.</p>
<p>The first four years of my career involved a lot of interaction with individual bits and bytes, which were being transmitted over serial port protocols. (one such example was. <a title="Wikipedia - Modbus" href="http://en.wikipedia.org/wiki/Modbus">Modbus</a>).</p>
<p>It was fun. It felt like proper programming.</p>
<p>Over the next decade, hardly anything at all like this came my way. And in those years, without realising, I&#8217;d lost a skill &#8211; The feeling for binary and hexadecimal numbers and how they translated to the comfortable decimal numbers with which we are all so familiar.</p>
<p>So, recently I was thrown into a project which involved translating the bytes coming from a serial port to a series of fields in a class. It wasn&#8217;t too taxing, but it was hindered by the fact that I had think about the conversions. It made me realise that this stuff can actually be quite useful.</p>
<p>Like a linguistic skill, it&#8217;s often better to learn to think in terms of the domain in which you are conversing. The best linguists, when communicating in German will think in German, rather than translating from their native language.</p>
<p>But my experience is that we often need to translate between these domains. Simply thinking in of that domain isn&#8217;t enough.</p>
<p>I&#8217;m not saying that you should be able to look at a hex value <strong>2f5a109888aedfbc1</strong>, or a binary value of <strong>00101010110100101010101010</strong> and know instantly what decimal value it is. I&#8217;m suggesting that up to a sensible exponent of 2, you should have a feeling for the equivalent decimal and hex representation (the binary one follows directly from the exponent).</p>
<table>
<thead>
<tr>
<td>2^</td>
<td>Binary</td>
<td>Hex</td>
<td>Decimal</td>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>10</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td>5</td>
<td>10000</td>
<td>10</td>
<td>16</td>
</tr>
<tr>
<td>8</td>
<td>100000000</td>
<td>100</td>
<td>256</td>
</tr>
<tr>
<td>10</td>
<td>10000000000</td>
<td>400</td>
<td>1024</td>
</tr>
</tbody>
</table>
<p>I&#8217;m suggesting that a feel for this up to an exponent of 32 is desirable. This, of course, takes us to the limit of a 32-bit value &#8211; 4 bytes &#8211; or an <strong>int</strong> (probably) to you and I. An exponent of 31 (with one subtracted from the final number) gives us the boundary of an <strong>unsigned int</strong>, 16 gives us an <strong>unsigned short int</strong>, 15 a <strong>signed short int</strong>, etc.</p>
<p>An old professor of mine at university used to boast that he knew, by heart, the decimal representation  of each power of 2 up to an exponent of 64. This was met with moderate derision from some of his students, but maybe he had a point&#8230;</p>
<p>&nbsp;</p>
<div class="shr-publisher-4037"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/21/learn-to-read-binary-and-hex-values/' data-shr_title='Learn+to+Read+Binary+and+Hex+Values'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/21/learn-to-read-binary-and-hex-values/' data-shr_title='Learn+to+Read+Binary+and+Hex+Values'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/21/learn-to-read-binary-and-hex-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delegates, Events and The 10 Type Members of C#</title>
		<link>http://www.jameswiseman.com/blog/2013/03/18/delegates-events-and-the-10-type-members-of-c/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/18/delegates-events-and-the-10-type-members-of-c/#comments</comments>
		<pubDate>Mon, 18 Mar 2013 16:30:00 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[delegates]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[types]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=3990</guid>
		<description><![CDATA[Have you ever stopped to think about the different &#8216;kinds&#8216; of things you can put in a class? If your colleagues are that way inclined, then I&#8217;d encourage you to ask. I&#8217;ll bet no-one gets all of them. Here they are: 1. Methods 2. Fields 3. Properties 4. Type Declarations (e.g. Nested Class) 5. Type [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Have you ever stopped to think about the different &#8216;<b>kinds</b>&#8216; of things you can put in a class?</p>
<p>If your colleagues are that way inclined, then I&#8217;d encourage you to ask. I&#8217;ll bet no-one gets all of them.</p>
<p>Here they are:</p>
<p>1. Methods<br />
2. Fields<br />
3. Properties<br />
4. Type Declarations (e.g. Nested Class)<br />
5. Type (static) Constructors<br />
6. Instance Constructors<br />
7. Events<br />
8. Operator Overloads<br />
9. Conversion Operators<br />
10. Constants</p>
<p>When I asked a colleague here, he included <strong>delegates</strong> in that list. I was stumped! Surely <strong>delegate</strong> should appear. Should my list should <a title="Spinal Tap - These go to 11" href="http://www.youtube.com/watch?v=ll7rWiY5obI" target="_blank">Go Up To 11</a>?</p>
<p>I got back to my desk and thought about it, and then the penny dropped.</p>
<p>First, we have to decide if we’re talking about delegate <strong>types</strong> or delegate <strong>instances</strong>. The failure to differentiate these is the source of most the confusion that I have encountered that surround delegates. Armed with this info we can start referencing our list above:</p>
<p>A delegate <strong>type</strong> is a type declaration. Like a class, struct or enum. So, that means it is classified by <strong>number 4 </strong>in our list above.</p>
<p>If we’re talking about a delegate <strong>instance</strong> then a this is just an <strong>instance of a type</strong>. If we put one of them in a class, it’s a <strong>field (2)</strong> or maybe a <strong>property (3)</strong>.</p>
<p>The difference between these two is the same as the difference between a <strong>nested class</strong> and an <strong>instance of a class</strong>.</p>
<p>So, why is an event so special about an <strong>event</strong>? Well, it’s a special sort of ‘thing’. It differs subtly from a <strong>Type</strong>, <strong>Field</strong> or <strong>Property</strong> enough to distinguish it from them. It all boils down to an understanding of the difference between <strong>delegates</strong> and <strong>events</strong>. Jon Skeet has a nice article about this:</p>
<p><a title="C# In Depth - Delegates and Events" href="http://csharpindepth.com/Articles/Chapter2/Events.aspx" target="_blank">http://csharpindepth.com/Articles/Chapter2/Events.aspx</a></p>
<blockquote><p>Events are pairs of methods, appropriately decorated in IL to tie them together and let languages know that the methods represent events.</p></blockquote>
<p>We already distinguish a <strong>Property </strong>as being something different from a <strong>Field</strong>. When compiled, a <strong>Property</strong> becomes a pair of methods with backing field. In a similar fashion, an <strong>Event</strong> becomes a pair of methods with a backing class that utilises these methods.<strong><br />
</strong></p>
<p>So there we are. <strong>Events</strong> are a special sort of <strong>Thing</strong> you put in another <strong>Thing</strong> and are enough to be a <strong>Thing In Its Own right</strong> and not just a sort of other <strong>Thing</strong>.</p>
<p>Clear?</p>
<p>Marvellous!</p>
<div class="shr-publisher-3990"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/18/delegates-events-and-the-10-type-members-of-c/' data-shr_title='Delegates%2C+Events+and+The+10+Type+Members+of+C%23'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/18/delegates-events-and-the-10-type-members-of-c/' data-shr_title='Delegates%2C+Events+and+The+10+Type+Members+of+C%23'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/18/delegates-events-and-the-10-type-members-of-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Casting and Variance in C# Part 7 &#8211; Variance</title>
		<link>http://www.jameswiseman.com/blog/2013/03/15/casting-and-variance-in-c-part-7-variance/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/15/casting-and-variance-in-c-part-7-variance/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 13:37:49 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[casting]]></category>
		<category><![CDATA[EduCastVariance]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[variance]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=3849</guid>
		<description><![CDATA[Ok Its been a little time since the last post, but I always resolved to finish this series, so here we go with Episode 7. Intro The subject of Variance in computer science is well documented and well described and you&#8217;ll find scores of articles on the subject if you cared to enter the term [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><h3>Ok</h3>
<p>Its been a little time since the last post, but I always resolved to finish this series, so here we go with Episode 7.</p>
<h3>Intro</h3>
<p>The subject of Variance in computer science is well documented and well described and you&#8217;ll find scores of articles on the subject if you cared to enter the term into your favourite search engine. I&#8217;ve included a selection of links at the bottom which may assist you in further reading.</p>
<p>So, why write another series on this when there&#8217;s so many already? Well, unfortunately, <strong>I Just Didn&#8217;t Understand</strong><strong> then</strong>. Let&#8217;s be clear on this, I found <strong>Covariance </strong>and <strong>Contravariance</strong> hard to comprehend to any level on which I was satisfied, and, sometimes the best way of understanding anything to try to explain it to someone else<sup>1</sup>. In fact, the &#8216;someone else&#8217; in question is a colleague of mine, James who might be a little surprised when he reads this.</p>
<p>The term <strong>Variance</strong> in relation to computing has its root in the mathematical area of <a title="Wikipedia - Category Theory" href="http://en.wikipedia.org/wiki/Category_theory" target="_blank">Category Theory</a><sup>2</sup>. The challenge is to convey the language of this domain to those who have never studied or even heard of it.</p>
<p>So, this article will try to describe these topic from a novice programmer&#8217;s perspective.  It&#8217;s also important to note that the explanation<em> won&#8217;t be entirely correct</em>, but it&#8217;ll do for now.</p>
<h3>A &#8216;Relationship&#8217;</h3>
<p>We&#8217;ve spoken at length about <strong>Casting</strong> and the notion of <strong>Assignment Compatibility</strong>. Generally speaking, the former can be achieved if the latter is met. More profoundly, <strong>Casting</strong> is an <strong>operation</strong>, whereas <strong>Assignment Compatibility </strong>describes a <strong>relationship</strong>. This is exactly what the terms <strong>Covariant</strong> and <strong>Contravariant</strong> do &#8211; they describe a <strong>Relationship</strong>.</p>
<p>The previous articles had hinted at <strong>Variance</strong> as a future topic, with the message <em>&#8220;we&#8217;re not quite there yet&#8221;</em>, however that was a lie, because <strong>Assignment</strong> <strong>Compatibility</strong> <em>is a special kind of <strong>Variance</strong></em>. If we can understand our rules for the former we find it easier to grasp the latter.</p>
<p>But, whereas <strong>Assignment Compatibility </strong>describes the relationship between two related <strong>Types</strong>, <strong>Variance</strong> describes the relationship between two  &#8217;<strong>Users Of</strong>&#8216; different types. To understand what we <em>might</em> mean by &#8216;<strong>Users </strong><strong>Of</strong>&#8216;, simply replace the word &#8216;<strong>Users</strong>&#8216; with a C# collection of your choice. For example:</p>
<ul>
<li><strong>Variance</strong> describes the relationship between two &#8216;<span style="color: #ff0000;"><strong>Lists</strong></span>&#8216; of different<strong> Types</strong><sup>3</sup>.</li>
<li><strong>Variance</strong> describes the relationship between two &#8217;<span style="color: #ff0000;"><strong>Arrays</strong></span>&#8216; of different <strong>Types</strong>.</li>
</ul>
<p>Although the above implies collections, we can also talk about <strong>Delegates</strong> and <strong>Interfaces</strong>, which aren&#8217;t strictly speaking &#8216;<strong>Collections Of</strong>&#8216;, but can certainly be &#8216;<strong>Users Of</strong>&#8216; the <strong>Types</strong>.</p>
<p>In short, <strong>Variance </strong>describes the relationship between an instance of a &#8220;<strong>Thing</strong> that <strong>uses</strong> a <strong>Type</strong>&#8220;, and another instance of an &#8220;identical <strong>Thing </strong>that uses a different <strong>Type</strong>.&#8221;</p>
<p>Whilst, in theory, <strong>Variance</strong> describes the relationship between <strong>any</strong> such &#8216;<strong>Users Of</strong>&#8216; two different types, in reality C# limits the &#8217;<strong>Users Of</strong>&#8216; to three particular areas:</p>
<ul>
<li>Arrays</li>
<li>Delegates</li>
<li>Generic Interfaces</li>
</ul>
<p>We&#8217;ll cover them in more detail later, but its enough to highlight currently that  <strong>Lists</strong>, <strong>Dictionaries</strong>, and other strongly typed collections do not support <strong>Variance</strong>, and the same is true for most <strong>Return Types</strong> and <strong>Function Parameters</strong>. Again, we&#8217;ll visit this a little later.</p>
<p>Finally its worth stating up front the different kinds of variance we can perceive. Relationships between two identical <strong>things</strong> that <strong>use</strong> different types can be described as:</p>
<ul>
<li><span style="line-height: 13px;">Covariant</span></li>
<li>Contravariant</li>
<li>Invariant</li>
</ul>
<p>We&#8217;ll leave it at that for the moment, and leave the description of these to later posts. And with that&#8230;</p>
<p><strong>Next up &#8211; Types of Covariance&#8230;</strong></p>
<hr />
<p><sup>1</sup> My friend, <a title="Ian Ozsvald" href="http://ianozsvald.com/" target="_blank">Ian Ozsvald</a> reckons that presenting on a topic is the best way of refining knowledge. In this respect, I would include &#8220;writing&#8221; as a form of presentation.</p>
<p><sup>2</sup> The term Variance is also used in Statistical and Probability Theory, which is different.</p>
<p><sup>3</sup> There is no variance on the generic List type in C#. I just wanted to get across a concept.</p>
<p>&nbsp;</p>
<div class="shr-publisher-3849"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/15/casting-and-variance-in-c-part-7-variance/' data-shr_title='Casting+and+Variance+in+C%23+Part+7+-+Variance'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/15/casting-and-variance-in-c-part-7-variance/' data-shr_title='Casting+and+Variance+in+C%23+Part+7+-+Variance'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/15/casting-and-variance-in-c-part-7-variance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Open Tech Calendar</title>
		<link>http://www.jameswiseman.com/blog/2013/03/15/open-tech-calendar/</link>
		<comments>http://www.jameswiseman.com/blog/2013/03/15/open-tech-calendar/#comments</comments>
		<pubDate>Fri, 15 Mar 2013 13:27:17 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[edinburgh]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[open-tech-calendar]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=3987</guid>
		<description><![CDATA[In the last few years Edinburgh has become a great place to be a tech professional. There&#8217;s a growing list of companies looking for the services of such people, and a growing list of events and groups to attend. James Baster, an organiser of one such group, Techmeetup, Edinburgh, recognised this fact, but also recognised the [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p><img class="alignnone" alt="" src="http://i0.wp.com/www.jameswiseman.com/blog/wp-content/uploads/2013/03/logoHeader.png?resize=65%2C62" data-recalc-dims="1" />In the last few years Edinburgh has become a great place to be a tech professional. There&#8217;s a growing list of companies looking for the services of such people, and a growing list of events and groups to attend.</p>
<p><a title="James Baster" href="http://jamesbaster.co.uk/" target="_blank">James Baster</a>, an organiser of one such group, <a title="Techmeetup, Edinburgh" href="http://techmeetup.co.uk/" target="_blank">Techmeetup, Edinburgh</a>, recognised this fact, but also recognised the frustration in pulling together all the local events for an area. I shared this frustration one day as I spent a few hours attempting to identify events in Edinburgh over the coming months.</p>
<p>So imagine my delight when he launched <a title="Open Tech Calendar" href="http://opentechcalendar.co.uk/index.php" target="_blank">Open Tech Calendar</a>!</p>
<p>This is a user-editiable list of tech events for your local area, created and maintained by the community. Essentially it&#8217;s a Tech Calendar Wiki. James couldn&#8217;t have called it TechCalendiki, but I thank him for not doing so!</p>
<p>Starting in Edinburgh, as it did, it&#8217;s unsurprising that there is a hug bias towards this location. At the time of writing there are 48 upcoming events. So, if a city with a population of a quarter of a million can boast such a lively tech community, imagine what say somewhere like London could achieve.</p>
<p>Although the calendar appears to cater just for the UK, James asks you to contact him if your location isn&#8217;t available.</p>
<p>I would strongly urge you to pass this on and spread the word. I think it&#8217;s a simple and great idea that deserves more attention and recognition.</p>
<div class="shr-publisher-3987"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2013/03/15/open-tech-calendar/' data-shr_title='Open+Tech+Calendar'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2013/03/15/open-tech-calendar/' data-shr_title='Open+Tech+Calendar'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2013/03/15/open-tech-calendar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Response to: Why Stackoverflow Sucks</title>
		<link>http://www.jameswiseman.com/blog/2012/11/01/a-response-to-why-stackoverflow-sucks/</link>
		<comments>http://www.jameswiseman.com/blog/2012/11/01/a-response-to-why-stackoverflow-sucks/#comments</comments>
		<pubDate>Thu, 01 Nov 2012 13:26:38 +0000</pubDate>
		<dc:creator>jameswiseman</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Stackoverflow]]></category>

		<guid isPermaLink="false">http://www.jameswiseman.com/blog/?p=3831</guid>
		<description><![CDATA[Some time ago I stumbled across a blog post Why Stackoverflow Sucks, and found that I disagreed with the sentiments of the author so profoundly, that I thought I&#8217;d write a response, despite the fact that is was posted over a month ago In doing so, I&#8217;m not wanting to sound like a total Stackoverflow fanboy [...]]]></description>
				<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Some time ago I stumbled across a blog post <a title="Why Stackoverflow Sucks" href=" http://sergworks.wordpress.com/2012/09/26/why-stackoverflow-sucks/" target="_blank">Why Stackoverflow Sucks</a>, and found that I disagreed with the sentiments of the author so profoundly, that I thought I&#8217;d write a response, despite the fact that is was posted over a month ago</p>
<p>In doing so, I&#8217;m not wanting to sound like a total Stackoverflow fanboy &#8211; I&#8217;m not &#8211; but the fact of the matter is that I have used SO to solve real world problems and has helped me immensely in my learning and understanding of different topics. Fundamentally this is not a post in support of Stackoverflow, more a response some of the criticism that I deem unfounded.</p>
<p>So let&#8217;s plough on.</p>
<p>The author writes:</p>
<blockquote><p>The paradox is that SO is not interested in users getting answers to their questions.</p></blockquote>
<p>And then&#8230;</p>
<blockquote><p>SO wants great questions and great answers.</p></blockquote>
<p>So which is it? The author&#8217;s paradox seems a little paradoxical to me.</p>
<blockquote><p>Usually Q&amp;A sites want their questioners to be happy, but not SO.</p></blockquote>
<p>Care to say which ones?</p>
<blockquote><p>Hence the reputation system and an army of Nazi retards moderating everything they can see.</p></blockquote>
<p>I see &#8211; the sort of sites where users like to post libellous insults.</p>
<p>So,  <strong>the author thinks Stackoverflow Sucks because:</strong></p>
<ul>
<li>SO doesn&#8217;t want user to get great answers because SO wants great answers.</li>
<li>Its moderators are Nazi retards.</li>
<li>It doesn&#8217;t keep trolls happy.</li>
</ul>
<p>So let&#8217;s go on</p>
<blockquote><p>If a question is considered poor by the user with moderating privileges, it will be downvoted, closed and finally deleted. But that is not all – SO has an automatic ban system. Users providing questions &amp; answers that received low marks can be banned by robots.</p></blockquote>
<p>And this is a bad thing, how? Banning people because they emit rubbish. Well, at least we have another argument:</p>
<p>So,  <strong>the author </strong><strong>thinks Stackoverflow Sucks because:</strong></p>
<div>
<ul>
<li>SO doesn&#8217;t want user to get great answers because SO wants great answers.</li>
<li>Its moderators are Nazi retards.</li>
<li>It doesn&#8217;t keep trolls happy.</li>
<li>You can get banned for posting bad questions.</li>
<li>A &#8216;robot&#8217; (i.e. not a Nazi retard) can ban a user.</li>
</ul>
</div>
<p>This of course implies that you can ask one question and it can get downvoted and some robot will ban you. This is actually not the case. I&#8217;ve seen someone with over fifty poor questions that hadn&#8217;t been banned.</p>
<p>So, the author asked a question on SO:</p>
<blockquote><p> I thought the question was interesting&#8230;sure that was not a great question&#8230;Also the question was not properly tagged..</p></blockquote>
<p>Here he&#8217;s actually admitted that the original question was bad, and that it incorrectly included one of the most popular tags on the site (PHP) exposing it to tens of thousands of users. A bad incorrect question on a popular tag, what going to happen there then?</p>
<blockquote><p>The question received 17 downvotes. The question got the comment `Smells like homework to me` and the comment got 14 upvotes;</p></blockquote>
<p>Well, boohoo! The question sounded exactly like homework to me. Of course, its worth of note that from September 14th  (12 days to prior to his post) <a title="The homework tag is now officially deprecated" href="http://meta.stackoverflow.com/q/147100/149297" target="_blank">The homework tag was officially deprecated</a>.</p>
<p>But OK, let&#8217;s address the question</p>
<blockquote><p>Here is a task:<br />
“3 brothers have to transfer 9 boxes from one place to another.<br />
These boxes weigh 1, 2, 4, 5, 6, 8, 9, 11, 14 kilos.<br />
Every brother takes 3 boxes.<br />
So, how to make a program that would count the most optimal way to take boxes?<br />
The difference between one brother’s carrying boxes weight and other’s has to be as small as it can be.”<br />
Can you just give me an idea or write a code with any programming language you want ( php or pascal if possible? ).</p></blockquote>
<p>And this is useful how? Ohhhh, I get it, it&#8217;s a puzzle! Right, hang on, let me take time away from my current work to answer a completely useless and arbitrary puzzle.</p>
<p>The broader Stackexchange network does have a place for this sort of question: <a href="http://codegolf.stackexchange.com/">Programming Puzzles &amp; Code Golf</a>. Rather than allowing this sort of question on Stackoverflow, the network has evolved to provide a forum for this sort of question. Although this wasn&#8217;t around at the time of the quetsion, it was around before the blog article was posted.</p>
<p>Ok, let&#8217;s go on</p>
<blockquote><p>The strange guy Bill the Lizard did not stop after closing the question.</p></blockquote>
<p>Holy crap! This guy Bill the Lizard (<a title="Bill the Lizard SO Profile" href="http://stackoverflow.com/users/1288/bill-the-lizard" target="_blank">Profile</a>/<a title="Bill The Lizard Home Page" href="http://www.billthelizard.com/" target="_blank">Home Page</a>), as well as being a Nazi and a Retard, is also <strong>strange</strong> now! On what basis is this? He seems like a reasonable chap to me.</p>
<p>So,  <strong>the author </strong><strong>thinks Stackoverflow Sucks because:</strong></p>
<div>
<ul>
<li>SO doesn&#8217;t want user to get great answers because SO wants great answers.</li>
<li>Its moderators are <strong>strange</strong> Nazi retards.</li>
<li>It doesn&#8217;t keep trolls happy.</li>
<li>You can get banned for posting bad questions.</li>
<li>A &#8216;robot&#8217; (i.e. not a Nazi retard) can ban a user.</li>
</ul>
</div>
<p>And finally&#8230;</p>
<blockquote><p>More than 1.5 year (!) after the question was answered he returned to it and deleted both the question and my answer (my answer probably because it contradicted his resolution).</p></blockquote>
<p>Excuse me while I unpack by miniature violin and start playing a sad tune very quietly.</p>
<p>Seemingly, Bill the Lizard as well as being strange, a Nazi AND a retard is a jealous megalomaniac AS WELL. And a whole 18 months later, the system provided enough visibility to enable someone to close a poorly worded irrelevant and useless questions.</p>
<p>So,  <strong>the author </strong><strong>thinks Stackoverflow Sucks because:</strong></p>
<div>
<ul>
<li>SO doesn&#8217;t want user to get great answers because SO wants great answers.</li>
<li>Its moderators are strange  <strong>jealous megalomaniac</strong> Nazi retards.</li>
<li>It doesn&#8217;t keep trolls happy.</li>
<li>You can get banned for posting bad questions.</li>
<li>A &#8216;robot&#8217; (i.e. not a Nazi retard) can ban a user.</li>
<li>It gives visibility on poor quality over a large time span.</li>
</ul>
</div>
<p>Ummmmm&#8230;???</p>
<p>I&#8217;m not presenting a case for Stackoverflow. It may well suck for many reasons, but not for the ones above. What it really boils down to is this. The author is unhappy because it doesn&#8217;t work how he think it should, and that it damaged his poor little libellous ego. That&#8217;s it. The fact of the matter is that the SO has risen into the top 100 (by some measures) of worldwide internet sites and has tens of thousands of happy and active users.</p>
<p>Before this, the world of Q&amp;A searches was deeply broken and now we have a forum where we can get solutions to problems, and a forum to engage with experts&#8230;for free.</p>
<p>That can&#8217;t be that bad&#8230;Can it?</p>
<p>&nbsp;</p>
<div class="shr-publisher-3831"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http://www.jameswiseman.com/blog/2012/11/01/a-response-to-why-stackoverflow-sucks/' data-shr_title='A+Response+to%3A+Why+Stackoverflow+Sucks'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http://www.jameswiseman.com/blog/2012/11/01/a-response-to-why-stackoverflow-sucks/' data-shr_title='A+Response+to%3A+Why+Stackoverflow+Sucks'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://www.jameswiseman.com/blog/2012/11/01/a-response-to-why-stackoverflow-sucks/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
