# Is a bad approach for a problem a good reason to close a question?

Related meta question, regarding the inverse of this question: Is solely suggesting another solution a bad answer?

These questions have one thing in common: They are about . They worded their question in a manner as "it reaches speed X, but I'd wish it would reach speed Y".

For the first linked question, there are (at the moment of writing) 3 close votes. Maybe 4, depends on how my "leave-open" vote works. Still.

We require that code works before we will review it. This is a good thing, because broken code takes many forms, and most of them inhibit review.

However, when it comes to performance issues, the code works. It's just not fast enough. Often, however, performance optimizations don't come from micro-optimizations - they come from using a different algorithm. I don't have statistics to back me up, but any answer that comes with a different (faster for expected $n$) time complexity sounds like a good answer.

That said...

My answer in the second linked question completely trivializes the asker's code. If the asker presents an implementation of algorithm A, and the best answer is "use algorithm B", then surely anything else after that is just a waste? Explaining to someone how algorithm A might be implemented better is a waste of time as they should use algorithm B instead.

For the first linked question: Should questions asking for a better algorithm be closed?
For the second linked question: Why does reviewing an inferior algorithm still have purpose?

## 2 Answers

Personally, I think the answer to this question "Is a bad approach for a problem a good reason to close that question?" is no, because it is only a bad approach because a better approach exists. And knowing that a better approach exists is no trivial matter.

Additionally, if X people sort using algorithm A in a certain year, and 1 year later algorithm B is invented by some clever person, would you close all the algorithm A questions on grounds of "use algorithm B"? That sounds silly.

Then there's something that feels wrong about closing a question whilst using an answer as the close reason. That is, if you were to copy the close reason and paste it into the answer field, the user would accept it. That just feels wrong.

My answer only covers half of the points I made, however. If the answer containing the better algorithm is posted quickly, what good would other answers be?

Other good answers would critique the code in question. Most likely with a disclaimer of "this answer over here is correct. Algorithm Y is faster, but here are some improvements that can be made in your existing code/algorithm." – ckuhn203 in the comments

• Other good answers would critique the code in question. Most likely with a disclaimer of "this answer over here is correct. Algorithm Y is faster, but here are some improvements that can be made in your existing code/algorithm." I'll be honest. The downvote on your answer to the primes question was mine. I felt it failed to actually review the code. Aug 4, 2014 at 12:19
• @ckuhn203 this question was not inspired by any downvotes. It was inspired by a large (3+) amount of close votes on what I believed to be a legitimate question (link 1) and a question in which I felt that my answer trivialized the question (link 2). Aug 4, 2014 at 12:25
• I understand @Pimgd. I was just trying to answer the question in your answer. Aug 4, 2014 at 12:37

It is my opinion that performance issues are bugs. A piece of software is not only subject to functional requirements (“program must find primes”), but also to non-functional requirements (“program must complete within x seconds”). A program with performance issues does not work as required.; the code is broken.

Code Review is not about solving problems, but about giving code reviews. Questions about algorithms may be suitable for Programmers, while optimizing may be on topic on Stack Overflow (Especially questions already containing an attempted solution make for great SO questions).

## Should questions asking for a better algorithm be closed?

Usually yes, and especially when OP is not asking for feedback on the current code, but for a reimplementation: Questions about code not yet written are off topic.

Regarding the example: “Finding Primes in Java”: The question is borderline off-topic according to this. The accepted answer does answer the question, but is certainly not a code review. Such answers are a good indication that the question should have been closed.

## Why does reviewing an inferior algorithm still have purpose?

If OP is not aware that a suboptimal algorithm was used, that can be a valid part of a review. However, the given piece of code will usually show many other things where you can give feedback on, such as formatting and style, general architecture, unexpected gotchas, ….

A code review is only superficially about perfecting a given snippet of code. In the long run, it's about enabling the programmer to write better code the next time.

• This is a dangerous answer: if the question asks for general review it's okay, but if it asks how to improve an aspect of it in order to meet an external requirement, it's off-topic? How could the same code with almost the same context make the difference between a bad and a great question? Aug 4, 2014 at 12:50
• also, what is a performance "bug"? there is no bug in performance. If it should be faster, then so be it. You are reducing CodeReview to StyleReview here, and that's definitely not the point of this site. Aug 4, 2014 at 12:52
• The thing is, I like the rest of the answer, it's only that one statement I disagree with. Aug 4, 2014 at 12:54
• Given your updated last statement, I'd value your input on my other question as it seems to be related meta.codereview.stackexchange.com/questions/2209/… Aug 4, 2014 at 13:53
• @Pimgd (RE: the 1st comment) Yes, it matters what OP is asking for. I think that there is a wide difference between “improve this code: make it faster” (that way lie help vampires) and “Here is some code. Please give feedback, I'd especially like to learn about ways to improve performance” (that way lies a community of learning). Because questions don't always precisely express what they want, I'd be in favour of using our own careful judgement. However, I'd like to see this site not becoming like SO – which is why it's good to consider whether we want to encourage certain questions.
– amon
Aug 4, 2014 at 13:59
• @Vogel612 See my updated post for more explanations on the connection between performance requirements and broken code. I am not trying to reduce CodeReview to StyleReview, but I'm trying to draw a line between solving problems, and learning to write better code. I do not think that solving problems of any kind (incl. performance issues) is part of the mission of this site.
– amon
Aug 4, 2014 at 14:01
• So someone could edit the performance "requirements" out of the question and it magically becomes on-topic? Aug 5, 2014 at 0:45