Searching for Code Snippets in an IDE


When writing a program, developers of all skill levels routinely and repeatedly turn to search engines for answers to questions; questions like “how do I read a file line-by-line”, “read an RSS feed”, “calculate the difference between two dates”, “delete whitespace”. More generally, how do I do X, where X is a small programming task that someone – surely – has already done before, and probably already shared a solution to.

Enter the Code Snippet Search tool from Microsoft Research, now available to C# programmers as a Visual Studio add-on. It is the outcome of a research project that Yi Wei (a former member of our group who studied automated testing and fixing, and whose flat in Z├╝rich I happened to takeover!) has been working on since 2011, and today is looking like a very promising tool. The basic idea is to streamline the process of finding reusable C# code snippets by integrating the experience into the Visual Studio IDE.

Automagically identifying, adapting, and inserting the code snippet that does the job

Automagically identifying, adapting, and inserting the code snippet that does the job

Accessed by triggering Visual Studio’s IntelliSense, the tool accepts queries in natural language (akin to the examples in my opening paragraph), processes them using Bing, then attempts to identify the most appropriate code snippet in an index built from MSDN, Stack Overflow, Dot Net Perls, and CSharp411 (taking into account various indications of quality, such as the number of votes from a particular community). Most impressively, the tool doesn’t just dump the identified code snippet and send you on your way; rather, it attempts to modify it to fit the variables and context of your program, with some reasonable success rates reported.

The Visual Studio blog has a nice overview of the technology alongside some screenshots of the add-on. If you want to see it in action without having to install the IDE, there is a web-based version (albeit with a slightly different interface) that you can play with, as well as a 2-minute video demonstration.

Support for other languages is planned to come later (I hope, apart from the obvious targets, that LaTeX finds its way onto the list!); but in the meantime, it will be interesting to observe how C# developers react to and use this technology in practice. Congratulations to Yi and his colleagues on their success!

A nugget for users: Chrome and 2-step verification


Reading this rather alarming story of blackmail and negligence prompted me to review my own security settings, starting with by far the most important aspect of my digital life: my Gmail account. For reasons that escape me (I hope they were good ones), I never did enable Google’s 2-step verification; today that changed (and most certainly it should have changed much sooner).

Enabling 2-step verification was painless but for one small niggle: that I could no longer use the account to sign into Google Chrome. After all sorts of fiddling and frustration (aggravated by the many written assurances of Chrome’s 2-step compatibility), I stumbled upon the unlikely cause of the problem: the fact that I had not a account but rather a one. This had been the case since registering in the midst of a trademark dispute over the Gmail brand, and despite its resolution in 2010, inertia meant that I continued to use the longer domain anyway. After recalling some difficulties we had with Google Analytics a few years ago – it wouldn’t delegate access to users – I decided to finally make the switch to to see what (if anything) might change. It turned out to do the trick, and Chrome immediately became compatible with my 2-step enabled account.

I suspect that I might have been one of the few remaining patrons of the domain. But for the benefit of any others, might I suggest that you also consider making the switch if you are seeing similar such oddities in 2-step verification, Chrome, Analytics, or any other Google service. (And should inertia hit you too, then perhaps it helps to know that addresses continue to work post-switch anyway!)