36

Earlier today I saw a question (see below) of really low quality, which only copy and pasted the whole code, without an MCVE and a clear pointer where exactly the error occurs. The English can be better, but it's not that bad in my opinion.

Should I try to edit the question to an MCVE? Or just leave it alone and move on?

I think that the question can be greatly improved to a good question, and I don't think this question has a dupe. I thought of editing it (see below).

My edit probably can be improved, but it's a lot better than the wall of code of the original question (I think). Note that the code (except for my error comment, and I removed the properties of Mesh) is copy-pasted from the code the OP posted.

Is this appropriate? Should one edit questions without an MCVE to a question with an MVCE? Or should the OP do it?

Does my edit make sense (i.e. is the question a good question?)?

What should I do?

I removed the code/errors so that this question doesn't get too long:D


std::unique_ptr::unique_ptr(__gnu_cxx::__alloc_traits >::value_type&)’

i'm using C++ std11 and i've the following code

//38 lines of code ommited

with my class Model that contain an std::vector meshes;

when i compile this code i'm the following error:

//55 lines of long errors ommitted

please i don't understand where's the error, i've a vector of Mesh and use the operator[] the give me a Mesh and with this i creat an unique_ptr

Thanks.

PS. those are my class:

//52 lines of code ommitted

Error when trying to create a unique pointer to an object

I am trying to make a vector of unique pointers to Mesh objects, but I am getting an error when I create the unique pointer to the object.

class Mesh {};

std::vector<std::unique_ptr<Mesh>> objects;
std::unique_ptr<Mesh> myMesh( myModel.meshes[0] ); //error: no matching function call

objects.push_back(std::move(myMesh));

meshes is a std::vector<Mesh>.

I can't seem to understand why it doesn't work because operator[] returns a Mesh, and I can use that Mesh to initialize a std::unique_ptr.

The full error is:

error: no matching function for call to ‘std::unique_ptr<Mesh>::unique_ptr(__gnu_cxx::__alloc_traits<std::allocator<Mesh> >::value_type&)’
  std::unique_ptr<Mesh> myMesh( myModel.meshes[0] );
                                                  ^

Why can't I create a unique pointer to a Mesh object?

5
  • 17
    Leave that for the OP, they will learn from doing that themselves. Commented Jul 4, 2016 at 17:24
  • @πάνταῥεῖ Sure, but maybe that will give them the initiative to do it for future questions, right?
    – Rakete1111
    Commented Jul 4, 2016 at 17:27
  • 11
    Well, it's always a bit borderline/problematic to edit code beyond fixing formatting issues. Commented Jul 4, 2016 at 17:42
  • 5
    Give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime
    – j08691
    Commented Jul 5, 2016 at 16:08
  • 2
    @j08691 PREACH IT! Right now we have a lot of users that would be starving to death. Too many people feel like it's helping others to do work for them... that might help some people but it teaches most people that I don't have to put in as much work because others will clean up my mess. Imagine a world where every question was a good question... not a (simple) duplicate, well worded with code properly formatted, what would we do with ourselves? We'd be answering a lot of interesting questions instead of being everyone's mother like I feel like right now.
    – JeffC
    Commented Jul 6, 2016 at 0:00

4 Answers 4

43

Should I try to edit the question to an MCVE? Or just leave it alone and move on?

No, IMHO neither is the the right action


I think it's always better to ask the OP for creating a MCVE in a comment.

While they're working on that, they'll even find the answer on their own, or at least learn something that's required when asking here.


Well, editing code beyond plain formatting issues to bang a question in shape for a MCVE is always a bit of borderline action.

For example, if someone posts c++ code like

int main() {
    std::cout << "Hello World!" << std::endl;
}

just adding

#include <iostream>

might actually obfuscate their problem, that they simply forgot to write the #include <iostream> statement.


Though already I did something like the above, in case of satisfying commenting nitpickers, where the question obviously didn't have anything to do with the missing #include <iostream> statement.

Yet, such edit doesn't implicitly lead to a MCVE, since in such cases there's usually more information missing I can't simply edit in, but only the OP will know (or needs getting to know then).


Otherwise such posts can be closed just straight away with the

  1. Questions about a problem that can no longer be reproduced or that was caused by a simple typographical error. While similar questions may be on-topic here, these are often resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting.

