Jake Worth

Jake Worth

Learn From It

Published: March 25, 2022 2 min read

You were stuck, and now you aren’t. Congratulations! Before you move on, I think that it’s vital to stop and learn from it. It’s the best way I know to get better and spare your future mind for increasingly harder problems.

Every time you get unstuck, ask yourself: when I was stuck, what was I missing?

  • Was I misreading a message?
  • Was I hypnotized by an irrelevant detail? 😵‍💫
  • Did I make a bad assumption and ignore anything that didn’t fit into my assumption?

What did I miss?

If you received help from someone, think back to the last question they asked before you got back on the path. What was that question? What were the questions before that question— what did your helper rule out? Everybody approaches problems differently, but great problem solvers tend to follow similar checklists.

Practical Example

From my current work: I’m developing a single-page-app and my browser screen is blank. There are many explanations for this problem, but only one is correct. Let’s figure it out.

My UI is premised on data; is the network request returning 200 and data? I check the Network Tab of Chrome Devtools; no, it is not. It’s returning 422. Immediately, I know that this is a backend problem. This seems like a small victory, but ruling out half my codebase has turned a big problem into a smaller problem.

What else is in the response?

  "exception": "undefined method `number' for nil:NilClass",
  "from": [
    "/app/helpers/orders_helper_decorator.rb:18:in `edit_item_path'",

See that ...? It’s 600+ lines of noise. Experience tells me that the relevant line of the stack trace is the very first one.

I jump to that method with Exuberant Ctags: :tag edit_item_path. The line mentioned in the trace is highlighted:

# orders_helper_decorator.rb

def edit_item_path(line_item)
    id: line_item.product.slug,
    order_number: line_item.order.number  )

Revisiting the error: "exception": "undefined method ``number' for nil:NilClass". We’re calling number on nil— my line item does not have an order to ask its number. I smack my forehead because I know that items once had to belong to an order, but currently, they don’t. I now have enough information to start solving the problem.

To summarize:

  • Frontend error! Is it a frontend problem? No.
  • Where’s the stacktrace pointing? Go there.
  • Reason through the stacktrace. Use debugger or print statements. Keep digging.

Once you figure it out, walk back through the solution and analyze your thinking. Where were you efficient and inefficient? How would a programmer you admire approach this problem? What kind of questions would they ask? This is one of my favorite exercises.

Today I Learned blog posts are a fantastic way to turn this reflection into a habit. Figure something out, write about it, ship. Josh Branchaud’s TIL is a great example of this practice.

When you get stuck and then unstuck, learn from it.

Get better at programming by learning with me. Subscribe to my newsletter for weekly ideas, creations, and curated resources from across the world of programming. Join me today!