in

ASP.NET Weblogs

J e r o e n ' s   w e b l o g

Now all I need is a title snippet

I have to admit, when I first saw the VS2005-integrated code snippets during the TechEd Europe 2004 (yes 2004) keynote, it sounded like the typical feature that I would never use. Well, to make a long story short, I've been using VC#2005 for a couple of days and it's already one of my favorite features!

Sometimes I would omit handling an exception in some code during development just because it's such a drag to keep writing all that try/catch/finally-stuff. Sure, the handling would make it into the code in the end - if only because some of the unit-tests triggering the exceptions simply wouldn't pass, but still, it's a bit of a risk not including them right away when all the context is still clear to you. So what I do now is this:

try[TAB][TAB]

And there it is: a try-block with a catch-clause. And the best part is that you get this in-code-wizard-type functionality to go through all the variable stuff in all these snippets. After that the cursor ends up in the logical next place to start typing. Great stuff!

Some more cool snippet-shortcuts (just type them in and follow with double TAB): cw (Console.WriteLine), mbox (MessageBox), for/forr (regular and reverse for-loop) and prop/propg (property get/set and just with a get, along with the backing variables).

Published Oct 31 2005, 06:54 PM by jvdbos
Filed under: ,

Comments

 

Erik Porter said:

Not to rub it in (too much) or anything, but you've been able type "try" and hit enter and get the block dumped out for you in VB since day one of .NET. Same thing with Properties (although you had to type out the definition of the property first.

That said, yes, I agree, snippets are slammin'. I use prop when in C# all the time! The best part about them is that they're just XML files so if you don't like the format (prop is a good example where people have different preferences) you can just go in and change it to how you like it...slammin'! Being productive is good! :)
October 31, 2005 2:07 PM
 

anonymous said:

This leads easily to bad design and it seems more like copy/paste coding.
October 31, 2005 2:09 PM
 

Jeroen van den Bos said:

Erik: I saw the XML-files yes, my first one to add will be a trycf or tcf (try/catch/finally) which doesn't appear to be standard.

Anonymous: How will it lead to bad design? It's not like people will go "Well I could do this right but I'll use this snippet instead". Just for the basic for-loops and property-stuff. At least that's what I'll use it for.
October 31, 2005 2:19 PM
 

Frans Bouma said:

I like the feature too! :).
October 31, 2005 3:19 PM

Leave a Comment

(required)  
(optional)
(required)  
Add