off-topic argument.

5
  • 1
    One case I think it's legitimate to edit is when the code was provided by an offsite link, eg pastebin. Just bringing the code into the question makes it much more readable, and can help avoid an unnecessary close/reopen cycle that wastes a lot of reviewers' time. Commented Jul 4, 2016 at 20:51
  • 13
    @RyanBemrose Well, even in most of these cases I'd leave a comment for the OP, that they should post their code into the question and bang it in shape as a mcve themselves. They should undergo that learning process themselves to teach them being better SO participants. BTW most of such links miss the minimal point from my experience. Commented Jul 4, 2016 at 20:54
  • Recommend moving the last part ("I think it's always better...") to the top just after "No, IMHO neither is the the right action". Commented Jul 6, 2016 at 5:29
  • 1
    For those that don't know, it's possible to use magic links for edit and mcve so you can say "Please edit your question and add an [mcve]"
    – Tas
    Commented Jul 6, 2016 at 22:15
  • @Tas This is a great generic comment. However, it's a MCVE, because [mcve] gets magically expanded; see e.g. here
    – anatolyg
    Commented Jul 7, 2016 at 9:18
29

I disagree somewhat with the other answers here.

If you understand the code well enough to answer, then definitely edit

anatolyg is correct in that you probably shouldn't be making non-trivial edits to code if you don't understand the problem(s) present in it.

But if you do know the answer, and have answered (or plan to answer shortly)... Then why wouldn't you want to have a good-looking question above your answer?

After all, the point of having a Minimal Complete Verifiable Example is to save future readers (including answerers) the pain of having to slog through pages of unnecessary code to get to the point where they understand what problem is being presented. If you've already had to do that, then you're in an ideal position to save others the trouble; arguably not doing so is a disservice to them, and reduces the chance that the question - or your answer - will do them any good.

If you want to take a slightly more self-serving perspective on it, then making a question that isn't painful to read means there's a better chance someone else will read your answer as well... And reward you for it.

There are also badges for this... Explainer, Refiner, Illuminator

20
  • 17
    Works best when the answer is shown to address the question fully, of course... last thing we want is to edit a question to fit an answer that turns out to be misleading or wrong...
    – BoltClock Mod
    Commented Jul 5, 2016 at 4:28
  • 2
    this say it all : If you understand the code well enough to answer, then definitely edit
    – dippas
    Commented Jul 5, 2016 at 15:44
  • 15
    If you understand the code well enough to answer, then answer it. If the answer is accepted - then edit the question.
    – AD7six
    Commented Jul 5, 2016 at 15:47
  • 2
    So disagree with this approach. It's called enabling.
    – Ken White
    Commented Jul 6, 2016 at 0:07
  • 1
    My ideal is that the question is a good-looking question before anyone answers it. If people learn to properly form a question before they get answers, then they will either go away (and we probably didn't want their questions anyway) or they learn to properly format their question the first time. Right now there are masses of questions being asked that are all bad questions... lazy askers looking for some quick code with no/minimal effort. I spend 90% of my time down voting and commenting all the garbage and very little time actually answering questions. The tide is too strong...
    – JeffC
    Commented Jul 6, 2016 at 0:07
  • As opposed to just answering without editing, @ken?
    – Shog9
    Commented Jul 6, 2016 at 0:30
  • 4
    No, as opposed to voting to close until the question is improved, at which time it can be answered. There's even an off-topic close reason for not providing a MCVE. Answering a terribly written question (with or without editing it) encourages other poor quality questions, both by this poster and others. Also, editing code in questions is highly discouraged here (as I'm aware you already know), and doing so also encourages others to do so, and they may not be as knowledgeable or conscientious as you. The author of the question should be responsible for writing the question properly.
    – Ken White
    Commented Jul 6, 2016 at 0:34
  • And there's meta.stackexchange.com/q/88627/172661, which is still relevant here. :-)
    – Ken White
    Commented Jul 6, 2016 at 0:49
  • The critical factor there, @ken, is not answering. If you're gonna answer anyway, all that "I'm not enabling bad askers" stuff goes out the window... You're still enabling, and now you're leaving a shit question hanging around too.
    – Shog9
    Commented Jul 6, 2016 at 1:40
  • 1
    I don't answer anyway. I vote to close, leave a comment as to why, and don't post an answer until it's been edited. Answering keeps the shit question hanging around, because many users ignore questions that have already been answered. If you vote to close, it locks it until the poster edits to get it reopened or until it gets sufficient downvotes to delete.
    – Ken White
    Commented Jul 6, 2016 at 1:44
  • Given this answer is solely concerned with situations where you "have answered (or plan to answer shortly)", I gotta wonder if you meant to reply to a different answer.
    – Shog9
    Commented Jul 6, 2016 at 1:46
  • 2
    Suggest you edit to clarify that you're saying that if you answer the question (correctly), then yes you should edit it (and strongly agree there, btw). And to say that if you don't, you shouldn't, and what to do instead. Ken's right about enabling, and the OP here didn't say he answered it. (Your "If you understand it well enough to answer" doesn't read that they answered it, just that they could.) Also agree with @AD7six - make sure the answer really is the answer before editing the question. If your answer isn't right, your edits are likely to make things worse, not better. Commented Jul 6, 2016 at 5:37
  • 1
    Eh, this answer can live or die on its merit. Frankly, I'm not a fan of this timid approach to editing or the notion that editors should have to ask permission; if that's where we're ending up here, I'll recognize it... but I won't condone it.
    – Shog9
    Commented Jul 6, 2016 at 6:15
  • 2
    I would love if this were a thing, but it simply isn't. Every time I edit a question down to an MCVE, the OP blows up: "That is not my code! I can't do nothing with your answer!". Because they don't understand what they're doing, all they're looking for is their exact code fixed. I won't do that anymore, just vote to close as off-topic because of lacking [mcve].
    – CodeCaster
    Commented Jul 6, 2016 at 6:26
  • 3
    Also downvote, @codecaster. It helps a lot.
    – Shog9
    Commented Jul 6, 2016 at 6:30
