News for hackers. Stuff that matters.
Re:You can't parse [X]HTML with regex (2009) by chrismorgan on Friday March 05, 2021 @05:39AM (#26355297)
“You’re asking the wrong question” is a valid response.
Re:You can't parse [X]HTML with regex (2009) by bill_mon on Friday March 05, 2021 @06:02AM (#26355433)
I disagree, I see it as saying "you don't know what you really want, but I can read your mind". It's disrespectful and not giving the benefit of the doubt.
Re:You can't parse [X]HTML with regex (2009) by ivanbakel on Friday March 05, 2021 @06:22AM (#26355569)
>It's disrespectful and not giving the benefit of the doubt.

Unfortunately, a good number of users who post questions on StackOverflow have not earned the benefit of the doubt. Browsing the site, you will occasionally come across questions which are the tech equivalent of asking "Which screwdriver is the right size to stick in this electrical socket?"

Frame challenges are a necessary part of learning, so they belong on a Q&A site. If a user doesn't want their problem to be challenged, the onus is on them to clarify in the question why their particular approach is the necessary one. It's only possible to respond with alternative solutions when the problem is not specified enough.

Re:You can't parse [X]HTML with regex (2009) by jstanley on Friday March 05, 2021 @06:58AM (#26355848)
> Which screwdriver is the right size to stick in this electrical socket?

Note that this is a legitimate technique in UK sockets.

The live and neutral pins have a little gate over them that is retracted when you insert the earth pin, so you need to first stick a screwdriver into the earth pin in order to get your fingers into the live pin.

Re:You can't parse [X]HTML with regex (2009) by jerven on Friday March 05, 2021 @09:35AM (#26357258)
I can't parse if this is humour or a mistake. Putting your fingers on the live pin is not a great idea, trying this to get an euro 15 plug into an UK socket, also not great but in a different category.
Re:You can't parse [X]HTML with regex (2009) by Keyframe on Friday March 05, 2021 @09:51AM (#26357408)
Well, there's also a mains tester screwdriver which is a legit tool that you stick into a socket and also participate in the electrict current loop for the light on it to light up.
Re:You can't parse [X]HTML with regex (2009) by bill_mon on Friday March 05, 2021 @07:08AM (#26355915)
Good points.

I'm not so sure benefit of the doubt must be earned. More like, any participant in a discussion forum must show it when answering, and do proper research before asking anything. If all questions are good questions, there's no problem. But, as you say, they really aren't. I think poor question should be down voted with a brief explanation instead of trying to answer the "real" question. Or moved to a Frame challenge forum.

Are we trying to answer the question or to solve the problem?

Re:You can't parse [X]HTML with regex (2009) by shawnz on Friday March 05, 2021 @08:01AM (#26356361)
> do proper research before asking anything.

Asking on SO is itself research. It is good to review the existing literature before taking contributors time, of course, but if the problem is not solved in the existing literature, then perhaps the framing issue isn't addressed by the existing literature either. In that case how could the learner know the best way to frame the problem in advance?

> I think poor question should be down voted with a brief explanation instead of trying to answer the "real" question. Or moved to a Frame challenge forum.

This precludes the possibility that some contributors might want to address the framing problem, whereas others might want to address the specific question as asked. They may have different opinions about whether it is framed wrong at all. It also means the OP is losing karma or getting penalized for no fault of their own.

Re:You can't parse [X]HTML with regex (2009) by kemitche on Friday March 05, 2021 @12:29PM (#26359415)
The problem is, the answers are useful to more than just the original questioner. Sure, the questioner may be doing things vastly wrong - but the people who land on that question's page via search may have legitimate reasons for doing things a certain way.

The silent majority of viewers will benefit from an answer that does both of (1) explaining why the answer is probably not what is wanted, and (2) answering the initial question _as written_ anyway, for future viewers.

Re:You can't parse [X]HTML with regex (2009) by ivanbakel on Friday March 05, 2021 @01:05PM (#26359871)
Then those other viewers will either benefit in the same way from the frame challenge as a learning experience, or they will have a sufficiently-specific problem that they can ask their own questions with more justification for taking a specific approach.

Answering the question as written has the risk that any solution will be blindly applied without appreciating why the approach itself should be avoided. This is especially true for those users who see SO as a "write my code" site, and copy-paste anything in backticks.

Re:You can't parse [X]HTML with regex (2009) by lordgrenville on Friday March 05, 2021 @06:42AM (#26355748)
Strongly disagree. The point of SO is for experts to answer questions. They've learned things the hard way and would like to help others do better. They're not being paid. As such, telling the questioner that their whole approach is wrong is appropriate and even preferable.

