2026.11.13 · 9 min · career · debugging · git · javascript
Things I wish I knew as a new developer.
Five habits nobody taught me when I started: read code with one question, read a stack trace for what and where, debug by halving, commit small so Git can undo it, and ask for help with a minimal reproduction. The research behind each, the commands, and the details people get wrong.
None of the things that made my first job hard were about writing code. They were about reading it, reading errors, finding bugs, undoing mistakes and asking good questions. Nobody teaches those in tutorials, so I made a five-part Instagram series about them, one habit a day. This post collects all five, with the sources behind each one.
1. You'll read far more code than you write
Tutorials have you build small apps from scratch. Your first job hands you thousands of files you didn't write. Robert C. Martin puts the ratio of reading to writing at "well over 10:1" in Clean Code, but that's his anecdote from replaying an hour of his own keystrokes, not a study.
The data comes from Xia et al. (IEEE TSE 2018): 78 professional developers, 7 projects, 3,148 working hours. On average they spent about 58% of their time on program comprehension. That counts time in browsers and documents too, so it isn't "58% of the time reading code". The same study found that senior developers spend a significantly smaller share of their time on comprehension than juniors. A reading method pays off most at the start.
The method: don't read the codebase top to bottom. Professionals "try to avoid program comprehension" (Roehm et al., ICSE 2012) and treat it as part of a change, never a task on its own. So pick one request you can trigger, start where it enters the program, and follow only that path. In a Next.js App Router project every API endpoint is a route.ts file whose folder path is the URL:
// 1. entry point (URL = folder path)
import { getUser } from "@/lib/users";
export async function GET(_req: Request, ctx: RouteContext<"/api/users/[id]">) {
const { id } = await ctx.params;
const user = await getUser(id); // 2. F12 → lib/users.ts
return Response.json(user); // 4. back to the browser
}
// lib/users.ts
export async function getUser(id: string) {
return db.user.findUnique({ where: { id } }); // 3. the database
}In VS Code that path is a few keys: Go to Definition (F12), Peek (Alt/⌥+F12), Find All References (Shift+F12), Quick Open (Ctrl/⌘+P), search all files (Ctrl/⌘+Shift+F). Pick a request you can trigger so you can check your trace with a breakpoint or console.log. If auth or validation middleware runs first, note it and move on unless your task needs it.
2. Error messages are clues with an address
A stack trace looks like a red wall, but only two lines do the work: what went wrong, and where it went wrong in your code. Frames are listed most recent call first: the call that caused the error is at the top, the one that started the chain at the bottom. In V8 (Chrome, Node, Edge) each frame reads at functionName (file:line:column), and only the top 10 are kept by default.
The trace above is illustrative, in V8's real format. Read the first line for what, skip the node_modules frames, and open the first frame that's yours at its line and column:
const { data } = useUsers(); // data is undefined until the fetch resolves
const rows = sortBy(data?.users, "name").map(u => <Row {...u} />);Your frame shows where the crash surfaced. The cause, here a fetch that hasn't returned yet, can sit a line or two earlier. Chrome DevTools helps by hiding known third-party frames by default.
I won't claim the message tells you the fix. Researchers agree error messages are often unhelpful, especially for novices (an ITiCSE 2019 working group), and studies on rewording them are mixed. It's a clue with an address. And looking things up is normal: in a CHI 2009 lab study, 20 programmers spent 19% of their time on the web, searched cryptic errors word for word, and looked up syntax they knew well.
What people get wrong:
- Reading from the bottom up. The bottom is where the program started, not where it broke.
- Trusting
bundle.js:1:48213. Without source maps the location is the bundle's. Vite and Next.js dev servers turn them on. - Searching with your own names in it. Strip your variable and file names so the search matches other people's posts.
3. Debugging is a method, not luck
Guessing (tweak a line, refresh, repeat) rules out one suspect per try. Halving rules out half every time. David Agans' Debugging: The 9 Indispensable Rules puts it in order: make it fail, quit thinking and look, then divide and conquer. Comment out half the code, or let Git halve the commits.
The figure is illustrative: 8 suspect commits, 3 tests. It scales well. git bisect uses a binary search over your history, and the git docs' own sample output reads "675 revisions left to test after this (roughly 10 steps)". 2^10 is 1,024, so about 10 tests cover 1,000 commits.
git bisect start
git bisect bad # current commit is broken
git bisect good v1.4.0 # this release worked
# test each commit git checks out, then type good or bad
git bisect reset # back to where you startedgit bisect run <cmd> automates it: exit 0 means good, 125 means skip, and any other code from 1 to 127 means bad. The same idea, automated on input instead of commits, is Zeller and Hildebrandt's Delta Debugging (2002): it cut a Mozilla crash from 896 lines of HTML to the single <SELECT> line in 139 test runs.
Two rules keep halving honest. It only works if the bug reproduces, so make a flaky bug fail reliably first. And change one thing at a time; three changes at once tell you nothing. If you can't make it fail again, you don't know it's fixed (Agans' rule 9).
4. Git is your undo button, so commit small and often
Pro Git puts the whole rule in two sentences: anything committed can almost always be recovered, and anything never committed is likely gone for good. So the fix for the fear of breaking things isn't more Git knowledge. It's committing more often, in "small logical steps", as Git's own workflow docs say.
| Command | What it does | Use it when |
|---|---|---|
git revert | adds a new commit that undoes an earlier one; history is kept | the commit is already pushed |
git reset | moves the branch tip; changes history | the commits are only local |
git restore | resets files; doesn't touch the branch | throwing away edits to a file |
git add -A && git commit -m "Add click handler" # one small step
git log --oneline # find the bad commit's id
git revert a1b2c3d # new commit that undoes it, history kept
git reflog # every place HEAD has been
git branch rescue HEAD@{1} # bring "lost" commits back on a branchThe reflog records where your branch tips have been, so commits "lost" to a reset --hard, a deleted branch or an --amend are still there. Entries expire after 90 days by default, but commits you lost are usually unreachable, and those go after 30. Recover onto a new branch, as Pro Git does, rather than reset --hard back, which would also wipe uncommitted edits.
What people get wrong:
- "The reflog saves everything." It saves commits.
reset --hardandrestorethrow away uncommitted changes for good. - Resetting a shared branch. Once it's pushed, use
revert. - Expecting the reflog on another machine. It's local; it isn't pushed and a fresh clone doesn't have it.
- Reverting with a dirty tree.
git revertneeds a clean working tree. Commit or stash first.
Small also pays off in review. At Google the median change is 24 lines, and small changes get first review feedback in under an hour on median, against about 5 hours for very large ones.
5. How to ask for help so people actually answer
"It doesn't work, help?" gets ignored, because the helper can't see your screen, your files or your goal. Jon Skeet's golden rule is to imagine you're the one trying to answer. A question gets answered when it has three things:
- What you tried. Raymond and Moen: describe the diagnostic steps you took before asking.
- Expected versus actual. Skeet: "I expected the result to be X, it's actually Y."
- A minimal reproduction. Minimal (as little code as still shows the problem), complete (everything needed to run it) and reproducible (checked that it really fails), in Stack Overflow's terms.
The third one is the trick. Cutting a 300-line component down to a few lines is debugging. Remove code bit by bit until the problem disappears; the last thing you removed is usually it. Here the question started as "my user card shows undefined, here's my whole component":
const res = await fetch("/api/user");
const data = res.json(); // missing await
console.log(data.name); // undefined: data is a PromiseExpected "Ada", got undefined. With three lines left, the missing await stands out: res.json() returns a Promise. Skeet, Raymond, Chris Ferdinandi and Yihui Xie all say the same thing from experience: building the small example often solves it before you send. That's expert opinion, not a measured rate, so I'll leave it at "often".
What people get wrong:
- Pasting all the code. A 300-line component makes the helper do your reducing for you.
- Asking about the attempted fix, not the goal. That's the XY problem. Say what you're actually trying to do.
- Asking to ask. Skip "anyone here know React?" and ask the question.
- Screenshots of errors. Paste them as text so people can search and copy them, and take out any keys or tokens first.
On a client project, I'd ask a new developer for exactly two things in their first week: one request traced end to end, and one question written with a minimal repro.
The short version
- Reading comes first: about 58% of developer time goes to comprehension, so trace one request from its entry point and ignore the rest.
- A stack trace's first line says what, its first frame from your own code says where; skip the library frames.
- Make the bug fail, then halve: about 10 tests find one bad commit in 1,000 with
git bisect. - Commit small and often; committed work is almost always recoverable with
revertor the reflog, uncommitted work isn't. - Ask with what you tried, expected versus actual, and a minimal repro; building the repro often solves it.
Sources: Martin, Clean Code ch. 1 · Xia et al., Measuring Program Comprehension (TSE 2018) · Roehm et al., How Do Professional Developers Comprehend Software? (ICSE 2012) · Next.js, Route Handlers · VS Code, Code Navigation · MDN, Error.prototype.stack · V8, Stack trace API · Chrome DevTools, ignoreList · Brandt et al., Two Studies of Opportunistic Programming (CHI 2009) · Compiler Error Messages Considered Unhelpful (review) · Agans' 9 rules (Wheeler's review) · Git, git-bisect · Zeller and Hildebrandt, Delta Debugging (TSE 2002) · Pro Git, Undoing Things · Git, gitworkflows · Git, git-revert · Git, git-reflog · Git, git-gc · Pro Git, Data Recovery · Sadowski et al., Modern Code Review at Google · Stack Overflow, Minimal Reproducible Example · Jon Skeet, Writing the perfect question · Raymond and Moen, How To Ask Questions The Smart Way · Chris Ferdinandi, The power of the reduced test case · Yihui Xie, The Minimal Reprex Paradox · The XY Problem · MDN, Response.json() · Don't ask to ask