<?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>FormatException &#187; C#</title>
	<atom:link href="http://www.formatexception.com/category/csharp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.formatexception.com</link>
	<description>Ramblings on developing in the Windows World</description>
	<lastBuildDate>Fri, 23 Sep 2011 15:34:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>NFop (ApacheFop.Net) with J# in .NET 4.0 and DotNetNuke 6</title>
		<link>http://www.formatexception.com/2011/09/nfop-apachefop-net-in-with-j-in-net-4-0-and-dotnetnuke-6/</link>
		<comments>http://www.formatexception.com/2011/09/nfop-apachefop-net-in-with-j-in-net-4-0-and-dotnetnuke-6/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 23:56:52 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=369</guid>
		<description><![CDATA[Recently we had a client that wanted to upgrade their web application containing modules we had written for them a long time ago for DotNetNuke 4.3 and they hadn&#8217;t had any upgrades since.  Fortunately the content on the site was fairly minimal so we decided just to set up a new instance of DNN 6 [...]]]></description>
			<content:encoded><![CDATA[<p>Recently we had a client that wanted to upgrade their web application containing modules we had written for them a long time ago for DotNetNuke 4.3 and they hadn&#8217;t had any upgrades since.  Fortunately the content on the site was fairly minimal so we decided just to set up a new instance of DNN 6 and move the content over.  This means we had to take modules written for DotNetNuke 4.3 all the way to DotNetNuke 6.0.  For the most part it really wasn&#8217;t too bad.  There were some issues with ajax and script manager as DNN 4.3 pre-dated DNN&#8217;s inclusion of a scriptmanager automatically, but the biggest problem was <a href="http://sourceforge.net/projects/nfop/">ApacheFop.Net</a> and J#.</p>
<p>The original developers of the modules used ApacheFop.Net for the PDF generation for all reports.</p>
<p><span style="text-decoration: underline;"><strong>Step 0:</strong></span></p>
<p>First I had to install the <a title="J# redistributable" href="http://www.microsoft.com/download/en/details.aspx?displaylang=en&amp;id=4712">J# redistributable</a>.</p>
<p><span style="text-decoration: underline;"><strong>Step 1:</strong></span></p>
<p>After doing that I moved over assembly entries from the 4.3 web config:</p>
<pre name="code" class="xml">&lt;assemblies&gt;
    &lt;add assembly="vjscor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /&gt;
    &lt;add assembly="vjslib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /&gt;
&lt;/assemblies&gt;</pre>
<p><span style="text-decoration: underline;"><strong>Step 2:</strong></span></p>
<p>This got close.  Now when trying to generate a report I got the following error:</p>
<blockquote><p>Could not load file or assembly &#8216;vjscor, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a&#8217; or one of its dependencies.</p></blockquote>
<p>Okay, well, then let&#8217;s use a binding redirect in the assembly binding section of the runtime of the web.config.  I&#8217;m not sure why it was trying to load 1.0.5000.0 when I told it to load 2.0.0.0, but we&#8217;ll correct that:</p>
<pre name="code" class="xml">&lt;runtime&gt;
    &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;probing privatePath="bin;bin\HttpModules;bin\Providers;bin\Modules;bin\Support;"/&gt;
        &lt;dependentAssembly&gt;
            &lt;assemblyIdentity name="vjslib" publicKeyToken="b03f5f7f11d50a3a"/&gt;
            &lt;bindingRedirect oldVersion="1.0.0.0-1.0.5000.0" newVersion="2.0.0.0"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
            &lt;assemblyIdentity name="vjsnativ" publicKeyToken="b03f5f7f11d50a3a"/&gt;
            &lt;bindingRedirect oldVersion="1.0.0.0-1.0.5000.0" newVersion="2.0.0.0"/&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
            &lt;assemblyIdentity name="vjscor" publicKeyToken="b03f5f7f11d50a3a"/&gt;
            &lt;bindingRedirect oldVersion="1.0.0.0-1.0.5000.0" newVersion="2.0.0.0"/&gt;
        &lt;/dependentAssembly&gt;
    &lt;/assemblyBinding&gt;
&lt;/runtime&gt;</pre>
<p><span style="text-decoration: underline;"><strong>Step 3:</strong></span></p>
<p>One step closer.  Now I get the error:</p>
<blockquote><p>A critical error has occurred.The type initializer for &#8216;java.lang.System&#8217; threw an exception.</p></blockquote>
<p>Well, at least it looks like it&#8217;s trying to load the J# libraries.</p>
<p>Finally after much googling around I finally hit upon the last step in the enigma at</p>
<p><a href="http://blogs.windwardreports.com/davidt/2011/02/calling-j-code-from-net-40.html">http://blogs.windwardreports.com/davidt/2011/02/calling-j-code-from-net-40.html</a></p>
<p>I added to my Default.aspx the external call for manually loading libraries:</p>
<pre name="code" class="csharp">//used for loading J# libraries
[DllImport("kernel32", SetLastError = true)]
static extern IntPtr LoadLibrary(string lpFileName);</pre>
<p>and then to the OnInit I added:</p>
<pre name="code" class="csharp">//load needed J# libraries
if (Environment.Version.Major &gt;= 4)
{
    string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), @"..\Microsoft.NET\Framework\v2.0.50727");
    folder = Path.GetFullPath(folder);
    LoadLibrary(Path.Combine(folder, "vjsnativ.dll"));
    LoadLibrary(Path.Combine(folder, "vjscor.dll"));
    LoadLibrary(Path.Combine(folder, "vjslib.dll"));
}</pre>
<p>I tried removing each step and the only step that you can do without is step one since we&#8217;re manually loading the libraries manually anyways.  Oddly, even though I&#8217;m now manually loading the libraries, I still need to do step two. Oh well, this is what works for me but as always YMMV.</p>
<p>&nbsp;</p>
<p>Thanks,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2011%2F09%2Fnfop-apachefop-net-in-with-j-in-net-4-0-and-dotnetnuke-6%2F&amp;t=NFop%20%28ApacheFop.Net%29%20with%20J%23%20in%20.NET%204.0%20and%20DotNetNuke%206" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2011%2F09%2Fnfop-apachefop-net-in-with-j-in-net-4-0-and-dotnetnuke-6%2F&amp;t=NFop%20%28ApacheFop.Net%29%20with%20J%23%20in%20.NET%204.0%20and%20DotNetNuke%206" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2011/09/nfop-apachefop-net-in-with-j-in-net-4-0-and-dotnetnuke-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Often Unused Operators: fixed()</title>
		<link>http://www.formatexception.com/2011/03/often-unused-operators-fixed/</link>
		<comments>http://www.formatexception.com/2011/03/often-unused-operators-fixed/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 16:43:26 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[fixed]]></category>
		<category><![CDATA[often unused operators]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=359</guid>
		<description><![CDATA[This post is inspired by Eric Clippert&#8217;s post on References and Pointers. I think it escapes a lot of C# devs that they have the same pointer abilities as C/C++, or maybe it&#8217;s that those features have been intentionally down-played by Microsoft for a reason. As C# devs we&#8217;ve come to rely on nice, safe [...]]]></description>
			<content:encoded><![CDATA[<p>This post is inspired by Eric Clippert&#8217;s post on <a href="http://blogs.msdn.com/b/ericlippert/archive/2011/03/07/references-and-pointers-part-one.aspx" target="_blank">References and Pointers</a>.</p>
<p>I think it escapes a lot of C# devs that they have the same pointer abilities as C/C++, or maybe it&#8217;s that those features have been intentionally down-played by Microsoft for a reason.  As C# devs we&#8217;ve come to rely on nice, safe and managed code and GC.  That doesn&#8217;t mean we can&#8217;t cause an out of memory exception or infinite recursion or some other bad thing along the way, but for the most part C# tries to protect us.  While I&#8217;m not going to cover pointers (something of which I have a fondness for given that my very first college class was &#8220;Fundamentals of C&#8221;) I do want to go over the fixed() operation.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/f58wzh21.aspx" target="_blank">Fixed</a> is basically telling the GC, &#8220;Don&#8217;t move me, don&#8217;t touch me, don&#8217;t GC me, don&#8217;t even look at me&#8221; which is why fixed can only be used within an unsafe context.  It&#8217;s important to mention that unsafe means, um, unsafe.  When you identify an area of code as unsafe you&#8217;re saying, &#8220;Hey, I know I&#8217;m doing something that could potientially be really bad and all the work MS has done to try and protect me I&#8217;m ignoring.  I really, really promise to only use smart code here.&#8221; </p>
<p>Here&#8217;s a bit of code using fixed:</p>
<pre name="code" class="csharp">unsafe void FixedExample()
{
&nbsp;&nbsp;&nbsp;&nbsp;double[] arr = { 0, 1.5, 3, 4.5, 6, 7.5, 9 };
&nbsp;&nbsp;&nbsp;&nbsp;fixed(double* p1 = &#038;arr[1])
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fixed (double* p2 = &#038;arr[5])
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int diff = (int)(p2 - p1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Print(diff.ToString());
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
}</pre>
<pre name="code" class="csharp">unsafe void FixedExample2()
{
&nbsp;&nbsp;&nbsp;&nbsp;double[] array =  { 0, 1.5, 3, 4.5, 6, 7.5, 9 };
&nbsp;&nbsp;&nbsp;&nbsp;fixed (double* arr = array)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double* p1 = &#038;arr[1];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;double* p2 = &#038;arr[3];
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int diff = (int)(p2 - p1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Debug.Print(diff.ToString());
&nbsp;&nbsp;&nbsp;&nbsp;}
}</pre>
<p>Basically, fixed allows you to get pointers to managed types which would otherwise be subjected to GC.  If you were to work just with pointers and not managed types you can do the above (using stackalloc) without even needing fixed.</p>
<pre name="code" class="csharp">unsafe void StackallocExample()
{
&nbsp;&nbsp;&nbsp;&nbsp;int arraySize = 7;
&nbsp;&nbsp;&nbsp;&nbsp;double* arr = stackalloc double[arraySize];
&nbsp;&nbsp;&nbsp;&nbsp;double j = 0;
&nbsp;&nbsp;&nbsp;&nbsp;for (int i = 0; i < arraySize; i++, j += 1.5)
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;arr[i] = j;
&nbsp;&nbsp;&nbsp;&nbsp;}

&nbsp;&nbsp;&nbsp;&nbsp;double* p1 = &#038;arr[1];
&nbsp;&nbsp;&nbsp;&nbsp;double* p2 = &#038;arr[15];
&nbsp;&nbsp;&nbsp;&nbsp;int diff = (int)(p2 - p1);
&nbsp;&nbsp;&nbsp;&nbsp;Debug.Print(diff.ToString());
}</pre>
<p>but of course the above code is very bad.  If you didn't notice, the second pointer points to the 16th element (since we're obviously 0 based) but I only allocated 7 doubles worth of memory.  If I were do try and do something with arr[15] (rather then just determine the distance between the two elements) that would be very bad as it wouldn't represent a value I had intended and would just be some random bit of whatever was stored in that memory location.  Interestingly enough, if you try the same in the first two examples you'll get a runtime exception.</p>
<p>Thanks,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2011%2F03%2Foften-unused-operators-fixed%2F&amp;t=Often%20Unused%20Operators%3A%20fixed%28%29" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2011%2F03%2Foften-unused-operators-fixed%2F&amp;t=Often%20Unused%20Operators%3A%20fixed%28%29" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2011/03/often-unused-operators-fixed/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Task Parallel Library and System.Collections.Concurrent Namespace</title>
		<link>http://www.formatexception.com/2010/12/the-task-parallel-library-and-system-collections-concurrent-namespace/</link>
		<comments>http://www.formatexception.com/2010/12/the-task-parallel-library-and-system-collections-concurrent-namespace/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 16:26:24 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=342</guid>
		<description><![CDATA[Arguably one of the biggest parts of .NET 4.0 was the Task Parallel Library (TPL). The TPL makes it ridiculously easy to parallelize code. With Parallel.ForEach, Parallel.For, Parallel.Invoke, and Task.Factory developing for today&#8217;s multi-core systems should be a matter of fact. Recently I was tasked with optimizing a large code base to utilize the TPL. [...]]]></description>
			<content:encoded><![CDATA[<p>Arguably one of the  biggest parts of .NET 4.0 was the <a href="http://msdn.microsoft.com/en-us/library/dd460717(VS.100).aspx">Task Parallel Library (TPL)</a>.  The TPL makes it ridiculously easy to parallelize code.  With Parallel.ForEach, Parallel.For, Parallel.Invoke, and Task.Factory developing for today&#8217;s multi-core systems should be a matter of fact.  </p>
<p>Recently I was tasked with optimizing a large code base to utilize the TPL.  The first problem?  List and Dictionary aren&#8217;t thread safe.  That&#8217;s right, two of the most common data structures aren&#8217;t thread safe.  Fortunately we&#8217;ve been provided with alternatives that are thread safe in the <a href="http://msdn.microsoft.com/en-us/library/dd287108.aspx">System.Collections.Concurrent Namespace</a>.  </p>
<p>The biggest difference I&#8217;ve seen between using List and using one of the alternatives, ConcurrentBag is that you can&#8217;t access items in a ConcurrentBag via an indexer.  The truth, however, is that alternative methods are provided via LINQ extension methods.</p>
<p>Consider:</p>
<pre name="code" class="csharp">ConcurrentBag&lt;int&gt; myBag = new ConcurrentBag&lt;int&gt;();

var task1 = Task.Factory.StartNew(() =&gt;
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LongRunningMethod();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myBag.Add(1);
&nbsp;&nbsp;&nbsp;&nbsp;});

var task2 = Task.Factory.StartNew(() =&gt;
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LongRunningMethod();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myBag.Add(2);
&nbsp;&nbsp;&nbsp;&nbsp;});

var task3 = Task.Factory.StartNew(() =&gt;
&nbsp;&nbsp;&nbsp;&nbsp;{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LongRunningMethod();
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;myBag.Add(3);
&nbsp;&nbsp;&nbsp;&nbsp;});

Task.WaitAll(task1, task2, task3);
Parallel.For(0, myBag.Count, i =&gt;
{
&nbsp;&nbsp;&nbsp;&nbsp;Debug.Print(myBag.ElementAt(i).ToString());
});

List&lt;int&gt; myList = new List&lt;int&gt;();
LongRunningMethod();
myList.Add(1);
LongRunningMethod();
myList.Add(2);
LongRunningMethod();
myList.Add(3);
for (int i = 0; i &lt; myList.Count; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;Debug.Print(myList[i].ToString());
}</pre>
<p>resulted in the output:</p>
<blockquote><p>1<br />
3<br />
2<br />
1<br />
2<br />
3</p></blockquote>
<p>with, obviously, the parallel methods being faster.</p>
<p>The other problem we ran into is manipulation of visuals.  As I&#8217;m sure you know manipulation of visuals is required to be on the main thread.  Otherwise you start getting all sorts of permission issues.  The minute you start having to move doing things on the main thread you lose the advantages you gained by moving towards all this parallelism.  Future projects will move towards the MVVM pattern but past projects we&#8217;ll have to work on what we can.</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F12%2Fthe-task-parallel-library-and-system-collections-concurrent-namespace%2F&amp;t=The%20Task%20Parallel%20Library%20and%20System.Collections.Concurrent%20Namespace" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F12%2Fthe-task-parallel-library-and-system-collections-concurrent-namespace%2F&amp;t=The%20Task%20Parallel%20Library%20and%20System.Collections.Concurrent%20Namespace" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2010/12/the-task-parallel-library-and-system-collections-concurrent-namespace/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String comparisons</title>
		<link>http://www.formatexception.com/2010/11/string-comparisons/</link>
		<comments>http://www.formatexception.com/2010/11/string-comparisons/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 17:15:18 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=320</guid>
		<description><![CDATA[At one of the blogs I most frequent there was a post asking, &#8220;Where is the bug?&#8221;. In the comments section it was mentioned, Use ToUpperInvariant rather than ToLowerInvariant when normalizing strings for comparison. Sure enough if you go to the Microsoft page on it, it says Use the String.ToUpperInvariant method instead of the String.ToLowerInvariant [...]]]></description>
			<content:encoded><![CDATA[<p>At one of the <a href="http://ayende.com/Blog/Default.aspx">blogs</a> I most frequent there was a<a href="http://ayende.com/Blog/archive/2010/11/17/where-is-the-bug-yet-again.aspx"> post asking, &#8220;Where is the bug?&#8221;</a>.  In the comments section it was mentioned,</p>
<blockquote><p><a href="http://ayende.com/Blog/archive/2010/11/17/where-is-the-bug-yet-again.aspx#43370">Use ToUpperInvariant rather than ToLowerInvariant when normalizing strings for comparison.</a></p></blockquote>
<p>Sure enough if you go to the Microsoft page on it, it says</p>
<blockquote><p><a href="http://msdn.microsoft.com/en-us/library/dd465121">Use the String.ToUpperInvariant method instead of the String.ToLowerInvariant method when you normalize strings for comparison</a></p></blockquote>
<p>Not wanting to blindly trust &#8220;Teh MAN&#8221; I threw together a quick testbed for testing many of the variants on doing string comparisons.</p>
<p>Here are the results (running 1 million comparisons) comparing<br />
Guid.NewGuid().ToString() to &#8220;Now is the time for all good men to come to the aid of their country.&#8221;:</p>
<table border="1">
<tr>
<th>Method</th>
<th>Time</th>
</tr>
<tr>
<td>equals operator</td>
<td>10 milliseconds</td>
</tr>
<tr>
<td>equals method</td>
<td>8 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToUpper)</td>
<td>436 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToUpperInvariant)</td>
<td>876 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToLower)</td>
<td>418 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToLowerInvariant)</td>
<td>878 milliseconds</td>
</tr>
<tr>
<td>Compare(OrdinalIgnoreCase)</td>
<td>29 milliseconds</td>
</tr>
<tr>
<td>Compare(InvariantCultureIgnoreCase)</td>
<td>113 milliseconds</td>
</tr>
<tr>
<td>Compare(CurrentCultureIgnoreCase)</td>
<td>135 milliseconds</td>
</tr>
<tr>
<td>Compare(ToUpperInvariant, Ordinal)</td>
<td>889 milliseconds</td>
</tr>
<tr>
<td>Compare(ToLowerInvariant, Ordinal)</td>
<td>889 milliseconds</td>
</tr>
</table>
<p><br/>If you read through Microsoft&#8217;s whole article you&#8217;ll see for case-insensitive ordinal comparisons they recommend</p>
<blockquote><p>String.Compare(strA, strB, StringComparison.OrdinalIgnoreCase)</p></blockquote>
<p>As you can see in the results this is borne out.  It&#8217;s not inconceivable that these results could be significant, especially when doing a significant number of string comparisons.</p>
<p>The problem arises when I change what&#8217;s being compared to a string that is almost identical to the original.</p>
<p>Here are the results (running 1 million comparisons) comparing<br />
&#8220;Now is the time for all good men to come to the aid of their countrt.&#8221; to<br />
&#8220;Now is the time for all good men to come to the aid of their country.&#8221;:</p>
<table border="1">
<tr>
<th>Method</th>
<th>Time</th>
</tr>
<tr>
<td>equals operator</td>
<td>37 milliseconds</td>
</tr>
<tr>
<td>equals method</td>
<td>36 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToUpper)</td>
<td>502 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToUpperInvariant)</td>
<td>1111 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToLower)</td>
<td>494 milliseconds</td>
</tr>
<tr>
<td>CompareOrdinal(ToLowerInvariant)</td>
<td>1120 milliseconds</td>
</tr>
<tr>
<td>Compare(OrdinalIgnoreCase)</td>
<td>369 milliseconds</td>
</tr>
<tr>
<td>Compare(InvariantCultureIgnoreCase)</td>
<td>176 milliseconds</td>
</tr>
<tr>
<td>Compare(CurrentCultureIgnoreCase)</td>
<td>191 milliseconds</td>
</tr>
<tr>
<td>Compare(ToUpperInvariant, Ordinal)</td>
<td>1096 milliseconds</td>
</tr>
<tr>
<td>Compare(ToLowerInvariant, Ordinal)</td>
<td>1099 milliseconds</td>
</tr>
</table>
<p><br/>In both cases I ran the test (with code below this) several times and each time it gave similar results.</p>
<p>So what does this all mean?  If you&#8217;re only doing a few thousand comparisons where case is an issue I wouldn&#8217;t worry about anything and just keep doing what you&#8217;re doing.<br />
Other then that I can only recommend staying with Microsoft&#8217;s suggestion.  While there was significant differences between the results, in general Microsoft&#8217;s suggestion would be more applicable without some sort of explicit knowledge of the data.  I think if you&#8217;re going to analyze much beyond this you risk attempting to over-optimize.</p>
<p>Thanks,<br />
Brian</p>
<pre name="code" class="csharp">string myStringToCompare = "Now is the time for all good men to come to the aid of their countrt.";// Guid.NewGuid().ToString();
string originalString = "Now is the time for all good men to come to the aid of their country.";
string results = "";

Stopwatch watch = new Stopwatch();

int numComparisons = 1000000;
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (myStringToCompare == originalString) { }
}
watch.Stop();
results += "equals operator:" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (myStringToCompare.Equals(originalString)) { }
}
watch.Stop();
results += "\nequals method:" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.CompareOrdinal(myStringToCompare.ToUpper(), originalString.ToUpper()) == 0) { }
}
watch.Stop();
results += "\nCompareOrdinal(ToUpper):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.CompareOrdinal(myStringToCompare.ToUpperInvariant(), originalString.ToUpperInvariant()) == 0) { }
}
watch.Stop();
results += "\nCompareOrdinal(ToUpperInvariant):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.CompareOrdinal(myStringToCompare.ToLower(), originalString.ToLower()) == 0) { }
}
watch.Stop();
results += "\nCompareOrdinal(ToLower):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.CompareOrdinal(myStringToCompare.ToLowerInvariant(), originalString.ToLowerInvariant()) == 0) { }
}
watch.Stop();
results += "\nCompareOrdinal(ToLowerInvariant):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.Compare(myStringToCompare, originalString, StringComparison.OrdinalIgnoreCase) == 0) { }
}
watch.Stop();
results += "\nCompare(OrdinalIgnoreCase):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.Compare(myStringToCompare, originalString, StringComparison.InvariantCultureIgnoreCase) == 0) { }
}
watch.Stop();
results += "\nCompare(InvariantCultureIgnoreCase):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.Compare(myStringToCompare, originalString, StringComparison.CurrentCultureIgnoreCase) == 0) { }
}
watch.Stop();
results += "\nCompare(CurrentCultureIgnoreCase):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.Compare(myStringToCompare.ToUpperInvariant(), originalString.ToUpperInvariant(), StringComparison.Ordinal) == 0) { }
}
watch.Stop();
results += "\nCompare(ToUpperInvariant, Ordinal):" + (watch.ElapsedMilliseconds) + " milliseconds";

