I felt there was a lot of benefit out of having this “snippet” functionality. Besides saving time typing, or manually cutting and pasting from one document to the next, everyone on the team used the same snippets and the markup of the pages we created was consistent. This came in handy as were converting a bunch of static html files to proper XHTML compliant format that was inserted into an XML content management system called Dynabase.
After I left that team, HomeSite was bought out my Macromedia and eventually phased out by Macromedia who had similar functionality in their Dreamweaver product, but at the point, I was no longer just an HTML code monkey. I made the transition to classic asp and vbscript and then eventually to .Net and ASP.Net.
Perceived Anti Patterns
For many years I didn’t use a snippet tool. Part of it was the support for snippets in tools like Visual Studio weren’t that good. The other part was that snippets just weren’t cool. You see, copy paste Programmers have given code snippets a bad name. A lot of developers I speak with tend to associate code snippets with inexperienced programmers or hackers, who copy some code off the web without really understanding what it does.
Ask those same developers what do they do when they are stuck on a coding problem, trying to get past some obtuse error message and they say “Google it.” And what do they do when they find a solution: Copy and Paste. Of course it’s not the act of copy and pasting that is the anti pattern, it’s trying to use code that you don’t fully understand.
Real Anti Patterns
But there was a real anti pattern that I found myself falling into with taking this approach time and time again. I found myself googling for solutions to the same problem over and over again. I can’t remember how many times I googled “C# serialize deserialize.” Or “Regex tutorial.”
More troubling were the times that instead of trying to enter keywords that seemed relevant to the issue, I found myself guessing the keywords I used the last time I was looking for something.
I also found myself doing similar things with my rss reader. I found myself sifting through old blog posts looking for a post that I remember addressing something I was trying to do. With Microsoft Outlook, it was usually SQL queries. I would try to remember who I sent one to and try to figure out when, filter by attachments to find a query I sent someone.
This was an information management problem that has wasted a ton of man hours. I know some developers who use OneNote, or all sorts of creative ways of organizing bits of code in text files. Some even use the built in support for snippets in the products they use not realizing there are other solutions.
A Snippet Solution
I created a product to address this need correctly. It’s called Snip-It Pro. And I want you to try it.
I made Snip-It Pro to work the way I wanted. I didn’t want a stand-alone application for managing snippets. The last thing I wanted to do is have to “ALT Tab” all day to get what I needed out of the program.
So Snip-It Pro is implemented as an application desktop toolbar so it can dock to the side of the screen. It is basically a plug in to all the tools you already have. As long as you can drag drop text into your IDE or editor, you can use Snip-It Pro. (You also drag code into snip-it pro to create snippets)
As a professional developer and consultant, I work with multiple languages in multiple environments. My primary IDE is Visual Studio.Net, but I spend a lot of time in SQL Server Management Studio, Expression Studio (for Xaml Silverlight editing), Textpad, Notepad, All parts of Microsoft Office, and other tools like Dreamweaver on occasion. Having all my personal bits of code available to drag drop into any of these application is really nice. The built in syntax highlighting for most popular languages helps too.
Lessons from HomeSite
The other lesson I learned from HomeSite is the power of being able to share snippets, so I implemented snippets as plain old xml files that could be placed on any folder or network share. So if a team wanted to use the same snippets, they just pointed to the same network share.
This capability is even more useful now than it was back in 2000. Like a lot of developers, these days I’m working in multiple environments. Between using virtual machines for development environments to using Remote Desktop or VNC to connect to remote machines, which themselves may be virtualized, it helps to be able to access the same snippets from multiple locations.
One feature I implemented that even HomeSite didn’t have is support for templated code snippets. You can simply add placeholders to your snippets by surrounding text with double square brackets, and the configure snippet bar will automatically display textboxes for those fields when you have a snippet selected. You can then fill out the values and then drag the snippet to where you want to use it and it will automatically have the values merged right in.
When Jeff Atwood lamented about the ability to trace where a code snippet came from in his post “A modest proposal for the Copy Paste School of code reuse” on his Coding Horror blog, I implemented a feature that will automatically add comments above a snippet with a unique ID and reference url of a snippet. This, coupled with Snip-It Pro’s ability to track the url of where a snippet came from when you copy it from the web, make it the perfect tool to save code you find online to.
Similarly, when I came across Snipplr, an online community dedicated to sharing code snippets (there are already over 18,000 snippets there) and discovered it had an API, I integrated it into Snip-It Pro so you can view all your favorite snippets and publish your own.
There is a nice video demo of Snip-It Pro on the Snip-It Pro home page. Take a look and give it a try. It’s a free fully functioning 30 day demo and I’m selling it for $39.95, but if you write a review of it on a blog or website, I’ll give you a free copy. Any feedback or feature ideas would be appreciated too.