Tim Anderson's ITWriting [Valid RSS]

Tech writing blog

Blog Home RSS Archives ITWriting.com
Add to Feedburner Add to Bloglines Add to Newsgator Add to My Yahoo

May 23, 2004

Are code snippets evil?

Posted 2293 days ago on May 23, 2004

One of the new productivity features in Visual Studio .NET 2005 is code snippets. This is a library of reusable code that you can quickly insert into your VB project. Sounds good, but the danger is that it is used as a kind of persistent clipboard, encouraging developers to copy and paste blocks of code instead of creating their own class libraries. Copy and paste is at the root of many classic development problems, such as code bloat and bugs that need to be fixed in more than one place. I've noticed here at Tech Ed (in the press pre-briefing) that presenters are using code snippets as a handy way to paste their demo code. Fair enough, but will this be another case of the IDE actually encouraging poor practice?



Re: Are code snippets evil?

Posted 2293 days ago by Tim Sneath • • wwwReply

I don't think they're inherently evil, but like almost any technology they have the potential to be abused. One of the challenges with the Base Class Libraries of the .NET Framework is the sheer scale of them - it's sometimes hard to find the method or function that you're after. Code snippets provide an alternative taxonomy to the namespace model that can make it easier to surface commonly-accessed tasks without distorting the overall structure.

Another usage for code snippets is to facilitate the wiring up of different components. For example, to send a mail using System.Web.Mail you need to set the SMTP server, create a message object and send it. This isn't necessarily the kind of thing you'd refactor into a separate method, but code snippets make the various required steps transparent.

But you're quite right that an abuse of code snippets would be to create a toolbox or function library - far better for maintenance to build a reusable object rather than repeatedly copy and paste code across multiple projects.

Are code snippets evil?

Trackback from Lazycoder weblog Posted 2293 days ago • Reply

Scobleizer: Microsoft Geek Blogger

Are code snippets evil?

Regarding snippets: Are you going to study them or are you going to just use them and use the over and over again?

What happens if you discover a bug in the snippet and you've copy-pa...

Re: Are code snippets evil?

Posted 2293 days ago by Addy Santo • • wwwReply

Code snippets are the root of all evil. In other related news, people don't kill - bullets do.

;)

Re: Are code snippets evil?

Posted 2292 days ago by Christopher (Chris) Galas • • • Reply

Code snippets are essential to learning and getting use to the new paradyme. For each new version of the Visual Studio, a shift in the paradyme occurs. New features, new ways of debugging and new languages to learn are introduced in each new version of the developers tools. I'm not sure if anyone remembers the old IDE for v5.1 (which was the first one), but it was similar to the editor in DOS. Look how far that has progressed in 10 years?

Its either studying and reusing these code snippets or picking up that 500+ page book with each new paradyme (shift in technology).

Are code snippets evil?

Trackback from Reflective Surface Posted 2292 days ago • Reply

Are code snippets evil?

Re: Are code snippets evil?

Posted 2292 days ago by Sam Spencer • • • Reply

Like any feature, code snippets can be abused.
The intention behind code snippets is not to relace class libraries and good coding practices, but to assist with them. The .Net framework supplies a vast array of functionality, what is not always clear is how to use the classes and routines to get the functionality the user desires. Snippets provide a way to provide examples for using the library functionality. Snippets provide a more organized and contextual way of getting examples of how to use libraries. Becuase of the xml nature of snippets, it not only provides the code but also the resoucres needed to make that code work.

One could argue that snippets can actaully improve code-reuse by providing examples of how to use a library rather than writing the code from scratch. I could imagine in a team environment, developers not only sharing the class libraries, but also the snippets demonstrating how to use the class libraries.


Add Comment

You are welcome to comment below. For your guidance, HTML is not supported and URLs will be displayed as plain text.

 Title

 Name

 Email - Optional, not displayed

 Website. Make Public?

Your comment

Please enter this code below:

 Code

Recent posts

Users plead with Borland to give up .NET
IE7 to be released 18th October,...
If Microsoft doesn't use UAC, why...
Google's unsettling lack of direction
Vista security: now prove it


Powered by bBlog