There's been
a lot of talk of all the hacks & odd searches you can do on Google Code Search.
Interesting,
amusing and maybe a
little scary. All of it clever. Clever is the first pass at a new tool, let's get on to the boring stuff! (Why does that interest me so much?)
I've wanted more times than I can count to tell Google that I mean to search for source. It's not as if you can add the name of the language - "C" or "C++" - to a normal search query and get anything meaningful. The obvious and canonical use of a tool like this is to find an example of code that does what you're trying to do. The simplest thing would be examples of a particular function or class in use. Maybe you want to see a
JTable instantiated and used. Maybe you need to know more about using the
PCMCIA bus in Windows drivers. Okay, that search doesn't work so well for closed source...
I think though that if Code Search catches on, rather than being a novelty like the specialized
US government search or
scholarly literature search, then it will be for more unique usage. Not one-off searches but things like browsing code. I'm just trying out the interface now, but it seems to me that Code Search provides a great way to have a look at source for some project without investing much time. For example, I can download the source for
the Gimp, the
Linux kernel,
Inkscape,
Expat,
GnuCash or any number of other great projects that I'm interested in. Many of these projects also let you browse their latest versions from CVS or Subversion, some
through a web interface. This is analogous to many sites that have their own on-site search. I use on-site search for some searches and I use a web search engine (sometimes restricted to that same site) for other types of search. So Code Search could be used to browse source in a way that's pretty consistent from project to project, even if it is a less complete interface than, say, an online CVS interface.
As a first whack, I'm going to try it on the Gimp. Specifically I've always wondered about how the Gimp interface to it's Scheme scripting works. My first simple search for
gimp script turns up a promising result on the second page. Looking at
soid-wrapper.c, I see some code that looks like it tells the scheme interpreter what functions are available. The Code Search syntax highlighting helps here as it does in a normal development environment, making it easier to pick out the helpful comments. By looking at the source of the page I found that Google puts in some name and id attributes so I can link directly to the
section of code that I'm reading (just add the value of the name or id attribute as an anchor on your link - like "#m15"). It looks like the names & ids are sporadic at best and I don't think that link will last forever. Still could be helpful in instant messaging or email at least. I guess that as the service matures they'll make this feature more predictable and obvious.
So the code in soid-wrapper.c (back to the Gimp code I'm actually reading) seems to set up the mapping between the Scheme-language names of exposed functions and internal function calls. It looks like the function gimp_procedural_db_proc_info() grabs the needed info and populates some arrays. I'd like to quickly look at where it gets this from (a plain text file, a database or some other resource I guess), but there's no easy way to jump to the function definition. This is something I'd expect in a C development environment and would really like to have available for Code Search. I understand that it's language-specific and that it's complicated by the fact that any project could define any function anywhere they want (potentially in a separate archive or library on a different site even). Nonetheless, it's a feature I need to really get anywhere browsing the source.
Given that my alternative in this case would be following the instructions on a page entitled
"CVS is Not That Scary", I guess I'll continue with Code Search and it's scaled down code browsing interface until I get more serious about messing with the Gimp. One of these days I'd like to try adding support for another scripting language. There's Scheme, Python and I think Perl depending on your platform, but I'd like to mess with it myself. The list of files in the same project shows up the left side of the window, this would be a great place to add a tree view that expands to show functions, classes or other language-specific constructs that are defined in each file. Once they've got that kind of information they should also be able to link from a function reference to the function definition. Leaps like that will bring it in line with other source browsing tools out there.
Google Code Search is pretty far behind compared to having the source available on your own computer but it's incredible ease of use makes it viable for introducing yourself to the source of many open source projects. That ease of use is a bigger feature than it sounds like, as I said earlier, searching web sites was nothing new when Google got in to it, but the simplicity of the search is what brought out a tool that we can use casually without knowing much up front.