15

I've experienced a couple of times at Stack Overflow a few discomforts when asking some questions because some users were a little passive-aggressive with me, so I am kinda afraid of using Stack Overflow and getting bullied by not knowing some things.

But, since we are dealing with humans answering question, I believe that it is much better than ChatGPT, since ChatGPT is still in development and can get some things wrong.

I have a couple of questions regarding some topics and concepts in React, and was wondering if I can create questions here asking how a specific block of code that I did and it worked how it works...

Can I do this?

7
  • 18
    Just to answer the question in the title "Can I ask a question for explanations of specific blocks of code, instead of using ChatGPT"; Yes you can. That's what used to happen before chatGPT was invented anyway\
    – user13267
    Commented Jun 14, 2023 at 4:28
  • 14
    As for the passive-aggressive users just ignore them. dealing with them is just a part of using the internet
    – user13267
    Commented Jun 14, 2023 at 4:29
  • 4
    The thing is that this is largely tied to the person asking the question and not so much the question itself. It is a type of question that will be immediately in the danger zone and will require careful wording and preparation. I would allow myself to say that for most people the way to go is to ask somewhere else. If you are such a person, can't say.
    – Gimby
    Commented Jun 14, 2023 at 8:22
  • 1
    Actually I think that GPT could be more useful for explaining code than for answering programming questions. So why not using ChatGPT (especially when integrated in your ide as codegpt for example)? For a good question on SO, the problem needs to be clear and focused, i.e. you should be able to pinpoint the understanding the code problem somehow. Commented Jun 14, 2023 at 8:58
  • 23
    I'd say if you ask to explain code without specifying what you don't know or don't understand about the code, it will likely be downvoted and voted to be closed for being unfocused and unclear. Commented Jun 14, 2023 at 9:18
  • 1
    When in doubt, look at other well-received questions. You will inevitably write some poorly-received questions, but understand that it's not directed at you, but whether the question is fit for the site.
    – Passer By
    Commented Jun 16, 2023 at 7:09
  • 1
    Seems overly general. Passive aggressive response to questions about 5 pages of code might be reasonable. Specifics do matter. Did those question demonstrate that you had read the guidelines in the Help Center?
    – IRTFM
    Commented Jun 20, 2023 at 1:55

5 Answers 5

31

Size and abstraction are factors. Don't treat us like ChatGPT and dump us a whole file from some codebase. Take a look at Makoto's answer to Is "How do I convert code from this language to this language" too broad?. If it's something reasonably scoped and abstracted away enough from highly-localized details, and you think it's something that someone else might likely wonder about in the future, then I think it's ok. I'd suggest also to take a look at the instructions on providing a minimal reproducible example: Can you simplify the code in a way that preserves the behaviour you want to understand? Are there any parts that can be removed or abstracted away from a specific application? These kinds of things are how you improve the long-term value of your question to the knowledge base.

Here's an example of my own that I once wrote: How do set(var ${var} value) and set(var "${var}" value) work in CMake? (I'm not saying it's perfect, but I think it's passable)

1
  • I really liked the answers here and indeed, but yours gave me the biggest insight. Indeed, I will always keep this in mind. Thank you! I asked this question because I had a really dumb question regarding a basic JavaScript function I wanted to ask on StackOverflow but was kinda scared to ask because I did'nt want to annoy anyone, but I did it like you said: Give details, say what I tried, etc, and it all worked ok. Thank you. Commented Jun 26, 2023 at 17:41
47

Within... reason. Above all, the goal should be asking questions in such a way that we can leave a useful Q&A pair that is likely to be useful to users in the future (and not just users who've read a given book.) With that in mind, the question should be focused on a particular concept or misunderstanding, rather than "here's a bunch of code, what does it do."

24

No, this is not a useful question to ask on Stack Overflow. The purpose of SO is to create a library of questions and answers so that other people can search find useful answers in the future. "How does <hunk of code that I wrote> work?" is not a question that anyone else is ever going to have unless, for some strange reason, they wrote the identical code.

If you have a question about a certain construct, or a certain function, that confused you with its behavior while you were writing code, and you can single out that construct and elucidate your confusion in English, that might make a valid question. But a question that is just a block of code plus "how does this work?" or "why does this work?" or "why doesn't this work?" should be closed — neither passively, nor aggressively, just closed.

1
  • Agreed, with a possible exception for an easily identifiable chunk of open-source code that someone else could stumble across and ask about, if its somewhat self-contained (answerable without knowing the architecture of the whole library). e.g. Why does glibc's strlen need to be so complicated to run quickly? has some aspects of "how does it work" along with "why is it faster". So if you can name the block of code in a way that future readers might search on, e.g. "Linux's xyz function" or "libfoobar's abc function", then others can find a Q&A. Commented Jun 16, 2023 at 22:49
6

My own choice to answer this type of question outside of the comments would depend on a few factors:

  1. Did the author make a reasonable attempt to understand the code by themselves? There's an expectation that the author at least attempted to run the code, or better yet, walk through it with a debugger.
  2. Like any question on SO, they must've done some research for solutions or similar questions first. Any syntax that can easily be understood through a quick glance at the documentation should not be included in the question.

If the question passes those requirements, it should no longer be about the snippet of code as a whole, but rather about particular lines of code or confusing syntax within the code.

The question could also be something to the effect of, "what is the motivation behind writing the code in this way?" A response might point out that this particular method is objectively more performant, more secure, less error-prone, etc, as long as it's not simply opinion-based.

1
  • Re "Like any question on SO, they must've done some research for solutions or similar questions first.": In the homework tags, work orders are perfectly acceptable (requirements (e.g., (artificial) constraints on the means) + input data + desired output; nothing else). Commented Jun 15, 2023 at 20:40
3

If you have specific questions about small sections of code, this might be considered to be acceptable by most people on this site, but you'll probably still find some people who don't. There's a lot of controversy about what's a good question vs what's a bad question, and some people are... finicky about that, as you've seen.

You might have better luck with the sister sites of:

https://softwareengineering.stackexchange.com
What's on-topic here?

and

https://codereview.stackexchange.com
What's on-topic here?

But, like this site, you'll still need to follow the rules or your question is still going to get downvoted or closed. Unfortunately, these sites aren't as heavily trafficked as the main Stack Overflow site, so YMMV with responses.

You must log in to answer this question.

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