35

My program was crashing and I eventually came up with a theory about what I was doing wrong. Based on that theory, I made a change and now my program works. However, I want to be sure that my understanding is correct. I thought about asking a question along the lines of "Here's my code. It wasn't working and I think the reason is X. Am I right?"

Is this type of question appropriate? After all, if I am right, what could a responder do other than say, "Yes, you're right"?

Would it be better to post my original problem without my solution and then answer my own question (people can comment if my answer is wrong)?

7
  • 37
    The first thing you should ask yourself is "Is this problem going to be helpful to a lot of people, or just me?". A good question needs to have widespread usefulness. The second is "now that I've fixed things, are there any existing questions and answers that might have helped me now that I've a better idea what to look for?" Commented Jun 7 at 20:25
  • 5
    specific example here aside, I don't see why such a category of questions should be outright categorized as inappropriate. There are misunderstandings that are common, and so Q&A clearing those up can be useful. but yes, I can also image lots of not as useful questions in this category. use your up/down votes.
    – starball
    Commented Jun 7 at 23:42
  • 1
    A proper [mre] question & self-answer is better, except that after the [mre] the question is very likely clearly a duplicate many times over & shouldn't be posted.
    – philipxy
    Commented Jun 7 at 23:53
  • Typically in "Is my understanding correct" questions asker descriptions are incoherent and/or involve leaps of reasoning, so the post is unclear. Clear explaining is difficult. Also the question if clarified would typically be specific to the asker & not helpful to others. But in response to comments & close votes re clarity askers seldom make an effort & essentially never manage to actually clearly give their reasoning. So I suggest they give the 1st place they are uncertain in some quoted competent presentation. The person who does not understand is seldom best to set the agenda.
    – philipxy
    Commented Jun 9 at 4:09
  • 4
    In general avoid yes/no questions. Always ask for the reasons behind instead. Like "Why is X resulting in Y?", "What solves X?", "How can I find out if X solves Y?". That way, depending on what you are most interested, you will learn something. People might also include that in an answer to a yes/no question but then one can ask explicitly about it. Commented Jun 10 at 6:22
  • 6
    Maybe post your "working code" on Code Review since it seems more aligned with your goal. They can inform you if the code is good or needs improvement.
    – Drew Reese
    Commented Jun 10 at 6:26
  • People always try to find cookie cutter rules on Stack Overflow, but it is impossible. Every question is different and needs to be judged on its own merit. There is only one universal truth; context is key. You'll have to judge for yourself if whatever information you provide provides context, or derails it. A meta post like this would work better if you had examples so those examples can be examined and explained.
    – Gimby
    Commented Jun 12 at 7:16

4 Answers 4

30

Typically you can answer such questions by testing—make the change in isolation with the same data/inputs and see if the problem is still reproducible, or not. So, at the very least, such questions would likely be met with downvotes for a lack of research.

Would it be better to post my original problem without my solution and then answer my own question (people can comment if my answer is wrong)?

Yes, this would be much better—this way you're not asking if a solution is correct, but rather asking for a solution—someone might come by and provide a better one than what you found!

11
  • 3
    You have a box to check to achieve that when you create a question on SO. This way, you can make your question have an answer immediately. Additionally, here is a link to a blog post about answering your own question: stackoverflow.blog/2011/07/01/…
    – Mougnou
    Commented Jun 10 at 10:33
  • 1
    You can answer practically every question asked on here by testing. I could see a valid way to ask about an understanding with research effort - "I was doing X and I read in the docs this quote > foo that Y does this" - in fact, heres a very old example of my own
    – Sayse
    Commented Jun 10 at 14:39
  • 4
    Typically you can answer such questions by testing I don't believe that's as true as some would like. Just because something works doesn't mean you're doing it right, and doesn't mean it will always work. Most questions pertaining to timezones would fall into that bracket and pretty much every question on threading. Knowing why it worked is equally important. Commented Jun 10 at 14:45
  • @Sayse You cannot answer "how do I" questions or "why doesn't my code work" by testing. You can only answer questions about working code by testing.
    – TylerH
    Commented Jun 10 at 15:21
  • @TylerH Unless it's a C++ question. A lot of incorrect C++ programs appear to be correct when testing on a specific machine.
    – yeputons
    Commented Jun 10 at 17:00
  • @yeputons C++ is not a special unicorn. If you test something on your computer and it works, you can still ask about whether the code is really correct, so long as you explain in detail why you suspect it might not be. Any question where you have code that works and you ask "but is it correct?" without explaining why it might not be is worth downvoting and close voting as needing more details as to what the asker's problem is. That's not unique to C++, or Haskell, or Raku, or Rust, or whatever your favorite complicated programming language is.
    – TylerH
    Commented Jun 10 at 17:42
  • @TylerH - Of course you can? trial and error is a very commonly used strategy to test out theories and ideas to overcome such questions
    – Sayse
    Commented Jun 10 at 18:35
  • @Sayse That's not what 'testing' means. Testing here means 'run the code', see if the expected output occurs, where you get the answer you are looking for, one way or the other, no matter how the code is written. It is, or should be, clearly different from a scenario where you figure out how to write code to achieve a task, which is another kind of problem altogether.
    – TylerH
    Commented Jun 10 at 21:48
  • 2
    @Sayse Also, in addition to what TylerH said, trial and error only works if you have some theory about something that might work. If you think something is possible, but have no idea what the relevant method call is, you can't exactly try every possible set of parameters to every possible set of method calls to see if any of them do that.
    – Ryan M Mod
    Commented Jun 10 at 21:53
  • @RyanM Is that "in addition", or "in contrast"? I too do not believe the premise that typically things can be understood by "testing." At the very least, not in a reasonable amount of time.
    – Mars
    Commented Jun 11 at 3:58
  • 1
    @Mars There's a limit of 60 seconds IIRC for removing your comment upvote.
    – TylerH
    Commented Jun 11 at 4:18
