DEV Community

Darkø Tasevski
Darkø Tasevski

Posted on Originally published at darkotasevski.dev

Recognizing Problems

The usual list of problem-solving techniques (ask questions about the problem, make it smaller, work backwards, build examples, draw it on paper) never matched what I saw happening when a hard problem finally clicked. I still use all of those every week, but they were never the thing that unlocked the problem, and I think the reason is that they help us pin down a shape we already half-recognize, while they can't give us a shape we've never seen.

Take two engineers looking at the same problem, where one of them sees it in thirty seconds ("that's a state machine, those booleans can't all be true at once") and the other grinds at it for an afternoon. The easy explanation is that the first one is smarter, but I don't think that's usually what's going on, and it's much more likely that the first one had seen that shape before and the second one hadn't.

Looking for patterns you don't have

"Look for patterns" is good advice, but it assumes we already have a library of patterns to look in.

The clearest example I have is a checkout flow with a dozen states, which for a long time I tracked the way most of us do at first, with a pile of boolean flags like isSubmitting, hasError, isComplete and needsRetry, and the bugs all came from the combinations that were never supposed to happen but did. If I'd never run into the idea of a state machine, no amount of working backwards or drawing it on paper would have gotten me to the fix, which was to stop tracking flags and start modeling states. The techniques work on a vocabulary of shapes, so without the shape they have nothing to grab onto, and we can shrink a problem, flip it around and cover the wall in examples and still not see it, simply because we don't have a word yet for what we're looking at.

This also explains the most boring item on every problem-solving list, the one that says practice matters and experience helps. That's true, but stated like that it doesn't tell you much. Practice matters for a specific reason, which is that every real problem you solve, and every solution you read closely, adds a shape to the library, like a debounce that keeps a handler from firing on every keystroke, memoization, optimistic updates with a rollback path, idempotency on a payment you might retry, or a cache (and the invalidation problem that comes free with it). None of those are techniques you apply by willpower - you either recognize the shape or you don't, and experience is how the library gets stocked.

How the library gets built

Memorizing a catalogue of patterns doesn't do it (I've tried, and it doesn't stick, because a pattern you can recite but have never needed isn't really yours yet). What works is solving real problems and then naming what you just did, and reading someone else's solution closely enough to notice what shape it was and not only that it worked. Being wrong a lot helps too, since the old advice that your ideas will be wrong more often than right is correct, and the useful part of it is that a failed attempt maps the territory. "That didn't work because this is a scheduling problem, not a sorting one" is a shape filed away for next time, so a lot of the vocabulary comes from the wrong turns.

The generic techniques are still useful, they're the tools we use to figure out which shape we're standing on, and for a problem that doesn't resemble anything in anyone's library they're all we have, which is also how new shapes get found in the first place. They just aren't the shapes themselves, and mixing the two up is why "I know all the problem-solving tips and I'm still stuck" is such a common (and frustrating) place to be. So when we're stuck it helps to know which of the two is missing. If we have the shape and can't apply it, the techniques are what to work on, and if nothing about the problem looks like anything we've seen, more grinding won't help and it's time to go and learn the shape.

A bigger library comes with its own problem, since once you have one everything starts looking like one of its shapes, and you'll reach for a state machine where a single boolean would have done (reaching for structure you don't need is a real cost, which is more or less the whole argument in Too Much Abstraction).

When a model names the shape for you

This is the part that is different now. A model will name the shape instantly, so we paste in the problem and it tells us it's a race between two async updates, or a caching problem, before we've drawn a single box. I use it, and it's a faster path to recognition than grinding for an afternoon ever was.

The problem is what it does to the library. If we let the model do the recognition every time, we stop adding shapes to our own, and the reps that would have taught us to spot it ourselves never happen, so we reach for the model again the next time and the dependency grows instead of fading. It's the old "don't jump straight into the code" advice moved up a level, to not jumping straight to the answer before we've tried to recognize the problem, because the trying is what builds the library.

What I try to do is form my own guess at the shape first, even a bad one, and only then let the model confirm or correct it. When I'm wrong, the correction has something to land on because I had a guess for it to hit, and when I skip the guess the answer usually doesn't stick.

Top comments (0)