Better Programming

Advice for programmers.

Follow publication

3 Tips to Overcome the XY Problem

Stop trying to figure out solution Y, when you don’t understand problem X

Milos Zivkovic
Better Programming
Published in
3 min readDec 16, 2020

--

Photo by Sergey Pesterev on Unsplash

You’ve had problems with files. Probably due to their file extensions. Let’s say you wanted the last three characters to determine the file type. You ask some people questions about it.

You search for code to find the last three characters. Your coworkers probably have some suggestions, so you ask them as well.

You’re stuck on your solution, without looking back at the problem.

You’ve got into the XY problem. Let’s go into the details of it.

What’s the XY Problem?

The XY problem is asking about your attempted Y solution. You should ask about actual X problem.

xyproblem.info

Let’s make a general algorithm of the XY problem visible. The definition is from xyproblem.info, so be sure to pay a visit there.

  • The user wants to do X.
  • The user doesn’t know how to do X but thinks they can fumble their way to a solution if they can manage to do Y.
  • The user doesn’t know how to do Y either.
  • The user asks for help with Y.
  • Others try to help the user with Y, but Y seems like a strange problem to want to solve.
  • The user wants help with X and Y wasn’t even a suitable solution for X.

You’re trying to get a file extension from the last three characters. That’s Y. Actual problem is finding all file extensions. That’s X.

Rather than talking about X, you’re talking about Y.

<n00b> How can I echo the last three characters in a filename?

<feline> If they’re in a variable: echo ${foo: -3}

<feline> Why 3 characters? What do you REALLY want? <feline> Do you want the extension?

<n00b> Yes.

<feline> There’s no guarantee that every filename will have a three-letter extension,

--

--

No responses yet

Write a response