<?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>Thycotic Software Ltd. &#124; Team Blog</title>
	<atom:link href="http://www.thycotic.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.thycotic.com</link>
	<description></description>
	<lastBuildDate>Fri, 05 Feb 2010 16:06:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Benefits of Pair Programming</title>
		<link>http://www.thycotic.com/the-benefits-of-pair-programming</link>
		<comments>http://www.thycotic.com/the-benefits-of-pair-programming#comments</comments>
		<pubDate>Thu, 04 Feb 2010 20:09:16 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=494</guid>
		<description><![CDATA[The Agile practice of Pair Programming is one of the more controversial development techniques within the software development community.  The controversy lies in the question of how two programmers working together on the same code can be more productive than the same two programmers writing code individually.]]></description>
			<content:encoded><![CDATA[<p><img src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/Katie_pair.jpg" alt="The Benefits of Pair Programming" width="500" height="225" /></p>
<h6 style="clear:both">February 4th | 2009</h6>
<p><strong>The Benefits of Pair Programming<br />
</strong></p>
<p>The Agile practice of Pair Programming is one of the more controversial development techniques within the software development community.  The controversy lies in the question of how two programmers working together on the same code can be more productive than the same two programmers writing code individually. The determining factor in answering this question is simple &#8211; more lines of code do not equal more productive software development.</p>
<p>Case studies have been conducted, the experts have weighed in, and the results are unequivocal: the benefits of Pair Programming can result in significant advantages for an organization developing software.</p>
<p>The success or failure of software is dependent on its quality, and Pair Programming directly improves quality in numerous ways. When two developers work together design pattern quality improves as the pair develops short, simple, and easy to maintain code with fewer bugs. Bugs are a major quality concern in software development; with two sets of eyes writing the code, more mistakes are caught, thereby decreasing the cost of development. Bugs found late in the development process are often costly to fix. Finding software defects early prevents and helps deter difficult problems down the road. Complexity often arises in programming, and two minds working to solve a problem together can see more options and draw conclusions more quickly than one.</p>
<p>Teams implementing Pair Programming also experience the benefits of increased team morale, worker discipline, and improved time management. Individuals on the team put more effort into writing good code, creating an atmosphere of collective code ownership.</p>
<p>Our team has been practicing Pair Programming for years, so I set out to get some input from them. Thycotic team programmer, Bryant Smith, has been Pair Programming daily for over five years.  Bryant commented “The code&#8217;s intention is clearer, it self-documents. What might be clear to me is not necessarily clear to others; assumptions are uncovered and more clearly stated. This is true with the unit test code as well as test coverage. When my pair is coding I often think outside the box about &#8216;what if&#8217; scenarios. This extra test coverage further documents the code&#8217;s intention.”</p>
<p>Another team lead member, Tucker, thought “A major benefit of Paired Programming is knowledge sharing. It breaks down code complexity across the dev team and quickly brings new people up to speed.” Tucker is currently working with 3 other developers—forming  two programming pairs every day.</p>
<p>Risk for management is also decreased as knowledge is spread around the team, pairs are rotated, and team members come and go. The benefits of Pair Programming to the development team, management, and the organization are significant as the software development process proves to be on time, within budget, and seemingly effortless for a Pair Programming team.</p>
<p class="authorblock" style="padding:10px;"><em><em>Katie McCroskey is a Marketing Manager at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/KMcCroskey"> Follow Katie</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/the-benefits-of-pair-programming/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Managed code isnt always the best solution</title>
		<link>http://www.thycotic.com/managed-code-isnt-always-the-best-solution</link>
		<comments>http://www.thycotic.com/managed-code-isnt-always-the-best-solution#comments</comments>
		<pubDate>Fri, 15 Jan 2010 18:38:56 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=491</guid>
		<description><![CDATA[Managed code is cool. In fact most of the code I write at work is managed code in C#. In one case our product team needed to write some unmanaged code as a Log On credential provider. Throughout Microsoft’s documentation on this, it was strictly mentioned that Managed Code is a bad idea. Well, why? It’s not just for performance.
]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/managed.jpg" alt="Managed Code isnt always the best solution" width="500" height="225" /></p>
<h6 style="clear:both">January 15th | 2009</h6>
<p><strong>Managed code isn&#8217;t always the best solution<br />
</strong></p>
<p>Managed code is cool. In fact most of the code I write at work is managed code in C#. In one case our product team needed to write some unmanaged code as a Log On credential provider. Throughout Microsoft’s documentation on this, it was strictly mentioned that Managed Code is a bad idea. Well, why? It’s not just for performance.</p>
<p>.NET inherently was designed to be version-independent, meaning an application that targets the .NET 1.1 Framework CLR cannot run on 2.0, and 2.0 CLR projects will not be able to run on the 4.0 CLR, when it’s released. This is why extensions for Windows can rarely be written in managed code. It is possible to write a Log On credential provider in managed code since .NET can be exposed to COM and vice-versa. It will even work. But assuming you write a credential provider that is built in .NET 2.0, and another vendor tries to provide one in .NET 1.1, or any version other than 2.0, the logon.exe process will attempt to load both versions of the .NET Framework. This will ultimately fail and the user will not be able to boot without going into safe mode.</p>
<p>The same applies to context menus for Explorer and Add-Ons Internet Explorer. They can both be extended using Managed Code, but all it takes is a version conflict to kill them off.</p>
<p>So, as much as we love our managed code, there are scenarios where it isn’t a good idea to use it. Ultimately, if you are trying to extend any application that uses COM (or any other unmanaged code solution) as its extension method, rather than Managed Code, then stick with Unmanaged Code.</p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/managed-code-isnt-always-the-best-solution/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Debugger Friend or Foe</title>
		<link>http://www.thycotic.com/debugger-friend-foe</link>
		<comments>http://www.thycotic.com/debugger-friend-foe#comments</comments>
		<pubDate>Thu, 07 Jan 2010 16:49:26 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[Visual Studop]]></category>
		<category><![CDATA[Debugger]]></category>
		<category><![CDATA[first chance exceptions]]></category>
		<category><![CDATA[re-evaulating the stack]]></category>
		<category><![CDATA[using debugger visual studio]]></category>
		<category><![CDATA[Visual Studio Debugger]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=484</guid>
		<description><![CDATA[The debugger is something that most developers get familiarized with pretty quick. I am not really even going to bother explaining it as it’s such a ubiquitous tool. We all use it for one main reason though: something doesn’t work the way we expect.]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/Debugger.jpg" alt="Debugger Friend or Foe?" width="500" height="225" /></p>
<h6 style="clear:both">January 7th | 2009</h6>
<p><strong>Debugger: Friend or Foe<br />
</strong></p>
<p>The debugger is something that most developers get familiarized with pretty quick. I am not really even going to bother explaining it as it’s such a ubiquitous tool. We all use it for one main reason though: something doesn’t work the way we expect.</p>
<p>I would suggest that it only be used as a <strong>last resort</strong>. The debugger, while effective and powerful, can lead you down rabbit holes—even if you are familiar with how debuggers work. Rather, start by writing a failing unit test that demonstrates the issue, and proceed from there. After all, if you are in the debugger it’s probably because something isn’t working right. And if something isn’t working right, shouldn’t you have a failing test?</p>
<p>Sometimes though, a failing test is just not enough. In these cases the debugger is a quick way to figure out how something works. It’s easier than sprinkling your code base with calls to <em>Debug.WriteLine</em>. The debugger also allows you to do cool things like m<a name="_GoBack"></a>odify where it is in the stack execution.</p>
<p>Let’s look at a piece of code. It’s pretty trivial:</p>
<pre class="csharpcode"><span class="kwrd">class</span> Program
{
    <span class="kwrd">private</span> <span class="kwrd">static</span> int _aNumber = 0;

    <span class="kwrd">static</span> void Main(<span class="kwrd">string</span>[] args)
    {
        int incrementedNumber = GetANumberIncremented();
        System.Console.WriteLine(incrementedNumber);
        System.Diagnostics.Debugger.Break();
    }

    <span class="kwrd">static</span> int GetANumberIncremented()
    {
        <span class="kwrd">return</span> ++_aNumber;
    }
}</pre>
<p>Paste this into Visual Studio and hit F5 to make it go. The 3<sup>rd</sup> line of the Main method should cause you to break into the debugger. This is the same as setting a breakpoint. I only used it so I wouldn’t have to explain where to put a breakpoint. Using the mouse, hover over <em>incrementedNumber</em>. Hopefully you’ll get 1, like I did.</p>
<p>Now let’s try something interesting: Select GetANumberIncremented() including the parenthesis, but not the semicolon. Right-click on the selection and use a familiar tool, Quick Watch. Now we get 2. What gives?</p>
<p>It may be obvious to some, but not to others. The debugger is, in most cases, invasive. Quick Watch is handy, but as we did it on a method we forced the debugger to re-run the method GetANumberIncremented. <strong>It’s re-evaluating the stack</strong>. With the Quick Watch window open, click “re-evaluate.” Now we get 3. Again, and we get 4, and so on. It’s screamingly obvious in this example, but imagine if it was in a 3<sup>rd</sup> party assembly and GetANumberIncremented was a public method. We would have no idea what the method was doing. This is a pretty tame case as we’re only incrementing a number. But you can probably imagine instances where this could easily put an application into a state it wasn’t intended for.</p>
<p>Another thing you can get bitten by on the debugger? <a href="http://blogs.msdn.com/davidklinems/archive/2005/07/12/438061.aspx"><strong>First chance exceptions</strong></a>. If you aren’t careful the debugger might tell you an exception is being thrown when it is actually being handled gracefully somewhere else. So when the time comes to run the application normally, it will work just fine.</p>
<p>Overall the debugger is an invasive tool that can lead you to some dead ends if you’re not careful.</p>
<p>I wouldn’t go so far as to say the debugger is evil. But I avoid it when I can and opt for unit tests instead. A unit test runs the code just as if it was being used by the application—or at least it should!</p>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  --></p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/debugger-friend-foe/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Dealing with Nullable Types and IIf in VBNET</title>
		<link>http://www.thycotic.com/dealing-with-nullable-types-and-iif-in-vbnet</link>
		<comments>http://www.thycotic.com/dealing-with-nullable-types-and-iif-in-vbnet#comments</comments>
		<pubDate>Fri, 01 Jan 2010 19:09:49 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[IIf Nullable Type]]></category>
		<category><![CDATA[SIif and Iif]]></category>
		<category><![CDATA[tenary operator]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=476</guid>
		<description><![CDATA[Here’s a tip that might bite some C# developers getting their feet wet with VB.NET. In fact, I got bit by this one recently, and it didn't help that it was knee deep in COM. Let's examine this harmless looking C# statement:

int? someSpoon;
string helloValue = someSpoon.HasValue
    ? "The spoon is " + someSpoon.Value
    : "There is no spoon";]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/null_types.jpg" alt="Are Extension Methods a Code Smell?" width="500" height="225" /></p>
<h6 style="clear:both">December 29th | 2009</h6>
<p><strong>Dealing with Nullable Types and IIf in VB.NET<br />
</strong></p>
<p>Here’s a tip that might bite some C# developers getting their feet wet with VB.NET. In fact, I got bit by this one recently, and it didn&#8217;t help that it was knee deep in COM. Let&#8217;s examine this harmless looking C# statement:</p>
<pre class="csharpcode"><span class="kwrd">int</span>? someSpoon;
<span class="kwrd">string</span> helloValue = someSpoon.HasValue
    ? <span class="str">"The spoon is "</span> + someSpoon.Value
    : <span class="str">"There is no spoon"</span>;</pre>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; }  --></p>
<p>This is a pretty typical use of the <strong>ternary operator</strong>. If someSpoon has a value, then the helloValue is &#8220;The spoon is &lt;value&gt;&#8221;, if it doesn&#8217;t have a value, it is &#8220;There is no spoon&#8221;. This is a safe use because someSpoon.Value will not be evaluated unless the condition is true.</p>
<p>VB.NET does not have a built-in operator similar to this, however it does have a function called <strong>IIf</strong>. Its syntax is this:</p>
<pre class="csharpcode"><span class="kwrd">Function</span> IIf(<span class="kwrd">ByVal</span> expression <span class="kwrd">As</span> <span class="kwrd">Boolean</span>, _
    <span class="kwrd">ByVal</span> truePart <span class="kwrd">As</span> <span class="kwrd">Object</span>, _
    <span class="kwrd">ByVal</span> falsePart <span class="kwrd">As</span> <span class="kwrd">Object</span>)</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  --></p>
<p>We&#8217;d be tempted to write something like this with our VB.NET IIf:</p>
<pre class="csharpcode"><span class="kwrd">Dim</span> someSpoon <span class="kwrd">As</span> <span class="kwrd">Integer</span>?
IIf(someSpoon.HasValue, _
    <span class="str">"The spoon is "</span> &amp; someSpoon.Value, _
    <span class="str">"There is no spoon"</span>)</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  --></p>
<p>But wait! We just introduced a bug. Take a minute to figure it out.</p>
<p>Got it? OK let&#8217;s see if we agree. The problem is that as IIf is just a plain function, someSpoon.Value <em>will always be evaluated</em>. If you call .Value on a nullable type without a value, you&#8217;ll get an exception. This is because the Value must be resolved before it is passed into IIf. C# doesn&#8217;t exhibit this behavior because the true part is completely ignored.<strong> </strong></p>
<p>So, what&#8217;s the fix?</p>
<p>You might be tempted to switch to an If/Else statement but I chose to write my own IIf using lambdas. It’s called SIIf—S is for safe—and it doesn&#8217;t exhibit this behavior. Instead of passing in the Value, we pass in a function that will be invoked to get the Value if it&#8217;s needed.</p>
<p>Here&#8217;s the source for it:</p>
<pre class="csharpcode"><span class="kwrd">Public</span> <span class="kwrd">Function</span> SIIf(Of T)(<span class="kwrd">ByVal</span> expression <span class="kwrd">As</span> <span class="kwrd">Boolean</span>, _
         <span class="kwrd">ByVal</span> trueExpression <span class="kwrd">As</span> Func(Of T), _
         <span class="kwrd">ByVal</span> falseExpression <span class="kwrd">As</span> Func(Of T))
    <span class="kwrd">If</span> expression <span class="kwrd">Then</span>
        <span class="kwrd">Return</span> trueExpression()
    <span class="kwrd">End</span> <span class="kwrd">If</span>
    <span class="kwrd">Return</span> falseExpression()
<span class="kwrd">End</span> <span class="kwrd">Function</span></pre>
<p>I also added generics—another annoyance to VB.NET developers who use <strong>Option Explicit</strong>. Here&#8217;s how it would be used:</p>
<pre class="csharpcode"><span class="kwrd">Dim</span> someSpoon <span class="kwrd">As</span> <span class="kwrd">Integer</span>? = <span class="kwrd">Nothing</span>
<span class="kwrd">Dim</span> result <span class="kwrd">As</span> <span class="kwrd">String</span> = SIIf(Of <span class="kwrd">String</span>)(someSpoon.HasValue, _
            <span class="kwrd">Function</span>() <span class="str">"The spoon is "</span> &amp; someSpoon.Value, _
            <span class="kwrd">Function</span>() <span class="str">"There is no spoon"</span>)</pre>
<p>All we really have to do is remember to put Function() before the 2nd and 3rd parameters. This prevents our exception from happening because Value is only ever invoked if the expression is true by the lambda.</p>
<p><span style="color:red; font-weight:bold;">Update: </span>As some of you have already pointed out, this functionality is built into the .NET Framework 3.5 using a three argument <strong>If</strong> statement, which I overlooked. I would recommend using this over my own solution if possible.</p>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  --></p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/dealing-with-nullable-types-and-iif-in-vbnet/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Cool Things to Do with Dynamics in dotNET 4</title>
		<link>http://www.thycotic.com/cool-things-to-do-with-dynamics-in-dotnet-4</link>
		<comments>http://www.thycotic.com/cool-things-to-do-with-dynamics-in-dotnet-4#comments</comments>
		<pubDate>Mon, 21 Dec 2009 15:44:25 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=472</guid>
		<description><![CDATA[Put simply, something marked as dynamic does not have any compile-time enforced semantics. Instead, all members of the instance are resolved at runtime by the Dynamic Language Runtime (DLR). Here is a simple example:]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/Kevin_is_cool.jpg" alt="Are Extension Methods a Code Smell?" width="500" height="225" /></p>
<h6 style="clear:both">December 21st | 2009</h6>
<p><strong>Cool Things to Do with Dynamics in .NET 4.0<br />
</strong></p>
<p>In <a href="http://www.thycotic.com/an-overview-of-c-4-0">An Overview of C# 4.0</a> I discussed some of new features in C# 4.0. One thing that I didn’t cover was the <strong>dynamic</strong> keyword.</p>
<p>Put simply, something marked as dynamic does not have any compile-time enforced semantics. Instead, all members of the instance are resolved at runtime by the Dynamic Language Runtime (DLR). Here is a simple example:</p>
<pre class="csharpcode"><span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
{
    dynamic int1 = 1;
    dynamic int2 = 2;
    dynamic result = int1 + int2;
    Console.WriteLine(result);
}</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>This, as expected, will print 3. However, the operator + and what int1 and int2 really are is resolved at run time. I’ll demonstrate this using the following code (which looks like it shouldn’t compile, but actually does):</p>
<pre class="csharpcode"><span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
{
    dynamic int1 = 1;
    dynamic ex1 = <span class="kwrd">new</span> Exception(<span class="str">"Oops!"</span>);
    dynamic result = int1 + ex1;
    Console.WriteLine(result);
}</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>This normally wouldn’t compile since an int type and the Exception type do not have a + operator. Regardless, this code compiles just fine. It’s only at runtime that we get an error:</p>
<p>Unhandled Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator &#8216;+&#8217; cannot be applied to operands of type &#8216;int&#8217; and &#8216;System.Exception&#8217;</p>
<p><strong>So, what use is this?</strong> Why don’t we just use the real types rather than dynamic? Possible scenarios for using dynamic are: when we don’t know what the type is; or when it came from an odd place, such as reflection. If a type is resolved via reflection, we can treat it as a dynamic and not worry about calling “Invoke” or “GetProperty” on it. The same goes with COM Interop. If a complete wrapper is missing then we can declare it as dynamic and continue to use it without significant complex code.</p>
<p>But the most interesting use of a dynamic is declaring your own. Enter the DynamicObject base type. This allows us to tell the object how to behave at run time and instruct it how to handle the resolution of properties and methods. We can build some very powerful tools with this.</p>
<p>I’ve done some neat things with PowerShell, and the thing that particularly amazed me was how easy it is to consume and manipulate XML. Here’s a PowerShell snippet that loads an XML file:</p>
<p>$xmlConfig = New-Object XML</p>
<p>$xmlConfig.Load(&#8221;Some XML Path&#8221;);</p>
<p>$backup = ($xmlConfig.configuration.appSettings.add | where {$_.key –eq &#8216;BackupEveryInMinutes&#8217;}).value;</p>
<p>This XML file looks something like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">configuration</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">key</span><span class="kwrd">="BackupEveryInMinutes"</span> <span class="attr">value</span><span class="kwrd">="1440"</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">appSettings</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">configuration</span><span class="kwrd">&gt;</span></pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>$backup will be assigned to 1440. I like the way you can just access the properties off of the $xmlConfig as if they were always there. In C# and .NET previously, this would have been impossible. However, using the DynamicObject, we can build one that does. Let’s start!</p>
<p>Let’s make a class that derives from DynamicObject.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> DynamicXml : DynamicObject
{
}</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>An important concept in this is being able to override TryGetMember. This is how we tell the DLR how to dynamically resolve something.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> DynamicXml : DynamicObject
{
    <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">bool</span> TryGetMember(GetMemberBinder binder, <span class="kwrd">out</span> <span class="kwrd">object</span> result)
    {
    }
}</pre>
<p>· <strong>binder – </strong>this is what is attempting to be bound, or resolved. It can tell us what the DLR is trying to figure out, such as a property name</p>
<p>· <strong>result –</strong> to tell the DLR the value of what is being resolved.</p>
<p>· <strong>return – </strong>if the dynamic was successfully resolved. In our case, we will return false if the XML document doesn’t contain a node. This will cause the DLR to throw an exception if the return value is false.</p>
<p>First we must load our XML document. Let’s use an XmlDocument (as opposed to the newer XDocument) as an example. The constructor will take an XmlNode since XmlDocument inherits from XmlNode.</p>
<p>So the usage scenario for our code will be something like this:</p>
<p>XmlDocument document = new XmlDocument();</p>
<p>document.Load(&#8221;pathtoxml.xml&#8221;);</p>
<p>dynamic dynamicXml = new DynamicXml(document);</p>
<p>string value = dynamicXml.configuration.appSettings.add.value;</p>
<p>The properties being used on the dynamicXml are the nodes of what we are trying to access. We can check the binder to see what property is being resolved. We can recursively return our dynamic object to continue resolution, too. The final result looks like this:</p>
<pre class="csharpcode"><span class="kwrd">using</span> System.Xml;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> System.Dynamic;

<span class="kwrd">namespace</span> CSharp4
{
    <span class="kwrd">public</span> <span class="kwrd">class</span> DynamicXml : DynamicObject
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> XmlNode _node;

        <span class="kwrd">public</span> DynamicXml(XmlNode node)
        {
            _node = node;
        }

        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">bool</span> TryGetMember(GetMemberBinder binder, <span class="kwrd">out</span> <span class="kwrd">object</span> result)
        {
            result = <span class="kwrd">null</span>;
            XmlNodeList nodes = _node.SelectNodes(binder.Name);
            <span class="kwrd">if</span> (nodes.Count == 0)
                nodes = _node.SelectNodes(<span class="str">"@"</span> + binder.Name); <span class="rem">//Check and see if it's an attribute.</span>
            <span class="kwrd">if</span> (nodes.Count == 0)
                <span class="kwrd">return</span> <span class="kwrd">false</span>;
            <span class="kwrd">if</span> (nodes.Count == 1)
            {
                XmlNode node = nodes[0];
                result = GetContent(node);
            }
            <span class="kwrd">else</span>
            {
                List&lt;dynamic&gt; results = <span class="kwrd">new</span> List&lt;dynamic&gt;();
                <span class="kwrd">foreach</span> (XmlNode node <span class="kwrd">in</span> nodes)
                {
                    results.Add(GetContent(node));
                }
            }
            <span class="kwrd">return</span> <span class="kwrd">true</span>;
        }

        <span class="kwrd">private</span> dynamic GetContent(XmlNode node)
        {
            <span class="kwrd">if</span> (node.NodeType == XmlNodeType.Attribute)
                <span class="kwrd">return</span> node.Value;
            <span class="kwrd">if</span> (node.HasChildNodes || node.Attributes.Count &gt; 0)
                <span class="kwrd">return</span> <span class="kwrd">new</span> DynamicXml(node);
            <span class="kwrd">return</span> node.InnerText;
        }

        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">string</span> ToString()
        {
            <span class="kwrd">return</span> <span class="kwrd">this</span>;
        }

        <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">implicit</span> <span class="kwrd">operator</span> <span class="kwrd">string</span>(DynamicXml xml)
        {
            <span class="kwrd">return</span> xml._node.InnerText;
        }
    }
}</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>Sure, it’s not perfect. It could handle collections better instead of returning a list and support for types other than a string. And this isn’t the best <a name="_GoBack"></a>solution either. It’s a nice syntax but using the XDocument and LINQ is a better alternative. However I think it’s a great use for dynamics.</p>
<p><strong>Do you agree?</strong> Let us know. Based on your feedback, we may include another installment on this subject—with improvements.</p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/cool-things-to-do-with-dynamics-in-dotnet-4/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Are Extension Methods a Code Smell</title>
		<link>http://www.thycotic.com/are-extension-methods-code-smell</link>
		<comments>http://www.thycotic.com/are-extension-methods-code-smell#comments</comments>
		<pubDate>Thu, 10 Dec 2009 15:12:23 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=465</guid>
		<description><![CDATA[The extension method is a handy feature that came in C# 3.0/VB.NET 9.0 and .NET Framework 3.5. Quite simply, it allows the appearance of extending a class and giving it additional functionality without actually having to modify that class. Here’s an example]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/extensions.jpg" alt="Are Extension Methods a Code Smell?" width="500" height="225" /></p>
<h6 style="clear:both">December 10th | 2009</h6>
<p><strong>Are Extension Methods a Code Smell?</strong></p>
<p>The <b>extension method</b> is a handy feature that came in C# 3.0/VB.NET 9.0 and .NET Framework 3.5. Quite simply, it allows the appearance of extending a class and giving it additional functionality without actually having to modify that class. Here’s an example:</p>
<pre class="csharpcode"><span class="kwrd">class</span> OtherClass
{
    <span class="kwrd">public</span> <span class="kwrd">void</span> Foo()
    {
        User user = <span class="kwrd">new</span> User();
        user.DisplayUserName();
    }
}

<span class="kwrd">public</span> <span class="kwrd">class</span> User
{
    <span class="kwrd">public</span> <span class="kwrd">string</span> UserName { get; set; }
}

<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Extensions
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> DisplayUserName(<span class="kwrd">this</span> User user)
    {
        <span class="kwrd">string</span> userName = user.UserName;
        <span class="rem">//Display userName</span>
    }
}</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>In the “Foo” method we are calling a method “DisplayUserName” which <i>appears</i> to belong to the User class, but is actually a static method in a completely different location.</p>
<p>Extension methods are currently present in the .NET Framework. Their most notable use is in LINQ. All of LINQ’s operators are implemented as an extension method on the IEnumerable&lt;T&gt; interface.</p>
<p><b>But can they be a code smell? </b>In most cases I would say yes, for several reasons.</p>
<p>Firstly, if it is something simple, why not just implement it in the object? In the case of the User, it may not be his responsibility to display to the interface. Therefore, to avoid violating the Single Responsibility Principle, it would be better to keep the functionality out of the User class. However, this turns something that might have been better as a service into a concrete static implementation, and this could be difficult to test by mocking. By creating a service and adding it to a container, we have a more appropriate solution.</p>
<p>Secondly, new developers—or even experienced ones—might be confused. It’s impossible to tell just by looking at the code if it’s an extension method or an actual method on the object. If you have multiple extension methods the code can be extremely difficult to read. It may even introduce bugs or make code reviews labor intensive.</p>
<p>A third scenario where I see extension methods as problematic is in the fact that they <i>seem </i>to be instance-based. That is, they have the appearance of accessing a method on an instance of an object. In actual fact, the compiler is just translating it to a normal static method. A developer might be tempted to do something like this:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> Extensions
{
    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">string</span> _userName;
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> DisplayUserName(<span class="kwrd">this</span> User user)
    {
        _userName = user.UserName;
        DoDisplay();
    }

    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">void</span> DoDisplay()
    {
        <span class="rem">//Do something with _userName</span>
    }
}</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>This is perfectly legal and working code, but by introducing something outside of the scope that is static, and not tied to an instance of User, we’ve introduced thread safety issues. I believe this is one of the reasons Extension Properties were not introduced—it’s an invitation for this sort of code.</p>
<p>Extension methods can be a slippery slope. While they may have been introduced for a perfectly valid and specific reason, there’s a broken window effect: if there’s one broken window in the neighborhood, it’s an invitation for other windows to be broken too. There’s an obvious invitation for extension methods to be written in such a way that if one extension method is written, then you’re inviting other people to use them in possibly careless ways.</p>
<p>Are they useful in any context at all? Yes, I believe they are. Usually for extending sealed classes for which you don’t have the source. A common pattern is to make string helpers as extension methods. Here’s an example:</p>
<pre class="csharpcode"><span class="kwrd">class</span> Program
{
    <span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
    {
        <span class="kwrd">string</span> sample = <span class="str">&quot;the quick brown fox jumped over the lazy dog&quot;</span>;
        <span class="kwrd">string</span> titled = sample.ToTitleCase();
        <span class="rem">//titled will be &quot;The Quick Brown Fox Jumped Over The Lazy Dog&quot;</span>
    }
}

<span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">class</span> StringExtensions
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> <span class="kwrd">string</span> ToTitleCase(<span class="kwrd">this</span> <span class="kwrd">string</span> s)
    {
        <span class="kwrd">return</span> System.Globalization.CultureInfo.CurrentUICulture.TextInfo.ToTitleCase(s);
    }
}</pre>
<p>&#160;</p>
<p>This might be an acceptable use of an extension method. We are extending a sealed and well-known class “string” and giving it additional functionality.</p>
<p>I could also see it working, on owned-code, with helper methods in <b>unit test</b> projects.</p>
<p>As far as organization goes, try keep extension methods down to a minimum, or none if possible. If you must use them, organize them in way that all the extensions are organized in &lt;ClassBeingExtended&gt;Extensions static class. Or to take it step further, append the extension method with “Extension” so it is easily identified as one.</p>
<p>I think they are cool – but ultimately the possible negatives outweigh the positives.<a name="_GoBack"></a></p>
<p>What say you readers? Are extension methods a quick way to shoot yourself in the foot?</p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/are-extension-methods-code-smell/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>An Overview of C# 4.0</title>
		<link>http://www.thycotic.com/an-overview-of-c-4-0</link>
		<comments>http://www.thycotic.com/an-overview-of-c-4-0#comments</comments>
		<pubDate>Tue, 01 Dec 2009 21:04:13 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C# 4.0]]></category>
		<category><![CDATA[C# 4.0 features]]></category>
		<category><![CDATA[COM interop C# 4]]></category>
		<category><![CDATA[generic interface]]></category>
		<category><![CDATA[Named and Optimal Parameters]]></category>
		<category><![CDATA[VB.NET C# 4.0]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=459</guid>
		<description><![CDATA[In Some Love for VB.NET 10 Too I focused on the new features in VB.NET 10. Now let’s take a look at C# 4.0. C# already has a strong, rich feature set which will, no doubt, be developed even further. I will discuss the actual C# 4.0 specification itself, not the .NET Framework, so the ever-popular "dynamic" keyword will be left for later. It deserves a post of its own.]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/Kevin_Csharp_40.jpg" alt="C# Sharp 4.0 features Kevin Jones" width="500" height="225" /></p>
<h6 style="clear:both">December 1rst | 2009</h6>
<p><strong>An Overview of C# 4.0</strong></p>
<p>In <a href="http://www.thycotic.com/some-love-for-vb-net-10-too">Some Love for VB.NET 10 Too</a> I focused on the new features in VB.NET 10. Now let’s take a look at C# 4.0. C# already has a strong, rich feature set which will, no doubt, be developed even further. I will discuss the actual C# 4.0 specification itself, not the .NET Framework, so the ever-popular &#8220;dynamic&#8221; keyword will be left for later. It deserves a post of its own.</p>
<h3>COM Cleanup</h3>
<p>This feature is pretty cool and it’s definitely going to get a big cheer from those who do a lot of COM automation. C# 4.0 has a few extra features that make working with COM a little easier. Word automation is a popular reason to use COM automation in the .NET Framework. Take this example which runs Word for you and adds a paragraph with bold text:</p>
<pre class="csharpcode"><span class="kwrd">object</span> oMissing = System.Reflection.Missing.Value;
var word = <span class="kwrd">new</span> Application();
word.Visible = <span class="kwrd">true</span>;
var doc = word.Documents.Add(<span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing);
var paragraph = doc.Content.Paragraphs.Add(<span class="kwrd">ref</span> oMissing);
paragraph.Range.Text = <span class="str">"Hello World!"</span>;
paragraph.Range.Bold = 1;
paragraph.Range.InsertParagraphAfter();
Console.ReadKey(<span class="kwrd">true</span>);</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>Something that immediately stands out is all those ref&#8217;s to oMissing. What is that? Simply put, C# doesn&#8217;t support optional parameters, but COM (and VB.NET) do. To indicate to the COM Callable Wrapper that you want it to be treated like &#8220;nothing&#8221; was passed in (as opposed to NULL) Missing.Value is required. In C# 4.0, that is no longer the case. Here it is in C# 4.0:</p>
<pre class="csharpcode">var word = <span class="kwrd">new</span> Application();
word.Visible = <span class="kwrd">true</span>;
var doc = word.Documents.Add();
var paragraph = doc.Content.Paragraphs.Add();
paragraph.Range.Text = <span class="str">"Hello World!"</span>;
paragraph.Range.Bold = 1;
paragraph.Range.InsertParagraphAfter();</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>Much better! What’s actually happening here is just syntactic sugar. The C# compiler automatically adds a <em>ref</em> to Missing.Value for you, which is easy to see with a tool like Reflector. If you want to pass in Missing.Value automatically from some parameters, and actual objects for others, read the section on named parameters farther down in this blog. In addition to adding Missing.Value for you, you can now—optionally—not pass a parameter by reference even if the signature declares it as ref.</p>
<p>A new addition to the C# 4.0 language is support for indexed properties. For example, let&#8217;s look at some code that adds a bookmark to the document:</p>
<pre class="csharpcode"><span class="kwrd">object</span> oMissing = System.Reflection.Missing.Value;
<span class="kwrd">object</span> endOfDoc = <span class="str">"\\endofdoc"</span>;
var word = <span class="kwrd">new</span> Application();
word.Visible = <span class="kwrd">true</span>;
var doc = word.Documents.Add(<span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing);
var paragraph = doc.Content.Paragraphs.Add(<span class="kwrd">ref</span> oMissing);
paragraph.Range.Text = <span class="str">"Hello World!"</span>;
paragraph.Range.Bold = 1;
paragraph.Range.InsertParagraphAfter();
var bookmark = doc.Bookmarks.get_Item(<span class="kwrd">ref</span> endOfDoc);
bookmark.Range.Text = <span class="str">"Goodbye World!"</span>;</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>bookmark is declared as doc.Bookmarks.get_Item(). Bookmarks is actually a property that supports indexing. C# 3.0 doesn&#8217;t support it. In C# 4.0 we can now index into it:</p>
<pre class="csharpcode"><span class="kwrd">object</span> oMissing = System.Reflection.Missing.Value;
<span class="kwrd">object</span> endOfDoc = <span class="str">"\\endofdoc"</span>;
var word = <span class="kwrd">new</span> Application();
word.Visible = <span class="kwrd">true</span>;
var doc = word.Documents.Add(<span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing);
var paragraph = doc.Content.Paragraphs.Add(<span class="kwrd">ref</span> oMissing);
paragraph.Range.Text = <span class="str">"Hello World!"</span>;
paragraph.Range.Bold = 1;
paragraph.Range.InsertParagraphAfter();
var bookmark = doc.Bookmarks[endOfDoc];
bookmark.Range.Text = <span class="str">"Goodbye World!"</span>;</pre>
<p>Neat. Does this mean C# 4.0 now supports indexable properties? Unfortunately not. As of now it can only consume them, not declare them—but it&#8217;s a step in the right direction. Also notice that we didn&#8217;t pass the endOfDoc by reference. With COM, you no longer <em>have</em> to pass an item by reference if you prefer not to. This only works on COM wrappers and not regular .NET managed code.</p>
<p>This brings us to the next feature of COM: embedded interop assemblies. A problem that COM presents for some developers, which .NET developers have to deal with when working with COM, is versioning—or making sure that the required interop wrapper is even installed. In .NET 4.0, the compiler will automatically embed your COM interop assemblies into your application if you simply right-click the reference and hit properties. This will prevent your compiled application from referencing the assembly. Instead, it will contain its own types. This ensures that your application is always using the same interop wrapper.</p>
<p>So our C# 3.0 code went from this:</p>
<pre class="csharpcode"><span class="kwrd">object</span> oMissing = System.Reflection.Missing.Value;
<span class="kwrd">object</span> endOfDoc = <span class="str">"\\endofdoc"</span>;
var word = <span class="kwrd">new</span> Application();
word.Visible = <span class="kwrd">true</span>;
var doc = word.Documents.Add(<span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing, <span class="kwrd">ref</span> oMissing);
var paragraph = doc.Content.Paragraphs.Add(<span class="kwrd">ref</span> oMissing);
paragraph.Range.Text = <span class="str">"Hello World!"</span>;
paragraph.Range.Bold = 1;
paragraph.Range.InsertParagraphAfter();
var bookmark = doc.Bookmarks.get_Item(<span class="kwrd">ref</span> endOfDoc);
bookmark.Range.Text = <span class="str">"Goodbye World!"</span>;</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>To This:</p>
<pre class="csharpcode">var word = <span class="kwrd">new</span> Application();
word.Visible = <span class="kwrd">true</span>;
var doc = word.Documents.Add();
var paragraph = doc.Content.Paragraphs.Add();
paragraph.Range.Text = <span class="str">"Hello World!"</span>;
paragraph.Range.Bold = 1;
paragraph.Range.InsertParagraphAfter();
var bookmark = doc.Bookmarks[<span class="str">"\\endofdoc"</span>];
bookmark.Range.Text = <span class="str">"Goodbye World!"</span>;</pre>
<p>That&#8217;s cleaner now, huh?</p>
<h3>Covariance and Contra-variance</h3>
<p>This new feature was added to C# 4.0 to help with generics. In today&#8217;s C# code, all generics are invariant. For example, given the type SomeType&lt;T&gt; and SomeType&lt;K&gt; let&#8217;s assume that K is a superclass of T. SomeType&lt;T&gt; and SomeType&lt;K&gt; will not have any inheritance relationship at all even though T and K have a relationship. Why can&#8217;t we do this?</p>
<p>Ensuring type safety. In this example, allowing this to occur falls short:</p>
<pre class="csharpcode">List&lt;<span class="kwrd">string</span>&gt; stringList = <span class="kwrd">new</span> List&lt;<span class="kwrd">string</span>&gt;();
List&lt;<span class="kwrd">object</span>&gt; objectList = stringList;
objectList.Add(<span class="kwrd">new</span> <span class="kwrd">object</span>());</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>Even though string inherits from object, we can&#8217;t assign it to a list of objects. Line three is a good example of why not: our objectList would really be a list of strings at run time, then blam! we add an object to it. Delegates have the same problem.</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">delegate</span> T Callback&lt;T&gt;();
<span class="kwrd">public</span> <span class="kwrd">void</span> DoCallback()
{
    Callback&lt;<span class="kwrd">object</span>&gt; callback = <span class="kwrd">new</span> Callback&lt;<span class="kwrd">string</span>&gt;(CallbackHandler);
}

<span class="kwrd">private</span> <span class="kwrd">string</span> CallbackHandler()
{
    <span class="rem">//Implementation Omitted</span>
}</pre>
<p>You would assume that this is OK. After all, why shouldn’t a callback of object be assigned to a callback of string if string always implements object? Well…for the same reason as the List.</p>
<p>Variance to the rescue! Where have we seen variance before? Arrays. This has always compiled:</p>
<pre class="csharpcode"><span class="kwrd">object</span>[] actuallyStrings = <span class="kwrd">new</span> <span class="kwrd">string</span>[] { <span class="str">"Hello"</span>, <span class="str">"World"</span> };
actuallyStrings[0] = <span class="kwrd">new</span> <span class="kwrd">object</span>();</pre>
<p>This will throw an ArrayTypeMismatchException, but the compiler allows it. With generics, we can do this in a way that is always compile time safe. If a <strong>generic interface</strong> or <strong>generic delegate</strong> has a <strong>reference type</strong> T as its type parameter and does not have any method or member that takes in a parameter of type T, we can declare it to be covariant on T. On the other hand, if that interface or delegate does not have any method or member that returns T, we can declare it to be contravariant on T.</p>
<p><strong>NOTE: </strong>That description was taken from Buu Nguyen&#8217;s post on <a href="http://www.codeproject.com/KB/cs/csharp_4_overview.aspx">Code Project</a>. It&#8217;s an elegant description and kudos to him for thinking of it.</p>
<p>Thus, in C# 4.0 we can declare on our delegate that T is <em>out</em> as we never accept a type of T.</p>
<pre class="csharpcode"><span class="kwrd">private</span> <span class="kwrd">delegate</span> T Callback&lt;<span class="kwrd">out</span> T&gt;();
<span class="kwrd">public</span> <span class="kwrd">void</span> DoCallback()
{
    Callback&lt;<span class="kwrd">object</span>&gt; callback = <span class="kwrd">new</span> Callback&lt;<span class="kwrd">string</span>&gt;(CallbackHandler);
    <span class="kwrd">object</span> result = callback();
}
<span class="kwrd">private</span> <span class="kwrd">string</span> CallbackHandler()
{
    <span class="kwrd">return</span> <span class="str">"Hello"</span>;
}</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>result in this case, is an object and rightfully so. Since T can only be an output type, and we know string always inherits from object, the compiler can safely assume the implicit cast.</p>
<p>So why is this a feature in C# 4.0? As Buu points out, this feature has actually been available to the CLR since generics were introduced in .NET 2.0, though none of the languages supported it.</p>
<h3>Named and Optional Parameters</h3>
<p>Named and default parameters partially complete the COM interop enhancements—something that many consider long overdue. With named parameters, you can specify the order in which your parameters are declared. This also comes into play with option parameters. Here is an example:</p>
<pre class="csharpcode"><span class="kwrd">static</span> <span class="kwrd">void</span> Main(<span class="kwrd">string</span>[] args)
{
    PrintTwoStrings(stringB: <span class="str">"World"</span>, stringA: <span class="str">"Hello"</span>);
}

<span class="kwrd">static</span> <span class="kwrd">void</span> PrintTwoStrings(<span class="kwrd">string</span> stringA, <span class="kwrd">string</span> stringB)
{
    Console.WriteLine(stringA);
    Console.WriteLine(stringB);
}</pre>
<p>Notice that I explicitly declared the parameters, even out of order. Likewise, I can make stringB optional with a default. This code will produce &#8220;Hello Japan&#8221;</p>
<pre class="csharpcode"><span class="kwrd">static</span> <span class="kwrd">void</span> Main()
{
    PrintTwoStrings(<span class="str">"Hello"</span>, stringB: <span class="str">"Japan"</span>);
}

<span class="kwrd">static</span> <span class="kwrd">void</span> PrintTwoStrings(<span class="kwrd">string</span> stringA, <span class="kwrd">string</span> stringB = <span class="str">"World"</span>)
{
    Console.WriteLine(stringA);
    Console.WriteLine(stringB);
}</pre>
<p>Even though stringB has a default, we explicitly set it to Japan. If we were to omit the stringB in the call to PrintTwoStrings:</p>
<pre class="csharpcode"><span class="kwrd">static</span> <span class="kwrd">void</span> Main()
{
    PrintTwoStrings(<span class="str">"Hello"</span>);
}</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>This will print &#8220;Hello World&#8221;. You can have multiple optional parameters, but they must all be placed after the required ones. This is to avoid confusion with overloads.</p>
<p>This also works with COM. If you have a COM method that takes an exceptional number of arguments, and you want to pass in Missing.Value for all but a few, you can use named parameters and it will default all of the others to Missing.Value.</p>
<p>It&#8217;s worth noting that C# and VB.NET are compatible with each other on named and optional parameters. VB.NET has actually supported both these features for years.</p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/an-overview-of-c-4-0/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Some Love for VB.NET 10 Too</title>
		<link>http://www.thycotic.com/some-love-for-vb-net-10-too</link>
		<comments>http://www.thycotic.com/some-love-for-vb-net-10-too#comments</comments>
		<pubDate>Tue, 24 Nov 2009 20:17:24 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=453</guid>
		<description><![CDATA[At Thycotic we typically work with C#. In fact, 90% of the code that we write is written in C#. However, it’s no secret that I am a VB.NET Fanatic. Generally, C# developers don’t look kindly on VB.NET developers because they consider VB.Net an inferior language. But I particularly like how it’s implemented in Visual Studio.]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/Kevin_hearts_VB.jpg" alt="Some Love for VB.NET 10 Too" width="500" height="225" /></p>
<h6 style="clear:both">November 24th | 2009</h6>
<p><strong>Some Love for VB.NET 10 Too</strong></p>
<p>At Thycotic we typically work with C#. In fact, 90% of the code that we write is written in C#. However, it’s no secret that I am a VB.NET Fanatic. Generally, C# developers don’t look kindly on VB.NET developers because they consider VB.Net an inferior language. But I particularly like how it’s implemented in Visual Studio.</p>
<p>One of the criticisms of VB.NET is that is that some of its features are not up to par with C#. That’s an indisputable fact, I’ll admit. But a lot has been done to the upcoming VB.NET 10 for the .NET Framework 4.0, to bring VB.NET closer to C# for syntactic sugar.</p>
<p><strong>Auto Properties</strong></p>
<p>C# 3.0 introduced a really cool feature called <strong>automatic properties</strong>. Essentially, the C# compiler emits a backing field for you so you don’t have to do it yourself. This feature will be available in VB.NET 10. Its syntax looks like this:</p>
<pre class="csharpcode"><span class="kwrd">Public</span> Property MyAutoProperty <span class="kwrd">As</span> Object<!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></pre>
<p>That’s it! It’s just that one line; even simpler than C#. Of course you can decorate it with ReadOnly or WriteOnly so that it only has a getter or setter. The one thing it can do that C# 3.0 or 4.0 <em>doesn’t</em> let you do, however, is auto-initialize it.</p>
<pre class="csharpcode"><span class="kwrd">Public</span> Property MyAutoInteger <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 10<!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></pre>
<p>MyAutoInteger will default to 10. The VB.NET compiler will secretly put this in the constructor or static constructor if the property is static, similar to the way fields can be auto-initialized.</p>
<p><strong>Subs as Lambdas</strong></p>
<p>C# 3.0 introduced a rich syntax for <strong>Lambda expressions</strong>, and VB.NET followed suit to support LINQ. One limitation is that the passed in delegate <em>must</em> be a function that returns a value, and not a sub. Consider the following:</p>
<pre class="csharpcode">Sub Main()
    DoWork(Sub(x) Console.WriteLine(x))
<span class="kwrd">End</span> Sub

<span class="kwrd">Public</span> Sub DoWork(ByVal <span class="kwrd">work</span> <span class="kwrd">As</span> <span class="kwrd">Action</span>(<span class="kwrd">Of</span> String))
    <span class="kwrd">work</span>("<span class="kwrd">Some</span> String Maybe")
<span class="kwrd">End</span> Sub
<!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></pre>
<p>This simply wouldn’t compile in VB.NET 9 with Visual Studio 2008 because DoWork expects an Action delegate, which does not return anything thus making it a Sub, not a Function. I’m happy to say this will compile in Visual Studio 2010.</p>
<p><strong>Collection Initializers</strong></p>
<p>If you’ve ever had a List or Dictionary you wanted to quickly initialize with data for something simple like a unit test, C# made this easy with <strong>collection initializers.</strong> VB.NET 10 introduces a similar syntax to allow initializing a collection.</p>
<pre class="csharpcode">Dim helloWorld <span class="kwrd">As</span> <span class="kwrd">New</span> List(<span class="kwrd">Of</span> String) <span class="kwrd">From</span> {"Hello", "World"}

This will create a list with “Hello” and “World” in the list. Likewise for a dictionary:

Dim helloWorld <span class="kwrd">As</span> <span class="kwrd">New</span> <span class="kwrd">Dictionary</span>(<span class="kwrd">Of</span> <span class="kwrd">Integer</span>, String) <span class="kwrd">From</span> {{1, "Hello"}, {2, "World"}}
<!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></pre>
<p>Good stuff!</p>
<p><strong>Line Continuations</strong></p>
<p>VB.NET was criticized for its reliance on line feeds to decide where the next statement block would start. Previously, to continue the statement to the next line you had to use an underscore to indicate that the next line was part of the current one. In VB.NET 10, that remains true. But VB.NET 10 allows flexibility while implicitly understanding where the underscore is. For Example:</p>
<pre class="csharpcode">Dim someNumber <span class="kwrd">As</span> String = "Hello" &amp;
     "World"</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  --></p>
<p><strong>or</strong></p>
<pre class="csharpcode">Dim someNumber <span class="kwrd">As</span> <span class="kwrd">Integer</span> = 10 +
     40</pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  --></p>
<p><strong> </strong></p>
<p><strong>Better COM Support &amp; Indexed Properties</strong></p>
<p>C# 4.0 introduced better handling for “missing” arguments in COM. VB.NET has had that for a while.</p>
<p>C# 4.0 has partial support for indexed properties to complete their COM enhancements. Sadly, C# only lets you consume them from COM, not declare them, which VB.NET has been able to do since its inception.</p>
<p>And let’s not forget that VB.NET has plenty of other language tools that C# lacks such as the “With” construct:</p>
<pre class="csharpcode">Dim builder = <span class="kwrd">New</span> StringBuilder()
<span class="kwrd">With</span> builder
    .Append("The ")
    .Append("Quick ")
    .Append("Brown ")
    .Append("Fox ")
    .Append("Jumped ")
    .Append("Over ")
    .Append("The ")
    .Append("Lazy ")
    .Append("Dog.")
<span class="kwrd">End</span> <span class="kwrd">With</span></pre>
<p><!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }  --></p>
<p>A contrived example, sure, but you get the idea of its usefulness. The “Handles” as a way of handling events is one of my favorite features. Of course C# developers will quickly to tell you that it’s a horrible syntax.</p>
<p><strong>Conclusion</strong></p>
<p>Both languages definitely have their advantages and disadvantages. Clearly though, VB.NET 10 has a lot of polish on it that cannot be ignored.</p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/some-love-for-vb-net-10-too/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Danger of Single Responsibility in Programming Continued</title>
		<link>http://www.thycotic.com/the-danger-of-single-responsibility-in-programming-continued</link>
		<comments>http://www.thycotic.com/the-danger-of-single-responsibility-in-programming-continued#comments</comments>
		<pubDate>Thu, 19 Nov 2009 14:50:06 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[Custom Development]]></category>
		<category><![CDATA[Extreme Programming]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=443</guid>
		<description><![CDATA[Doug Rohrer responded to my initial post on this topic with a good refactoring of the classes involved in a manner similar to the Strategy pattern. I agree with many of his points—the hypothetical developer certainly chose the wrong responsibilities; misunderstood the Single Responsibility Principle; and generally made the code a mess. That said, I believe that SRP is most definitely dangerous, not because of what happens when it is used correctly, but because of how easy it is to get it wrong. Misapplying the SRP can result in code that makes God objects look easy to maintain.]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/DavidCookseyDanger.jpg" alt="The Danger of Single Responsibility in Programming Cont." width="500" height="225" /></p>
<h6>October 16th 2009 | David Cooksey</h6>
<p><strong>The Dangers of Single Responsibility in Programming Continued</strong></p>
<p>The Dangers of Single Responsibility, Cont.</p>
<p>Doug Rohrer responded to my <a href="http://www.thycotic.com/the-dangers-of-single-responsibility-in-programming">initial post</a> on this topic with a <a href="http://weblogs.asp.net/drohrer/archive/2009/11/10/in-response-to-quot-the-dangers-of-single-responsibility-in-programming-quot.aspx">good refactoring</a> of the classes involved in a manner similar to the Strategy pattern. I agree with many of his points—the hypothetical developer certainly chose the wrong responsibilities; misunderstood the Single Responsibility Principle; and generally made the code a mess. That said, I believe that SRP is most definitely dangerous, not because of what happens when it is used correctly, but because of how easy it is to get it wrong. Misapplying the SRP can result in code that makes God objects look easy to maintain.</p>
<p>For clarity’s sake, I’ll go one step further—it is easy to misunderstand the sentence “A class should have only one reason to change” as a literal commandment to be applied at the line or method level. This results in disaster. One common example of how the SRP is misunderstood can be seen in this <a href="http://blog.developers.ba/post/2009/04/16/Single-responsibility-principle-Does-it-mean-I-cant-have-more-than-one-method-in-my-class.aspx">thread</a>, where the poster asks if the SRP means that each class can have only one method. Luckily the poster received a good informative answer, but that is not the case for all developers learning about the SRP.</p>
<p>Here is an example of code modifications I have seen motivated by a desire to apply the SRP.</p>
<p>BEFORE</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Check
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> IDataProvider _dataProvider;

        <span class="kwrd">public</span> Check(IDataProvider dataProvider)
        {
            _dataProvider = dataProvider;
        }

        <span class="kwrd">public</span> <span class="kwrd">bool</span> Run()
        {
            IBusinessObject data = _dataProvider.Get();

            <span class="kwrd">if</span> (data.Condition1 &amp;&amp; data.Condition2)
            {
                <span class="kwrd">string</span> message = <span class="kwrd">string</span>.Format(<span class="str">"Check failed, {0} {1}"</span>, data.Property1, data.Property2);
                <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(message);
            }
            <span class="kwrd">return</span> data.Property3 != data.Property4;
        }
    }</pre>
<p><!--<br />
.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>AFTER</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Class
    {
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> IDataProvider _dataProvider;
        <span class="kwrd">private</span> <span class="kwrd">readonly</span> ICheckErrorMessageProvider _checkErrorMessageProvider;

        <span class="kwrd">public</span> Check(IDataProvider dataProvider, ICheckErrorMessageProvider checkErrorMessageProvider)
        {
            _dataProvider = dataProvider;
            _checkErrorMessageProvider = checkErrorMessageProvider;
        }

        <span class="kwrd">public</span> <span class="kwrd">bool</span> Run()
        {
            IBusinessObject data = _dataProvider.Get();

            <span class="kwrd">if</span> (data.Condition1 &amp;&amp; data.Condition2)
            {
                <span class="kwrd">string</span> message = _checkErrorMessageProvider.GetErrorMessage(data);
                <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(message);
            }
            <span class="kwrd">return</span> data.Property3 != data.Property4;
        }
    }
<span class="kwrd">public</span> <span class="kwrd">class</span> CheckErrorMessageProvider : ICheckErrorMessageProvider
    {
        <span class="kwrd">public</span> <span class="kwrd">string</span> GetErrorMessage(IBusinessObject data)
        {
            <span class="kwrd">return</span> <span class="kwrd">string</span>.Format(<span class="str">"Check failed, {0} {1}"</span>, data.Property1, data.Property2);
        }
    }</pre>
<p><!--<br />
.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>Here, the developer asked the SRP question “Does this class have only one reason to change?” and got the answer “No, it could change because the formatted text could change, or because the logic could change”, and refactored the String.format out into its own provider. While harmless on the surface, this artificial separation of concerns does not add any value. The new class is so specific that it cannot be used anywhere else. In addition, the developer is likely to forget the CheckErrorMessageProvider name almost immediately, so if a text change is required he will most likely go to the Check class first, and then go the extra level down into the string provider in order to make the text change. <strong><em>In other words, the complexity of the code was increased for no benefit.</em></strong></p>
<p>I believe that after correctness, simplicity is the most important programming principle. Simpler code is easier to understand when first read; easier to remember; easier to test; easier to refactor; and easier to add features to. Anything that adds complexity makes all of these tasks harder, especially on larger projects with many non-trivial sub-systems. Applying single responsibility at the line or method level diffuses business logic into a cloud of tiny classes that do next-to-nothing individually, and thoroughly obscure the logic they represent.</p>
<p>In conclusion, yes, the SRP is not dangerous when applied correctly. But then, most things are dangerous because of what happens when they are misused, and the Single Responsibility Principle is no exception. Handle with care!</p>
<p><strong><em><em>David Cooksey is a Senior .NET Consultant at Thycotic Software, an agile software services and product development company based in Washington DC. Secret Server is our flagship </em><a href="http://www.thycotic.com/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/the-danger-of-single-responsibility-in-programming-continued/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Want to join a team of top notch developers in the DC Metro area?</title>
		<link>http://www.thycotic.com/want-to-join-a-team-of-top-notch-developers-in-the-dc-metro-area</link>
		<comments>http://www.thycotic.com/want-to-join-a-team-of-top-notch-developers-in-the-dc-metro-area#comments</comments>
		<pubDate>Thu, 19 Nov 2009 14:35:52 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[Jobs]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=441</guid>
		<description><![CDATA[We are hiring! - > .NET Agile Developers in Washington D.C.]]></description>
			<content:encoded><![CDATA[<h2>If you can solve the problem below, you may just have what it takes.</h2>
<p><a href="http://www.thycotic.com/codetest.txt">www.thycotic.com/codetest.txt</a></p>
<p>Please submit your <strong>solution </strong>with your <strong>resume </strong>and <strong>cover letter</strong> in an email to TDDjobs@thycotic.com</p>
<p>At Thycotic you&#8217;ll join a highly capable team of .NET developers who work on consulting projects for clients, and interesting products. Improve your agile development skills while working with a team of skilled, passionate developers. We&#8217;re hiring, and we&#8217;d love to hear from you!</p>
<p>Required:</p>
<ul>
<li> You have the permanent legal right to work in the United States</li>
<li> You have excellent written and spoken English</li>
<li> You live, breathe, sleep, eat and drink C#</li>
<li> You have a strong understanding of Object Oriented principles, the .NET Framework, ASP.NET, relational databases and web application development</li>
<li> You are able to communicate effectively with co-workers and clients/customers</li>
<li> You are willing to work in the Washington DC Metro Area</li>
<li> You want to develop using Test Driven Development</li>
<li> You want to develop using Pair Programming</li>
</ul>
<p>Why work at Thycotic:</p>
<ul>
<li> Your ideas and opinions will be valued</li>
<li> You will continuously learn about new development techniques and technologies</li>
<li> We are a seasoned Agile .NET shop – not many of those around!</li>
<li> We are a Microsoft Gold Certified Partner</li>
<li> Follow a technical career path</li>
<li> Excellent benefits package</li>
<li> You will be working in the heart of Washington, DC</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/want-to-join-a-team-of-top-notch-developers-in-the-dc-metro-area/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The AJAX UpdatePanel Is it your worst enemy?</title>
		<link>http://www.thycotic.com/the-ajax-updatepanel-is-it-your-worst-enemy</link>
		<comments>http://www.thycotic.com/the-ajax-updatepanel-is-it-your-worst-enemy#comments</comments>
		<pubDate>Tue, 17 Nov 2009 15:49:01 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=438</guid>
		<description><![CDATA[Most AJAX Frameworks have the UpdatePanel, and they are all similar in function, but I’m referring specifically to the one built into the Microsoft AJAX Framework. If you haven't used AJAX before, it's a useful tool to know and understand, but I wouldn't recommend going much further than that.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><img style="vertical-align: middle" src="http://teststore.thycotic.net/images/KevinUpdatePanel.jpg" alt="" width="500" height="225" /></p>
<h5 style="text-align: right">November 17th 2009 | Kevin Jones</h5>
<p><strong>The AJAX UpdatePanel: Is it your worst enemy?<br />
</strong></p>
<p>A recent code camp presentation I did sparked a debate about the “UpdatePanel” in AJAX. It’s no secret I believe it barely qualifies as real AJAX at all.</p>
<p>Most AJAX Frameworks have the UpdatePanel, and they are all similar in function, but I’m referring specifically to the one built into the Microsoft AJAX Framework. If you haven&#8217;t used AJAX before, it&#8217;s a useful tool to know and understand, but I wouldn&#8217;t recommend going much further than that.</p>
<p>The UpdatePanel is a control that simply designates its contents as an asynchronous callback, or “AJAX” call. Take a look at this ubiquitous example of updating a label with the servers time – sans a postback:</p>
<pre class="csharpcode">&lt;asp:ScriptManager runat=<span class="str">"server"</span> ID=<span class="str">"MyScriptMap"</span> EnablePartialRendering=<span class="str">"true"</span> /&gt;
&lt;asp:UpdatePanel runat=<span class="str">"server"</span> ID=<span class="str">"TimeUpdatePanel"</span>&gt;
    &lt;ContentTemplate&gt;
        &lt;asp:Label runat=<span class="str">"server"</span> ID=<span class="str">"TimeLabel"</span> /&gt;
    &lt;/ContentTemplate&gt;
    &lt;Triggers&gt;
        &lt;asp:AsyncPostBackTrigger ControlID=<span class="str">"UpdateTimeButton"</span> EventName=<span class="str">"Click"</span> /&gt;
    &lt;/Triggers&gt;
&lt;/asp:UpdatePanel&gt;
&lt;asp:Button runat=<span class="str">"server"</span> ID=<span class="str">"UpdateTimeButton"</span> OnClick=<span class="str">"UpdateTimeButton_Click"</span> Text=<span class="str">"Update Time"</span> /&gt;</pre>
<p><!--</p>
<p>.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>The code behind it looks like this:</p>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Page_Load(<span class="kwrd">object</span> sender, EventArgs e) {
    SetTime();
}

<span class="kwrd">private</span> <span class="kwrd">void</span> SetTime() {
    TimeLabel.Text = DateTime.Now.ToString(<span class="str">"G"</span>);
}

<span class="kwrd">protected</span> <span class="kwrd">void</span> UpdateTimeButton_Click(<span class="kwrd">object</span> sender, EventArgs e) {
    SetTime();
}</pre>
<p><!--<br />
.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>Pretty simple. When we click the UpdateTimeButton the label updates the time with the current time, and without causing a postback. Great, right? It’s easy and requires little knowledge of advanced AJAX functionality.</p>
<p>Then what’s the problem?</p>
<p>Firstly, it’s slow and cumbersome. Secondly, it’s not very flexible. Let’s use our trusty tool – Firebug – to see what the AJAX Framework is really doing under the covers.</p>
<p>Here’s the post:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="175" valign="top"><strong>MyScriptMap</strong></td>
<td width="463" valign="top">MyScriptMap|UpdateTimeButton</td>
</tr>
<tr>
<td width="175" valign="top"><strong>UpdateTimeButton</strong></td>
<td width="463" valign="top">Update Time</td>
</tr>
<tr>
<td width="175" valign="top"><strong>__ASYNCPOST</strong></td>
<td width="463" valign="top">True</td>
</tr>
<tr>
<td width="175" valign="top"><strong>__EVENTARGUMENT</strong></td>
<td width="463" valign="top"></td>
</tr>
<tr>
<td width="175" valign="top"><strong>__EVENTTARGET</strong></td>
<td width="463" valign="top"></td>
</tr>
<tr>
<td width="175" valign="top"><strong>__EVENTVALIDATION</strong></td>
<td width="463" valign="top">/wEWAgLsi+LQBwLJqc+YBE5RYQbIcM8reKtnUnkQkSFh4HRl</td>
</tr>
<tr>
<td width="175" valign="top"><strong>__VIEWSTATE</strong></td>
<td width="463" valign="top">/wEPDwULLTE4MzQ0ODUyNDIPZBYCAgMPZBYCAgMPZBYCZg9kF</p>
<p>gICAQ8PFgIeBFRleHQFFDExLzgvMjAwOSA3OjEzOjEwIFBNZG</p>
<p>RktDZ2TbaSW4PmU5zi/+6LeFQPeOA=</td>
</tr>
</tbody>
</table>
<p>According to IIS, this is about 344 bytes. That’s a lot of data to post just to get a new date. So <em>why</em> did we need to post so much information?</p>
<p>The ViewState is the biggest part of this. ASP.NET fundamentally uses the ViewState for a whole slew of reasons, but in order for ASP.NET to process the request it needs the ViewState. There is also a field called the EventValidation. It contains information that ensures the ViewState hasn’t been tampered with. Since the EventValidation goes together with the ViewState, the AJAX call needs to send this information too. The rest of the data tells the ASP.NET runtime exactly what happened: which button was clicked; the name of the ScriptManager; etc.</p>
<p>That’s quite a bit of information. This is what the server sent back:</p>
<blockquote><p>55|updatePanel|TimeUpdatePanel|&lt;span id=&#8221;TimeLabel&#8221;&gt;11/8/2009 7:13:35 PM&lt;/span&gt;|128|hiddenField|__VIEWSTATE|/wEPDwULLTE4M</p>
<p>zQ0ODUyNDIPZBYCAgMPZBYCAgMPZBYCZg9kFgICAQ8PFgI</p>
<p>eBFRleHQFFDExLzgvMjAwOSA3OjEzOjM1IFBNZGRkbHZ0Gxr67</p>
<p>EAa/bNdqZfXC6A7YPA=|48|hiddenField|__EVENTVALIDATION|</p>
<p>/wEWAgLUiOrpBgLJqc+YBK3kgBaC8Pr4C9SpWuCECT5qBkBH|16|</p>
<p>asyncPostBackControlIDs||UpdateTimeButton|0|postBackC</p>
<p>ontrolIDs|||16|updatePanelIDs||tTimeUpdatePanel</p>
<p>|0|childUpdatePanelIDs|||15|panelsToRefreshIDs||TimeUpda</p>
<p>tePanel|2|asyncPostBackTimeout||90|20|formAction|</p>
<p>|UpdatePanelTime.aspx|</p></blockquote>
<p>Much more than just a simple date and time. ASP.NET is sending back a lot of information in the form of a single string that is delimited by pipes, and parsing it. The total size of it as IIS is 556 bytes. After the third pipe you’ll find the content of the label we were updating – HTML and all.<strong><em> This is the essence of the UpdatePanel.</em></strong> It works by sending its content to the server and the server sends back new content. The client framework then replaces the old content with the new content.</p>
<p>Clever enough, but it can lead to poor performance and bad design.</p>
<p><strong>Is there a different way?</strong></p>
<p>Yes, and though it can be a little inconvenient you gain more in the long term.</p>
<p>AJAX is <strong>A</strong>synchronous <strong>J</strong>avaScript <strong>a</strong>nd <strong>X</strong>ML. Ironically, XML is becoming the less popular means of AJAX communication. JSON (pronounced Jason) has become the primary means of AJAX based requests. JSON is easy to work with, and more compact than XML. Here is a simple example of a key and value pair.</p>
<pre class="csharpcode">[
    {<span class="str">"Key"</span>:<span class="str">"The Key 1"</span>,<span class="str">"Value"</span>:<span class="str">"The Value 1"</span>},
    {<span class="str">"Key"</span>:<span class="str">"The Key 2"</span>,<span class="str">"Value"</span>:<span class="str">"The Value 2"</span>}
]</pre>
<p><!--<br />
.csharpcode, .csharpcode pre<br />
{<br />
font-size: small;<br />
color: black;<br />
font-family: consolas, "Courier New", courier, monospace;<br />
background-color: #ffffff;<br />
/*white-space: pre;*/<br />
}<br />
.csharpcode pre { margin: 0em; }<br />
.csharpcode .rem { color: #008000; }<br />
.csharpcode .kwrd { color: #0000ff; }<br />
.csharpcode .str { color: #006080; }<br />
.csharpcode .op { color: #0000c0; }<br />
.csharpcode .preproc { color: #cc6633; }<br />
.csharpcode .asp { background-color: #ffff00; }<br />
.csharpcode .html { color: #800000; }<br />
.csharpcode .attr { color: #ff0000; }<br />
.csharpcode .alt<br />
{<br />
background-color: #f4f4f4;<br />
width: 100%;<br />
margin: 0em;<br />
}<br />
.csharpcode .lnum { color: #606060; } --></p>
<p>In .NET, it’s fairly easy to return JSON data from a web service so long as all of the types returned can be serialized. If we were to create a simple web service that returns the date and time, we could use JavaScript to request it from the web service. The Microsoft AJAX Framework includes a framework to make this much easier than hand coding requests from JavaScript. Here is what our web service method looks like:</p>
<pre class="csharpcode">[WebMethod]
[ScriptMethod(UseHttpGet = <span class="kwrd">false</span>)]
<span class="kwrd">public</span> <span class="kwrd">string</span> GetDateAndTime()
{
    <span class="kwrd">return</span> DateTime.Now.ToString(<span class="str">"G"</span>);
}
<!--
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
--></pre>
<p>It looks like a typical web service method, but notice the addition of the ScriptMethod attribute on the method. In order to wire AJAX into a web service, additions to the web.config file are required. Visual Studio 2008 will create a new web.config file with all of the correct settings in place to get you started with AJAX.</p>
<p>Calling it from our client side script is very simple:</p>
<pre class="csharpcode">&lt;div&gt;
    &lt;asp:ScriptManager runat=<span class="str">"server"</span> ID=<span class="str">"MyScriptMap"</span> EnablePartialRendering=<span class="str">"true"</span>&gt;
        &lt;Services&gt;
            &lt;asp:ServiceReference Path=<span class="str">"~/DataSource.asmx"</span> /&gt;
        &lt;/Services&gt;
    &lt;/asp:ScriptManager&gt;
&lt;/div&gt;
&lt;script language=<span class="str">"javascript"</span> type=<span class="str">"text/javascript"</span>&gt;
    function updateTime() {
        var service = <span class="kwrd">new</span> Ajax4Samples.DataSource();
        service.GetDateAndTime(iHaveDateAndTime, <span class="kwrd">null</span>, <span class="kwrd">null</span>);
    }

    function iHaveDateAndTime(theTime) {
        var myTimeSpan = $get(<span class="str">'MyTimeSpan'</span>);
        myTimeSpan.innerHTML = theTime;
    }
&lt;/script&gt;
&lt;span&gt;The Server's Time <span class="kwrd">is</span>: &lt;/span&gt;
&lt;span id=<span class="str">"MyTimeSpan"</span>&gt;&lt;%= DateTime.Now.ToString(<span class="str">"G"</span>) %&gt;&lt;/span&gt;
&lt;input type=<span class="str">"button"</span> onclick=<span class="str">"updateTime();"</span> <span class="kwrd">value</span>=<span class="str">"Update Time"</span> /&gt;</pre>
<p>This is a page that updates a span—MyTimeSpan—with the response from what the web service returns. We do this by adding our web service as a ServiceReference. It generates a large piece of JavaScript that allows communication with the web service. From there, a few lines of JavaScript request the data from the service. When we click Update Time, we don’t actually send <em>any </em>data to the server. And why should we?</p>
<p>The response is as simple as this:</p>
<p>{&#8221;d&#8221;:&#8221;11/8/2009 8:22:26 PM&#8221;}</p>
<p>Just a date and a time that totals 28 bytes. The “d” is a little bit of magic that the AJAX Framework itself is using. However when you consume it you needn’t worry about the “d”. The AJAX Framework includes some metadata in responses to make things easier, such as type names, to allow for a typing system.</p>
<p>Sure there’s a little more coding to it but it allows a greater degree of freedom and functionality with AJAX. There are other frameworks that complement the Microsoft AJAX one, including jQuery which allows for easy manipulation of the DOM and finding controls.</p>
<p>My conclusion: avoid the update panel at all costs. It’s cheap and easy to implement, but it’s slow and doesn’t allow adequate flexibility.</p>
<p class="authorblock" style="padding:10px;"><em><em>Kevin Jones is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/vcsjones"> Follow Kevin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/the-ajax-updatepanel-is-it-your-worst-enemy/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thycotic brings Password Management to SuperComputing 2009</title>
		<link>http://www.thycotic.com/thycotic-brings-password-management-to-supercomputing-2009</link>
		<comments>http://www.thycotic.com/thycotic-brings-password-management-to-supercomputing-2009#comments</comments>
		<pubDate>Mon, 16 Nov 2009 21:22:10 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[1]]></category>
		<category><![CDATA[information security passwords]]></category>
		<category><![CDATA[iPhone password manager]]></category>
		<category><![CDATA[Password Management]]></category>
		<category><![CDATA[SuperComputing]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=434</guid>
		<description><![CDATA[Thycotic will be in Portland Oregon this week, exhibiting at SuperComputing from November 14th to the 20th . Stop by our booth (#354) to catch a peek of the iPhone version of Secret Server enterprise password management.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><img style="vertical-align: middle" src="http://teststore.thycotic.net/images/supercomputing.jpg" alt="" width="500" height="225" /></p>
<h5 style="text-align: right">November 163th 2009 | Jonathan Cogley and Dan Parker</h5>
<p><strong>Thycotic brings Password Management to SuperComputing 2009<br />
</strong></p>
<p>Thycotic will be in Portland Oregon this week, exhibiting at SuperComputing from November 14th to the 20th .  Stop by our booth (#354) to catch a peek of the iPhone version of Secret Server enterprise password management.</p>
<p>Are you responsible for end-user passwords? As to see a demo of our new self-service password reset application, Password Reset Server.</p>
<p>Come visit us to talk about password management or information security.</p>
<p>See you there!</p>
<p><img style="vertical-align: middle" src="http://teststore.thycotic.net/images/booth.jpg" alt="" /></p>
<p class="authorblock" style="padding:10px; float:left"><em><em>Jonathan Cogley is the CEO of Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/JonathanCogley"> Follow Jonathan</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/thycotic-brings-password-management-to-supercomputing-2009/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Top 10 Takeaways from DevConnections Day Four</title>
		<link>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-four</link>
		<comments>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-four#comments</comments>
		<pubDate>Fri, 13 Nov 2009 14:27:27 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[DevConnections]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=429</guid>
		<description><![CDATA[Whew! Day Four (officially day Three, but I am counting the pre-conference workshop)
came to a close with the famous “64-bit Question” session where .NET Rocks! hosts Carl Franklin and
Richard Campbell gave away some fantastic swag, like $10,000 Team System licenses.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><img style="vertical-align: middle" src="http://teststore.thycotic.net/images/jimmy_partial_devconnections.jpg" alt="" width="500" height="225" /></p>
<h5 style="text-align: right">November 13th 2009 | Jimmy Bosse</h5>
<p><strong>Top 10 Takeaways from DevConnections Day Four<br />
</strong></p>
<p>Whew! Day Four (officially day Three, but I am counting the pre-conference workshop)came to a close with the famous “64-bit Question” session where .NET Rocks! hosts Carl Franklin and Richard Campbell gave away some fantastic swag, like $10,000 Team System licenses. Too bad I didn’t win one. It was a great final day and I chose a well rounded set of sessions:</p>
<ul>
<li> It’s the Least You Can Do: Improve Security in Your ASP.NET Applications by Rachel Appel</li>
<li> Understanding Efficient User Interface Design by Markus Egger</li>
<li> Performance Isn’t Optional &#8211; Making Web Services Work by Richard Campbell</li>
<li> Building a Rich Web UI at the Speed of jQuery UI by Dino Esposito</li>
</ul>
<p>And from our home office in Walla Walla, Washington…</p>
<ol>
<li>
<h3>Read the SANS Institute Report, “…<a href="http://www.sans.org/top25-programming-errors/" target="_self">25 Most Dangerous Programming Errors</a>…”</h3>
<p>We can’t be 100% secure, but reading the report will help you think about the most obvious concerns and direct you to resources for addressing these concerns.</li>
<li>
<h3>Use White Lists instead of Black Lists.</h3>
<p>You can’t think of everything even if you try. If you are protecting a file upload, compare how many types of files a user might attempt to upload vs. the specific few you want them to actually upload. White List those few and reject the rest.</li>
<li>
<h3>The UI is how your users will judge your application.</h3>
<p>Most of our work as developers goes into the back end but we are judged on the front end. When was the last time a user said, “Your data model is fantastic and I love how you have separated your concerns?”</li>
<li>
<h3>Don’t confuse Learnability with Usability.</h3>
<p>Usability is a measure of how productive and intuitive the UI is for the average user. Learnability is a measure of how quickly a user can learn a new application.</li>
<li>
<h3>Most of your users are “Good &#8211; Average” level users.</h3>
<p><span style="font-size: 10pt;">A user will quickly transition from a beginner user to an average user while very few will ever become expert users. Yet, as developers, we often program to those two extremes. Refocus your efforts on the majority of users who are somewhere in between. Note that for a public site this paradigm is a little different as the majority of users may very well be beginners who only visit occasionally</span></li>
<li>
<h3>Performance Tuning comes after development.</h3>
<p>You will never really know what areas of your application will be bottleneck until people are actually using it.  If you attempt to tweak your application for performance in advance, you will just be guessing, and often incorrectly.</li>
<li>
<h3>Decompose your performance problems.</h3>
<p>By creating tests for each tier independently you can determine which tier is your bottleneck or if your problems are elsewhere, like a 10Base-T hub between your server and firewall.</li>
<li>
<h3>Sometimes you need to cache less for better performance.</h3>
<p>Cached items are low priority so they can be thrown out by the garbage collector when resources need to be freed. If you are caching<br />
too much you could actually be forcing the system to run out of resources thereby forcing the system to purge your caches. Only cache things that have high usage.</li>
<li>
<h3>Go download jQuery UI.</h3>
<p>This framework can help you do some amazing things with the UI, from tabs to modal dialog, this framework is slick.</li>
<li>
<h3>jQuery is better with ASP.NET MVC.</h3>
<p>Because MVC developers are often in a bare metal HTML frame of mind, not because of any technical limitations.</p>
<p>My first DevConnections has been a fantastic experience. I heard some phenomenal speakers, met new developers from all over the world, and sharpened my saw. I am excited to bring the things I’ve learned back to our team. But first I am going to have a restful weekend – I never thought a conference could be so exhausting.</p>
<p>If you have any questions about this series of posts or about DevConnections, feel free to send me an email (jimmy.bosseATthycotic.com) or message me on Twitter @jimmybosse.</p>
<p class="authorblock" style="padding:10px;"><em><em>Jimmy Bosse is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/jimmybosse"> Follow Jimmy </a></p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-four/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Top 10 Takeaways from DevConnections Day Three</title>
		<link>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-three</link>
		<comments>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-three#comments</comments>
		<pubDate>Thu, 12 Nov 2009 14:48:19 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[DevConnections]]></category>
		<category><![CDATA[$.fn]]></category>
		<category><![CDATA[Firebug .NET]]></category>
		<category><![CDATA[Namespaces in Javascript]]></category>
		<category><![CDATA[Service locator Dependecy Injection]]></category>
		<category><![CDATA[Single Responsibility]]></category>
		<category><![CDATA[Tablix new]]></category>
		<category><![CDATA[WCF and .asmx]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=424</guid>
		<description><![CDATA[Wednesday seemed to go at a breakneck pace. The sessions I attended on Tuesday were all given by Microsoft employees and only one
presenter used VS 2008. These presentations were all about how I was going to get things done when VS 2010 launches (allegedly in March 2010.)
The sessions I attended on Wednesday have more to do with how to get things done today (or when we get home from the conference) and everyone was using VS 2008.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><img style="vertical-align: middle" src="http://teststore.thycotic.net/images/jimmy_partial_devconnections.jpg" alt="" width="500" height="225" /></p>
<h5 style="text-align: right">November 10th 2009 | Jimmy Bosse</h5>
<p><strong>Top 10 Takeaways from DevConnections Day Three<br />
</strong></p>
<p>Wednesday seemed to go at a breakneck pace. The sessions I attended on Tuesday were all given by Microsoft employees and only one<br />
presenter used VS 2008. These presentations were all about how I was going to get things done when VS 2010 launches (allegedly in March 2010.)<br />
The sessions I attended on Wednesday had more to do with how to get things done, today (or when we get home from the conference), and everyone was using VS 2008.</p>
<p>My biggest complaint about DevConnections is there are too many good sessions. There were several sessions that I wanted to attend that were in conflict with one another.<br />
The sessions I managed to settle on were:</p>
<ul>
<li> What ASP.NET Developers Should Know About JavaScript by Scott Allen</li>
<li> Introduction to jQuery with ASP.NET by Rick Strahl</li>
<li> WCF the Manual way&#8230; the Right way by Miguel Castro</li>
<li> .NET Rocks!- SQL Server Reporting Services by Carl Franklin &amp; Richard Campbell with guest Paul Litwin</li>
<li> Refactoring Today’s .NET Code to Good Design Practices by Dino Esposito</li>
</ul>
<p>And so, without further ado, the top 10 takeaways from day three:</p>
<ol>
<li>
<h3>Get the FireBug plug-in.</h3>
<p>It seems like every presenter uses FireBug in Firefox, even the Microsoft team. It is very useful when working with your web UI. <a href="http://getfirebug.com" target="_blank">Go get it</a> if you haven’t already.</li>
<li>
<h3>Use $.fn to create your own jQuery plug-ins.</h3>
<p><span style="font-family: tahoma; font-size: x-small;"><span style="font-size: small;"><span style="font-family: Calibri;">jQuery is such an amazingly fluent framework and so easy to extend to your own needs.</span></span></span></li>
<li>
<h3>You can create pseudo namespaces in JavaScript.</h3>
<p>For example, if you want to create a Point object in a Geometry namespace:<br />
var Geometry = {};<br />
Geometry.Point = function(x, y) {…</li>
<li>
<h3>Use “JavaScript-Behind” for your pages.</h3>
<p>It is easy to inline your JavaScript, but for anything other than the most trivial tasks you should move your JavaScript to .js files.</li>
<li>
<h3>Don’t make any new .asmx pages.</h3>
<p>Use WCF. Microsoft no longer supports WSE (.asmx) web services. Your existing services will work, but don’t make any new ones.</li>
<li>
<h3>Write your own WCF services without the project templates.</h3>
<p>Although the WCF project types are helpful to get you up and running quickly, they are full of stuff you don’t need and can make your job harder in the long run. Miguel Castro has a good article on this topic <a href="http://www.code-magazine.com/Article.aspx?quickid=0809101" target="_blank">here</a>.</li>
<li>
<h3>Microsoft has merged the Matrix , Table, and List regions  into a Tablix.</h3>
<p>A silly name but a very useful change. How many times have you wanted to add a static column to a Matrix or otherwise mix a table with a Matrix? Many times, I know. Now it is possible with the Tablix.</li>
<li>
<h3>The Code window in Reporting Services still sucks.</h3>
<p>Sorry, I wish I had better news.</li>
<li>
<h3>Single Responsibility Principle is a Principle, not a Law.</h3>
<p>You are striving to give a class one reason to change, not extract every line of code into its own class.  A Principle means that you aim to code towards a goal but have to also balance that with the needs and design of your system and the problems you are trying to solve.<br />
Shameless Plug: Dino Esposito,  IDesign software architect and author,  asked me about our Single Responsibility <a href="http://www.thycotic.com/the-dangers-of-single-responsibility-in-programming" target="_blank">blog post</a> by my colleague David Cooskey.</li>
<li>
<h3>Service Locator is good. Dependency Injection is better.</h3>
<p>With service locators, the “injection” of the dependency is being done from within the class itself. This makes it hard to identify<br />
these dependencies from outside the class. With dependency injection, these dependencies are easy to identify.</p>
<p>Today promises to be another flurry of fantastic sessions. Check back tomorrow for more highlights from DevConnections.</p>
<p class="authorblock" style="padding:10px;"><em><em>Jimmy Bosse is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/jimmybosse"> Follow Jimmy </a></p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-three/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Top 10 Takeaways from DevConnections Day Two</title>
		<link>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-two</link>
		<comments>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-two#comments</comments>
		<pubDate>Wed, 11 Nov 2009 15:10:54 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[DevConnections]]></category>
		<category><![CDATA[AJAX Control Tool kit]]></category>
		<category><![CDATA[asp .net MVC]]></category>
		<category><![CDATA[Charlie Calvert]]></category>
		<category><![CDATA[future of C#]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=418</guid>
		<description><![CDATA[After a quick coffee break and then 4 great sessions: The Future of C# by Charlie Calvert. What’s New in ASP.NET MVC. What’s New in the AJAX Control Toolkit and Microsoft Ajax Library (#devconnajax) by Jim Wang (@turanuk) and James Senior (@jsenior)Testing in ASP.NET by Federico Silva Armas
]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><img style="vertical-align: middle" src="http://teststore.thycotic.net/images/jimmy_partial_devconnections.jpg" alt="" width="500" height="225" /></p>
<h5 style="text-align: right">November 10th 2009 | Jimmy Bosse</h5>
<p><strong>Top 10 Takeaways from DevConnections Day Two<br />
</strong></p>
<p>Tuesday at DevConnections (#devconnections) was a whirlwind of excellent sessions by the Microsoft ASP.NET team. It started with the Keynote by Scott Guthrie (@scottgu) and went on to feature what&#8217;s new in ASP.NET 4.0 and VS 2010 Web Development. Shortly after were four great sessions:</p>
<ul>
<li>The Future of C# by Charlie Calvert. </li>
<li>What’s New in ASP.NET MVC. </li>
<li>What’s New in the AJAX Control Toolkit and Microsoft Ajax Library (#devconnajax) by Jim Wang (@turanuk) and James Senior (@jsenior)</li>
<li>Testing in ASP.NET by Federico Silva Armas</li>
</ul>
<p>After so many enlightening sessions, my Evernote notebook is filled with many amazing things that I learned, even with my laptop battery dying twice. It is hard to whittle them down to ten but here goes, again in no particular order.</p>
<ol>
<li>
<h3>
	VS 2010 supports multiple monitors.</h3>
<p>
	You can finally move a document off the tab and onto a second monitor. Now you don’t have to waste that beautiful 24” monitor just filling it with palettes!
	</p>
</li>
<li>
<h3>
	The Web.Config file of a new web project is empty.<br />
	</h3>
<p>
	Ok it has a few lines of XML, but it is no longer War &#038; Peace.
	</p>
</li>
<li>
<h3>C# will now have named parameters.<br />
	</h3>
<p>
	At first this gave me flashbacks of Objective-C, but I have come to embrace this new feature. While today’s IDEs make it easy to see the<br />
	signature of methods to understand what the parameters of a method call are, it is great at quick glance to see explicitly what each one<br />
	is without having to dig into the code, like in a printout or blog post.
	</p>
</li>
<li>
<h3>
	C# and VB will have access to the DLR.<br />
	</h3>
<p>
	Sitting on top of the Dynamic Language Runtime will allow your C# code to create a variable of type dynamic to hold references to objects<br />
	(like COM Interop) and call methods you know exist on those objects, without the compiler complaining.
	</p>
</li>
<li>
<h3>
	Say goodbye to <%= Html.Encode({something}) %><br />
	</h3>
<p>
	And hello to <%: {something} %>. Isn’t that better?
	</p>
</li>
<li>
<h3>
	Areas will help you with your giant Controller directory<br />
	</h3>
<p>
	A new feature called &#8220;Areas&#8221;, will allow you to divide your giant MVC projects into more logical directory structures.
	</p>
</li>
<li>
<h3>
	Microsoft Ajax Minifier<br />
	</h3>
<p>
	If performance is paramount in your website, this tool will squeeze every last byte out of your JavaScript libraries.
	</p>
</li>
<li>
<h3>
	Ajax Library Preview 6.<br />
	</h3>
<p>
	The demos from this library were really slick. Go get it and make your website sparkle.
	</p>
</li>
<li>
<h3>
	Lightweight Test Automation Framework<br />
	</h3>
<p>
	While there are too many automated UI testing frameworks out there, experience has shown that each one is good for different<br />
	testing scenarios. You can quickly tack LTAF on to your website and get started with UI testing.
	</p>
</li>
<li>
<h3>
	Custom Logging for LTAF<br />
	</h3>
<p>
	Extending logging in LTAF to meet your needs is nice. Federico even mentioned a custom logger that would screenshot<br />
	the browser when the test failed. Now that is a great idea!
	</p>
</li>
<li>
<h3>
	<strong> BONUS!!! </strong> WebSiteSpark<br />
	</h3>
<p>
	If you are and independent developer or a small shop, check out WebSiteSpark (http://www.microsoft.com/web/websitespark/).<br />
	For $100 you get access to an amazing set of Microsoft tools and technologies to help get you started.
	</p>
</li>
<p> Today promises to be another flurry of fantastic sessions. Check back tomorrow for more highlights from DevConnections.</p>
<p class="authorblock" style="padding:10px;"><em><em>Jimmy Bosse is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em> On Twitter? <a href="http://twitter.com/jimmybosse"> Follow Jimmy </a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-two/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Top 10 Takeaways from DevConnections Day One</title>
		<link>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-one</link>
		<comments>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-one#comments</comments>
		<pubDate>Tue, 10 Nov 2009 21:03:03 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[DevConnections]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=412</guid>
		<description><![CDATA[There were many tidbits of information that I thought were important to remember and at the lunch break I decided that I would post for you the Top 10 things tidbits (in no particular order) I took away from Dan’s presentation.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center"><img style="vertical-align: middle" src="http://teststore.thycotic.net/images/jimmy_partial_devconnections.jpg" alt="" width="500" height="225" /></p>
<h5 style="text-align: right">November 10th 2009 | Jimmy Bosse</h5>
<p><strong>Top 10 Takeaways from DevConnections Day One<br />
</strong></p>
<p>Yesterday I attended the pre-conference workshop, “SharePoint Jump Start: Reimagining Collaboration” hosted by Dan Holme. This workshop was a great tour on getting your first SharePoint site up and running, with an expert guide warning you of the pitfalls and gotchas you might encounter; the best way to introduce your users to collaboration; and some basic business intelligence to wow your boss, without any code. </p>
<p>There were many tidbits of information that I thought were important to remember and at the lunch break I decided that I would post for you the Top 10 things (in no particular order) I took away from Dan’s presentation.</p>
<ol>
<li>
<h3>Use the “Advanced” installation option.</h3>
<p>The basic option is a quick choice for when you are evaluating SharePoint, but installing from the Basic option will prevent you from scaling your installation in the future.</p>
</li>
<li>
<h3>Create a SharePoint Administrator account to use for installation.</h3>
<p>SharePoint will embed the account in several locations, and a dedicated administrative account for SharePoint will avoid headaches in the future.</p>
</li>
<li>
<h3>Ensure the Host Headers you use for your Sites are A Records, not C Records.</h3>
<p>The C Record aliasing will cause problems down the road. If you are using C Records, convert them to A Records.</p>
</li>
<li>
<h3>Enforce Check-In/Check-Out on all your libraries.</h3>
<p>Ensuring your users are locking files they are editing will prevent conflicts.</p>
</li>
<li>
<h3>Give managers “Override Check-Out” permission.</h3>
<p>Someone will check out a file and then not be available to check it in when you need it. You won’t have to field calls from<br />
	managers needing to unlock a file if you create a role for the permission and assign it to your managers. </p>
</li>
<li>
<h3>The names of objects you create are often their URLs.</h3>
<p>Most of the time when you are creating Libraries, Sites, etc. in SharePoint, the name you give it in the creation<br />
	forms will also be the URL for that object. Make sure your keep the name short and avoid spaces. You can usually edit the “friendly name” that is displayed in the UI later.</p>
</li>
<li>
<h3>Limit the number of versions in your Document Libraries.</h3>
<p>SharePoint does not diff the changes when storing your versions. Every version is a complete copy taking<br />
	up space in your database. If you do not cap the number of versions, you will quickly run out of space in your database.</p>
</li>
<li>
<h3>Most of the “Workflow” requests of your users can be handled with alerts.</h3>
<p>If a workflow request starts with, “I want to be emailed when…” then an alert will probably be the simplest option.</p>
</li>
<li>
<h3>You can use SharePoint lists as data for your Excel pivot tables.</h3>
<p>This can enable you to provide some basic but impressive “Business Intelligence” functionality quickly and easily.</p>
</li>
<li>
<h3>Folders are obsolete in a Metadata world.</h3>
<p>You don’t need folders to organize your documents. If you collect the proper metadata about your documents<br />
	it is easier for your users to find information than even the best intentioned folder structure. I loved Dan’s<br />
	example of this, “Say you have a photo library with a directory for beach photos, sunset photos, and dog photos.<br />
	What do you do with the photo of a dog at the beach during sunset?”</p>
</li>
</ol>
<p> The session was extremely useful and Dan is a great speaker. I recommend you attend a session with him if you get the chance.  If Day One was an indication of the rest of the conference, it will turn out to be great week. </p>
<p class="authorblock" style="padding:10px;"><em><em>Jimmy Bosse is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC.  Secret Server is our flagship </em><a href="/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/top-10-takeaways-from-devconnections-day-one/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tortoise more than just version control</title>
		<link>http://www.thycotic.com/tortoise-more-than-just-version-control</link>
		<comments>http://www.thycotic.com/tortoise-more-than-just-version-control#comments</comments>
		<pubDate>Mon, 09 Nov 2009 16:02:27 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=409</guid>
		<description><![CDATA[For most developers version control, or source control, is a minimum requirement. The primary purpose of version control is to enable multiple team members to work in the code without stepping on one another’s toes. It is also great for branching (creating a new direction in the code that may or may not be integrated back in to trunk) and tagging (marking a particular snapshot of the code, such as a release)]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/jimmy_SVN.jpg" alt="" width="500" height="225" /></p>
<h6>August 24th 2009 | Jimmy Bosse</h6>
<p>For most developers version control, or source control, is a minimum requirement. The primary purpose of version control is to enable multiple team members to work in the code without stepping on one another’s toes. It is also great for branching (creating a new direction in the code that may or may not be integrated back in to trunk) and tagging (marking a particular snapshot of the code, such as a release).</p>
<p><strong>Our Subversion Repository is the ultimate code documentation.</strong></p>
<p>Using source control as documentation is a whole lot better than placing comments inside your code. If you need to write a comment to explain what your code does, then its logic probably needs simplifying. Well-commented commit notes, on the other hand, remind you exactly what you were thinking when you first committed that code.</p>
<ul>Good commit notes contain four important elements:</p>
<li>An explanation: WHY? Explain why you are writing the code.</li>
<li>The Identity of the Writer. We use the initials of the pair committing the code.</li>
<li>Story Number. An identifier linking the commit to the user story it is implementing.</li>
<li>A Summary. Brief notes about what you are trying to achieve in the code you are submitting.</li>
</ul>
<p><strong>The most important one is WHY.</strong></p>
<p>We frequently find ourselves looking at a block of code and trying to figure out why it’s there. The longer a piece of code remains in a codebase, the greater the chance you’ll forget why it was written in the first place. If good commit notes were written, the “blame” feature becomes your best friend. Its name is misleading as it implies that its purpose is to reveal the culprit who broke something, but in fact it is intended to remind you who wrote the code, and the purpose for which they wrote it. If you are fortunate enough to have a repository for your user stories, you’ll always have a sense of the bigger picture at the time the code was written.</p>
<p>As you work on a software project, your understanding of the problem evolves, as does your approach to the solution. Something that is obvious and finely-crafted today might look like a silly hack to you six months from now.</p>
<p>Leave your future self a note as to how awesome you thought you were at the time. <em>You’ll thank yourself for it—and so will your team members.</em><strong> </strong></p>
<p><strong><em><em>Jimmy Bosse is a Team Lead at Thycotic Software, an agile software services and product development company based in Washington DC. Secret Server is our flagship </em><a href="http://www.thycotic.com/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/tortoise-more-than-just-version-control/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build Your Solutions from the Context Menu</title>
		<link>http://www.thycotic.com/build-your-solutions-from-the-context-menu</link>
		<comments>http://www.thycotic.com/build-your-solutions-from-the-context-menu#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:52:26 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[General Software Development]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=406</guid>
		<description><![CDATA[Many times you want to quickly refresh your solution from the repository and quickly build it without having to open Visual Studio. Follow these simple steps to add a Registry Key that will add a context menu for you solution files.]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img style="vertical-align: middle;" src="../wp-content/uploads/2009/06/QuickTip.jpg" alt="Quickly look up table information in SQL Server Management Studio" width="500" height="225" /></p>
<h5 style="text-align: right;">Sept 2nd 2009 | Jimmy Bosse</h5>
<p><strong>Build Your Solutions from the Context Menu<br />
</strong></p>
<p>Many times you want to quickly refresh your solution from the repository and quickly build it without having to open Visual Studio. Follow these simple steps to add a Registry Key that will add a context menu for you solution files.</p>
<p>Launch RegEdit: Start &gt; Run &gt; type regedit &gt; click OK.</p>
<p>Navigate to HKEY_CLASSES_ROOT &gt; SystemFileAssociations.</p>
<p>If there is no “.sln” key, add a key for “.sln”.</p>
<p>If there is no key for “shell” in “.sln” then add a key for “shell”.</p>
<p>Add a “Build Solution” key in “shell”.</p>
<p>Add a “command” key to “Build Solution”.</p>
<p>Set the default value for command to:</p>
<p>cmd.exe /k “call “%%VS90COMNTOOLS%%\vsvars32.bat” x86&amp;&amp;msbuild “”%1″” /p:Configuration=Debug /t:Rebuild /l:FileLogger,Microsoft.Build.Engine;logfile=MSBuildDebug.log&amp;&amp;pause&amp;&amp;exit”</p>
<p>Reboot, and now you can build your solution file from the context menu.</p>
<p><strong>Tada!</strong></p>
<p>Note that this specific entry will only build debug builds for 2008 solutions. You can modify the VS90COMNTOOLS and Configuration=Debug to add entries for other versions of Visual Studio and other build configurations.</p>
<p style="padding: 10px; margin-bottom: 30px;"><em><em>Jimmy Bosse is a Team Lead at Thycotic Software, an agile software consulting and product development company based in Washington DC. Secret Server is our flagship </em><a href="../products_secretserver_overview.html" target="_blank"><em>enterprise password management</em></a><em> product.</em></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/build-your-solutions-from-the-context-menu/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Bridge Pattern – When a single class hierarchy is not enough</title>
		<link>http://www.thycotic.com/the-bridge-pattern-when-a-single-class-hierarchy-is-not-enough</link>
		<comments>http://www.thycotic.com/the-bridge-pattern-when-a-single-class-hierarchy-is-not-enough#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:41:54 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[Extreme Programming]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=399</guid>
		<description><![CDATA[The bridge pattern allows both the implementation and the abstraction of a programming scenario to vary. Let’s take a look at a specific use case in order to understand the benefit the bridge pattern provides. Imagine we are writing a top-down scrolling action game. The player will be able to choose from a variety of vehicles and will be up against a maze full of passive and active obstacles. In order to increase replayability, the vehicles available will include tanks, helicopters, and motorcycles, with expansions planned to include additional vehicles.]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/DavidCookseyBridge.jpg" alt="" width="500" height="225" /></p>
<h6>September 10th 2009 | David Cooksey</h6>
<p><strong>The Bridge Pattern – When a single class hierarchy is not enough</strong></p>
<p>The bridge pattern allows both the implementation and the abstraction of a programming scenario to vary. Let’s take a look at a specific use case in order to understand the benefit the bridge pattern provides.</p>
<p><strong>Imagine we are writing a top-down scrolling action game. </strong>The player will be able to choose from a variety of vehicles and will be up against a maze full of passive and active obstacles. In order to increase replayability, the vehicles available will include tanks, helicopters, and motorcycles, with expansions planned to include additional vehicles. Tanks will have a cannon and a machine gun, helicopters will have missiles and a machine gun, while the motorcycle will allow the player to throw grenades and wield a samurai sword. Throughout the course of the game, upgrades will alter the abilities of each weapon (better missiles, more ammo for the machine gun, swords of awesome lethality, etc).</p>
<p>So, how do we plan our class structure in such a way that we can treat each vehicle the same at the high level, while allowing for flexibility in both the selected vehicle and the weapons it is currently using?</p>
<p>Ideally our top-level implementation should allow us to do something like PlayerVehicle.FireWeapon1() without concerning ourselves with the specific vehicle or weapon the player is using.</p>
<p><strong>The bridge pattern gives us the flexibility we need.</strong></p>
<p>First we create a vehicle base class.</p>
<pre>  public abstract class Vehicle
{
public IWeapon weapon1;
public IWeapon weapon2;

public abstract void Move();
public void ShootWeapon1()
{
weapon1.Fire();
}

public void ShootWeapon2()
{
weapon2.Fire();
}
}</pre>
<p>By leveraging the “has-a” relationship between a vehicle and its weapons we allow the weapons to vary. The exposed ShootWeapon1 and ShootWeapon2 functions perform the same function in this case as calling .weapon1.Fire() on the vehicle itself. By making Vehicle an abstract class we leave all details of movement up to its concrete implementations.</p>
<pre>public class Tank : Vehicle
{
public Tank()
{
weapon1 = new SimpleCannon();
weapon2 = new BasicMachineGun();
}

public override void Move()
{
// Check for physical obstacle, if no obstacle move the tank.
}
}

public class Helicopter : Vehicle
{
public Helicopter()
{
weapon1 = new AirToAirMissile();
weapon2 = new BasicMachineGun();
}

public override void Move()
{
// Move helicopter
}
}</pre>
<p>As a result, both the Tank and Helicopter listed above will work as the vehicle in the following code sample.</p>
<pre>      Vehicle vehicle = new Tank();

vehicle.Move();
vehicle.ShootWeapon1();
vehicle.ShootWeapon2();</pre>
<p>The bridge pattern allows us to change vehicles and weapons independently. This concept is extensible to as many degrees as are necessary to allow independent variation. For example, a futuristic update to the game might add varying kinds of passive or reactive shields to the vehicles. No problem, just create an IShield interface and add it to the Vehicle abstract class.</p>
<p>Essentially, the bridge pattern is just an implementation of a recognition that two concepts exist in a “has-a” relationship and need to vary independently. As such, it provides the required flexibility with no drawback other than a small increase in the complexity of the class hierarchy.</p>
<p><strong> </strong></p>
<p><strong><em><em>David Cooksey is a Senior .NET Consultant at Thycotic Software, an agile software services and product development company based in Washington DC. Secret Server is our flagship </em><a href="http://www.thycotic.com/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/the-bridge-pattern-when-a-single-class-hierarchy-is-not-enough/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>These aren’t your father’s regular expressions</title>
		<link>http://www.thycotic.com/these-arent-your-fathers-regular-expressions</link>
		<comments>http://www.thycotic.com/these-arent-your-fathers-regular-expressions#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:34:25 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[1]]></category>
		<category><![CDATA[-g construct]]></category>
		<category><![CDATA[.NET regex]]></category>
		<category><![CDATA[.NET regular expressions]]></category>
		<category><![CDATA[gstack]]></category>
		<category><![CDATA[regex capture group]]></category>
		<category><![CDATA[RegexOptions.IgnorePatternWhitespace]]></category>
		<category><![CDATA[regexs. regular expressions]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=396</guid>
		<description><![CDATA[Now I’ll demonstrate how to match two different kinds of balanced expressions. The first will be strings of the form “()” “(())” “((()))” “(((())))”. When we match this kind of of regular expression there are essentially two phases: pushing elements onto the stack as we match the opening parentheses, and popping them off the stack as we match the closing parentheses. The Regexp that matches this expression is:]]></description>
			<content:encoded><![CDATA[<p><img src="http://teststore.thycotic.net/images/MorganRegularExpressions.jpg" alt="" width="500" height="225" /></p>
<h6>September 17th 2009 | Morgan Kleene</h6>
<p><strong>These aren’t your father’s regular expressions</strong></p>
<p>Regular expressions, as they’re traditionally defined, make it impossible to match balanced patterns like “ab”,” aabb”,”aaabbb”, “aaaabbbb”, etc. The Microsoft.NET implementation has augmented traditional regular expressions with new features that allow us to match arbitrary balanced constructs.</p>
<p>I’ll demonstrate a few patterns and build up to a Regular expression that matches a small xml-like language.</p>
<p>There are a few Regexp language ingredients that allow us to match balanced patterns. The first is the named ‘capture group’, and its interesting implementation in .NET. Given the Regex “^a(?abc)(?123)b$” consider what happens when we execute it on the string “aabc123b”: Both “abc” and “123” are captured by the group “g”. The following code demonstrates this by printing out “abc” and then “123”:</p>
<pre>Regex r = new Regex(@"^a(?&lt;g&gt;abc)(?&lt;g&gt;123)b$");
      foreach (var s in r.Match("aabc123b").Groups["g"].Captures)
      {
          Console.WriteLine(s);
      }</pre>
<p><em>NOTE: the ‘^’ at the beginning of the Regex means to only match at the beginning of line and the ‘$’ means to match only at the end of the line.</em></p>
<p>Imagine a stack associated with each group, in our case <em>g</em>, onto which the captured elements are pushed. Most stacks can be popped as well as pushed, right? These stacks can as well. By labeling the second group <em>–g</em> instead of <em>g</em>, matching the text in the parentheses pops off the top element of the <em>g </em>stack. So the following code prints absolutely nothing. Matching the “123” pops “abc” off of the <em>g</em> stack.</p>
<pre>Regex r = new Regex(@"^a(?&lt;g&gt;abc)(?&lt;-g&gt;123)b$");
      foreach (var s in r.Match("aabc123b").Groups["g"].Captures)
      {
          Console.WriteLine(s);
      }</pre>
<p>An important aspect of the <em>-g</em> construct is that if the <em>g</em> stack is empty then the elements enclosed cannot be matched. The expression “^(&lt;g&gt;a)(&lt;-g&gt;a)(&lt;-g&gt;a)$” will never be matched.</p>
<p>Now I’ll demonstrate how to match two different kinds of balanced expressions. The first will be strings of the form “()” “(())” “((()))” “(((())))”. When we match this kind of of regular expression there are essentially two phases: pushing elements onto the stack as we match the opening parentheses, and popping them off the stack as we match the closing parentheses. The Regexp that matches this expression is:</p>
<pre>@"^(?&lt;p&gt;\()*(?&lt;-p&gt;\))*(?(p)(?!))$"</pre>
<p>The only new part is the (?(p)(?!)) construct at the end of the line. This construct means that if the <em>p</em> group is nonempty then we should match the pattern “?!”. The pattern “?!” is a negative lookahead, in this case with no argument. This means that the entire pattern matches only in the case that it is not followed by the space between words, which is impossible. What this pattern does is force failure when the <em>p</em> group is not empty to prevent matching things like “((()”, where all the opening parentheses are not consumed by the closing parentheses.</p>
<p>The previous regex does not deal with things like “()((()))(())” because we have restricted all opening parentheses to precede all closing parentheses. It is a simple matter to change this, and allow the parentheses to occur in any order. The following regex will match all strings of balanced parentheses:</p>
<pre>@“^(?:
(?&lt;p&gt;\()
|
(?&lt;-p&gt;\))
    )*
(?(p)(?!))$”</pre>
<p><em>NOTE: this is compiled using the RegexOptions.IgnorePatternWhitespace option, to allow spacing for clarity.</em></p>
<p>We can think of this expression as “Match an opening parenthesis and push it on the p stack. Match a closing parenthesis and pop the p stack only if the p stack contains an opening parenthesis. If we reach the end of the expression assert that the <em>p</em> stack is empty.”</p>
<p>Think about what happens in these examples: Consider the string “(((”. This fails because the group “p” contains “(((“ when we reach the end of the string. Consider the string “)(“. This fails because the only time we match a closing parenthesis is when there is an opening parenthesis on the “p” stack; the first character is never matched.</p>
<p>We must make sure that we only match things that we’ve seen before. In .NET that’s a breeze. The “\k&lt;g&gt;” construct gives us access to the top of the stack associated with the <em>g</em> group.</p>
<pre>Regex r = new Regex(@"^(?&lt;g&gt;abc)(?&lt;-g&gt;\k&lt;g&gt;)$");
      foreach (var s in r.Match("abcabc").Groups["g"].Captures)
      {
          Console.WriteLine(s);
      }</pre>
<p>In the above code, nothing is printed. We match “abc”, push “abc” on the top of the <em>g</em> stack and then pop everything off the <em>g</em> stack when we reach the <em>-g</em> group and the “\k&lt;g&gt;” construct matches what’s on top of the <em>g</em> stack.</p>
<p>Finally we’re ready to see the expression that matches an arbitrary html-like language. The regular expression matches a language with balanced opening and closing tags. There are no attributes or any inner content, but extending such an expression to deal with things like that shouldn’t be too much of a problem.</p>
<pre>@"^(?:
                            (?:&lt;(?&lt;tagName&gt;[^&gt;]+)&gt;)
                                    |
                              (?&lt;-tagName&gt;&lt;/\k&lt;tagName&gt;&gt;)
                            )*
                           (?(tagName)(?!))$"</pre>
<p>We first match the opening tag and capture the name of the tag to the</p>
<p>“tagName” group. When we encounter something that looks like a closing tag we only match (and pop the opening tag off of the “tagName” stack) if the same opening tag is already on the “tagName” stack. When we get to the end of the string we make sure that all opening tags have been matched by asserting that the “tagName” stack is empty.</p>
<p>.NET Regular expressions are a bit more powerful than the Regexes most of us are used to due to the addition of a stack that can push and pop arbitrary elements. If you have a simple, balanced pattern to match they can be extremely helpful.</p>
<p>References</p>
<p>[1] Friedl, J. 2006 <em>Mastering Regular Expressions</em>. O’Reilly Media, Inc.</p>
<p><strong><em><em>Morgan Kleene is a Senior .NET consultant at Thycotic Software, an agile software services and product development company based in Washington DC. Secret Server is our flagship </em><a href="http://www.thycotic.com/products_secretserver_overview.html"><em>password management software</em></a><em> product.</em></em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/these-arent-your-fathers-regular-expressions/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