14

Yes, it's a good idea and should be allowed. I would argue that intentionally withholding your understanding/assumptions doesn't help anybody.

If your understanding is correct, I can just say "yes it's correct". I don't want to waste my time explaining things you already know, so I want to know that you know.


The other answer said:

Typically you can answer such questions by testing—make the change in isolation with the same data/inputs and see if the problem is still reproducible, or not. So, at the very least, such questions would likely be met with downvotes for a lack of research.

But I disagree. If you can check your assumption by experimentation, then do that and don't ask the question in the first place! Instead of asking and withholding information. (Or ask and self-answer to share knowledge.)

Or, in some cases experimentation might not prove anything. In some languages (C/C++), the program may appear to work, but have hidden issues that you wouldn't know about if you didn't read the spec.

13
  • 1
    "then do that and don't ask the question in the first place! Instead of asking and withholding information." This is unclear--not asking the question in the first place is more withholding of information than asking and not providing an answer.
    – TylerH
    Commented Jun 10 at 13:57
  • "Or, in some cases experimentation might not prove anything. In some languages (C/C++), the program may appear to work, but have hidden issues that you wouldn't know about if you didn't read the spec." I don't see how this invalidates the argument made in the quote. If anything, it just underscores it; users should read the spec before asking, if they don't, that's a lack of research effort.
    – TylerH
    Commented Jun 10 at 13:57
  • 2
    @TylerH The spec is long (about 2000 pages for C++ last time I checked) and hard to navigate for a newbie. Commented Jun 10 at 14:06
  • Questions about understanding the spec are certainly to be expected, but Ctrl+F is not hard even for newbies.
    – TylerH
    Commented Jun 10 at 14:09
  • 2
    @TylerH If the spec was sane, yes. C++ spec is not sane. For starters you need to know the proper name for the thing you're searching, and then you need to understand what it says. :) Commented Jun 10 at 14:14
  • 1
    @TylerH "This is unclear--not asking the question in the first place is more withholding of information than asking and not providing an answer." I elaborate in the second paragraph. It's not bad in general, it's bad when asking a question because it can waste my time. Commented Jun 10 at 14:42
  • How is asking a question wasting your time? Sorry, I don't buy that. OP isn't concerned about your time, they're concerned about an answer to their question. If you think a question may have wasted your time after reading it, that's a you problem, not a them problem.
    – TylerH
    Commented Jun 11 at 4:23
  • @TylerH It's not reading the question that wastes time, it's writing an answer (in some cases). I don't mind spending time on an answer if it helps another human (if they actually learn something new from reading it), but if they already know what I explained to them, then it's a waste of my time. Commented Jun 11 at 4:33
  • @HolyBlackCat Your argument mostly holds if SO was a helpdesk, but you don't write answers just for the asker, you write them mostly for future visitors of the Q/A (at least that's the focus of the site) and for them the question about a specific understanding with a yes/no answer is much less useful than a properly split up problem solution(s) pair. Especially if the answer to "is my understanding correct" is no.
    – cafce25
    Commented Jun 12 at 13:41
  • @cafce25 I agree that "yes you're correct" shouldn't be an answer, it can be a comment. But you can restate OP's assumptions in your answer if they are correct, perhaps in a more structured manner. Knowing their assumptions lets you e.g. address specific misunderstandings in your answer in more detail. Commented Jun 12 at 14:04
  • In other words, them stating their assumptions doesn't have to affect the way you answer in any way, and it doesn't prevent you from creating a good Q&A pair. Commented Jun 12 at 14:09
  • "doesn't prevent you from creating a good Q&A pair." – except it massively complicates the question and thus impedes understanding it. It's bad for the same reasons we don't edit answers into the question. Also "yes you're correct" should never be a comment since comments are not meant to answer the question, they are for clarification, constructive criticism, and minor or transient information.
    – cafce25
    Commented Jun 12 at 14:30
  • @cafce25 I guess it depends on how verbose OP is being. A single line "I think X is happening here, is that correct" looks benign (and you can explain what exactly is X in your answer), while half a page of text is too much. Commented Jun 12 at 14:57
