Earlier quoted context omitted.
> There are a few people who frequently have this complaint, but I don't think it's a real problem. If you actually need to do Y in a situation where most people who think they need to do Y are wrong, it's not everyone else's responsibility to divine that you are the magical case. Well, that's strange, because what they do is still divining. They try to divine "what you actually wanted", even though you asked another…
> known-quantity HTML where regex will work just fine (say, extract all href out of all a elements), Regex doesn’t work fine even on that. You still need to tell apart actual tags from contents of attributes, comments, uninterpreted contents of , and so on. A regex alone doesn’t give you the ability to do that. If you want to parse HTML, you need a parser. Simple as that.
The XY Problem (2014)
61–70 of 111 posts
Re: The XY Problem (2014)
#62Earlier quoted context omitted.
> known-quantity HTML where regex will work just fine (say, extract all href out of all a elements), Regex doesn’t work fine even on that. You still need to tell apart actual tags from contents of attributes, comments, uninterpreted contents of , and so on. A regex alone doesn’t give you the ability to do that. If you want to parse HTML, you need a parser. Simple as that.
Only if you care about absolute accuracy in sufficiently complex pages. There are many use cases I can think of that really don't.
Like, I know ".+foo\s+([a-z]+)" will work, because I've crafted it for a specific site whose sources I've seen.
Re: The XY Problem (2014)
#63Many will refer to stackoverflow since that's the reason this website was created in the first place. But one of the most important thing in solving problems in programming is context. Here is one real question I got in an interview: How do you efficiently sort a table containing a million record in JavaScript? My question was "in the front end?" And my answer was it's probably not a good idea to sort that much data…
For instance, if I was making heavy use of local storage where I have no back end, it is nice if that question is already answered. At that point I don't really care if the previous user got a better method, that's what I need to do now.
Re: The XY Problem (2014)
#64To quote the TFA: 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 solution for X. (emphasis mine) Whose time was wasted? For the asker, the exploration of Y and the eventual realization that it is not a good way to pursue X is a learning experience with value. For the answerer, they may feel their time is wasted if the goal is…
Is that how "TFA" is used now?
Re: The XY Problem (2014)
#65Earlier quoted context omitted.
> There are a few people who frequently have this complaint, but I don't think it's a real problem. If you actually need to do Y in a situation where most people who think they need to do Y are wrong, it's not everyone else's responsibility to divine that you are the magical case. Well, that's strange, because what they do is still divining. They try to divine "what you actually wanted", even though you asked another…
> known-quantity HTML where regex will work just fine (say, extract all href out of all a elements), Regex doesn’t work fine even on that. You still need to tell apart actual tags from contents of attributes, comments, uninterpreted contents of , and so on. A regex alone doesn’t give you the ability to do that. If you want to parse HTML, you need a parser. Simple as that.
Most of the time it works just fine for my purposes.
And it's not like I don't know alternatives. And I've written a toy compiler in the past (C with classes subset), done heavy XSLT work, know how to write a parser (manually, with flex/yacc, with PEG), have parsed XML with SAX, DOM, XOM, have used xpath expressions, css and jquery selectors, and used libs like BeautifulSoup.
Most of the time a quick regex will do just fine for that purpose.
See, I don't intend to send the href's to the ISS or to some medical equipment that will blow up if, god forbid, I accidentally found an A tag in a comment or inside a script or attribute.
And I'll probably run another regex or simple editor or awk filter to get rid of some false positives and I'll be fine.
>If you want to parse HTML, you need a parser.
That's a tautology, so it's always true.
If on the other hand you just need to extract some information from an HTML file, and you can just open the bloddy file and see its structure and it is perfectly servicable with a regex, you might not need a parser at all. Simple as that.
Re: The XY Problem (2014)
#66Re: The XY Problem (2014)
#67The worst XY problem is knowing you want to do Y, even if its strange or whatever, asking how to do it, and people asking you "why do Y? Do X instead". Happens all the time in Stack Overflow. Just answer the fucking question, and then give the lecture on why you think it should be done that way, or why it shouldn't be done at all...
You have to consider that SO exists not only to answer your specific problem, but also to help other users who might face a similar problem. In that context, it might be helpful to mention, if you are the asking person, include the details why you cannot do X, if you know you can't; or, if your question doesn't include details about your specific circumstance, answers that mention that common solution is to do X inst…
Might also point out that a lot of people finding the question later on Google because they the same question are just trying to do the same assignment, so Stack Overflow is undermining its own stated purpose here.
Re: The XY Problem (2014)
#68Yes, it is often the case that the person has the wrong idea of how to solve X, but this does not always say something about the validity of problem Y. Often times knowing how to do Y is valuable for other contexts besides X. We should try to be friendly and make it clear that Y is not a good way to achieve X without downplaying Y, necessarily.
Re: The XY Problem (2014)
#69This is the entire game in consulting. Your client comes to you asking for something but with certain expectations in mind. The job of a good consultant is to meet those expectations - stated or not. You learn pretty quickly how to figure out what they’re really asking.
Client states they need something like Y, consultants assess the situation, understand they should do X but keeps it to themselves, the parties come to an agreement to solve Y and do so. Client states they need something like X..
Re: The XY Problem (2014)
#70The XY Problem (2014) - https://news.ycombinator.com/item?id=20068686 - June 2019 (158 comments)
Ask HN: What's your favorite technical formulation (i.e., the XY problem)? - https://news.ycombinator.com/item?id=17344147 - June 2018 (1 comment)
The XY problem - https://news.ycombinator.com/item?id=13578522 - Feb 2017 (1 comment)
The XY Problem - https://news.ycombinator.com/item?id=10023882 - Aug 2015 (70 comments)
The X-Y Problem - https://news.ycombinator.com/item?id=52486 - Sept 2007 (1 comment)