10

In the question AutoHotkey choking on same-line curly brace for compound if statements, the author included the following code-block to demonstrate their issue.

 ^!p::
IfWinExist ahk_class QWidget, ,qutIM{ ;if there is a qutIM-window other than the buddy-list...
    IfWinNotActive ahk_class QWidget, ,qutIM{ ;ans it is not active...
        WinActivate
    }else{ ;the closing bracket in front of the else here puts AHK off...
        WinMinimize
    } 
}else{ ;do some stuff with the buddy-list
    ; [...]
} 
return

The accepted answer confirms that this issue was caused by the use of same-line brackets with the compound if-statements IfWinExist and IfWinNotActive.

Having faced this problem myself, I believe the issue could be demonstrated with a simpler example.

^!p::
   IfWinNotActive ahk_class QWidget, ,qutIM {
      WinActivate
   } else {  ;the closing bracket in front of the else here puts AHK off...
      WinMinimize
   }
return

While I think this simplified example would make the question more readable, (as per the often cited How to create a Minimal, Complete, and Verifiable example), I'm hesitant to make such a drastic change to the author's code.

My first thought was to leave a comment asking the question author if this change would be acceptable, but the user's account was deleted quite some time ago.

Is it acceptable to simplify code with a minimal, verifiable example if it doesn't change the question's intent?

6
  • 6
    Generally, less is more. Just wait until you've got 2K rep and can unilaterally apply such edits, then learn to time it right so either nobody is online or everybody is asking new questions, so your edit will drown in the noise and nobody will revert it. I tried doing it a handful of times and drama ensued almost each and every time, so I stopped doing it.
    – CodeCaster
    Commented Aug 28, 2017 at 17:15
  • 10
    You need to be extremely careful if you're doing this after the question has received answers. And no—don't do it through suggested edits, because the reviewers won't be able to vouch for the quality of your changes.
    – Cody Gray Mod
    Commented Aug 28, 2017 at 17:17
  • 6
    The reviewers can barely gauge the quality of non-technical changes...
    – canon
    Commented Aug 28, 2017 at 20:30
  • 3
    How about adding your simplified code at the end of the post (and write a note about it at the top)?
    – Autonomous
    Commented Aug 28, 2017 at 20:35
  • @ParagS.Chandakkar That... is a really good idea. Keep the old code block in-tact, but add a simplified example to the bottom. Can you post that as an answer?
    – Stevoisiak
    Commented Aug 28, 2017 at 20:37
  • @StevenVascellaro Thanks. I added that as an answer.
    – Autonomous
    Commented Aug 28, 2017 at 22:10

3 Answers 3

15

Under normal circumstances I'd err on the side of caution and I wouldn't simplify the code myself. The main reason being that there is a risk (however small) that you'll get it wrong and "simplify out" the cause of the bug.

The right thing to do is leave a comment and/or a link to what you think is the simplified code and then let the poster act on it (or not).

However, if the OP has definitely gone and you are confident that you're right then by all means make the edit. However, with less then 2k reputation your edit will be reviewed and there's a high chance that the edit will be rejected as people generally don't like edits to code as they are difficult to review - particularly if you don't have experience in the language.

If you also have an answer, you could post the simplified version with your fix in it.

If the question already has a reasonable answer or two then there is even less reason for making edits. Simplifying the code isn't going to attract any more useful answers than the question already has, and it's going to bump an answered question to the home page where it doesn't really need to be.

5
  • This question has already been answered pretty definitively, so I'm not sure what my answer would add. I could suggest it as an edit to the accepted answer...
    – Stevoisiak
    Commented Aug 28, 2017 at 17:19
  • 5
    @StevenVascellaro - even less reason to edit the question then.
    – ChrisF Mod
    Commented Aug 28, 2017 at 17:20
  • 2
    I only found this post by pure coincidence 2 weeks after I had already solved the issue on my own. I think providing a simpler example would be helpful for future readers.
    – Stevoisiak
    Commented Aug 28, 2017 at 17:27
  • @StevenVascellaro I was thinking of suggesting that you could try asking a new question with the simpler version of the code and then hope that it gets closed as a duplicate, but that's not really constructive either.
    – ChrisF Mod
    Commented Aug 28, 2017 at 20:52
  • 4
    RE your last paragraph: I'm inclined to say the opposite is true - questions with too much code doesn't have much future value - if it has a great answer or two, such an edit can change it from a question no-one even bothers reading to a great reference question. If it doesn't have answers, one can just leave a comment and it's not a big deal if OP doesn't bother fixing it (because there's not much value lost to begin with). Commented Aug 29, 2017 at 10:20
