-11

There are many scenarios where an asker needs to show a relatively long snippet of code to make the problem reproducible, however the problem is usually very tiny, which typically only involves a single wrong line of code.

In such cases, when we read the answers, it is very difficult to locate the wrong code shown in the answers. Because a code snippet in SO doesn't even include line numbers.

So I think a compare feature should be provided. Or at least, provide a way to show the line numbers when the reader wants to see them. (A button or something.)

4
  • 6
    Unnecessary IF the answer, as it should, explains what the error is and how it is resolved. Code only answers are, IMO, poor answers
    – Paulie_D
    Apr 26, 2020 at 4:36
  • @Paulie_D "Unnecessary IF the answer, as it should, explains what the error is and how it is resolved." This may be true for the asker, however, for other answer readers, It would be relatively hard to locate the problem the anserwer pointing out, particularly when there's repeated simple code such as ++iter
    – con ko
    Apr 26, 2020 at 5:06
  • 5
    The asker should not even consider posting until they can give a minimal reproducible example that includes pointing out the first line of code that doesn't produce a program state that they expect plus what they expected & why they expect it. And "minimal" means that the code is the smallest code they can give that is code that works extended by a bit more code. (So your question here is an XY question.) PS Run a diff.
    – philipxy
    Apr 26, 2020 at 5:56
  • I've needed this feature but I don't expected it on S.O. You can use a offsite diff like this. You can save the results and post a link
    – gman
    Apr 26, 2020 at 6:00

1 Answer 1

13

If there's a bunch of code, and the fix is only for a small part of it, the answer should only include that small part (possibly with enough additional code for context). If the answer is mostly a code dump of the original code with a few minor tweaks it isn't very helpful and should be edited to be more concise.

3
  • I can't completely agree. "the answer should only include that small part (possibly with enough additional code for context)" this is undoubtedly true. However, this is the only thing we can do in the current situation. You may suggest that during these decades, SOers all get used to it, however, don't you think, given this feature , many things would be much clearer? And I'm sure it will save time for those who is not the asker but interested in the answer given in the question post.
    – con ko
    Apr 26, 2020 at 5:14
  • 3
    @JohnDing Users have been encouraged to explain their code changes for a long time (look for code-only answer topics in meta). Answers that consist of "try this" followed by a long code block are low quality and should be downvoted (or edited). Still, you could just copy/paste code into any IDE and many text editors and compare them easily. I don't see much benefit in implementing it on SO. Apr 26, 2020 at 5:58
  • 7
    @JohnDing if an answer is just a code dump with no explanation whatsoever, thus requiring you to play "find the differences" in order to understand what this answers...then it's not a good answer. I encourage you to downvote those answers. As you yourself said here - they are not useful and they aren't clear. That's matches exactly with the tooltip for downvotes. In some cases, they are outright wrong and it's not easy to find out whether that's the case or not, too. Adding a diff feature would encourage bad answers, so I am against it.
    – VLAZ
    Apr 26, 2020 at 8:12

You must log in to answer this question.

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