From what I've heard Jeff Atwood and Joel Spolsky had different views on this and Spolsky's more tolerant, "no such thing as a stupid question" approach won out within the company, but is less popular among the people who write answers.

Re:You can't parse [X]HTML with regex (2009) by shawnz on Friday March 05, 2021 @07:23AM (#26356031)
I don't think it is disrespectful to suggest someone is falling victim to the XY problem.

Actually I think it is a common and expected outcome that when investigating a new problem, we often get stuck in "XY problem" traps while researching the solution.

I very much value any feedback that suggests I should rethink the entire problem with a simpler model, because without experience it's hard to know what the simplest models are.

Re:You can't parse [X]HTML with regex (2009) by anaerobicover on Friday March 05, 2021 @12:38PM (#26359521)
Absolutely agree. In my experience this is one of the more valuable features of asking someone to discuss a problem I'm mired in. Because they haven't been looking under every rock and studying the bark of every tree like I have, they're very likely to quickly see when I've wandered into entirely the wrong part of the forest.
Re:You can't parse [X]HTML with regex (2009) by bryanrasmussen on Friday March 05, 2021 @07:00AM (#26355866)
unfortunately sometimes people who ask questions are really junior, and need to be told they are going to have an unpleasant surprise if they go down the path they are planning on going.

sometimes people who ask questions know the pitfalls but don't clarify that they know adequately because they are pressed for time. in this case those people unfortunately run the risk of being talked down to and they should accept that.

on the other hand if they have clarified adequately that they know what they're doing and they still want to do something that might seem weird then I agree it is disrespectful. Which is a thing you see often enough on StackOverflow to be notable.

Re:You can't parse [X]HTML with regex (2009) by umanwizard on Friday March 05, 2021 @07:03AM (#26355885)
Maybe so, but what about the non-junior person who needs to do something weird for an actual valid reason and stumbles on the refusal to answer the question years later? StackOverflow answers aren’t just for the original asker.
Re:You can't parse [X]HTML with regex (2009) by andybak on Friday March 05, 2021 @07:46AM (#26356242)
I think in that case - the new person should probably post a new question.

The point is that the original question - as framed - was better served by saying "if you go back a step and reexamine your assumptions, you'll find there is a better path to your intended goal".

The new person has a different goal or a different set of constraints.

Re:You can't parse [X]HTML with regex (2009) by detaro on Friday March 05, 2021 @10:09AM (#26357629)
Because asking new questions and getting them closed as duplicate because they sound vaguely similar to an existing question is sooo helpful an experience...
Re:You can't parse [X]HTML with regex (2009) by andybak on Friday March 05, 2021 @11:10AM (#26358409)
Yeah - but I'm just playing with hypothetical ideal cases here. "Annoying flawed habits of Stack Overflow moderators" isn't something that's on my list of things I'm thinking about. ;-)

EDIT - which got me thinking. Maybe the "correct" thing to do is answer the original question as asked but gently point out to the person asking it that there is probably a better solution for them if only they had asked a different question.

The original question still stands and has an answer useful for other people. The original questioner has the opportunity to learn and ask the question they should have asked in the first place.

It's going to be annoying for someone - so it should at least be the person that kicked things off in the first place.

Re:You can't parse [X]HTML with regex (2009) by andybak on Friday March 05, 2021 @06:34AM (#26355673)
> It's disrespectful

How do you respectful tell someone you think they are mistaken? I'd rather not be pussyfooted around by someone if I'm in the role of "person who has asked a question based on a faulty assumption". Don't be rude but don't avoid trying to answer truthfully to the best of your ability.

Re:You can't parse [X]HTML with regex (2009) by bill_mon on Friday March 05, 2021 @07:13AM (#26355956)
> How do you respectful tell someone you think they are mistaken?

How about "you're mistaken"?

The problem is with "You don't know what you're talking about, but I do, so let me answer your real question".

Re:You can't parse [X]HTML with regex (2009) by andybak on Friday March 05, 2021 @08:59AM (#26356910)
The wording used was "You’re asking the wrong question” not "You don't know what you're talking about".

I find that perfectly fine. It was slightly disingenuous to reword it.

Re:You can't parse [X]HTML with regex (2009) by tester34 on Friday March 05, 2021 @06:59AM (#26355855)
>It's disrespectful and not giving the benefit of the doubt.

So what?

If actually OP knows that this is bad approach, then OP will clarify that he's aware and yada yada.

What's the problem? lack of thick skin?

