<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>dev{shaped} &#187; productivity</title>
	<atom:link href="http://devshaped.com/tag/productivity/feed/" rel="self" type="application/rss+xml" />
	<link>http://devshaped.com</link>
	<description></description>
	<lastBuildDate>Mon, 13 Jul 2009 14:47:13 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<!-- podcast_generator="podPress/8.8" -->
		<copyright>&#xA9; </copyright>
		<managingEditor>derek@webradius.com ()</managingEditor>
		<webMaster>derek@webradius.com()</webMaster>
		<category></category>
		<itunes:keywords></itunes:keywords>
		<itunes:subtitle></itunes:subtitle>
		<itunes:summary></itunes:summary>
		<itunes:author></itunes:author>
		<itunes:category text="Society &amp; Culture"/>
		<itunes:owner>
			<itunes:name></itunes:name>
			<itunes:email>derek@webradius.com</itunes:email>
		</itunes:owner>
		<itunes:block>No</itunes:block>
		<itunes:explicit>no</itunes:explicit>
		<itunes:image href="http://devshaped.com/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<image>
			<url>http://devshaped.com/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
			<title>dev{shaped}</title>
			<link>http://devshaped.com</link>
			<width>144</width>
			<height>144</height>
		</image>
		<item>
		<title>Efficiency Upgrade</title>
		<link>http://devshaped.com/2009/05/efficiency-upgrade/</link>
		<comments>http://devshaped.com/2009/05/efficiency-upgrade/#comments</comments>
		<pubDate>Wed, 13 May 2009 00:59:00 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[MAXoutput]]></category>
		<category><![CDATA[efficiency]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[resources]]></category>

		<guid isPermaLink="false">http://devshaped.com/?p=179</guid>
		<description><![CDATA[by Derek Hatchard
 Developers solve problems. Good developers solve problems efficiently. The reward for that efficiency is [insert your preferred reward here]. Let&#8217;s assume you&#8217;re simply motivated by the satisfaction of a job well done (or maybe a promotion, a raise, longer lunch breaks, or just some extra time with your family). Whatever the motivation, [...]]]></description>
			<content:encoded><![CDATA[<p>by <a href="http://derekh.com/" target="_blank">Derek Hatchard</a></p>
<p><img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 22px 22px; display: inline; border-top: 0px; border-right: 0px" border="0" align="right" src="http://devshaped.com/wp-content/uploads/2009/01/derek-hatchard.jpg" /> Developers solve problems. Good developers solve problems efficiently. The reward for that efficiency is [insert your preferred reward here]. Let&#8217;s assume you&#8217;re simply motivated by the satisfaction of a job well done (or maybe a promotion, a raise, longer lunch breaks, or just some extra time with your family). Whatever the motivation, the secret to solving problems efficiently is not inventing everything from scratch. Certainly the secret is not spinning your mental wheels hoping for inspiration. And most definitely the secret is not using Intellisense to arbitrarily try classes, methods, and properties until something works.</p>
<p>The secret to solving development problems efficiently is having the right information and the means to find the information you don&#8217;t have.</p>
<p><span id="more-179"></span></p>
<p>If you have been developing software for more than a week, you know that a working knowledge of language syntax and program construction (that is, &quot;programming&quot;) is only a small part of the necessary skill set for solving problems with software. As a developer, you need to understand the technologies, processes, and methods available to you. You also need to have a set of reliable resources you can turn to when you encounter problems.</p>
<p>Below you will find some resource recommendations to help you find the information you need to help solve development problems more efficiently so you can get on with living the rest of your life.</p>
<h1>Finding Answers to Specific Problems</h1>
<h2>Search Engines</h2>
<p>I have heard colleagues muse about the changing role of &quot;software developer,&quot; postulating that development has become a job mostly concerned with research and discovery. While that is no doubt an overstatement, the ability to find information quickly is an important skill. The place many of us turn to first is our search engine of choice whether it&#8217;s Live Search, Google, or a meta search site like Dogpile.</p>
<p>The appeal of most search engines is the beautiful simplicity of a single search box, but the needs of a developer are not simple when you factor in multiple versions of frameworks, programming languages with similar constructs, and behavior differences between competing products (I&#8217;m looking at you, Structured Query Language and Cascading Style Sheets). With just a short time investment, you can learn some advanced search operators and tricks to help narrow search results to exactly the information you need. For example, search for &quot;live advanced search keywords&quot; or &quot;google advanced operators&quot; and you&#8217;ll find a bunch of operators to help you become a search ninja.</p>
<p>In addition to your search engine of choice, Wikipedia can be an invaluable problem solving tool. I have found Wikipedia to be especially useful when searching for general topics such as common computer science algorithms and concepts. Although I often end up at Wikipedia through search engine results, Wikipedia has its own search box right on the home page (<a title="http://wikipedia.org/" href="http://wikipedia.org/">http://wikipedia.org/</a>).</p>
<p>Of course not all problems will have solutions waiting to be discovered via a search engine. Some problems have already been solved in another part of your organization and you simply have no idea about the pre-existing solution. There are many tools designed to help companies deal with code asset management and search behind the firewall. One interesting product is Krugle, a specialty search engine built for indexing and searching code.</p>
<h2>Stack Overflow</h2>
<p>Searching is great when you know exactly what to search for and somebody else has previously solved a similar problem. When you are dealing with a more difficult issue, you may want to pose your specific problem to other developers for advice. There are plenty of discussion boards and forums for developers on the Internet to ask and answer questions.</p>
<p>One intriguing and useful site is Stack Overflow, a &quot;collaboratively edited question and answer site for programmers.&quot; This innovative developer Q&amp;A site allows users to post responses to questions and vote answers up or down based on usefulness, accuracy, etc. In addition to posting questions, you can search Stack Overflow or browse posted questions by tag. When you are posting a question on Stack Overflow, the application automatically searches existing questions and shows you matches that might already contain the answer you seek.</p>
<p>For obscure topics and scenarios such as bizarre error codes, Stack Overflow can be a job saver.</p>
<h2>Twitter</h2>
<p>Microblogging seems to be all the rage these days and some developers find services like Twitter to be an extremely effective way to share tips and send out requests for help. Twitter and similar services can be a two-edged sword, though, as they can be as much a distraction as a tool for information exchange.</p>
<p>If you are not familiar with Twitter, it lets you follow posts or &quot;tweets&quot; from other Twitter users. Tweets can be no more than 140 characters. You choose who you want to follow.</p>
<p>There are plenty of ways to use Twitter that will surely reduce your efficiency, but with a bit of intentionality in your approach, you can build a reasonable size network of trusted colleagues with whom you can swap questions, answers, tips, and tricks. (When your friends hear you are &quot;on Twitter,&quot; they may demand to know your Twitter username. You might need to maintain separate Twitter accounts for work and personal use.)</p>
<h2>Officemates, Coworkers, and IM Contacts</h2>
<p>If you are anything like me, you find it tempting to just ask an officemate or IM contact for an answer. Of course this means solving my problem at the expense of my colleague who is distracted from doing his/her own work. With your recently acquired ninja search engine skills, take a look at some of the research on the impact of interruptions on productivity and ponder how a work culture that accepts interruptions as common practice could ultimately make you a less effective developer. Just something to think about before you start picking the brains of your cubicle mates.</p>
<h2>Other Options</h2>
<p>What sources do you rely on for finding answers to specific problems? Leave a comment below.</p>
<h1>Keeping Up with New Technologies</h1>
<p>With the rapid and continuous rate of change in the software development space, keeping up with the latest and greatest technologies could be a full-time job – in fact it is in many organizations! It really has become impossible to keep up with everything, but you should not let the fear of information overload prevent you from staying informed about significant changes directly related to your area of expertise. Being informed about new technologies helps you make informed choices about the tools, platforms, and libraries you will use to get from problem to solution.</p>
<h2>Blogs</h2>
<p>One easy way to stay informed about topics that might affect you is to subscribe to at least a few blogs in your area. Scott Guthrie&#8217;s blog is a good choice if you only want to get the big headline news like a new release of the .NET Framework (<a title="http://weblogs.asp.net/scottgu/" href="http://weblogs.asp.net/scottgu/">http://weblogs.asp.net/scottgu/</a>). If you&#8217;re a Silverlight developer, Tim Heuer&#8217;s blog would be a good choice (<a title="http://timheuer.com/blog/" href="http://timheuer.com/blog/">http://timheuer.com/blog/</a>). If you&#8217;re an ASP.NET developer, perhaps try the Visual Web Developer Team Blog (<a title="http://blogs.msdn.com/webdevtools/" href="http://blogs.msdn.com/webdevtools/">http://blogs.msdn.com/webdevtools/</a>). </p>
<p>If checking blogs via a blog reader is not your thing, you might want to use a service that will deliver new blog posts to you via email.&#160; FeedBlitz (<a title="http://www.feedblitz.com/" href="http://www.feedblitz.com/">http://www.feedblitz.com/</a>) is a service I use for several blogs that I want to track even when I&#8217;m too busy to spend time reading my larger blog subscription list. Or you might want to add a few feeds to a customized browser home page through a service like Pageflakes or Netvibes.</p>
<h2>Podcasts</h2>
<p>Another way to stay current on technology is by listening to audio podcasts like .NET Rocks (<a title="http://dotnetrocks.com/" href="http://dotnetrocks.com/">http://dotnetrocks.com/</a>) and Hanselminutes (<a title="http://hanselminutes.com/" href="http://hanselminutes.com/">http://hanselminutes.com/</a>). Internet audio shows like these are generally packed with great technical content that helps keep you up to date. Podcasts can be an easy way to transform a tedious commute into a serious professional development opportunity. Personally I use the Zune desktop software (<a title="http://zune.net/" href="http://zune.net/">http://zune.net/</a>) to automatically download new podcast episodes and sync them to my Zune device. If you don&#8217;t have a Zune, you can still grab the MP3 files from the Zune download folder and copy them to any portable media player.</p>
<h2>User Groups</h2>
<p>User groups are another great way to stay current on new technologies. User groups are community-run technical groups that hold events (both in-person and virtual) for members to learn about technologies related to the focus area(s) of the groups. User group events often happen outside of normal work hours, which can admittedly make it difficult for some people to attend. In addition to learning opportunities, user group events can be a great place to discuss technical issues you are tackling and increase the size of your network of colleagues that you can turn to for help.</p>
<p>Go to <a title="http://www.ineta.org/" href="http://www.ineta.org/">http://www.ineta.org/</a> to find details (including meeting times and places) for .NET-focused user groups in your neck of the woods.</p>
<h1>Challenging Your Thinking</h1>
<p>When building software, your existing methods for thinking about problems are used to design a solution based on the tools and information you have available. Too many times I have seen developers stuck in a mental rut and developing solutions inefficiently because of outdated or misguided thinking about the problem at hand. Case in point: I used to spend far too much time building and deploying simple tools and utilities as compiled executables until I learned to embrace scripting as a fully legitimate form of programming (after having turned my back on my past as a UNIX scripting hack). In part my thinking was influenced by the experiences of other developers who were sharing their experiences online.</p>
<p>If you do not have people challenging your think, I believe you will stagnate as a developer. That means talking to or reading the musings of other developers. Ideally you will find yourself disagreeing with or questioning their thoughts on a regular basis. You aren&#8217;t being challenged if you only read what likeminded people write.</p>
<p>Below are some sources that I find useful in challenging my thinking and assumptions. They might not work for you, which is fine, but I encourage you to find your own trusted sources that will regularly challenge your thinking.</p>
<p><strong>CodingHorror.com</strong> is written by the brilliant and prolific Jeff Atwood. It has been a constant trove of insight and reasoned perspective, ranging from discussions of technical details to choosing a programming chair. (Jeff is one of the founders of the abovementioned Stack Overflow.)</p>
<p><strong>JoelOnSoftware.com</strong> is written by the equally brilliant Joel Spolsky. He is the source of such gems as &quot;The Joel Test: 12 Steps to Better Code&quot; and &quot;Things You Should Never Do.&quot; In addition to development topics, Joel writes about management and business issues. (Joel is the other founder of Stack Overflow.&#160; Hmmm&#8230; perhaps I have a bias.)</p>
<p><strong>Ted Neward</strong> writes a technical blog (<a title="http://blogs.tedneward.com/" href="http://blogs.tedneward.com/">http://blogs.tedneward.com/</a>) that I regularly enjoy. Although I don&#8217;t read every post, I always find his pontifications worth digesting.</p>
<p><strong>Daniel Crenna </strong>(<a href="http://dimebrain.com/blog">http://dimebrain.com/blog</a>) is another technical blogger whose musings I enjoy reading. Daniel is a great community champion and the founder of several open source projects. His blogging pace has slowed down in 2009 as he&#8217;s been working on some useful projects, but I keep hoping he&#8217;ll starting writing again soon. He&#8217;s a web / RIA guy, an area I&#8217;m interested in, so he stays in the ol&#8217; blog list.</p>
<h1>Join the Conversation</h1>
<p>What do you do to be more efficient as a developer? What are your favorite resources for challenging your thinking? How do you keep up on technology changes in your area of expertise? How do you find solutions to specific problems? Leave a comment to share <strong>YOUR</strong> tips with us.</p>
</p>
<p>&#8212;&#8211;</p>
<p><em>Derek Hatchard is the content editor for </em><a href="http://microsoft.com/youshapeit/msdn"><em>http://microsoft.com/youshapeit/msdn</em></a><em> and </em><a href="http://devshaped.com"><em>http://devshaped.com</em></a><em>. He is also the founder of </em><a href="http://crowdspace.net/"><em>Crowd Space</em></a><em>. You can find him online at </em><a href="http://derekh.com"><em>http://derekh.com</em></a><em>, </em><a href="http://ardentdev.com"><em>http://ardentdev.com</em></a><em>, and </em><a href="http://twitter.com/derekhat"><em>http://twitter.com/derekhat</em></a><em>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://devshaped.com/2009/05/efficiency-upgrade/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Accelerate Your Coding with Code Snippets</title>
		<link>http://devshaped.com/2009/01/accelerate-your-coding-with-code-snippets/</link>
		<comments>http://devshaped.com/2009/01/accelerate-your-coding-with-code-snippets/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 03:44:00 +0000</pubDate>
		<dc:creator>Derek</dc:creator>
				<category><![CDATA[MAXoutput]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[noyes]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://devshaped.com/2009/01/accelerate-your-coding-with-code-snippets/</guid>
		<description><![CDATA[by Brian Noyes
 One of the most underutilized productivity features in Visual Studio 2005 and Visual Studio 2008 is Code Snippets. Even though most developers have heard about them, I find when working with consulting customers that there are few developers who use them on a regular basis. Even if they do use them, they [...]]]></description>
			<content:encoded><![CDATA[<p>by <a href="http://briannoyes.net" target="_blank">Brian Noyes</a></p>
<p><a href="http://devshaped.com/wp-content/uploads/2009/01/brian-noyes.jpg"><img title="Brian_Noyes" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 22px 22px; border-right-width: 0px" height="57" alt="Brian_Noyes" src="http://devshaped.com/wp-content/uploads/2009/01/brian-noyes-thumb.jpg" width="85" align="right" border="0" /></a> One of the most underutilized productivity features in Visual Studio 2005 and Visual Studio 2008 is Code Snippets. Even though most developers have heard about them, I find when working with consulting customers that there are few developers who use them on a regular basis. Even if they do use them, they vastly underutilize them by only using a couple of them and never create their own. In this article, I give you a quick intro into what code snippets are, how they work, what is available out of the box, and how to go beyond that by quickly creating your own code snippets.</p>
<h2>Code Snippets Overview</h2>
<p>Code snippets were introduced in Visual Studio 2005 and allow you to emit a chunk of code into your editor by typing a few keystrokes (a shortcut mnemonic). I&#8217;m going to use C# for the examples in this article, but just realize that code snippets work in Visual Basic and other .NET languages as well. That chunk of code can just be a static chunk of code, but what really makes code snippets powerful is that they can have placeholders that you can quickly overtype when you invoke the code snippet.</p>
<p> <span id="more-21"></span>
<p>To try them out, the best one to start with is one you can probably use the most often: the <b><i>prop</i></b> snippet. Code snippets have both a title and a shortcut, although these will often both just be set to the shortcut value. The <b><i>prop</i></b> snippet emits a property with a backing member variable in Visual Studio 2005, or an auto-implemented property in Visual Studio 2008. Code snippets show up in the IntelliSense list as well, so if a snippet has a longer shortcut than a few letters, often you can just invoke it by typing a few of the letters and select it out of IntelliSense.</p>
<p>For example, if I go inside a class declaration and type <b><i>prop</i></b> and hit <b><i>Tab</i></b> twice (once to dismiss the IntelliSense list, the second time to invoke the code snippet), I get the following in the editor:</p>
<p style="font-family: courier new, courier"><span style="color: blue">public</span> <span style="background: lime; color: blue">int</span> <span style="background: lime">MyProperty</span> { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }</p>
<p> 
<p>The type and property name will be highlighted in green, indicating that they are the placeholders defined in the snippet. For this snippet, the type is the first placeholder and will be selected so that if you start typing, you will overtype what is there. So for example, say I want a string property. I type <b><i>string</i></b> and hit <b><i>Tab</i></b>. Tab moves between the placeholders, and when the focus is placed on the next placeholder, it selects it as well so you can overtype with the value you want. So if I type <b><i>Name</i></b> and hit <b><i>Enter</i></b>, I leave the placeholder mode and my changes are accepted. If I keep hitting Tab, it revisits the placeholders in order in case you accidently tabbed past one or changed your mind as you were filling things in.</p>
<p>This one may not be stunning in its time savings, but when you add up the keystrokes (4 + 1 + 6 + 1 + 4 + 1) you have 17 versus the 30 for typing out the whole property yourself. Wham! You just became almost twice as fast at writing code! OK, don&#8217;t tell your manager just yet, you need to actually get used to doing this all the time first… </p>
<p>Now consider setting a switch case statement for an enumeration with a number of values. For example, say you needed to set up a switch/case on the states for System.Windows.Input.MouseAction. If you had a local variable of that type with something like the following method:</p>
<p style="font-family: courier new, courier"><span style="color: blue">public</span> <span style="color: blue">void</span> HandleMouseInput(<span style="color: #2b91af">MouseAction</span> action)     <br />{     </p>
<p>} </p>
<p> 
<p>If I go inside that method and type <b><i>switch Tab Tab</i></b>, I get the following snippet with a placeholder on the variable <b><i>switch_on</i></b>. </p>
<p style="font-family: courier new, courier"><span style="color: blue">public</span> <span style="color: blue">void</span> HandleMouseInput(<span style="color: #2b91af">MouseAction</span> action)     <br />{     <br />&#160; switch (<span style="background: lime">switch_on</span>)     <br />&#160; {     <br />&#160;&#160;&#160; <span style="color: blue">default</span>:     <br />&#160; }     <br />}     </p>
<p> 
<p>If I type in <b><i>action</i></b> for the placeholder (the local variable of enum type MouseAction) and hit <b><i>Enter</i></b>, the snippet fills in all the enum values as case statements:</p>
<p style="font-family: courier new, courier"><span style="color: blue">public</span> <span style="color: blue">void</span> HandleMouseInput(<span style="color: #2b91af">MouseAction</span> action)     <br />{     <br />&#160;&#160;&#160; <span style="color: blue">switch</span> (action)     <br />&#160;&#160;&#160; {     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.LeftClick:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.LeftDoubleClick:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.MiddleClick:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.MiddleDoubleClick:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.None:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.RightClick:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.RightDoubleClick:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">case</span> <span style="color: #2b91af">MouseAction</span>.WheelClick:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">default</span>:     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: blue">break</span>;     <br />&#160;&#160;&#160; }     <br />}     </p>
<p> 
<p>That is a huge keystroke savings filling all the tedious structure code! You just need to fill in what to do for each case.</p>
<h2>Built-in Code Snippets</h2>
<p>The list of built-in code snippets for C# is actually fairly short. There is really only a small number included out of the box. You can find the full list here with a short description of each for the core C# language snippets: (<a href="http://msdn.microsoft.com/en-us/library/z41h7fat(VS.80).aspx)">http://msdn.microsoft.com/en-us/library/z41h7fat(VS.80).aspx)</a>. There are some additional ones in other categories that ship with Visual Studio 2008, but the list is still fairly short for C#.&#160; Visual Basic actually ships with hundreds. But this shouldn&#8217;t make you feel shorted as a C# developer. You can actually find a greatly expanded library of C# code snippets that shipped after VS 2005 here: <a href="http://msdn.microsoft.com/en-us/vs2005/aa718338.aspx">http://msdn.microsoft.com/en-us/vs2005/aa718338.aspx</a>. You can also find libraries of other code snippets out on CodePlex and other places on the net.&#160; <b><i>do</i></b>, <b><i>while</i></b>, <b><i>for</i></b>, <b><i>foreach</i></b>, and a number of other common control structures are all in the basic set, along with everything from data access patterns to file IO patterns in the expanded sets. <b><i>ctor</i></b> is another one that is handy for declaring a default constructor for a class.</p>
<p>There is a Code Snippet Manager in the Tools menu of Visual Studio that will let you browse all the built in snippets, import new ones, and search online. However, if you understand what is going on under the covers, it is actually easier to just manipulate them as files.</p>
<h2>Inside Code Snippets</h2>
<p>Code snippets themselves are nothing more than XML files with a particular schema that reside in some directories that Visual Studio is aware of. Specifically, snippet files end with a (not surprising) extension of .snippet. The built-in code snippets that ship with Visual Studio reside under the folder C:\Program Files\Microsoft Visual Studio 9.0 under VC# or VB respectively. Visual Studio is the default editor for that file type, so you can just browse to those folders and double click on the .snippet files and edit the XML in Visual Studio. If you want to create your own snippets, put them in your Documents folder under Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets (or similar path for VB or 2005). Visual Studio watches this file all the time, so changes or additions to snippets take effect immediately without needing to restart Visual Studio.</p>
<p>There are a lot of elements supported in the schema but the key ones to focus on are Shortcut in the Header element, and the Declarations and Code elements under the Snippet element. Say I wanted to emit a code snippet like the following with a placeholder over the <b><i>Boo!</i></b> string so I could overwrite it:</p>
<p style="font-family: courier new, courier">System.<span style="color: #2b91af">Console</span>.WriteLine(<span style="color: #a31515">&quot;Boo!&quot;</span>); </p>
<p>To do so, I would have a code snippet that looks like this inside: </p>
<p style="font-family: courier new, courier"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml</span><span style="color: blue"> </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue"> </span><span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot;<span style="color: blue"> ?&gt;</span>     <br /><span style="color: blue">&lt;</span><span style="color: #a31515">CodeSnippets</span><span style="color: blue">&#160; </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet</span>&quot;<span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160; &lt;</span><span style="color: #a31515">CodeSnippet</span><span style="color: blue"> </span><span style="color: red">Format</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0.0</span>&quot;<span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Header</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Shortcut</span><span style="color: blue">&gt;</span>cwboo<span style="color: blue">&lt;/</span><span style="color: #a31515">Shortcut</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Header</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Snippet</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Declarations</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Literal</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">ID</span><span style="color: blue">&gt;</span>output<span style="color: blue">&lt;/</span><span style="color: #a31515">ID</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Default</span><span style="color: blue">&gt;</span>Boo!<span style="color: blue">&lt;/</span><span style="color: #a31515">Default</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Literal</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Declarations</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;</span><span style="color: #a31515">Code</span><span style="color: blue"> </span><span style="color: red">Language</span><span style="color: blue">=</span>&quot;<span style="color: blue">csharp</span>&quot;<span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;![CDATA[</span><span style="color: gray">System.Console.WriteLine(&quot;$output$&quot;$end$);</span><span style="color: blue">]]&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Code</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160;&#160;&#160; &lt;/</span><span style="color: #a31515">Snippet</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&#160; &lt;/</span><span style="color: #a31515">CodeSnippet</span><span style="color: blue">&gt;</span>     <br /><span style="color: blue">&lt;/</span><span style="color: #a31515">CodeSnippets</span><span style="color: blue">&gt;</span>     </p>
<p>In this case, the IntelliSense shortcut to invoke it is <b><i>cwboo</i></b>. The code snippet declares one literal variable named <b><i>output</i></b> with a default value of <b><i>Boo!</i></b>. The actual code of the snippet has to be declared inside an XML CDATA section because some legal characters in C #and other languages could cause XML parsing errors. The <b><i>output</i></b> literal is a named placeholder in the emitted code which will be replaced with the default value and highlighted for overtyping as discussed earlier. You can see that when you use a literal in the snippet, you enclose it within leading and trailing <b><i>$</i></b> delimiters. Everything else in the snippet (except other variables) is emitted as plain text in the editor when the snippet is invoked. You can see I am also using a built-in literal <b><i>$end$</i></b>, which specifies where the input cursor is placed when you hit <b><i>Enter</i></b> to leave the placeholder mode of snippets.</p>
<h2>Creating Your Own Snippets</h2>
<p>By now you are probably emitting some form of &quot;Eeewwww!!!&quot; sound at the thought of editing the XML whenever you want to create your own snippets. The good news is that you don&#8217;t have to. There are a couple of free tools out there to help you create and edit snippets without ever needing to touch the XML directly. One I have been using for years as a C# guy is Snippy (<a href="http://www.codeplex.com/snippy">http://www.codeplex.com/snippy</a>). It puts a very simple dialog interface on top of the XML schema for you to create your snippets (see Figure 1).</p>
<p><a href="http://devshaped.com/wp-content/uploads/2009/01/snippy.png"><img title="snippy" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="480" alt="snippy" src="http://devshaped.com/wp-content/uploads/2009/01/snippy-thumb.png" width="482" border="0" /></a> </p>
<p><strong><em>Figure 1: Snippy</em></strong></p>
<p>A great way to start many custom snippets is to start with an existing one and just edit it. Just remember to do a &quot;Save As…&quot; and save it to your Documents code snippets folder mentioned earlier so you don&#8217;t overwrite the built-in ones.</p>
<p>Another choice is the Code Snippet Editor for Visual Basic 2008 (</span><a href="http://msdn.microsoft.com/en-us/vbasic/bb973770.aspx">http://msdn.microsoft.com/en-us/vbasic/bb973770.aspx</a>). For those language bigots, you will have to get over the title: it actually supports multiple languages (see Figure 2).</p>
<p><a href="http://devshaped.com/wp-content/uploads/2009/01/csevb.png"><img title="CSEVB" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="400" alt="CSEVB" src="http://devshaped.com/wp-content/uploads/2009/01/csevb-thumb.png" width="482" border="0" /></a> </p>
<p><strong><em>Figure 2: Code Snippet Editor for Visual Basic 2008</em></strong></p>
<p>Either one of these will allow you to quickly create your own snippets and stop typing the same code over and over again.</p>
<h2>Code Snippet Functions</span></h2>
<p>I showed you the switch snippet earlier in the article, and that may lead you down the path of thinking you can pull off anything with a snippet. Unfortunately that is one of the most powerful ones you will find. There is a whopping three functions in the C# library for expanded capabilities in your snippets (</span><a href="http://msdn.microsoft.com/en-us/library/ms242312.aspx"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">http://msdn.microsoft.com/en-us/library/ms242312.aspx</span></a><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">). The <b><i>GenerateSwitchCases</i></b> function is the one that did the magic for the <b><i>switch</i></b> code snippet. The <b><i>ClassName</i></b> function will emit the class name of the class in which the snippet is invoked. This is used by the <b><i>ctor</i></b> snippet I mentioned earlier to declare a default constructor. And lastly there is the <b><i>SimpleTypeName</i></b> function, which will take a fully qualified type name, and will emit both a <b><i>using</i></b> statement in C# (<b><i>Imports</i></b> in VB) and the root class name so that you don&#8217;t have fully qualified types in the emitted code. This is used by the built-in snippet <b><i>cw</i></b>, which emits a Console.WriteLine statement. Take a look at that built-in snippet if you want to see the way it is used. Unfortunately there is no way to add your own custom functions. If you want more power to do more custom things in your snippets, you might want to take a look at third party tools such as Developer Express CodeRush (</span><a href="http://www.devexpress.com/CodeRush"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">http://www.devexpress.com/CodeRush</span></a><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">) or JetBrains ReSharper (</span><a href="http://www.jetbrains.com/resharper/">http://www.jetbrains.com/resharper/</span></a><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;">). They have things called templates that are like code snippets on steroids and are also extensible.</span> </p>
<h2>Wrap Up</h2>
</p>
<p>Now you should have a good idea what code snippets are, how they work, and how to go beyond what you get out of the box. Let me share with you my approach to code snippets: If I find myself typing some code and I get that &quot;déjà vu&quot; feeling of &quot;I know I&#8217;ve written this little chunk of code before&quot;, I stop myself, write it as a code snippet, and then I won&#8217;t ever have to write it again. Too often developers take the longer path because they think they will be &quot;wasting time&quot; by going and doing something like authoring a code snippet for the code they are writing. Many times, it is not authoring the code snippet that is the real waste of time. </p>
<p>&#8212;-</p>
</p>
</p>
<p><em>Brian Noyes is chief architect of IDesign (</span></em><a href="http://www.idesign.net"><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;"><em>www.idesign.net</em></span></a><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;"><em>), a Microsoft Regional Director and MVP, writer and speaker. He is the author of Developing Applications with Windows Workflow Foundation, Smart Client Deployment with ClickOnce, and Data Binding with Windows Forms 2.0. He is also a frequent speaker at conferences worldwide including Microsoft TechEd, DevConnections, VSLive!, DevTeach and others. You can contact him through his blog at </em></span><a href="http://briannoyes.net"><em>http://briannoyes.net</span></em></a><span style="font-family: &quot;Arial&quot;,&quot;sans-serif&quot;"><em>. </em></span></p>
]]></content:encoded>
			<wfw:commentRss>http://devshaped.com/2009/01/accelerate-your-coding-with-code-snippets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
