Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

The X-Y Problem


  • Please log in to reply
2 replies to this topic

#1 Guest

Guest

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 914 posts
  • Location:USA
  • Programming Language:C, Java, Python, Bash, Others
  • Learning:Assembly, Scheme

Posted 11 April 2011 - 07:56 PM

I found this on reddit recently, and I thought it would be a good thing for CodeCallers to be aware of when helping people. I've seen it happen before, so it's a pretty common occurrence.

The original text is hosted on Greycat's Wiki. I copied the full text of this from there in case the link stops working in the future.

The X-Y Problem, as it is sometimes called, is a logical fallacy which leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help. It often goes something like this:

  • User wants to do X.
  • User doesn't know how to do X, but thinks they can fumble their way to a solution if they can just manage to do Y.
  • User doesn't know how to do Y either.
  • User asks for help with Y.
  • Others try to help user with Y, but are confused because Y seems like a strange problem to want to solve.
  • After much interaction and wasted time, it finally becomes clear that the user really wants help with X, and that Y wasn't even a suitable substitute for X.
Here's an example.

<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> Then ASK FOR WHAT YOU WANT!
<feline> There's no guarantee that every filename will have a three-letter extension,
<feline> so blindly grabbing three characters does not solve the problem.
<feline> echo ${foo##*.}
Another example:
<lhunath> when starting a process from shell, the process inherits the gid of the shell - I'm looking to start a process with a different GID than my own, so I assumed I should first newgrp to the new group and then start the process - however, newgrp audio gives the following error when run as non-root: Cannot execute bash: No such file or directory
<lhunath> newgrp - audio works, however, but I can't use this in a shell script to start a certain process with a different GID since it spawns a subshell

<greycat> What are you *really* trying to do?

<lhunath> trying to start wine with GID of audio

<greycat> lhunath: well... daemontools includes a setuidgid program that could do it, but to run that, you have to start out as root, and then define a user account whose primary group has the GID you desire.
<greycat> I suspect what you *Really* want to do is "make wine's audio work".  Which means you probably want to add yourself to group 'audio' in /etc/group, and logout and back in.

<lhunath> grin, if only it were that easy. no, what I'm *really* trying to do is to get the rlimits that I set in pam for @audio to apply to the wineserver process so that it can use the sched_fifo to give audio threads a higher priority for games that request it. for wineserver to be able to use the rlimits, it needs to have a gid of the @audio that I defined in /etc/security/limits.conf

<greycat> You don't actually think that rlimits magically "pop up" when a process is invoked with a specific UID/GID, do you?
<greycat> rlimits are set within your *own* process and then handed down to your children when you fork/exec thme.
<greycat> Only specific things read pam.d config files -- things that are linked with libpam.
<greycat> Like /bin/login or /usr/sbin/sshd.

<lhunath> greycat: should if I define '@audio          -       rtprio          90' in /etc/security/limits.conf ;x

<greycat> lhunath: what process do you think reads that file?

<lhunath> pam
<lhunath> hrm.

<greycat> lhunath: and you think that "wine" is linked with libpam?
<greycat> you need to set the limits you want, *and then* run the program you want.
<greycat> it will inherit them.
<greycat> I do stuff like this all the time:    su --> ulimit -v whatever --> su - freenet --> start the Freenet node
<greycat> usually exec su - freenet, so that a raw root shell isn't left lying about if/when the freenet processes terminate

<lhunath> heh.

<goldfish> nice

<greycat> See, *this* is why I ask things like "What are you really trying to do"
This one happens a lot. Seriously, we see something like this at least once a week:
<chron> i'm editting a sed stream like:  sed 's/^/blah/'
<chron> but i want to replace with 'blah/' instead of 'blah'
<chron> editting a stream*

<greycat> blah\/ or use a different separator

<_matt> blah\//

<chron> thanks
<chron> i'm trying to ls a directory, and every file or folder that shows in ls, i want it to come out like file1 file2 file3  (all in one line)
<chron> instead of columns or list

<greycat> echo *

<trash> chron: echo dir/*

<chron> i'm trying to compare 2 files: file1 and file2, if there is any matching line in file1 from file2, i want it gone from file1

<greycat> !faq subtract
->#bash http://wooledge.org/mywiki/BashFaq#faq36 -- How can I get all lines that are: in both of two files (set intersection) or in only one of two files (set subtraction).

<trash> !bashphorism2
->#bash The questioner will keep changing the original question until it drives the helpers in the channel insane.

* greycat goes out on a limb and guesses that the actual question is "I want to synchronize a directory against another directory"

<chron> no
<chron> i know what i'm doing, i swear
<chron> lol

<trash> I swear you don't.

<chron> cool worked, thanks guys
<chron> i have a file with <package>-<ver> in a list (separate lines), for example: gnu-netcat-0.7.1, and i want to remove -<ver>
<chron> gnu-netcat-0.7.1 becomes gnu-netcat

<Knirch> !pe
->#bash Parameter Expansion. Expressions like ${foo%.mp3} and so on -- see man bash, and then search for Parameter Expansion. See also, http://wooledge.org/mywiki/BashFaq#faq74 and http://tiswww.tis.case.edu/~chet/bash/bashref.html#SEC30

<greycat> chron: ${foo%-*}
<greycat> !pe
->#bash Parameter Expansion. Expressions like ${foo%.mp3} and so on -- see man bash, and then search for Parameter Expansion. See also, http://wooledge.org/mywiki/BashFaq#faq74 and http://tiswww.tis.case.edu/~chet/bash/bashref.html#SEC30

<chron> and that will work even with something like gnu-netcat-0.7.1 ?
<chron> when it has the hyphen after 'gnu'

<greycat> !pe
->#bash Parameter Expansion. Expressions like ${foo%.mp3} and so on -- see man bash, and then search for Parameter Expansion. See also, http://wooledge.org/mywiki/BashFaq#faq74 and http://tiswww.tis.case.edu/~chet/bash/bashref.html#SEC30

<chron> ok ok

<savetheWorld> foo=gnu-netcat-0.7.1;  echo ${foo/-[0-9]*/}

