What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 131 Stack Exchange communities.

In a lot of questions one can see that the OP's code works almost correctly, but his/her approach is not the best one. For example:

remove specific line returns ("\n") from file

Where one answer fixes OP's code, while the other provides a much better idiomatic solution, which differs from OP's one.

In some cases however (mostly when error messages are involved) this may lead to users stumble upon solutions that don't actually solve their issues.

I realize that my question is subjective, but which one can be generally considered better - fixing OP's code or fixing OP's approach?

share|improve this question

2 Answers 2

up vote 9 down vote accepted

It is usually best to explain what is going wrong with the OP's approach and why. Additionally, if there is an easy way to correct the problem, you should demonstrate it.

If you can think of a better approach, this should be posted in addition to a diagnosis of the original problem.

An example would be a user making a mistake while using the wrong tool for a certain task (eg. regex for HTML parsing). An okay answer would simply identify the problem in the code. A better answer would mention a superior approach to solving the problem. The best answer would identify the problem in the OP's code while also mentioning that the problem can be solved much more easily using a proper parser.

share|improve this answer

I would say your guiding principle should be what best helps the asker and anyone else who comes and finds the question and your answer later. Often, that means offering a different approach.

Be careful, though; Some people may look at such a solution, and think you have not answered the question asked. Semantically-speaking, doing such a thing doesn't 'answer the question'. If you think there's any doubt that someone would mistake that - or if you suspect the OP might not appreciate such an alternate option - you might want to start your answer by briefly answering their specific question, and then go on to provide your alternate solution.

share|improve this answer

You must log in to answer this question.

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