16

I edited an answer here to make it more deadlock-safe:

Why can't I use the 'await' operator within the body of a lock statement?

Someone else has reverted my edit, saying that it changes the original too much and should be posted as a separate answer. I feel my edit is in keeping with the spirit of the original and makes no changes to the public API of SemaphoreLocker.

Should my edit stand or should it be posted as a separate answer?

1
  • 2
    One possibility is to make it a separate Q&A, if it reuses a lot of code from an existing answer but makes a substantial improvement. E.g. Q= "I've found this code, how do I make it more deadlock-safe", A = "Your code + explanations", assuming it's not a duplicate. This makes attribution a lot easier, allows you to properly explain the issues and how your change improves it, and doesn't make a substantial code change to a highly-upvoted answer (which is dangerous, few people vet these changes and you don't want the code on highly upvoted answers to suddenly become invalid).
    – Erik A
    Feb 27, 2023 at 10:04

3 Answers 3

38

Any time you find yourself introducing code, you should look to post a new answer. Edits are suitable for very minor changes to code or formatting, not introducing new syntax.

5

The pattern I generally see, based on what you've done, is someone (i.e., you) posting a separate answer and leaving a comment (on the answer that you edited) saying e.g.

this answer is subject to deadlocks. Please see my answer (hyperlink) for a more deadlock-safe option.

I personally think posting a new answer is the better option because while you yourself might think you're right, the tens or hundreds of up-voters on the answer that you intend to edit might disagree with the changes you've added. That's a big consideration when making an edit: are my changes so substantial that voters or the original author might disagree.

3

Edits give credit to the original answerer for any code that's present. If you make a substantial edit such as you did, the answerer is essentially responsible for the code quality, and since it's not something they thought of, it does not make sense for them to be responsible for code that differs in implementation.

Of course, fixing typos and formatting issues are still acceptable since it's the code they meant to write. In your example, they arguably never intended to write that - you used a different function in the body, namely WaitAsync(TimeSpan) with a specific argument. So public API aside (which is moot here), your code merits a separate answer.

You must log in to answer this question.

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