8

What should we do with flawed attempts to solve a problem, where the flaw is unrelated, both are common, and the question isn't explicit?

This is an extremely common issue I've been running into with new questions, but I was prompted again by considering this old question I just dupe-hammered: Python - Check if a number is a square

We have a canonical for checking whether integers are perfect squares, so given the title that's an obvious closure. However, OP's code is also a textbook exhibition of a common logical error, which is a) addressed by the top answer and b) has nothing to do with number theory.

Specifically, the problem is with trying to "search" a list of candidates to see whether any of them meets a condition (equivalently: whether all of them meet the opposite condition, and negating that result), using an explicit for loop, and eagerly returning a value the first time through the loop, whether or not the condition is met. (Correct logic should only return affirmatively if the condition is met, and then return negatively only after the loop - the same idea applies, mutatis mutandis, for checking for "all" candidates meeting the condition).

This is a very common logical problem with code written by new programmers. It's the sort of thing that I would otherwise close as a typo, but I know that it really isn't a typo - people writing the code really do expect it to work this way because they are confused in the same, recognizable and MRE-able way. For another example, see the canonical Why does non-equality check of one variable against many values always return true?; many things are marked as typos ("obviously you meant and rather than or, right?") that really should be duplicates of this question. The classic Python FAQ Why does "a == x or y or z" always evaluate to True? How can I compare "a" to all of those? is also something like this: a problem that's easy to understand and that experienced developers might consider a typo, but that large numbers of people get wrong in the same way.

We don't, to my knowledge, have a good canonical for the "search with a loop for anything meeting the condition" problem, although ironically we do have questions addressing ways to do the search without a loop (specifically, using the built-in any and all functions). I'm working on finding or writing something like that, so that the logical issue can be addressed first, and then reference can be made to more sophisticated approaches like any/all.


My current stance is:

  1. In most cases, a question that asks "how do I do X (using a specific technique | "manually" or "explicitly" | without a particular standard library tool)?" is really a duplicate of the base "how do I do X?". The right place to put "alternative" approaches to X-ing is under that main canonical; if it's possible (and at all sensible) to do it in a specific way that isn't covered yet, rather than have a separate question for that specific way, the correct tool is for someone to place a bounty.

  2. However, for some values of X, it will happen that many people try to use a specific technique Y, and commonly get it wrong in the same way Z. Sometimes this will be X-specific, but typically it just happens that the X problem is good bait for using Y, and the underlying question isn't really about X at all, but about Z. We should have good Z canonicals that have a classic flawed Y implementation (with the Z flaw) in the question, that explain why Z is wrong, and also show (or reference other questions) alternatives to Y - and all of this should be agnostic to X, if at all possible.

But this is where we encounter a problem. Constantly, new questions are asked that look like: "I tried to do X. Here is my code: Y [which exhibits the Z flaw]. Description of how it failed." The first question I linked at the top is a shining example of that (aside from being 5+ years old). Note in particular that there is no question mark anywhere.

These are perhaps better than average, even, but I don't know what to do here.

  • Is this a duplicate of "how to do X"?
  • Is this a duplicate of the debugging question for the Z flaw?
  • Perhaps both?
  • Does it "need more focus" because OP presumably wants both answered?
  • Is it "unclear" because OP didn't say which question is being asked? If so, should we insist on questions explicitly containing a question (i.e. following QUASM)?

Aside from that, I have been meaning now for a long time to make the complaint that the insistence on code examples is actively making many questions worse. Many times someone will come to Stack Overflow with "How do I do X?" and no code. While it's true that many values of X are overly broad, "what have you tried?" is often a terrible response. The worst-case scenario (surprisingly common) is that OP has tried Y, and got it wrong in the Z way, and posts it, and now the above dilemma has been introduced to a question that didn't need it.

Is there anything else I'm missing here?

