Filed under .NET, Rants

So, how useful do you find code snippets to be in VS2005? I mean, beyond the “I don’t know how to do something, aha! here’s an example!” use that would be better served up in expanded help file examples.

On the surface, I suppose they could be handy in some circumstances. For instance, setting up TRY CATCH blocks maybe, or….um… ok, having a hard time coming up with other examples. I suspect snippets are one of those gizmos that make you “feel” more productive without actually making anyone truly more productive. They seem like Stephen Colbert‘s answer to developer performance.

My problem with these kinds of macro code “generators” is that they just seem like so much “cut and paste” programming. If you’ve every had to work on code that was built by cut and paste, you know it’s more fun to steam your eyeballs out of their sockets.

If a piece of code warrants being “set up” as a snippet, it probably ought to be encapsulated into its own function/sub/method/whatever, where it can be reused properly.

Here’s a sample snippet for “iterating through a collection”:

      ' Iterate through a collection
        For Each name As String In names


Now maybe I’m just being a curmudgeon here, but that comment, I’d have to redo, and the rest of it, I can type in less time than it’d take to find the snippet, esp with intellisense. Sure, I could also set up a shortcut for it, but even then, does this sort of thing really save time? Or rather, does it save real time?

You might make the argument that the snippets for creating properties can save time, but if I’m creating that many properties, that consistently, I’m guessing I’m going to use something like MyGeneration instead.

And in the end, a snippet might save a few keystrokes here and there, but, when you look at the entire life span of a project, I’d wager that even if you snorted snippets and peed the Quake physics engine, you’d be lucky to save yourself a few thousandths of a percentage point of the total time you spent coding.

Makes me wonder what the Freakonomics guys would say about them.


  1. Ralf says:

    "Why won’t this compile?"

    "Did you really declare a variable named MyCollection?"

    Perhaps this current stab at sample code is to encourage standards? There’s 20 bazillion ways to code a simple loop, but by providing an approved template Microsoft hopes to imprint The Correct Way upon the new generation of zombie developers?

  2. Darin says:

    Maybe, but I wouldn’t bet on it working. Code Reviews, mentoring, and just reading good code are the best ways to encourage good habits. The autoformatting in the VS IDE helps a lot too, I believe.

    It still bothers me when I read of people writing "codes" to do this or that. Encryption "codes", string handling "codes", etc.

    But I’m just being grouchy now…

Post a Comment

Your email is never published nor shared. Required fields are marked *