12

As mentioned in the comments, the goal is to ask a question that is useful to as many people as possible. So rather than ask the very specific question "is my understanding correct?", just ask the actual question at heart:

Ex:

Is my understanding that function Foo() is async correct?
The below code change makes my code work, but I'm not sure why.

Can be rewritten as:

Is Foo() async?
The code below returns a Task, so if I don't add "await" the return value isn't as expected.

Of course, do the necessary research first, but I'm sure you already know that.

1
  • 1
    yes! As a fallback you can always restructure to directly ask the reason and offer your thoughts at the end of the question: "Can you explain why this works? ... I'm wondering if it's because ... but I'm not sure." seems pretty good. It leaves a lot of scope for the answer to put things in clearer terms with more background information. Commented Jun 10 at 14:50
1

Is this type of question appropriate? After all, if I am right, what could a responder do other than say, "Yes, you're right"?

Yes, you're right.

Would it be better to post my original problem without my solution and then answer my own question (people can comment if my answer is wrong)?

Now with this question, I cannot reply "Yes, you are right" anymore. You successfully force me to give me more details. So while I think "Is my understanding correct" questions are appropriate, it will be better for you, the answerers and other people if you can find out one more deeper question, and shift the focus of the question to that. Assuming your initial question is "Is my understanding that function Foo is async correct?", then you are assuming "Foo is async". That's your theory that help you fix the problem, but it's an unverified one. So you can just make an extra step and research on whether Foo is actually async or not. Then:

  • If there is no information whether Foo is async or not, then your question is now obviously: "Is Foo async?"
  • If Foo is actually async, then you will have more confident to self-answer the question. Or you can ask follow up questions like:
    • Why should Foo be async?
    • How to improve this code using Foo? (Code review question)
  • If Foo turns out to be not async, then the question now becomes "This code suggests that Foo is async, but it's not. Why is that?" It's the same of asking "What is the thing that walks like a duck and quacks like a duck, but isn't a duck?"

I think all of these questions are much more interesting.

7
  • What exactly are you saying with "Yes, you're right." to the first quote? It sort of asks two diametrically opposed things that one could respond to, so saying "yes" to both is unclear.
    – TylerH
    Commented Jun 10 at 13:56
  • I was actually answering the first question. Why do you think the linebreaks are unnecessary? They are there as rhetorical devices
    – Ooker
    Commented Jun 10 at 15:07
  • Linebreaks are formatting tools, not rhetorical devices. They also increase the amount of scrolling needed for no reason.
    – TylerH
    Commented Jun 10 at 15:22
  • well, the amount of scrolling is a rhetorical device as well. Anyway, why is this answer bad?
    – Ooker
    Commented Jun 10 at 15:37
  • I don't know what you mean by 'why is this answer bad'. If you're asking why some people have downvoted it, presumably that's because they disagree with the arguments the answer makes. And no, amount of scrolling is not a rhetorical device. Rhetorical devices are structures of words used to invoke a certain reaction. Invoking reactions vis-a-vis formatting is bad and almost universally guaranteed to annoy readers.
    – TylerH
    Commented Jun 10 at 15:39
  • "Rhetorical devices are structures of words" — ah I see. Thanks. "Invoking reactions vis-a-vis formatting is bad and almost universally guaranteed to annoy readers." — do you mean in general, or just readers of this site in particular? "[T]hey disagree with the arguments the answer makes" — yeah I mean why people downvoted or disagree with it. Do you have any idea?
    – Ooker
    Commented Jun 11 at 4:17
  • I mean in general; don't make readers scroll, just use an ellipsis. Et cetera.
    – TylerH
    Commented Jun 11 at 4:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .