Are You Solving the Right Problem? (i.e. the XY Problem)

Ever heard of the XY problem? No? Those of you in tech support may have seen it without knowing its name, but it actually happens quite often in programming and tech support. 

Here is an example from xyproblem.info, albeit rewritten for JavaScript

n00b> How do I get the last 3 letters of the filename? 

feline> If it's in a variable, you can slice it like str.slice(-3)

feline> Wait, why are you asking?  What do you really want? 

feline>Do you want the extension (of a file)? 

n00b> Uh, yes? 

feline>There's no guarantee that every file name will have a three-letter extension, so blindly grabbing three characters does not solve the problem.

With that said, here are three ways to get it, using regex, split, or slice+lastIndexOf 

See the problem? noob asks for X (last 3 characters of string), but actually wanted to solve Y (get file extension). What if there was no extension? What if the extension is MORE THAN 3 letters? 

See how it completely changes the problem? 

What really happened goes like this:

  1. n00b wants to solve a problem (get the extension of a filename)
  2. n00b has no idea how to do it, but thinks of a related approach that could work (get last 3 characters) and assumes that's the solution. 
  3. n00b don't know how to do that either
  4. n00b, instead of asking for help on the ORIGINAL problem, asked how to solve this alternate problem. 
  5. but the ancillary problem is similar but UNRELATED to the original problem, and trying to solve it results in an overly complicated mess
  6. after a ton of wasted time and futile struggle, n00b finally revealed the actual problem
So, are you solving the right problem? Or an XY problem? 

Comments

Popular posts from this blog

Yet another take on recursion

Problem Solving for Programmers: a Neglected Topic?

How to Solve a Problem, with Examples