37

Say there's a question that currently has two different solutions, one of them being significantly better than the other. You have a third, different approach to the question - BUT it doesn't work the best. It's just alright. Comparable to the second solution. Should you (I) post it?

Should correct (and perhaps innovative) solutions be not posted if there exist faster performing/more efficient solutions?

(And is this actually question-dependent? Or is there a fixed code for Stack Exchange?)

6
  • 12
    There's no rule against it.. A question should have answers, and the voting system will decide which is best. If you have an answer that you think users will find helpful then post it.
    – Clint
    Commented May 16, 2018 at 17:56
  • 27
    Definitely post additional alternate answers, but please do not post the same solution someone else already posted. We see that frequently on high traffic questions that accumulate a lot of votes, and it is likely a tactic for low reputation users to gain a couple of coattail upvotes by posting a same or very similar solution to those already present. Sometimes those get cleaned up in moderation, but others hang around for years causing noise. Commented May 16, 2018 at 18:10
  • 2
    My answer is "Yes!" but with one caveat. If you are using a 3rd party library which OP has not mentioned, be explicit that you are using a 3rd party library and, if relevant, give a brief reason why. I, and many others, have often been downvoted for giving numpy / pandas library-based answers to python questions. Funnily enough, the user sometimes ends up accepting these answers even when they are downvoted.
    – jpp
    Commented May 16, 2018 at 21:36
  • 2
    Better yet, if you know why this new answer is not faster or has better performance, state that in the answer. That can help the future reader judge it uses.
    – EMBarbosa
    Commented May 18, 2018 at 13:53
  • If there are different approaches to solving a problem, providing them could potentially teach future readers things they had not otherwise encountered yet.
    – Taplar
    Commented May 18, 2018 at 16:21
  • The problem is not giving an alternative solution, it's facing all the down votes becsuse it is an alternative solution
    – TheGeneral
    Commented May 19, 2018 at 11:36

6 Answers 6

50

You should be posting an answer if you think that your answer would be a helpful addition to future readers of the question. You're free to use whatever criteria you personally feel is appropriate in determining what you think "helpful" means. If you think that performance is all that matters, and that a less performant solution isn't helpful, you can make that decision. If you feel that your answer is clearer, easier to understand, applicable to a wider range of possible readers or additional situations, or any other criteria besides performance, then by all means, post your answer.

If you think that your answer has no benefits to readers beyond what's already conveyed in the other answers, then don't post it. If even you don't think that it would be useful to other people, then that's not a very good sign for its usefulness for others.

Note that if you feel there are very small/minor problems with other answers, you could consider either editing them or commenting on them such that they can address whatever problems you feel that they have. That wouldn't be appropriate for an entirely different approach to solving the problem, as you mentioned (if you feel that other approach is useful for readers, that merits its own answer) but if you feel a portion of an existing answer is simply unclear (or less clear than it could be), or just missing a small detail, it doesn't always require a whole new answer.

5
  • 3
    What's the protocol to follow when someone posts a new answer just because yours missed that small detail? Asking for a friend. ;-) I've seen it happen before and I'm not sure a tussle in the comments is the best way to go about it.
    – cs95
    Commented May 18, 2018 at 6:47
  • 2
    @coldspeed: Hard to say in general. Sometimes suggesting an edit would have been more "polite" but it really depends on the context. Commented May 18, 2018 at 10:34
  • @LightnessRacesinOrbit, thanks. Yes, that would seem like the sane course of action, but users who are willing to put you off like that are usually walking the thin line between sanity and repfarming...
    – cs95
    Commented May 18, 2018 at 12:50
  • @coldspeed: We're encouraged to assume good faith, but I do see what you're saying. Commented May 18, 2018 at 12:54
  • I agree. "Helpful" is the right keyword here.
    – PM 77-1
    Commented May 18, 2018 at 16:47
16

Yes, all well-written answers to a question should be included. Sometimes people have specific limitations as to why they cannot use the top-voted answer, such as an out-of-date version of the product or work based limitations. Sometimes people want to understand the solution more profoundly and seeing several solutions instead of just one helps them. Sometimes when we see different ways of doing things we learn new ideas.

