<?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>Thu, 11 Mar 2010 20:49:32 +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>Outlook Folder Macros for Getting Things Done</title>
		<link>http://www.thycotic.com/outlook-folder-macros-for-getting-things-done</link>
		<comments>http://www.thycotic.com/outlook-folder-macros-for-getting-things-done#comments</comments>
		<pubDate>Fri, 05 Mar 2010 17:25:46 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[GTD]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=528</guid>
		<description><![CDATA[I have been using GTD (Getting Things Done) for about 5 years now and it works. It is a great system to manage all aspects of your work and personal life. The turning point for me was when I had too many tasks and correspondence to manage in my head or my inbox. GTD allows you to create “contexts” where you will do work – for example @home, @computer, @phone, @errands,]]></description>
			<content:encoded><![CDATA[<p><img src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/JonathanMacros.jpg" alt=".NET Quirks" width="500" height="225" /></p>
<h6 style="clear:both">March 5th | Jonathan Cogley</h6>
<p>I have been using GTD (Getting Things Done) for about 5 years now and it works. It is a great system to manage all aspects of your work and personal life. The turning point for me was when I had too many tasks and correspondence to manage in my head or my inbox. GTD allows you to create “contexts” where you will do work – for example @home, @computer, @phone, @errands, @withAccountant, @withCindy or even just filing for future reference #Done. This lets you move items from your inbox to the proper place for the work to be done. This makes your inbox more of a processing center (with the focus being <strong>getting to zero</strong>). Getting your inbox to empty and knowing that all tasks are in the right places brings on a Zen-like feeling of calm and control <img src='http://www.thycotic.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  .</p>
<p>My tool for email is the corporate standard &#8211; Microsoft Outlook 2007. I love Outlook – it is an incredibly rich and powerful client which allows me to quickly move between my email and my calendar (don’t even get me started on web mail!). Creating “contexts” is easy – simply create folders representing each context and then move items from your inbox to each folder. And there begins the problem …</p>
<p>Moving items between folders in Outlook is painful – there are only two built-in options:</p>
<p>1) Drag the item using the mouse from your inbox to the folder (try that 50 times in one morning!).</p>
<p>2) Use the keyboard. Ctrl-Shift-V brings up the Move to Folder dialog, then navigate the folders using the cursor keys and hit Enter (also way too slow).</p>
<p><img style="clear:both" src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/Macro1.jpg" alt="" /></p>
<p style="clear:both"> What about an Outlook macro? Outlook has the capability to allow tedious items to be recorded or even coded using VBA (Visual Basic for Applications). Not exactly my language of choice but if it works, use it. You can access macros within Outlook by going to Tools | Macros | Visual Basic Editor. Right click on modules in the Project Explorer and click Insert | Module.
<p><a href="http://stagestore.thycotic.net/wp-content/uploads/2008/05/gtd-macros.txt"> &gt;&gt;See the Macros (.txt file) </a></p>
<p>The sub procedure “MoveToFolder” is really the meat of the code – it uses the recursive GetFolder to find folders by name anywhere in the inbox structure and then moves the selected items to the folder while also keeping track of items for undo. To get it all working, simply create new sub procedures for each context you want to target – for example: MoveToFolder_WaitingFor targets the “@waitingfor” folder. Save your macros and close the Visual Basic Editor (you can return to it at any time to add more target sub procedures).</p>
<p>Now we need to tie these macros to shortcut keys and menu items. This is very easy in Outlook – right click on the menu toolbar and select “Customize”, go to the “Toolbars” tab.</p>
<p><img style="clear:both" src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/Macro2.jpg" alt="" /></p>
<p style="clear:both">Click “New” to create a new toolbar. Call it “GTD” (or whatever) and click OK. Now drag the new toolbar onto the main toolbar at the top of Outlook. Then right click the new toolbar, click “Customize”, then go to the Commands tab to find the macros. Drag macros to the toolbar, then right click on the new toolbar item to further customize the text, icon and keyboard shortcut. Note that the keyboard shortcut you select mustn’t interfere with other standard shortcut keys in Outlook else they won’t work (I have used ALT-\, ALT-o, ALT-C, etc).</p>
<p><img style="clear:both" src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/Macro3.jpg" alt="" /></p>
<p style="clear:both"> To add a new macro to move to a different folder, simply copy one of the existing ones, rename it and then add it to your toolbar. </p>
<p><strong>Were these macros helpful? How do you manage your email GTD-style?</strong></p>
<p><em>Note: I did have some trouble implementing “Undo” for the folder moves (essential for when you accidentally move the wrong thing!). Outlook doesn’t seem to support Undo in the same manner as other VBA-enabled applications. Just map the “UndoMoveToFolder” to get it working.</em></p>
<p class="authorblock" style="padding:10px;"><em><em>Jonathan Cogley is the CEO of 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"><em>enterprise password management</em></a><em> product.</em><strong>Are you on Twitter? <a href="http://www.twitter.com/JonathanCogley"> Follow Jonathan </a></strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thycotic.com/outlook-folder-macros-for-getting-things-done/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thinking in Regex A Csharp Regex Tutorial with Examples</title>
		<link>http://www.thycotic.com/thinking-in-regex-a-csharp-regex-tutorial-with-examples</link>
		<comments>http://www.thycotic.com/thinking-in-regex-a-csharp-regex-tutorial-with-examples#comments</comments>
		<pubDate>Thu, 04 Mar 2010 15:07:55 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=520</guid>
		<description><![CDATA[Regular Expressions (regex) can be a difficult language to learn. The terse syntax is one factor—regex—are notoriously difficult to read, but another factor is the problem space. Pattern-matching problems require a different mindset than software development in general. However, if you can phrase the question in precise terms, translation to regex becomes easier, even trivial in many cases.]]></description>
			<content:encoded><![CDATA[<p><img src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/DavidCookseyRegex.jpg" alt="Regular Expressions" width="500" height="225" /></p>
<h6 style="clear:both">March 4th | 2009</h6>
<p><strong>Thinking in Regex &#8211; A C# Regex Tutorial with Examples<br />
</strong></p>
<p>Regular Expressions (regex) can be a difficult language to learn.The terse syntax is one factor-regex are notoriously difficult to read-but another factor is the problem space. Pattern-matching problems require a different mindset than software development in general. However, if you can phrase the question in precise terms, translation to regex becomes easier, even trivial in many cases.</p>
<p>Given this, there are a few things to keep in mind when tackling a problem with regex.</p>
<ol>
<li><strong>Be specific in your requirements. </strong>“I want to prevent bad characters” is not useful. “I want to exclude asterisks” is useful.</li>
<li><strong>Know the text your regex will run on.</strong> A regex to match a URL can be very simple, or as complex as this <a href="http://internet.ls-la.net/folklore/url-regexpr.html">monster</a>. The goal is the simplest regex that will always work with your input text.</li>
<li><strong>Be sure you&#8217;re not matching too much.</strong> Once your regex is matching what you want it to match, test it against various not-quite-right text samples to avoid embarrassing mistakes.</li>
</ol>
<p>Let&#8217;s say that you have some html that looks roughly like this:</p>
<pre class="csharpcode"><span class="kwrd">&lt;</span><span class="html">body</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">form</span> <span class="attr">id</span><span class="kwrd">="form1"</span> <span class="attr">runat</span><span class="kwrd">="server"</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">div</span><span class="kwrd">&gt;</span>
        He <span class="attr">&amp;amp;</span> I are best buddies.
        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">="http://www.mywebsite.com/page.aspx?param1=1&amp;param2=2&amp;param3=3"</span><span class="kwrd">&gt;
</span>http://www.mywebsite.com/page.aspx?param1=1&amp;param2=2&amp;param3=3<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">="http://www.mywebsite.com/page2.aspx?param1=1&amp;param2=2&amp;param3=3"</span><span class="kwrd">&gt;
</span>http://www.mywebsite.com/page.aspx?param1=1&amp;param2=2&amp;param3=3<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">="http://www.mywebsite.com/page3.aspx?param1=1&amp;param2=2&amp;param3=3"</span><span class="kwrd">&gt;</span>
http://www.mywebsite.com/page.aspx?param1=1&amp;param2=2&amp;param3=3<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>
        <span class="kwrd">&lt;</span><span class="html">a</span> <span class="attr">href</span><span class="kwrd">="http://www.mywebsite.com/page4.aspx?param1=1&amp;param2=2&amp;param3=3"</span><span class="kwrd">&gt;
</span>http://www.mywebsite.com/page.aspx?param1=1&amp;param2=2&amp;param3=3<span class="kwrd">&lt;/</span><span class="html">a</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">div</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">form</span><span class="kwrd">&gt;</span>
<span class="kwrd">&lt;/</span><span class="html">body</span><span class="kwrd">&gt;</span></pre>
<p>There are many pages like this, some with many more links. You need to fix the ampersands displayed as the text of the link to be <strong>&amp;amp;</strong> but you do not want to replace ampersands within the href attribute or in the rest of the body of the page. This sounds a little tricky, so let&#8217;s refine our requirements.</p>
<p>We want to replace <strong>&amp;</strong> with <strong>&amp;amp;</strong> within the text part of an anchor tag only. We don&#8217;t want to replace <strong>&amp;</strong> when it is followed by <strong>amp;</strong></p>
<p>Better. But, what exactly does &#8216;text part&#8217; or &#8216;anchor tag&#8217; mean in terms of characters?</p>
<p>Specifically, we want to replace <strong>&amp;</strong> with <strong>&amp;amp;</strong> between the <em>&lt;a&gt;</em> and <em>&lt;/a&gt;</em> character blocks, unless immediately followed by <strong>amp;</strong></p>
<p>Now that we have phrased our task this way, it is much easier to form a solution. Let&#8217;s build a .Net regex to solve this problem. .Net supports variable length lookbehind (more on this following the example), so we can build our regex in neat groups that apply conditions surrounding the text we want to replace.</p>
<pre class="csharpcode">Regex.Replace(inputText, <span class="str">"&amp;"</span>, <span class="str">"&amp;amp;"</span>);</pre>
<p>This will replace any <strong>&amp;</strong> with <strong>&amp;amp;</strong> Now we want to apply our conditions.</p>
<p>1) Must not be followed by amp;</p>
<p>2) Must come after (be preceded by) &lt;a&gt;</p>
<p>3) Must be followed by &lt;/a&gt;</p>
<p>So the resulting regex looks like this:</p>
<pre class="csharpcode">Regex.Replace(inputText, <span class="str">@"(?&lt;=\&lt;a[^&lt;&gt;]*&gt;[^&lt;&gt;]*)&amp;(?!amp;)(?=[^&lt;&gt;]*&lt;/a&gt;)"</span>, <span class="str">"&amp;amp;"</span>);</pre>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="332" valign="top"><strong>Condition</strong></td>
<td width="332" valign="top"><strong>Regex</strong></td>
</tr>
<tr>
<td width="332" valign="top">Must not be followed by &amp;amp;</td>
<td width="332" valign="top">(?!amp;)</td>
</tr>
<tr>
<td width="332" valign="top">Must be preceded by &lt;a&gt; tag</td>
<td width="332" valign="top">(?&lt;=\&lt;a[^&lt;&gt;]*&gt;[^&lt;&gt;]*)</td>
</tr>
<tr>
<td width="332" valign="top">Must be followed by &lt;/a&gt;</td>
<td width="332" valign="top">(?=[^&lt;&gt;]*&lt;/a&gt;)</td>
</tr>
</tbody>
</table>
<p><strong>(?!, (?=,</strong> <strong>(?&lt;=</strong>, and <strong>(?&lt;!</strong> are lookarounds. <strong>&amp;(?!amp;)</strong> can be read as “Match <strong>&amp;</strong>, then check the next four characters. If they are <strong>amp;</strong> fail the match.” The other two conditions follow a similar pattern, requiring a preceding &lt;a ….. &gt; tag and a following &lt;/a&gt; tag before any <strong>&lt;</strong> or <strong>&gt; </strong>is encountered. Restricting the text within &lt; …. &gt; blocks from containing additional &lt;&gt; characters prevents our regex from spanning multiple anchor tags.</p>
<p>Two invaluable aids to learning and using regex in .NET are <a href="http://www.ultrapico.com/Expresso.htm">Expresso</a> (a regex tool written in .NET), and the helpful forum community at <a href="http://regexadvice.com/forums/68/ShowForum.aspx">RegexAdvice</a>. If regex interests you I highly recommend playing with the tool and browsing the forum. And since you’re still reading—this probably means you!<br />
<!-- .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 class="authorblock" style="padding:10px;"><em><em>David Cooksey is a Senior .NET Developer 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/thinking-in-regex-a-csharp-regex-tutorial-with-examples/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quirks in .NET &#8211; Part 2 Marshalling Booleans</title>
		<link>http://www.thycotic.com/quirks-in-net-part-2</link>
		<comments>http://www.thycotic.com/quirks-in-net-part-2#comments</comments>
		<pubDate>Thu, 25 Feb 2010 14:29:22 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=512</guid>
		<description><![CDATA[This week Platform Invoke is under my microscope. It isn’t necessarily a quirk, but it can be a hair-pulling experience when you get it wrong. More specifically, getting the marshaling done properly. Even more challenging, getting it right on both 32-bit and 64-bit environments.]]></description>
			<content:encoded><![CDATA[<p><img src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/dotnetquirks.jpg" alt=".NET Quirks" width="500" height="225" /></p>
<h6 style="clear:both">February 25th | 2010</h6>
<p><strong>Quirks in .NET Part -2  Marshalling Booleans<br />
</strong></p>
<p>In <a href="http://www.thycotic.com/quirks-in-dot-net-part-1">Quirks in .NET – Part 1</a>, we talked about the quirky call vs. callvirt instructions.</p>
<p>This week <strong>Platform Invoke</strong> is under my microscope. It isn’t necessarily a quirk, but it can be a hair-pulling experience when you get it wrong. More specifically, getting the marshaling done properly. Even more challenging, getting it right on both 32-bit and 64-bit environments.</p>
<p><strong>Marshaling Booleans</strong></p>
<p>Marshaling is done primarily for two reasons: you need functionality that is not built into the .NET Framework, but is found in existing Win32 APIs; and you have existing functionality in an unmanaged library you want to reuse.</p>
<p>Let’s start with the basics: What managed types map to unmanaged types? Some are common sense and some are not. Let’s talk about the System.Boolean type for a second.</p>
<p>Most people assume it takes exactly 1 bit in managed world, but in memory it’s a byte. We can prove it with this code:</p>
<pre class="csharpcode"><span class="kwrd">int</span> sizeBoolean = <span class="kwrd">sizeof</span> (<span class="kwrd">bool</span>);
<span class="kwrd">int</span> sizeInt = <span class="kwrd">sizeof</span> (<span class="kwrd">int</span>);
Console.Out.WriteLine(<span class="str">"size of boolean = {0}"</span>, sizeBoolean);
Console.Out.WriteLine(<span class="str">"size of int = {0}"</span>, sizeInt);</pre>
<p>The size of operator returns the value in bytes, and a bool is 1. Here’s where things get tricky. In unmanaged world, there are two types—three really—BOOL, BOOLEAN, and COM’s VARIANT_BOOL.</p>
<p>The .NET Framework will try guess which one you mean when marshaling, but it won’t always get it right. When a managed bool is marshaled in a Platform Invoke method, it will marshal it automatically as a 4 byte type which is the more common marshaling case. However, if you cause an interface to get marshaled to COM and that interface has a Boolean as a return or method parameter, it will marshal it automatically as a 2-byte VARIANT_BOOL. Since COM interfaces tend to mix and match Booleans of different sizes, it’s always best to be explicit about <em>which</em> Boolean to marshal it to using the MarshalAsAttribute attribute.</p>
<p>You’ll have to look at the IDL or header file of the unmanaged code to determine which you need to use. Sometimes it requires a bit of playing around too.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="187" valign="top"><strong>Unmanaged Type</strong></td>
<td width="156" valign="top"><strong>Size (in bytes)</strong></td>
<td width="264" valign="top"><strong>MarshalAs Enum</strong></td>
</tr>
<tr>
<td width="187" valign="top"><strong>BOOL (Win32)</strong></td>
<td width="156" valign="top">4</td>
<td width="264" valign="top">UnmanagedType.Bool</td>
</tr>
<tr>
<td width="187" valign="top"><strong>BOOLEAN (Win32)</strong></td>
<td width="156" valign="top">1</td>
<td width="264" valign="top">UnmanagedType.I1</td>
</tr>
<tr>
<td width="187" valign="top"><strong>VARIANT_BOOL (COM)</strong></td>
<td width="156" valign="top">2</td>
<td width="264" valign="top">UnmanagedType.VariantBool</td>
</tr>
</tbody>
</table>
<p>In <a href="http://www.thycotic.com/quirks-in-net-part-3">Quirks in .NET &#8211; Part 3</a> we’ll look at numbers and binary</p>
<p class="authorblock" style="padding:10px;">
<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/quirks-in-net-part-2/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Quirks in .NET &#8211; Part 1 Call vs Callvirt</title>
		<link>http://www.thycotic.com/quirks-in-dot-net-part-1</link>
		<comments>http://www.thycotic.com/quirks-in-dot-net-part-1#comments</comments>
		<pubDate>Thu, 18 Feb 2010 20:25:28 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=504</guid>
		<description><![CDATA[There are a lot of cool yet strange things in the .NET Framework. A lot of them make you go, “Huh. I didn’t know that.” Let’s take a look at a few of them.]]></description>
			<content:encoded><![CDATA[<p><img src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/dotnetquirks.jpg" alt="Debugger Friend or Foe?" width="500" height="225" /></p>
<h6 style="clear:both">February 18th | 2010</h6>
<p><strong>Quirks in .NET Part -1 Call vs Callvirt<br />
</strong></p>
<p>There are a lot of cool yet strange things in the .NET Framework. A lot of them make you go, “Huh. I didn’t know that.” Let’s take a look at a few of them.</p>
<p><strong> call vs. callvirt </strong></p>
<p>This one is especially interesting to me. In the Microsoft IL specification there are two instructions to call a method, put simply—call and callvirt. call will simply call a method, while callvirt is used to a late-bound method call, meaning that the method which is going to be called is chosen at runtime and not compile time as the simple call would. This is needed for virtual methods when a VTable lookup is required.</p>
<p>Interestingly, all calls to instance classes are compiled as callvirt, even if the method being called is not virtual (thus at compile time we know exactly which method will be called.) I thought it was a bug at first, but really it was a fix for another bug. Consider this code:</p>
<pre class="csharpcode"><span class="kwrd">class</span> Program
{
    <span class="kwrd">static</span> <span class="kwrd">void</span> Main()
    {
        HelloWorld instance = <span class="kwrd">null</span>;
        instance.SayHello();
    }
}

<span class="kwrd">public</span> <span class="kwrd">class</span> HelloWorld
{
    <span class="kwrd">public</span> <span class="kwrd">void</span> SayHello()
    {
        System.Console.WriteLine(<span class="str">"Hello 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>Looks like it would immediately blow up, right? We should get a NullReferenceException. And in fact, if we compile this with the C# compiler, we do! Let’s look at the IL for the Main() method.</p>
<pre class="csharpcode">  L_0000: nop
  L_0001: ldnull
  L_0002: stloc.0
  L_0003: ldloc.0
  L_0004: callvirt instance <span class="kwrd">void</span> HelloWorld::SayHello()
  L_0009: nop
  L_000a: ret</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>Sure enough, it uses a callvirt, but here’s the interesting part: If the compiler used a call, rather than callvirt, this code would actually run. In fact, we can do that, too. Let’s change the callvirt to a call, recompile the IL using ilasm, and see what happens.</p>
<p><img src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/netquirks.jpg" alt="netquirks" width="500" height="275" /></p>
<p style="clear:both;">Yeah, it appears that our program, which should be causing a NullReferenceException, isn’t. This is why the .NET compilers don’t use call, even though using call is a perfectly acceptable in this case. For that matter, the only time a regular call will be used is when you call a method on a struct, or a static method on a class.</p>
<p>If you use the Reflection.Emit namespace frequently, or are looking into it, this is something to watch out for.</p>
<p>In <a href="http://www.thycotic.com/quirks-in-net-part-2">Quirks in .Net  Part 2.</a> we&#8217;ll look at Marshalling Booleans.</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/quirks-in-dot-net-part-1/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>FsUnit &#8211; Test Fsharp with Fsharp</title>
		<link>http://www.thycotic.com/fsunit-test-fsharp-with-fsharp</link>
		<comments>http://www.thycotic.com/fsunit-test-fsharp-with-fsharp#comments</comments>
		<pubDate>Thu, 11 Feb 2010 16:09:35 +0000</pubDate>
		<dc:creator>jfrankel</dc:creator>
				<category><![CDATA[F#]]></category>

		<guid isPermaLink="false">http://www.thycotic.com/?p=499</guid>
		<description><![CDATA[ I started out with a set of Nunit tests in C#, but kept running head-first into type problems with the method signatures and return types. Another hiccup was that my VS 2008 C# code couldn't see my F# code until I referenced the generated F# dll directly via Browsing. Adding a simple project reference didn't work.]]></description>
			<content:encoded><![CDATA[<p><img src="http://stagestore.thycotic.net/wp-content/uploads/2008/05/DavidCookseyF.jpg" alt="FsUnit - Test Fsharp with Fsharp" width="500" height="225" /></p>
<h6 style="clear:both">February 11th | 2009</h6>
<p><strong>FsUnit – Test F# with F#<br />
</strong></p>
<p>I recently spent some time putting together an F# lab with a series of unit tests designed to help teach the language. I started out with a set of Nunit tests in C#, but kept running head-first into type problems with the method signatures and return types. Another hiccup was that my VS 2008 C# code couldn&#8217;t see my F# code until I referenced the generated F# dll directly via Browsing. Adding a simple project reference didn&#8217;t work.</p>
<p>For example, here&#8217;s a simple F# function that returns the square of the input for any member with (*) defined and a C# assert based on it.</p>
<p>F# module:</p>
<p>#light</p>
<p>namespace Samples</p>
<p>module SampleOne =</p>
<p>let inline Square (x : ^x) = x * x;</p>
<p>C# code:</p>
<p>Assert.AreEqual(9, Samples.SampleOne.Square(3));</p>
<p>Seems simple enough, right? Except for the build error. “The Type arguments for method &#8216;Samples.SampleOne.Square&lt;x,a&gt;(x)&#8217; cannot be inferred from the usage. Try specifying the type arguments explicitly.” What the compiler is telling us here is that we&#8217;re calling a generic function without specifying the types.</p>
<p>To make the compiler happy, we have to do the following instead:</p>
<p>Assert.AreEqual(9, Samples.SampleOne.Square&lt;int, int&gt;(3));</p>
<p>Elegant? No, not really. The syntactic magic that F# uses to allow us to infer types is not available within C#.</p>
<p>Here&#8217;s a simple F# function that calls ToString on all members of a list and returns it as a new list.</p>
<p>let ListToString x = List.map (fun x → x.ToString()) x;</p>
<p>Its signature in F# looks like: val WorkOnList : (`a → string list)</p>
<p>In C# … Microsoft.FSharp.Core.FSharpFunc&lt;Microsoft.FSharp.Collections.FSharpList&lt;b&gt;, Microsoft.FSharp.Collections.FSharpList&lt;string&gt;&gt; SampleOne.WorkOnList&lt;a,b&gt;(a x)</p>
<p>Confusing, at best. Luckily there’s a testing framework that avoids these issues and is designed for F#.</p>
<p><strong>FsUnit to the Rescue</strong></p>
<p><a href="http://code.google.com/p/fsunit/">FsUnit</a> is a library that defines a simple, easy-to-use testing syntax within F#. It currently works with NUnit, but is intended to work with MbUnit, xUnit, and MsTest in the future. It’s a breeze to set up, simply reference nunit.framework, FsUnit.NUnit, and include the FsUnit F# script that sets up the syntax.</p>
<p>Using FsUnit, we can describe our functions and write a test for them as follows:</p>
<pre class="csharpcode">#light
namespace Tests
<span class="kwrd">open</span> NUnit.Framework
<span class="kwrd">open</span> FsUnit

<span class="kwrd">module</span> module1 =
    let inline <span class="kwrd">public</span> Square x = x * x;  

    [&lt;TestFixture&gt;]
    type ``Sample Tests`` ()=

        let WorkOnList x = List.<span class="kwrd">map</span> (fun (x) -&gt; x.ToString()) x;
        let lame x = List.head x;

        [&lt;Test&gt;] member test.
         ``Test One`` ()=
            Square 5 |&gt; should equal 25;
            Square 0 |&gt; should equal 0;
            Square 1.5 |&gt; should equal 2.25;
            WorkOnList [1;2;3;4;5] |&gt; should equal ["1";"2";"3";"4";"5"]</pre>
<p>Much more elegant and concise than the C# mess above. <strong>Spaces in test names are allowed—a feature I love. </strong>I&#8217;ve written far too many tests along the lines of ShouldCorrectlyDoOperationWhenValueAandValueBDoNotExceedValueC.</p>
<p>Languages typically use spaces to separate words instead of capitalization for a reason.</p>
<p>Keep in mind that this test syntax does not cause a compile time error if types do not match. For example, a function defined as let x = 0; does not cause a compile error when tested with x |&gt; should equal &#8220;horse&#8221;.</p>
<p>In conclusion, I recommend giving FsUnit a try if you intend to test F# code. Test in the language you wrote the code in!</p>
<p class="authorblock" style="padding:10px;"><em><em>David Cooksey is a Senior .NET Developer 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/fsunit-test-fsharp-with-fsharp/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<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>7</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 style="clear:both;">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>
	</channel>
</rss>
