5

SO encourages to answer your own question and asks you to show the effort made before asking a question.

Let's assume I have a problem and find a solution, which I dislike because of some reasons (it's a correct answer, but I assume there might be better ones).

Is it better to include this partial answer in the question or should I rather ask the question and "immediately" answer my own question?

5
  • 1
    if your looking for a more optimized way of doing something does it not fall into the realms of programming-practices on softwareengineering.stackexchange.com
    – user623150
    Commented Aug 2, 2017 at 13:52
  • 2
    It depends. You could use your answer as part of your question to demonstrate what you tried. In that case you need to explain why it doesn't fulfill your requirements (dislike is not a requirement, but an opinion), for example: it takes > 60 seconds to run (you need < 5), it uses > 100Mb memory (you need <100KB) , it doesn't allow you to extent the way you want. Remember that this might be on the edge of what could also be asked on codereview.se. (that is: if you have working code that only needs improvement)
    – rene
    Commented Aug 2, 2017 at 13:58
  • If you have working code you can go to CodeReview.SE and ask for help improving it. Commented Aug 2, 2017 at 14:01
  • 1
    It would be nice if I could ask how to solve problem X without having to be bogged down by a Y "solution" that happens to work but only by circumstance without having to be forced to ask on Code Review when I'm looking for a solution to problem X, and not a code review of solution Y.
    – BoltClock Mod
    Commented Aug 2, 2017 at 14:14
  • @BoltClock That's going to depend on the nature of the problem with the solution. If it's functionally perfect but just aesthetically problematic, than simply refactoring the existing solution is fine. If it's fundamentally flawed such that it, say, will never possibly perform up to minimum standards, or requires stipulations in the input that won't always be true, then that's different, and honestly means that it's not really a correct answer in the first place.
    – Servy
    Commented Aug 2, 2017 at 14:45

1 Answer 1

6

I would go for including the "bad" solution in the question as it's part of the problem. Adding it as an answer could appear to be that this is a real solution to the problem and put people off answering.

So you'd have something like:

I have this problem:

I've come up with this solution:

But it's not suitable because of reasons:

It's not a problem that's suitable for Code Review as you're not interested in improving your current code, you want to replace it with something different and better (for some definition of better).

You'll need to make it clear that you are after a different solution to try to minimise the number of people who'll try to improve your "bad" code for you.

2
  • My favorite part of questions like this is when people literally copy the solution in the question and repost it in an answer.
    – BoltClock Mod
    Commented Aug 2, 2017 at 14:28
  • @BoltClock Sometimes it's because the question omits the, "But it's not suitable because of reasons" bit, or because the solution doesn't actually have the problems stated. (But yes, sometimes it's because the answerer doesn't notice that part).
    – Servy
    Commented Aug 2, 2017 at 14:42

You must log in to answer this question.

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