Last year, jumping from an HTML/CSS/JS mindset to working with full-stack apps was confusing. A single rendered page on a full-stack (e.g. Rails or Django or MeteorJS) app could be drawing in code from *multiple* files in different folders. I was often confused about where everything was located.

Eventually, my co-worker Tim gave me two great tips, which made a *huge* difference in my ability to debug problems in more complicated apps.

Tip #1: Install and use the silver searcher (https://github.com/ggreer/the_silver_searcher). Once I started learning how to search for keywords by typing in “ag [keyword] -C5” or “ag [keyword] -l” in my terminal, I was able to figure out much more easily the files that certain bugs were located.

The first example returns to you the file paths and line numbers where the keyword match (as well as 5 lines before and after the matching row for context).

The second example returns the file paths and line numbers that match the keyword, but shows up as a list, and does not include any of the code or context. Using the “-l” search parameter is helpful if some of your search returns happen to be one long string.

Tip #2: Use find . -name “keyword”

This command searches for file names that match a specified keyword. Helpful if — for example, the word “apple” is the name of a file, but is never within the contents of any of my code.

=====

Interesting to reflect that in addition to being competent at “googling” for solutions on the internet, part of being a developer is becoming competent at searching for things in your own codebase.

blog comments powered by Disqus
  • Hi, I'm Linda! I enjoy going to tech meetups, learning web development, and blogging about the learning path. Follow me @LPnotes

Subscribe to The Coding Diaries