Re:You can't parse [X]HTML with regex (2009) by tomashubelbauer on Friday March 05, 2021 @05:44AM (#26355329)
Yes, but I wish people who like to assume and answer saying so would still answer the question they think is wrong. Context matters and I don't think you can determine that with certainly nearly as often as some people online like to think.
Re:You can't parse [X]HTML with regex (2009) by shawnz on Friday March 05, 2021 @07:16AM (#26355974)
In this case the answer is correct given the parameters of the question: There is no way to have a regex that only matches the things which OP wants to match, but not any of the things OP doesn't want to match.

Given a specific situation, like a particular page or something, sure, regexes are still a possibility for solving the problem. The 2nd highest answer on the page details exactly that. So what is the problem? Is every single contributer obligated to artificially entertain the OP's preconceptions before giving the advice which they believe actually helps best? For example, if I were knowledgeable about XML but not regex, should I just not contribute in such a situation?

Re:You can't parse [X]HTML with regex (2009) by josefx on Friday March 05, 2021 @09:00AM (#26356922)
Do you educate people about the complexity of the physics and bureaucracy involved with defining the current time every time someone asks you "what time is it?" Or do avoid going onto irrelevant tangents that get you labeled as crazy and just tell them the current time?
Re:You can't parse [X]HTML with regex (2009) by IgorPartola on Friday March 05, 2021 @09:21AM (#26357136)
What time is it isn’t an invalid question. “How do I make my hamster grow wings and fly?” is. How to parse HTML with a RegEx is an in-between. For a specialized case, why not? Answer that question, then provide a counter example to show how it will be very fragile, then explain the theory, then show a better way. IME that tends to work better to teach someone what you think they should know.
Re:You can't parse [X]HTML with regex (2009) by jasode on Friday March 05, 2021 @09:55AM (#26357461)
>Do you educate people about the complexity of the physics and bureaucracy involved with defining the current time every time someone asks you "what time is it?"

Maybe you're (inadvertently) making a caricature by using a simple "what time is it?" question but many user questions are under-specified.

Because of that, Stackoverflow answerers in particular do go into the extra complexities because it's part of its editorial DNA to restate the q&a so it's a high-quality community knowledgebase instead of just answering the direct question as stated. I tried to explain this hard-to-grasp nuance previously: https://news.ycombinator.com/item?id=21115438

But sometimes, this X-Y problem editorializing mechanism gets so enthusiastic that it can detract from a correct answer. Here's a famous example of a string bytes extraction question with smart people arguing with the correct answers from user541686 (was Mehrdad) and Michael Buen:

+ correct answer has lots of X-Y pushback in the comments: https://stackoverflow.com/questions/472906/how-do-i-get-a-co...

+ another correct answer from Buen that emphasizes user541686/Mehrdad works for broken unpaired surrogates: https://stackoverflow.com/questions/472906/how-do-i-get-a-co...

The meta layer issue is that the question is underspecified which causes 2 sides with very intelligent people arguing whether or not it's an X-Y problem!

Re:You can't parse [X]HTML with regex (2009) by shawnz on Friday March 05, 2021 @10:47AM (#26358114)
I think the top answer in your example is highly misleading and deserves to have the caveats highlighted more clearly even though it's not "wrong". It is saying, "you don't need to worry about encoding", but really the point it is proving is "if you just use ONLY toCharArray and BlockCopy on ONLY one system and framework version then you can be sure they always use the same encoding as one another, so in that situation you don't need to worry".

So, the solution works, but only in specific situations which are not clearly explained and might be totally unrelated from OP's situation, and furthermore it doesn't really address the second part of OP's question "why take encoding into consideration?" I wouldn't necessarily call the problems with that answer just "XY pushback".

Re:You can't parse [X]HTML with regex (2009) by mumblemumble on Friday March 05, 2021 @12:39PM (#26359542)
Only when you know enough about the person's context to be able to tell them what question they should be asking instead.

If you don't have that context, then the correct thing to do is to ask for more information, or say, "did you consider this", or find some other way to come up with a constructive response. You don't just assume you know what the person really wants to do and then try to mainsplain it to them.

Re:You can't parse [X]HTML with regex (2009) by dgellow on Friday March 05, 2021 @05:48AM (#26355354)
Really, it depends the context. You might be aware that’s not something to generally do and still want to know the answer to the actual question.
Re:You can't parse [X]HTML with regex (2009) by anoncake on Friday March 05, 2021 @06:14AM (#26355519)
But not a valid answer. That's what comments are for.
Re:You can't parse [X]HTML with regex (2009) by anon946 on Friday March 05, 2021 @05:59AM (#26355414)
If the question were about full validated parsing of HTML with a regex, then I'd agree that "You can't do that" might be part of a valid answer. But finding tags is not doing a full validating parse.

Note that the set of valid C programs is not a context-free language. Yet it's common to use a context free-based approach to parsing. You just add additional code to handle the context-sensitive aspects (such as a symbol table).