Last active
August 29, 2015 14:00
-
-
Save phsteve/11347841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To learn you really you need to do it a while. But we'll discuss some techniques that are helpful. | |
Starting: | |
clone (always, if you want to study) | |
git ls-files, skim, to see where code is | |
Finding where some feature is implemented, bottom up: | |
usually the easiest way to find anything specific | |
demo example: CPython, __add__ | |
grep, preferably git grep, or grep foo -- $(find . -name \*.c) etc. | |
string literals are great to grep for | |
(from UI, or external APIs: commands, SQL queries, etc) | |
for log messages etc., search for constant-looking substrings | |
for short words, use grep -w, or \b, or quotes (for entire literal), etc. | |
get more context with grep -10, -A10 | |
finding stuff, top down: | |
demo example: luajit | |
find 'main', or appropriate for language | |
have to guess to ignore boring stuff, drill down on interesting | |
have to skim code; gets easier as you read more | |
(and more in this language, or this codebase) | |
once you have a toehold in the code, navigating: | |
grep -w | |
grep 'def foo', or '^foo', '^\S.*foo', etc, to find just definitions | |
better: ctags, other tools below (highly recommended if spending much time on one codebase) | |
once you're looking at code, understanding: | |
VCS history | |
git log --stat -p -- $file | |
/^c in pager to go up/down a commit at a time | |
git log -G | |
git log --full-diff (I didn't mention this, but very handy; check 'git help log') | |
fancier tools for finding things: | |
ctags, etags | |
OpenGrok http://opengrok.github.io/OpenGrok/ | |
linux: livegrep, lxr (sadly lxr seems only half-working) | |
chromium: https://code.google.com/p/chromium/codesearch | |
github search (not very good; handy mainly when haven't cloned) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment