Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I was looking at this answer and I was working through the code and I thought, "it would be great to improve the answer with my code." But then again, the answer already works. I would just change things like this:

if (x < 0) {
    x *= -1;


x = ABS(x)

and rename some variables for clarity. But then I thought, should I make fixes if they are not 100% relevant to the central point of the question/answer? The author might get offended and in fact could argue that ABS is worse than multiplying, etc. etc.

Leave it alone, right, unless it's actually WRONG?

share|improve this question
You will note that that I added a couple of spaces to your code example for clarity. That's about the only code improvement I'm personally comfortable with. If I have a suggestion for genuine code improvement (like your example), I will leave a comment with my suggestion, or post an answer. – Robert Harvey Sep 30 '11 at 6:32
I wouldn't even change x *= -1; to x = -x; – Nick Dandoulakis Sep 30 '11 at 10:43
@NickDandoulakis agreed, and there's probably a benchmark somewhere that changing the sign is slower than multiplying ;) – Dan Rosenstark Sep 30 '11 at 13:50
@Yar, hahaha I was expecting such a comment :) – Nick Dandoulakis Sep 30 '11 at 16:30

I suggest leaving a comment about it. The OP might have reasons for doing it a certain way, and since changing it isn't critical, leaving a comment lets the OP take a look at it and see if there was a reason for doing it the original way. If not, the OP can change it if he/she prefers your version. At the same time, your comment will help other readers even if the OP decides to not change it.

share|improve this answer

I would only submit changes to code if it is actually wrong; stylistic changes are not what Stack Overflow is about.

share|improve this answer
And even in that case, I'd first consider posting a comment, unless the user is not very active. – Benjol Sep 30 '11 at 5:44
I'm sorry Jeff. I have to respectfully disagree. It seems to me that changing the code if it's wrong also changes the answer. Isn't it better to down vote and leave a comment? When I receive comments about my own incorrect code, I change it myself. If the code was left by an inactive user, the comment will still be there. – Herbert Sep 10 '12 at 16:35

Yeah, that's the kind of thing I would just point out in a comment. This example code is admittedly a bit silly, but for bigger or more subjective issues, it will help both the asker and others who view the question to see the original code and the suggested alternative. If you just go in and replace stuff, a valuable learning experience may go completely overlooked. This reason on top of just politeness.

share|improve this answer

You must log in to answer this question.

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