13

Often, the best approach may be to show the questioner how to reduce the problem to an MCVE; something like:

The code as presented can be reduced to the following which demonstrates the problem:

int main()
{
    return EXIT_SUCCESS;
}

This gives you

327373.c:3:12: error: ‘EXIT_SUCCESS’ undeclared (first use in this function)

The error message now clearly points to line 3; the solution is to ensure that EXIT_SUCCESS is defined, by adding

#include <stdlib.h>

It may still be worthwhile to tidy up the wording of the question (and, especially, the title - that's what people see first). I'm wary of making any changes to the posted code unless it's utterly trivial (e.g. re-indenting code that's otherwise readable).

In the answer, you have free rein to re-write the code to be a clear as possible - and this allows you to show off the contrast in clarity between your code and the original!

3

When you remove irrelevant code to make a MCVE, you should already know where the problem is (or else, you wouldn't know which code is irrelevant).

But in this case, it would be easier to just write an answer! Do it and move on.

If you know the answer and adjust the question to fit your answer, you are effectively hijacking someone else's question and turning it into your self-answered question. This can be confusing (self-answered questions already are confusing, and this is even more); do it only if you have a strong point to make (e.g. the updated question and answer are going to be very useful for others).

If you don't know the answer, the best thing you can do is request MCVE from OP (use comments), and optionally help him make it - explain which parts of code to remove, how to merge several files into one self-contained one, etc.

2
  • just write an answer. Do it and move on. leaves a crappy, poorly asked question hanging around. I totally disagree with this idea. It's a way to try to increase your own rep at the expense of this site's quality.
    – Ken White
    Commented Jul 6, 2016 at 22:24
  • Imagine OP's issue can be reduced to a clear example that has 5 lines of code. Then, if you edit the question, it will be like "Where is the problem in these 5 lines of code?", while the answer is obvious for anyone (including OP, just for the sake of argument). And then you write the answer. This is very confusing! I prefer such question being deleted. An alternative - you don't edit the question. Then it stays like it was: "Where is the problem in this poorly-written 100-line chunk of code?" - and then your answer is "Right here, in these 5 lines". Not too useful either, but less confusing.
    – anatolyg
    Commented Jul 7, 2016 at 8:41

You must log in to answer this question.

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