When I am coding and I don’t know a certain syntax or algorithm, I always get sample code that I can use as a template or for reference. There are plenty of good sources like Sourceforge.net, but sometimes those services just won’t do, especially if you only need to see a snippet of a function (i.e. to have an idea of the syntax or logic) and not the whole source code of the project.
Google Code Search provides a way for us to search for sample code online in many different programming lanaguages (C, C++, JavaScript, Python, Java, C#, etc). You can search for strings using regular expressions and you can limit your search to a specific programming language, license or filename.
First let me show you how easy it is to use. Open the search page, http://www.google.com/codesearch, then enter a query string. In the example below I entered “bubble sort” to look for code that implements the bubble sort algorithm. Like in other Google search pages, the search is fast and returns within a couple of seconds.
![]()
Each search results contain the filename, the code snippet, license and language.
Depending on the string you search, there could be several implementations in different languages, such as Java, C#, ASP.NET, VB, and more – scroll to other search results to see the one that matches your programming language.
Click the code snippet to see the whole file. I like the way how Google maintained the structure of the classes at the left side while showing the source of the file class on the right side.
Programmers of all levels will appreciate this code searching engine. According to Google, they crawl as much publicly accessible source code as they can find, including archives (.tar.gz, .tar.bz2, .tar, and .zip), CVS repositories and Subversion repositories.
By the way, there is also an advanced code search that lets you filter the search to a certain language, license, package, and/or files.
http://www.google.com/codesearch/advanced_code_search?hl=en
Ben Carigtan shows you how it’s done.







Be The First To Comment
Please Leave Your Comments Below