Besides, as the author of the answer, you are not the person to judge how good that answer is compared to the other answers. You should absolutely do your best job of writing it, but the community is the group who decides which is(are) the best answer(s). You may not consider your answer as good as the highest voted one that already exists, but perhaps with time more and more people will find your answer even more useful than the current ones, to the point where it gets upvoted to the highest place for reasons you didn't anticipate... Or maybe your answer is wrong and it gets downvoted. Either way, the community will make sure that your answer gets to where it needs to be, so add it!

2
  • 6
    Yes - maybe the top answer uses too much RAM, or it's lookup-table blows a small cache and RO data reads are slow. There are all kinds of tech. reasons why approach X may be better than approach Y, and future users would appreciate being given the choices:) Commented May 16, 2018 at 19:20
  • 1
    This. There's a reason more than one answer can be posted, and a reason the OP gets to choose and other answers aren't summarily deleted. Commented May 18, 2018 at 10:33
8

I'm going to play devil's advocate here and advise against it, but only under certain circumstances. If I were experienced enough to know that my answer is technically inferior in every aspect to those posted so far, I would abstain from posting it—as I have done so in the past—because at that point, you're really only posting for rep and adding noise to the question.

If you are not experienced enough to make this judgement, feel free to post it, and let the community decide through the voting system.

4
  • 2
    I agree. Most problems have multiple solutions, but if you know your solution is inferior to the ones already posted, there is no point in posting an answer with that. For instance, you can multiply 5 and 6 through 5 * 6 or 6 * 5, but there's no point in using 6 + 6 + ... (5 times) or 5 + 5 + ... (6 times). If you're too eager to post an answer, be sure to mention its downsides, so that anyone (blindly) copy-pasting it into their code is aware of the problems. Commented May 18, 2018 at 6:36
  • @Nisarg Something like 6+6+... could (very) occasionally have its uses... see for instance [Why doesn't GCC optimize aaaaaa to (aaa)*(aa*a)? ](stackoverflow.com/q/6430448/2096401)
    – TripeHound
    Commented May 18, 2018 at 9:40
  • 1
    @TripeHound It's just an example. Commented May 18, 2018 at 9:43
  • 2
    @Nisarg I'll admit I was being a bit pedantic (sorry), but the more serious point is that it's very hard to tell (even in a "seemingly obvious" case like your example) that an alternative solution can't have some benefit for some users under some conditions. For some questions there will be some alternatives that aren't worth posting as an answer, but so long as a poster can identify a plausible reason why their solution could be preferred, I'd rather have it posted "just in case".
    – TripeHound
    Commented May 18, 2018 at 10:04
4

All answers should be posted, as there could be cases where it becomes the only practical solution. This is especially true as the answer is not solely for the original asker, but for all people who arrive at that question via search (as long as they are searching for the right thing...)

4

Sometimes the obvious way to code something may have flaws or limitations that aren't obvious. It may be helpful to the OP and future readers to have an example that shows how not to do it. Of course, they should also be shown the right way(s), either as part of the same answer, or in other answers. Of course, if you do this you must clearly explain the problems with the code. And there's a chance that you will receive downvotes anyway.

-2

Say there's a question that currently has two different solutions, one of them being significantly better than the other. You have a third, different approach to the question [...] comparable to the second solution1.

In other words: Your proposed solution is also significantly worse than an existing solution. If that is the full story, then there is really only one valid answer to the question, whether to post: Don't.

There still can be exceptions, where it might be reasonable to post an inferior solution, if it adds value. The following is an (incomplete) list of questions you should ask yourself to asses, whether your contribution does in fact add value:

  • Can you identify all issues inherent to your solution?

    This is a mandatory preliminary. If you fail to express the consequences of using your proposed solution, readers will have no way of making a judicious decision as to whether it is applicable to their problem. At this point it is probably best to just bail out, without even looking at the other considerations.

  • Does your proposed solution relax requirements?

    A solution with fewer requirements, such as relaxed pre-conditions or fewer dependencies, can provide additional value to some users. Help them decide by explaining, how they can benefit.

  • Does your solution improve code readability and/or maintainability?

    Readable/maintainable code is always a bonus. Make sure to explain how this is achieved in contrast to competing solutions.

  • Does your solution provide better performance characteristics?

    Some (even if few) users have strict performance requirements. An otherwise inferior solution that consumes less CPU cycles or memory can still be a better option for those users.

If you cannot answer any of those question (particularly the first one), and you do decide to post your contribution nonetheless, make sure to explicitly note, that you are not aware of the full set of consequences as a result of applying your solution.

You must log in to answer this question.

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