14
  • 2
    Possibly related, but I think not a duplicate: meta.stackoverflow.com/questions/290728 Commented Feb 17, 2023 at 15:51
  • 4
    While it isn't a close-reason, I feel there is no shame in coming to the conclusion that questions promoted as X but actually about Y are not useful... Commented Feb 17, 2023 at 16:03
  • 2
    @MisterMiyagi I understand what you're getting at, but I'm still fundamentally opposed to the idea that a "library of detailed, high-quality answers" should tolerate the inclusion of questions that are "not useful" (which, in my mind, implies they fundamentally cannot support a high-quality answer). Commented Feb 17, 2023 at 16:05
  • I mean... expecting users with a new variation to the same problem to have the reputation to apply a bounty and be willing to part ways with 50 rep is a bit... unlikely IMO. Merging does exist for cases like this
    – Kevin B
    Commented Feb 17, 2023 at 16:08
  • @KarlKnechtel I agree with the spirit, but as far as I can tell the close reasons are not designed for this kind of quality. These questions generally are clear/focused/detailed/... and not themselves obviously duplicates to either the general X nor the practical Y canonical. Commented Feb 17, 2023 at 16:09
  • @KevinB I have closed questions and put a bounty on the canonical for a more specific answer, in some cases; and added my own answer to the canonical in others. Commented Feb 17, 2023 at 16:42
  • 1
    "the insistence on code examples is actively making many questions worse" No, the problem is they never do give a MRE--minimal code with with the problem, that is working code minimally extended by bad code, with what they expected & why, justified by referencing documentation. It's always just a code dump. Once one actually gives a MRE the question becomes a canonical.
    – philipxy
    Commented Feb 17, 2023 at 18:33
  • 4
    @philipxy what code exactly does one need to supply for "How do I make a string uppercase"? There are many other variations that in my opinion cannot really have code supplied. Because to do so is to answer the question. So either the code can be correct and the question makes no sense or incorrect and then answerers are led to explain the incorrectness rather than answer the "How to".
    – VLAZ
    Commented Feb 17, 2023 at 18:40
  • @VLAZ If an appropriate MRE is the null MRE then so be it. Re your quoted question, it seems canonical & a shopping list request, a sort of question that for very basic simple questions seems to be on-topic. Except even that particular example should give code to confirm context & what they mean by "string" & should confirm there aren't any other requirements. Also that doesn't seem to be the sort of question at issue in this meta question. We would expect it to be pinned down from an original after a MRE is developed.
    – philipxy
    Commented Feb 17, 2023 at 20:07
  • This is unclear. What is the point you want to discuss? On what are you giving your "stance"? On what point are you concerned about "missing" something? What is the "very common logical problem"? You say "specifically", but you mean "for example"--an example of what? Please read what you have written. Seems maybe you are (unclearly) trying to address when "OP's code" specification is for "a canonical", "so given the title that's an obvious closure. However, OP's code is also a textbook exhibition of a common logical error". But then what about it? "what to do here"? PS Close--no [mre].
    – philipxy
    Commented Feb 18, 2023 at 4:50
  • Maybe you are trying to ask/discuss: 'Constantly, new questions are asked that look like: "I tried to do X. Here is my code: Y [which exhibits the Z flaw]. Description of how it failed."' 'What to do here'? But this post is not clear. My next comment here is my prefab comment for such questions, which I accompany with a downvote & close vote as unfocused or unclear or [mre] or duplicate, depending on the main drift of the question.
    – philipxy
    Commented Feb 18, 2023 at 5:27
  • "Please ask 1 specific researched non-duplicate question. Please either ask about 1 bad definition/query/function with the obligatory [mre], including why you think it should return something else or are unsure at the 1st subexpression that it doesn't give what you expect or are stuck, justified by reference to authoritative documentation, or ask about your overall goal giving working parts you can do with justification & ideally a [mre]. Then misunderstood code doesn't belong. But please ask about unexpected behaviour 1st because misconceptions get in the way of your goal. [ask] [Help]"
    – philipxy
    Commented Feb 18, 2023 at 5:30
  • "We don't, to my knowledge, have a good canonical for the "search with a loop for anything meeting the condition" problem, although ironically we do have questions addressing ways to do the search without a loop" - I try not to know anything about Python, but one thing I do know because it is a fascinating bit of trivia is that using a loop in Python is usually a code smell. So this lack of canonical would make sense to me specifically in the context of Python.
    – Gimby
    Commented Feb 21, 2023 at 11:36
  • @Gimby Outside of numerical computing, that's frankly... not true. Mildly put. One of the key abstractions in Python are iterators, i.e. stuff to loop through. Commented Feb 21, 2023 at 11:55

0

You must log in to answer this question.