5

This question comes up again and again, and its answers are always conflicting.

I'm in the camp that would like to see each and every question reduced to its most bare bones, a Minimal, Complete, and Verifiable example pur sang. Any unnecessary namespace imports, boilerplate code and code that doesn't add anything to reproduce the problem should be removed, to improve the chance that later readers discover that the problem also applies to their scenario.

Now of course the average asker isn't capable of creating a MCVE, otherwise they most likely wouldn't have to ask the question to begin with. In that same trend, when you edit their freshly asked question, and they'll receive answers based on the code you trimmed down, they maybe won't understand those answers.

On the other hand, when they've already got their answers and perhaps even accepted one, you're free to edit the code to make it more readable to everyone else. We're not here for the askers in the first place anyway.

So in that sense I'd say: leave freshly asked questions alone, unless there's a lot of code you can remove without a doubt.

Then for older questions which already have answers: edit both question and answers all in one go, and hope nobody notices it, so it won't be reverted by someone who disagrees.

That being said, definitely don't do such edits while your edits will be peer reviewed. Wait until you have 2000 reputation. Anything beyond an obvious typo fix has a slim chance of being approved, let alone changes to code.


Do note that what I'm talking about here applies to relatively popular questions (say, 1000+ views, more than one answer) and where the code in that question is so verbose that it could greatly benefit from some trimming, where that change does not change the question itself. I'm talking about questions where code blocks start with 10+ very common namespace imports which can be implied from the types being used in the code, classes with 10+ members where those members are not relevant to the question at all, and so on.

I'm not advocating that we go around and try to edit all code in all questions as we see fit; I'm advocating that we edit popular questions so that the future readers that are bound to visit it will be able to more quickly assess whether the code in the question actually applies to the problem that they're having.

This tip-toeing around editing questions because "it's the OP's question after all" ignores everything this site is about, namely clear and succinct questions that benefit many more than just the asker.

6
  • Only the OP can make such edits though. If someone tries to simplify the posted code, chances are that they remove too much, perhaps even the actual cause of the bug. What one editor thinks must be the source of the bug is not necessarily the true culprit.
    – Lundin
    Commented Aug 29, 2017 at 10:56
  • 2
    @Lundin of course not. Anyone who's somewhat skilled in the subject of the question can edit a question and verify that the code they're about to post still reproduces the problem being discussed in the question. If you can't verify that, you're indeed not qualified to be making that edit.
    – CodeCaster
    Commented Aug 29, 2017 at 11:09
  • Scenario: OP asks why there is garbage output. The question contains 2 bugs, one bug which is an obvious beginner bug, and one bug which is very intricate and obtained from the function complex_calculation(). Some intermediately experienced programmer stops by, spots the obvious newbie bug, posts an answer addressing it, then edits the question to become a MCVE - removing complex_calculation().
    – Lundin
    Commented Aug 29, 2017 at 11:39
  • However, the OP says that the problem remains even after fixing the newbie bug. As it turns out, the second bug which was far more intricate, was actually to blame. The true reason was something "intermediately experienced programmer" was not aware of. Now the OP will never get a complete answer since the question was vandalised and any expert who reads the topic won't find the true bug either.
    – Lundin
    Commented Aug 29, 2017 at 11:40
  • 3
    Step 3: OP posts the intricate bug in its own question, where it belonged in the first place. We end up with two focused documents, instead of yet another forum-style OP-specific "here's how you fix all the things that are wrong with this code" dead-end.
    – jscs
    Commented Aug 29, 2017 at 11:56
  • "hope nobody notices it" it's sad that we have to resort to these tactics... I think that the most concrete example of stuff most people disagree on yet doesn't cause any ripple is the several deleted questions, answers and edits that I've done to these days and still haven't seen a meta complain about it. YAY for SO being so big that my actions are drown by the noise.
    – Braiam
    Commented Aug 29, 2017 at 15:38
1

The code editing FAQ doesn't explicitly cover this but given what it says is and isn't OK, you shouldn't make this change. This is likely to be seen as conflicting with the author's intent.

Note that the reviewer isn't always familiar with the programming language in the post and won't necessarily be able to tell whether your edit changes the behavior of the code. They'll just see that you took stuff out and conclude that that's clearly against the wishes of the OP.

You must log in to answer this question.

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