avatarTremaine Eto

Summary

The web content provides advanced guide on how to effectively search GitHub for code snippets and examples, emphasizing the importance of leveraging existing code to improve efficiency in programming tasks.

Abstract

The article "Dev Tips: Searching GitHub Like a Pro" advises developers on the efficient use of GitHub's search capabilities to find relevant code examples. It stresses the value of not reinventing the wheel by utilizing the vast repository of code available on GitHub. The guide outlines steps for a pro-level search, including signing in to access all public repositories, using specific search queries, and filtering results by language and relevance. It also offers tips on using advanced search features, URL query parameters for languages not listed in the sidebar, and special search filters to refine results. The article encourages developers to go beyond basic search methods and harness the full potential of GitHub Search to enhance their coding process with real-world examples.

Opinions

  • The author believes that it is often unnecessary and inefficient to code everything from scratch when solutions already exist on GitHub.
  • The article suggests that while many developers are adept at using Google and Stack Overflow, they underutilize GitHub Search, missing out on a valuable resource.
  • The author expresses a preference for the "Recently indexed" sort option, as it provides the newest and potentially most relevant code snippets.
  • The author provides a workaround for finding code in languages that are not immediately listed in GitHub's language sidebar, indicating a belief that GitHub's UI may not always surface all available options.
  • There is an appreciation for GitHub's advanced search features, which allow for more precise queries, such as searching by file extension types.
  • The author encourages readers to contribute their own search tips, indicating a collaborative mindset and the belief that shared knowledge benefits the software engineering community.

Dev Tips: Searching GitHub Like a Pro

You’ve heard the saying before: don’t re-invent the wheel. In plain terms, if something already exists and has been proven to work, then it’s kind of a waste of time to go through the entire process of creating it on your own.

In programming, I really couldn’t emphasize this point more. Now, there’s a time and place for coding things on your own: maybe it’s for school projects where you will learn from the process, or maybe it’s a software engineering job interview where you can’t just simply say, “Well, I would just use C++’s append() method for this.”

However, in most cases, you’re going to want a solid reference — it’s not always the case where you’ll just copy and paste, but in my full-time software engineering experience, it’s so helpful to at least have something to go off of when writing my code.

That’s where GitHub steps in: it literally has millions of lines of code — many of it relevant to the use case you’re trying to program — available at your fingertips. Searching through it to help you complete your daily tasks may seem painfully obvious when you’re reading this; maybe you’re wondering why I’m sharing this, but I honestly don’t see enough developers doing it. In fact, I see many proudly proclaim their Google-Fu and their Stack Overflow savviness, but often they can’t find everything they need and neglect the power of GitHub Search.

How to search on GitHub the pro’s way

First of all, you’re going to want to be signed in on GitHub in order to be able to search for all public repositories’ code.

Next, just search what you want in the input on the top left of the toolbar (given the rapid rate of UI changes these days across the internet, this could change one day):

Your new best friend.

Let’s say I want to figure out how to use AWS DynamoDB’s ScanInput , but I can’t figure out how to get an example going just from the documentation alone or I just want to see other ways people are using it. So, I type “ScanInput” into the search box.

I then select Code because I want to see actual snippets of code that pertain to ScanInput , and since I am programming in Go, I select Go. This part is crucial because PHP code won’t really help me that much.

1,000+ possible coding assistants.

When you get your results, don’t assume every result is relevant to you; this is where your own knowledge has to come in. I see that the first results immediately are not really relevant to AWS DynamoDB, so I eventually keep scrolling and find some relevant results.

Utilize a different sort

In the screenshot above, you’ll notice that the results are sorting by “Best match”. I’m not sure what GitHub’s algorithm is for this, but it’s 100% worth trying different sorts if you’re having much luck. I really love the “Recently indexed” sort because it essentially shows the newest relevant code that people have pushed. I’ve just found that you’re more likely to get results that more closely align with your code’s versions, schemas, etc.

My favorite sort selection.

Searching for languages that don’t show up in the sidebar

Let me show the sidebar that came up when we searched for ScanInput again to show you a potential issue you may come across:

More likely than not, the language you want will be in this sidebar. However, there have been times where my language hasn’t been here. I used to think it’s just a limitation of GitHub, but then I realized a workaround: query parameters in the URL.

When I selected Go, the query parameter l=Go was added to the URL. If I wanted some Python results, therefore, I could just pop in Python where Go was. Once I do that, Python results appear! Note that you can also do this with GitHub’s advanced search feature, which I will go over next.

Advanced search

If you click on “Advanced Search” underneath the Languages sidebar, you have some more power behind your search. I’ve found certain filters in here to be quite useful; I like to query based on file extension types, for instance.

Special search filters cheat sheet

You can leverage the special filters GitHub offers in the search box itself instead of using the visual interface. Under the “Languages” toolbar, you’ll see a cheat sheet available:

For another reference on this special search syntax, check out the GitHub Help documentation.

And there you have it! GitHub’s search functionality has given me awesome real-world examples countless times as a software engineer; it can be one of your most valuable tools too.

If you have any more search tips, please leave them below in the comments!

More from cloud-native: the gathering

Programming
Technology
Coding
Software Development
Productivity
Recommended from ReadMedium