<greycat> savetheWorld: stupid.

* savetheWorld humbly accepts greycat's gentle critique, begs forgiveness and asks for more information

<chron> how do you do it for every line?

<greycat> !faq 1
->#bash http://wooledge.org/mywiki/BashFaq#faq1 -- How can I read a file line-by-line?

<greycat> savetheWorld: foo=glibc-2.5-2.5.1
<greycat> in that case, you want glibc-2.5 to be the output, but yours fails.

<savetheWorld> greycat: but I just tested it.
<savetheWorld> foo=glibc-2.5-2.5.1;  echo ${foo/-[0-9]*/}
<savetheWorld> glibc

<greycat> savetheWorld: and that's wrong.

<chron> it's not glibc-2.5

<savetheWorld> ah, rats
<savetheWorld> hmm - right end anchor.... ah, first dash traveling left from the right hand end.

<greycat> which is precisely what ${foo%-*} does

<savetheWorld> ah, didn't see you post that the first time.

<greycat> it was delayed by some lag

<savetheWorld> and % is non greedy, %% is greedy.
<savetheWorld> right?

<igli> yup

<savetheWorld> tx

<chron> ok greycat was right, but i needed savetheWorld's solution

<greycat> !bashphorism1
->#bash the questioner's first description of the problem/question will be misleading.

<chron> lol because some packages look like blah-2.5-r4
<chron> thanks both

<greycat> Has to be a Gentoo user.

<chron> lol
<chron> quit being so uncanny

<igli> chron: what are you working on?

<chron> emerging all packages in a category
<chron> that are not already merg'd

<igli> all in the whole cat?

<greycat> and the reason you can't just type "emerge blah-2.5-r4" is...?

<trash> he has to type emerge =blah-version

<chron> not only that but

<greycat> and the reason you can't just type "emerge =blah-2.5-r4" is...? ;-)

<igli> he needs the list first

<chron> i want to get ones that aren't already merg'd

<trash> chron: just add -u

<greycat> !xy
->#bash http://wooledge.org/mywiki/XyProblem

<chron> and i need to get that not-already-merged list
<chron> into /etc/portage/package.keywords
<chron> i know what i'm doing :>

<igli> cd /usr/portage/"$cat"; list=($(echo *))

<greycat> You're a gentoo user.  By definition, you don't have a clue what you're doing.

<greycat> igli: you mean list=(*)

<savetheWorld> "you keep saying that.   I do not think it means what you think it means"..... TPB.

<chron> but my /etc/portage/package.keywords looks very funny with massive comments

<igli> god yes, sorry, just woke up

<chron> no gentoo means i know what i'm doing

<trash> chron: LOL
<trash> that was a good one.

<savetheWorld> Inconceivable!

<chron> please don't tell me you use debian
<chron> else i'd be laughing for days

<greycat> Now that's a case where LOL was probably literal.

<igli> chron: don't get into this seriously
<igli> #friendly-coders when they've mauled you enuff chron
<igli> ;)

<chron> well i know what i'm doing, and it's already in progress :>

<greycat>    --noreplace (-n)
<greycat>           Skips the packages specified on the command-line that have
<greycat>           already been installed.

<chron> yea that's the solution i'm using when i'm doing actually merger
<chron> last step :)

<igli> cd /usr/portage/"$cat"; list=(*); emerge -n ${list[@]}
<igli> cd /usr/portage/"$cat"; list=(*); emerge -n "${list[@]}" # sorry

<greycat> or just cd /usr/portage/"$cat" && emerge -n *

<igli> heh :)

<greycat> but hey, that would be too obvious and simple!

<igli> "" not needed in gentoo, but best to be safe

<chron> ok i can use that as my last step

<greycat> us poor ignorant Debian and BSD users can't handle his Gentoo elitism.

<igli> chill out greycat :)

<chron> but what i did to get the list in the first place was echo *

<igli> well do that instead

<chron> cd /usr/portage/$cat && emerge -n $whateverthatgotechoed
<chron> lolz

<igli> use *

<chron> or i can just copy and paste what i echo *'d

<greycat> emerge -n *

<chron> ah

<igli> indeed

<trash> indeed lolZ

<chron> lolZ

<igli> hehe that is hilarious

If anyone has some examples of this happening on CodeCall, feel free to share!

Edited by Alexander, 12 April 2011 - 12:33 PM.
Moved to The Lounge

  • 0
Root Beer == System Administrator's Beer
Download the new operating system programming kit! (some assembly required)

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 12 April 2011 - 12:30 PM

Very often if one person does not state their intentions, they are automatically asking their question incorrectly (see How To Ask Questions The Smart Way, and possibly help vampires.) This is exacerbated by the breadth of possible ways to do one thing.

The main issue: The poster has not read the features of one language, therefor will ask a question based on their knowledge. A reply will most certainly be "Have you not thought about using X?", when it could had been void if A) The user had posted their intentions, B) A user had questioned their intentions.

With either of the two, it does not even matter in respect to confusion, if they had looked beforehand at possible solutions.

This leads to me without hesitation asking this. This in fact happens every hour on here in a subtler manner, I could do a google search of this site of me asking the same question over and over, about what they really mean and I am sure results will be plenty.
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.


#3 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 04 May 2011 - 07:11 AM

Ah - Here is one: http://forum.codecal...189-file-c.html
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.