Gadgets Magazine

Microsoft Launches Visual Studio Add-On For Code Snippets

Posted on the 06 March 2014 by Palmgear @PalmgearBlog

Regardless of whether you are a seasoned programmer or a beginner, it’s likely you spend a lot of your time looking for code snippets on Stack Overflow and similar sites. Things have changed, a team from Microsoft Research in Cambridge wants to streamline this process and bring it into the IDE. The team today launched the Bing Code Search add-on, which directly integrates code snippet search for C# (with other languages coming later) into Visual Studio.

What’s important here is that this isn’t just a basic search tool. Instead, you can ask queries using natural language (“how to read files line by line”). The tool’s language processing and search is powered by Bing, and everything runs on Azure.

The team has indexed snippets from Stack Overflow, MSDN, Dotnetperls and CSharp411. All the snippets in the index were automatically checked to ensure they compile, but in the search, the algorithms also look at votes from the given community that the snippet comes from and other quality signals.

The best thing, though, is that it doesn’t just copy and paste the snippet into the code, but it will also try to modify the code to fit the variables you already use in your own code.

Even if you don’t have Visual Studio installed, you can try a web-based version (with a slightly different interface) here.

bingcodesearch1

As Youssef Hamadi, a senior researcher at Microsoft Research Cambridge and Yi Wei, a post-doc researcher who worked on this project with Hamadi, told me, having your own variables in the code makes it far easier to read the code, as most programmers who have ever copied and pasted a code snippet can probably attest to.

For single-variable queries, the tool is about 70 to 80 percent accurate in picking the right variable. For snippets with two variables, it’s at just over 60 percent. Unsurprisingly, it also tends to perform better, the more common the question is.

Hamadi believes the tool will appeal to all levels of developers, but he thinks that beginners will definitely benefit from it, because it will make it easier for them to learn how to use a language, as well as very advanced programmers, who can quickly determine which snippet will work best in their code.

In Microsoft’s internal tests, programmers who used the Bing Code Search add-on were over 60 percent faster in solving a battery of coding exercises than those who used regular web search.

As for the partnerships, Stack Overflow’s VP of engineering David Fullerton told me that he doesn’t expect this integration to hurt its traffic. Every snippet, he noted, will also show a link to the original source, and he expects that developers who want to dive deeper into the code and see the comments and discussion around the snippet will continue to be active in the Stack Overflow community.

For the time being, the team considers this tool an experiment, but if developers react positively to it (and it’s hard to see why they wouldn’t), it may just become a built-in Visual Studio feature. Over time, the team also plans to support more languages. C# is obviously a very important language for Microsoft and has a very active developer community (and the Stack Overflow community, for example, has historically been very .Net-centric anyway).

Looking ahead, it’ll be interesting to see where Microsoft takes this technology. Taken to the extreme, you could maybe even start programming using just natural language queries in the long run. Hamadi hinted that Microsoft has more planned for the technology that the team developed.


Back to Featured Articles on Logo Paperblog