watch.Reset();
watch.Start();
for (int i = 0; i &lt; numComparisons; i++)
{
&nbsp;&nbsp;&nbsp;&nbsp;if (string.Compare(myStringToCompare.ToLowerInvariant(), originalString.ToLowerInvariant(), StringComparison.Ordinal) == 0) { }
}
watch.Stop();
results += "\nCompare(ToLowerInvariant, Ordinal):" + (watch.ElapsedMilliseconds) + " milliseconds";

txtResults.Text = results;</pre>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F11%2Fstring-comparisons%2F&amp;t=String%20comparisons" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F11%2Fstring-comparisons%2F&amp;t=String%20comparisons" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2010/11/string-comparisons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading/Migrating to .net 4.0, two gotcha&#8217;s I found</title>
		<link>http://www.formatexception.com/2010/05/upgrading-migrating-to-net-4-0-two-gotchas-i-found/</link>
		<comments>http://www.formatexception.com/2010/05/upgrading-migrating-to-net-4-0-two-gotchas-i-found/#comments</comments>
		<pubDate>Mon, 24 May 2010 15:04:11 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.Net 4.0]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=274</guid>
		<description><![CDATA[Recently while upgrading a large project to .net 4.0 we ran into two problems. The first was simply that none of our xaml dictionaries were styling anything. The second was that all of our images looked horrible. These two problems aren&#8217;t mentioned anywhere by Microsoft in their guide to migrating to .net 4.0. The first [...]]]></description>
			<content:encoded><![CDATA[<p>Recently while upgrading a large project to .net 4.0 we ran into two problems.  The first was simply that none of our xaml dictionaries were styling anything.  The second was that all of our images looked horrible.  These two problems aren&#8217;t mentioned anywhere by Microsoft in <a href='http://msdn.microsoft.com/en-us/library/ee941656.aspx'>their guide to migrating to .net 4.0</a>.</p>
<p>The first problem relates to merged dictionaries within a dictionary.  In our project we have a master dictionary in a common project.  All other projects call this common project.  The common project contains only the xaml resource dictionaries.  Our main dictionary looks kind of like:</p>
<pre name="code" class="xml">&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    &gt;
    &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source="ComboBoxStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
        &lt;ResourceDictionary Source="ButtonStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
   &lt;/ResourceDictionary.MergedDictionaries&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p>Virtually every element in our application is styled via this dictionary.  This creates a clean set of styles in seperate files that makes maintenance of these really simple.  The problem is that in .net 4.0 none of the styles in these dictionaries were being applied.  It seemed like .net 4.0 just wouldn&#8217;t go down into the resource dictionaries and get the proper styles.  After posting <a href='http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/f1231b5c-9fd2-40b7-8398-ebf7af8c0d2f/#c9f8b070-1e0f-4865-9c4f-72812ad8b906'>a question in the msdn forums</a> I took a look around Connect (Microsoft&#8217;s listing of bugs) and <a href='https://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references#'>found that someone else had the same problem</a>.  </p>
<p>Fortunately one of the MSDN moderators came to my rescue and posted a workaround.  Oddly enough all you have to do is include an empty style after the merged dictionary and everything starts working again.  Our new master resource dictionary looks something like:</p>
<pre name="code" class="xml">&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    &gt;
    &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source="ComboBoxStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
        &lt;ResourceDictionary Source="ButtonStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
   &lt;/ResourceDictionary.MergedDictionaries&gt;
   &lt;Style TargetType="{x:Type Window}"/&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p>and now all cascading styles are being applied correctly.</p>
<p>The second problem has to do resizing and scaling of images.  Once again <a href='http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/76398b1c-4d56-4601-ad11-c2e4636f62ba'>I started with a post on MSDN forums</a> and then went <a href='https://connect.microsoft.com/VisualStudio/feedback/details/550163/bitmapscalingmode-default-has-changed-from-highquality-to-lowquality'>and took a look around connect</a> (I really should begin starting at Connect).  It seems that in .net 4.0 in order to increase the effeciency of everything they changed the default rendering of images from Fant (extremely high quality) to Low quality.  Not finding any easy solutions I simply changed our master resource dictionary from as show above to:</p>
<pre name="code" class="xml">&lt;ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    &gt;
    &lt;ResourceDictionary.MergedDictionaries&gt;
        &lt;ResourceDictionary Source="ComboBoxStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
        &lt;ResourceDictionary Source="ButtonStyle.xaml"&gt;&lt;/ResourceDictionary&gt;
   &lt;/ResourceDictionary.MergedDictionaries&gt;
   &lt;Style TargetType="{x:Type Window}"/&gt;
       &lt;!--Fix for images rendering in low quality--&gt;
   &lt;Style TargetType="{x:Type Image}"&gt;
      &lt;Setter Property="RenderOptions.BitmapScalingMode" Value="HighQuality"/&gt;
   &lt;/Style&gt;
&lt;/ResourceDictionary&gt;
</pre>
<p>so that images would always defualt to rendering in High Quality.  After I created this solution someone posted as a workaround in Connect just to add:</p>
<pre name="code" class="csharp">RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.HighQuality);
</pre>
<p>to the constructor of your main window and this will inherit to all images by default.  I haven&#8217;t tried this solution and I&#8217;m not sure what would happen if you have projects other than the main project that open their own windows.  It would seem like this should be a global setting since you&#8217;re setting the static in RenderOptions and this should work fine.  For us this was unneeded since every window in all our projects calls the xaml shown above.</p>
<p>Well, if we run into anything else I&#8217;ll post it here but these were the only two issues we&#8217;ve found so far.  It&#8217;s been a big benefit to upgrade for us to .net 4.0 if for no other reason then to have Parallel.For and Parallel.ForEach.</p>
<p>Thanks,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;t=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2010%2F05%2Fupgrading-migrating-to-net-4-0-two-gotchas-i-found%2F&amp;t=Upgrading%2FMigrating%20to%20.net%204.0%2C%20two%20gotcha%27s%20I%20found" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2010/05/upgrading-migrating-to-net-4-0-two-gotchas-i-found/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Development for iPhone and Android with Mono</title>
		<link>http://www.formatexception.com/2009/10/development-for-iphone-and-android-with-mono/</link>
		<comments>http://www.formatexception.com/2009/10/development-for-iphone-and-android-with-mono/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 15:13:07 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mono]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=267</guid>
		<description><![CDATA[Okay, for the first time ever I&#8217;m a bit jealous of iPhone users.(See below)  Novel (the sponsor of Mono) has released the MonoTouch, a C# and .NET development platform for the iPhone.  Granted it&#8217;s $400 for the platform but at least it&#8217;s not Objective C.  For those of you that don&#8217;t know Mono, it&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p><span style="text-decoration: line-through;">Okay, for the first time ever I&#8217;m a bit jealous of iPhone users.</span>(See below)  Novel (the sponsor of Mono) has released the MonoTouch, a C# and .NET development platform for the iPhone.  Granted it&#8217;s $400 for the platform but at least it&#8217;s not Objective C.  For those of you that don&#8217;t know Mono, it&#8217;s a platform agnostic port of the .NET libraries, stable at about the equivalent of .NET 3.0 (which means LINQ and a bunch of other cool stuff).  That means, yes, if you want to you can do ASP.NET hosting on apache and linux.  Novell has long been a sponsor of mono and it seems like they&#8217;re going to get the opportunity to make some money back with the release of MonoTouch.  Of course you still need to have a Mac and be part of Apple&#8217;s iPhone Developer Program which is enough to kill it for me.</p>
<p>See<br />
<a href="http://monotouch.net/" target="_blank">http://monotouch.net/</a></p>
<p>For those of us with an Android phone, Mono is running in Android, it&#8217;s just not very stable.  <a href="http://www.koushikdutta.com/2009/01/compiling-mono-under-android-build.html" target="_blank">Here is a post</a> of one of the Mono developers that compiled the Mono libraries from his Android from a debian install on his SD card.  Yes, in Android he&#8217;s running debian to compile Mono.  Is that not just sweet nerdy goodness?  While there is no time line for a full stable release of Mono on Android it&#8217;s in active development and, unlike the iPhone/MonoTouch option, it probably won&#8217;t cost a thing once it gets stable.</p>
<p>So what does this mean for us doing smart phone development?  When I was in college I applied for and received a grant for a platform agnostic project, written in java, to do streaming media, web cam and audio between multiple PCs.  For the first month of the project I developed on linux (don&#8217;t remember the branch) with Java.  I moved all the code to Windows and came across serious threading issues.  I fixed all those and spent the next month developing in Windows.  After that second month I moved everything back to linux and ran across serious threading issues.  For the last month of the project I compiled to a shared directory and tested on both linux and Windows.  I highly doubt there will ever be a stable environment that will work for all platforms, hardware is just too different.  MonoTouch has specific interfaces to the iPhone APIs.  Once Mono for Android gets stable I&#8217;m sure there are going to be wrappers for the Java APIs for Android.  But is this a bad thing?  Isn&#8217;t competition good?</p>
<p>Later,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F10%2Fdevelopment-for-iphone-and-android-with-mono%2F&amp;t=Development%20for%20iPhone%20and%20Android%20with%20Mono" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F10%2Fdevelopment-for-iphone-and-android-with-mono%2F&amp;t=Development%20for%20iPhone%20and%20Android%20with%20Mono" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2009/10/development-for-iphone-and-android-with-mono/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ACM&#8217;s Software Engineering Code of Ethics and Professional Practice</title>
		<link>http://www.formatexception.com/2009/09/acms-software-engineering-code-of-ethics-and-professional-practice/</link>
		<comments>http://www.formatexception.com/2009/09/acms-software-engineering-code-of-ethics-and-professional-practice/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 17:47:17 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=261</guid>
		<description><![CDATA[Recently I came across ACM&#8217;s Software Engineering Code of Ethics and Professional Practice.   One of the things I&#8217;ve tried to push around here is the idea that we as software engineers must constantly strive to stay current in our ever changing world.  Like a doctor who must stay current with the latest medical procedures and [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I came across <a href="http://www.acm.org/about/se-code" target="_blank">ACM&#8217;s Software Engineering Code of Ethics and Professional Practice</a>.   One of the things I&#8217;ve tried to push around here is the idea that we as software engineers must constantly strive to stay current in our ever changing world.  Like a doctor who must stay current with the latest medical procedures and drugs we as software engineers must stay current with the latest language features and APIs.  It&#8217;s nice, egotistically speaking, to see that other people share my opinions on the matter <img src='http://www.formatexception.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  Though I know this was created in 1999 I don&#8217;t think a lot of people are familiar with it.  I&#8217;d recommend reading the full version at the link above but here is the short version:</p>
<p><a name="short"><strong>Software Engineering Code of Ethics and Professional Practice  (Short Version)</strong></a></p>
<p><strong>PREAMBLE</strong></p>
<p>The short version of the code summarizes aspirations at a high level of the  abstraction; the clauses that are included in the full version give examples and  details of how these aspirations change the way we act as software engineering  professionals. Without the aspirations, the details can become legalistic and  tedious; without the details, the aspirations can become high sounding but  empty; together, the aspirations and the details form a cohesive code.</p>
<p>Software engineers shall commit themselves to making the analysis,  specification, design, development, testing and maintenance of software a  beneficial and respected profession. In accordance with their commitment to the  health, safety and welfare of the public, software engineers shall adhere to the  following Eight Principles:</p>
<p>1. PUBLIC &#8211; Software engineers shall act consistently with the public  interest.</p>
<p>2. CLIENT AND EMPLOYER &#8211; Software engineers shall act in a manner that is in  the best interests of their client and employer consistent with the public  interest.</p>
<p>3. PRODUCT &#8211; Software engineers shall ensure that their products and related  modifications meet the highest professional standards possible.</p>
<p>4. JUDGMENT &#8211; Software engineers shall maintain integrity and independence in  their professional judgment.</p>
<p>5. MANAGEMENT &#8211; Software engineering managers and leaders shall subscribe to  and promote an ethical approach to the management of software development and  maintenance.</p>
<p>6. PROFESSION &#8211; Software engineers shall advance the integrity and reputation  of the profession consistent with the public interest.</p>
<p>7. COLLEAGUES &#8211; Software engineers shall be fair to and supportive of their  colleagues.</p>
<p>8. SELF &#8211; Software engineers shall participate in lifelong learning regarding  the practice of their profession and shall promote an ethical approach to the  practice of the profession.</p>
<p><strong>This Code may be published without permission as long as it is not changed  in any way and it carries the copyright notice. Copyright (c) 1999 by the  Association for Computing Machinery, Inc. and the Institute for Electrical and  Electronics Engineers, Inc.</strong></p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;"><a name="short"><strong>Software Engineering Code of Ethics and Professional PracticeSoftwareasdf</strong></a></div>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F09%2Facms-software-engineering-code-of-ethics-and-professional-practice%2F&amp;t=ACM%27s%20Software%20Engineering%20Code%20of%20Ethics%20and%20Professional%20Practice" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F09%2Facms-software-engineering-code-of-ethics-and-professional-practice%2F&amp;t=ACM%27s%20Software%20Engineering%20Code%20of%20Ethics%20and%20Professional%20Practice" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2009/09/acms-software-engineering-code-of-ethics-and-professional-practice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.Net 4.0 stuff on the way.</title>
		<link>http://www.formatexception.com/2009/08/net-4-0-stuff-on-the-way/</link>
		<comments>http://www.formatexception.com/2009/08/net-4-0-stuff-on-the-way/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 21:51:21 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.Net 4.0]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=256</guid>
		<description><![CDATA[Here&#8217;s some nice .Net 4.0 stuff on the way. I&#8217;ve been working on some poker tournament software with a lot of the new 4.0 features in mind. Once I have a couple of posts ready I&#8217;ll throw them up. Thanks, Brian Share and Enjoy:]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s some <a href="http://jyotsnakalambe.wordpress.com/2009/08/14/new-release-net-framework-4-0-features/">nice .Net 4.0 stuff on the way</a>.  I&#8217;ve been working on some poker tournament software with a lot of the new 4.0 features in mind.  Once I have a couple of posts ready I&#8217;ll throw them up.</p>
<p>Thanks,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;t=.Net%204.0%20stuff%20on%20the%20way." title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F08%2Fnet-4-0-stuff-on-the-way%2F&amp;t=.Net%204.0%20stuff%20on%20the%20way." title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2009/08/net-4-0-stuff-on-the-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Self-referencing Bindings</title>
		<link>http://www.formatexception.com/2009/06/self-referencing-bindings/</link>
		<comments>http://www.formatexception.com/2009/06/self-referencing-bindings/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 14:56:22 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=243</guid>
		<description><![CDATA[Between keeping up with what&#8217;s coming for .Net 4.0 as well as the end of a large DOD contract I&#8217;ve been a bit busy (and no developer fatigue, just busy ). But don&#8217;t fret loyal readers, more will be coming soon. Until then here is a bit of xaml for self-referencing bindings. &#60;TextBlock Grid.Column="1" Width="75" [...]]]></description>
			<content:encoded><![CDATA[<p>Between keeping up with what&#8217;s coming for .Net 4.0 as well as the end of a large DOD contract I&#8217;ve been a bit busy (and no developer fatigue, just busy <img src='http://www.formatexception.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ).  But don&#8217;t fret loyal readers, more will be coming soon.</p>
<p>Until then here is a bit of xaml for self-referencing bindings.</p>
<pre name="code" class="csharp">&lt;TextBlock
  Grid.Column="1"
  Width="75"
  Foreground="{StaticResource ActiveTabForeground}"
  TextWrapping="NoWrap"
  TextTrimming="CharacterEllipsis"
  ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
  Name="txtHeader"/&gt;</pre>
<p>As you can see I often use these with TextBlocks where I&#8217;m using text trimming.  The reason being that, with text trimming, the text gets cut short if it exceeds the width of the textblock.  This way users will be able to mouse over the textblock and get the tooltip containing the full value.</p>
<p>Where else would this be useful?  Well, um, I don&#8217;t know since I only use this with tooltips on TextBlocks.  But it is certainly helpful for that.</p>
<p>Enjoy,<br />
Brian</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F06%2Fself-referencing-bindings%2F&amp;t=Self-referencing%20Bindings" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F06%2Fself-referencing-bindings%2F&amp;t=Self-referencing%20Bindings" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2009/06/self-referencing-bindings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developer Fatigue?</title>
		<link>http://www.formatexception.com/2009/05/developer-fatigue/</link>
		<comments>http://www.formatexception.com/2009/05/developer-fatigue/#comments</comments>
		<pubDate>Tue, 19 May 2009 17:24:23 +0000</pubDate>
		<dc:creator>Brian</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.formatexception.com/?p=231</guid>
		<description><![CDATA[In the recent Visual Studio magazine I saw the following survey: Do you sense developer fatigue due to the pace of Microsoft Technology introductions? Yes, some fatigue 45% No, little or no fatigue 26% Yes, significant fatigue 24% Don&#8217;t know 5% (I love kicking it ol&#8217;school and using tables) To the 26% that said no [...]]]></description>
			<content:encoded><![CDATA[<p>In the recent Visual Studio magazine I saw the following survey:</p>
<table border="1">
<tbody>
<tr>
<td colspan="2">Do you sense developer fatigue due to the pace of Microsoft Technology introductions?</td>
</tr>
<tr>
<td>Yes, some fatigue</td>
<td>45%</td>
</tr>
<tr>
<td>No, little or no fatigue</td>
<td>26%</td>
</tr>
<tr>
<td>Yes, significant fatigue</td>
<td>24%</td>
</tr>
<tr>
<td>Don&#8217;t know</td>
<td>5%</td>
</tr>
</tbody>
</table>
<p>(I love kicking it ol&#8217;school and using tables)</p>
<p>To the 26% that said no I say, &#8220;Good, you&#8217;re doing your job.&#8221;  To the rest of you, &#8220;Get to work.&#8221;</p>
<p>I don&#8217;t often write opinion pieces preferring to keep the focus of this blog more on tutorial type posts, maybe because I don&#8217;t really consider myself any real authority.  I do my job and in the course of my job I learn a lot that I want to pass on to other people.</p>
<p>So why start now?  Well, this survey struck a nerve for me.  Maybe it&#8217;s because this has some fingers in my <a href="http://www.formatexception.com/2009/04/my-thoughts-on-oracle-sun-and-java/">post about Oracle and Java</a>.  In that post I reveled in the fact that Microsoft is able to keep the .Net framework moving forward at a fast pace and that, relative to .Net, Java has become fairly stagnant.</p>
<p>In Jeff Atwood&#8217;s post, <a href="http://www.codinghorror.com/blog/archives/001002.html">The Two Types of Programmers</a> he discusses the two types of programmers as mentioned in an article by Ben Collins-Sussman which says there are two classes of programmers, the &#8220;20%&#8221; and the &#8220;80%&#8221; programmers.</p>
<p>To this I have a serious problem.  I spend a great deal of time reading the latest programming books, blogs and magazines.  I do so because I want to stay current in my field.  If I was doctor it would be expected that I would stay up-to-date on the latest research and trends in the medical fields.  So should we as programmers.</p>
<p>Our job is to be the best programmers we can be.  Fatigue should be irrelevant.  Even if you are working in a world were the language features and APIs aren&#8217;t moving forward there is still a lot you can do.  Read up on patterns and anti-patterns, if you haven&#8217;t read Code Complete, do so.  I find the idea that programmers are perfectly happy to rest on their laurels completely ridiculous.  Strive to become a better programmer, push yourself and your knowledge.  As you become better at your job you will become a better person all-around.  Knowledge is power.</p>
<p>If you stay current fatigue isn&#8217;t an issue.  By keeping current incrementally there won&#8217;t be any fatigue.  Start reading up on .Net 4.0 right now.  By the time .Net 4.0 releases you will be pretty caught up and boom!, no more fatigue.</p>
<p>You may say, &#8220;Well, my job is to use this or that API or SDK.  Knowing anything outside of that is irrelevant.&#8221;  To that I&#8217;m calling &#8220;Bullshit!&#8221;  It&#8217;s not about just writing code.  If being a programmer was just about writing code then anybody could be a programmer.  Writing code is easy.  Writing code cleanly, efficiently so it&#8217;s easy to maintain, now that takes some skill.  The best way to do so is to stay current.</p>
<p>Saying that you&#8217;re experiencing &#8220;fatigue due to the pace of Microsoft Technology introductions&#8221; is a serious cop-out.  Staying current is your job because the more current you are the better programmer you are.  If I was a fry-cook I&#8217;d want to be the best damn fry-cook on the planet, learn the lingo, find the right temperature for the grill so it cooks the eggs and burgers efficiently, work on recipes that taste good and can cook fast.  I&#8217;m not a fry-cook, however, I&#8217;m a computer programmer.  Being the best programmer I can be means that I have to stay current on new technology.  Screw fatigue.</p>
<p>Thank you, that&#8217;s my time</p>
<p><em>high-pitched whine as I drop the microphone</em></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F05%2Fdeveloper-fatigue%2F&amp;t=Developer%20Fatigue%3F" title="Facebook"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Fwww.formatexception.com%2F2009%2F05%2Fdeveloper-fatigue%2F&amp;t=Developer%20Fatigue%3F" title="HackerNews"><img src="http://www.formatexception.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a>


<br/><br/>]]></content:encoded>
			<wfw:commentRss>http://www.formatexception.com/2009/05/developer-fatigue/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

