Github sample code searches, or how to google Github successfully

We’re hiring at my company, Hayden Software, and I’ve been asked to help interview for my contract, so I’ve had a few different opportunities to ask candidates how they track down programming problem solutions.  The usual answer?  Either Google or Stack Overflow.  Both are reasonable answers, though are a bit broad brush in terms of their coverage.  If I find something mentioned in documentation, what I’d _really_ like is to see a working example of it.  Particularly since most programmers seem to write awful documentation.

I’ve taken, of late, to trying to use GitHub as my compendium of source code examples.  I’ll assume that the folks who cared about this post already know what GitHub is…  if you’re hear to read a post about clowning, you’ll have to wait for the next one…  GitHub announced in 2013 that it had reached over 10 million code repositories.  It’s not quite yet the infinite monkey theorem, but there’s definitely enough source code there to make me think that any library or framework feature that I’m interested in using already has a bit of sample code for it in someone else’s repository.

But how to find the examples I’m seeking?

Recently I was seeking examples of fabric8’s docker-maven-plugin in use.  It’s one of a couple of plugins that are supposed to help with managing Docker builds and Docker containers.  I don’t personally find Docker build files particularly challenging, but perhaps the managing the containers part would somehow be made easier with the plugin.  (TL;DR: finally didn’t find it useful, at least for our uses).  But in my hunt, I wanted to find examples of folks using this thing…

That plugin would be used in a pom file.  So, I want to find pom files that make use of the plugin.  In the case I originally went looking for, I wanted to use something called inline plugin configuration.  Basically, if I was going to use a Maven file to do the docker build, I wanted to keep all of the build information in the single pom file.  The docs described it as possible, but it just wasn’t coming together for me.  So, the query against Github:

(inline assembly docker-maven-plugin fabric8 dockerfile)  filename:pom.xml fabric8

Look across all repositories for a file named pom.xml which had certain keywords in it, and which were part of a repository or owned by a user which included the word fabric8. Found a few examples (and, and), but nothing which blew me away on the usefulness of that plugin and approach.

What about when I wanted to see examples of a particular routing package used in Go code?

language:go beego router

Wow, that gave me back 7K+ results.  Maybe narrow that down a bit?  I’d like to narrow that down by cross-checking the stars on the owning repository: theoretically, something with more stars would have more useful examples.  Interestingly, I cannot seem to get that to work as I’d like…  Although I can hunt for repositories with the phrase beego in their name or referenced in their description, I cannot get it to further check files.  The query below ignores the ‘stars’ descriptor and gives the same 7K+ results.  (I say ignores because I pulled up one of the repositories and it showed zero stars.)

language:go stars:>10 beego router

So, GitHub filtering has its challenges and quirks.  That said, I can also filter on looking for code within a particular repository or by  particular user, both of which help in filtering out the wheat from the chaff.

I can’t learn everything in software on my own, but if I can learn from someone else’s example (good or bad, assuming I recognize the difference), I can get the thing done and build upon my knowledge very efficiently.  Would love to hear if other folks have code search tricks and techniques, on GitHub or otherwise.

 

Leave a Reply

Your email address will not be published. Required fields are marked *