44

At times, I have a problem and I already have a solution to it, but I still consult Stack Overflow to see if there are more elegant or more performant solutions.

Usually I then find one or more questions with my exact problem, each with a number of valid answers - some of them better than my approach, some worse.

Should I still post my answer to give other readers more options, more flavours, or should I not add my own answer and vote for the already topmost answer to streamline the process of solution-finding for future readers?

12
  • 36
    Quality is the main driver of the site, not quantity.
    – Gimby
    Commented Aug 6 at 9:34
  • 4
    Well obviously I try to put as much quality into my answers as I can. The question was more about offering choice. You would agree, that you can solve almost all code problems in various ways, depending on weather you prioritise execution speed, readability, flexability, filesize, design patterns, etc..., wouldn't you? I wouldn't post an answer that's inferior in every way. That wasn't how I intended my question. Commented Aug 6 at 9:42
  • 23
    If you think your answer is distinct and useful, sure, post it. If you believe that it's not useful, then don't. Besides that, there is no catch-all response here, it depends on the exact situation and posts involved.
    – yivi
    Commented Aug 6 at 9:59
  • 37
    While usefulness is subjective, here's a data point. I was often helped by "inferior solutions" that worked under my constraints (assumptions or requirements in the optimal solution that I could not reproduce for various reasons). I was very pleased that the posters of these answers chose to post them (some even admitting other solutions are better, but maybe not works for everyone). Commented Aug 6 at 10:17
  • 2
    Could you give please a verifiable example of a question on the main site and show us how inferior your solution would be to existing answers? It would be like a yardstick to measure the meaning of the broad expression "inferior solution". Commented Aug 6 at 10:29
  • 5
    @AugustoVasques this one I posted just today and was what led me to write this question: stackoverflow.com/a/78837829/3735561 Commented Aug 6 at 10:31
  • 4
    Indeed, often a far inferior method is the only one that works for many users due to constraints. If it falls short of other answers, it's good to mention that, but as long as it works (or answers OP's question), it's not a problem to post it.
    – TylerH
    Commented Aug 6 at 18:55
  • 2
    I do sometimes add an answer even when another answer has been accepted or when I think another answer should be accepted, in order to provide further information that I think will be useful to the OP — especially when I have a lot to say and I need formatting, so that a comment won't do. I typically say, explicitly, "don't accept this answer, I'm just filling in some additional blanks". In this way the useful additional information is there, it can help others, people can even upvote it, but I have not robbed the accepted answer of its rightful place.
    – matt
    Commented Aug 6 at 22:50
  • 2
    If you think your solution is inferior in all situations then don't post it. If you think there are situations where your solution could be better then post it. Example: If your solution uses (significant) less memory than other solutions, it could be useful for someone solving the same problem on a memory constrained system.
    – 4386427
    Commented Aug 7 at 7:10
  • "and vote for the already topmost answer" -- Don't vote for an answer because it has a lot of votes. Vote for answers (plural) that you find useful/helpful. You are under no obligation to agree that the topmost answer is useful.
    – JaMiT
    Commented Aug 9 at 2:37
  • @JaMiT the sentence you quoted would have gone on to explain why I do that (besides showing my gratitude for helping me out). It's so that future readers, who are ok with just any answer, as long as it works, find a solution more quickly. Commented Aug 9 at 6:16
  • @LukasKroess "as long as it works" -- This is a key phrase not mentioned in the question. (I am not willing to assume that the topmost answer works. I've seen a few that were wrong.) According to what you actually wrote in the question (maybe not what you intended to write), you say that if you find an answer that works, you should vote for the topmost answer. There is no qualification about that answer being what worked for you. A simple addition like "the topmost answer that helped" would make a huge difference. (Although, I would prefer recommending "all answers that helped".)
    – JaMiT
    Commented Aug 9 at 16:09

2 Answers 2

42

Please don't post a new answer if:

  1. You are fundamentally taking the same approach in code as an existing answer.

    Even if you think your code is more elegant or adds an optimization, it would be better to improve the existing answer - perhaps after first checking in the comments if this would be accepted. Keep in mind that if the question is suitable in the first place, there shouldn't ordinarily be significant opportunity to play around with this; if you can, that suggests the question needs more focus.

    Of course, an exception should be made for questions that are specifically about optimization. In this case, post if you think you are improving on existing answers, and don't if you don't.

  2. You are fundamentally just presenting ideas from one or more existing answers, without adding new analysis.

    This is, in my experience, far and away the leading cause of the long tail of crap, and it's very difficult to clean up the resulting mess (moderators are extremely reluctant to delete such answers, because verifying the custom flag for them may require subject matter expertise).

Please do post a new answer if:

  1. You contribute novel analysis - such as comparing and contrasting existing answers (perhaps highlighting a trade-off that make one better than the other in certain situations or vice-versa), or using a new metaphor to explain a difficult concept).

    For example, I like to think I added significant value here.

  2. You demonstrate a novel approach, even if it's suboptimal or even esoteric - as long as it's fairly reasonable and properly explained. Recognizing that a problem could be solved a certain way but probably shouldn't be, is often highly educational. If it takes a bit of lateral thinking to arrive at such an approach, that too can lead to surprising insight. Not to mention, performance characteristics of various approaches to a problem can change over time.

    For example, I've sometimes accidentally used this technique while refactoring existing code that used either zip or itertools.count. (The idiomatic approach with enumerate is slightly more performant, but this way is actually completely reasonable.)

13
  • I am genuinly thankful for all the replies, comments and answers to this question and I would now consider this one the accepted answer BUT (and again: I honestly don't do this to start a fight, just for argument's sake) aren't you contradicting yourself by posting this answer when there was already this one: meta.stackoverflow.com/a/431176/3735561 As I have read them, both your answers could be boiled down to the same core message, that an answer should present a different approach to the existing answers. Commented Aug 7 at 6:23
  • 5
    @LukasKroess while both answers try to carry the same message, they aren't really the same. MisterMiyagi's is short and to the point. Karl's offers points to consider when posting, with examples.
    – VLAZ
    Commented Aug 7 at 6:27
  • @VLAZ but "carrying the same message" in a meta question, is what I equated to "taking the same approach" in a non-meta / code related question. But I guess in non-code related discussions, we really must take the whole text as content, and not just take one core message and have the rest just be flavourtext Commented Aug 7 at 6:35
  • This looks like a unique, good answer to me. Kudos for the demonstration. Commented Aug 7 at 7:07
  • 4
    @LukasKroess it contributes novel analysis. But it's even simpler than that - you're trying to say that if the core of two answers is the same, there is no difference. That's trivially provable to be false, as you've accepted this one, not the equivalent one. Suggesting you found some different value in this answer. The only other alternative is that you've flipped a coin for which one to choose, given there is no difference. But I sincerely doubt you flipped a coin.
    – VLAZ
    Commented Aug 7 at 7:26
  • 1
    @VLAZ I changed the accepted answer from the previous one to this one to reward the form (/length) in which it was presented - with absolutely no disrespect to @MisterMiyagi! As I said: I genuinely appreciate all the feedback on this question and didn't want things to get heated, so I guess I'll leave it at this Commented Aug 7 at 7:37
  • 2
    FWIW, I think there's plenty of value in answers like MisterMiyagi's. I'm just... better at writing this kind. Commented Aug 7 at 12:16
  • 5
    No harm in having a short and sweet answer and "the manual". Different target audiences.
    – Gimby
    Commented Aug 7 at 13:13
  • 1
    And it is generally not OK to expand someone else's short and sweet answer into a long-form answer. Some edits may add some length and that's fine, but fundamentally changing the form and/or goal of an answer is frowned upon because it is changing the answer -- the message does change. This one is totally different from the other, even if they agree. Commented Aug 7 at 22:15
  • Problem is, you rarely get much, if any credit for new solution approaches, if answering to older questions from my experience, which got out of focus. It seems more likely to get negative feedback and minus points for arguably noticeable formal issues, mostly even without any useful feedback, which is largely discouraging.
    – fozzybear
    Commented Aug 8 at 7:35
  • In Fastest way to remove first and last lines from a Python string you awarded +250 bounty to an answer which did not present any significantly novel analyses over existing answers.
    – wim
    Commented Aug 8 at 18:41
  • @wim disagreed; it gave performance results that were what I was explicitly soliciting (not previously available, and relevant to the question which specifically asked about performance), and attempted to explain those results. While I appreciated your attempt, overall I deemed the other one a) more substantive; b) sufficient to meet my expectations for the bounty. Commented Aug 8 at 19:35
  • 1
    We will have to agree to disagree on that Q&A. As for this meta answer, it offers excellent advice (upvoted, bookmarked) and I will be linking to it in future when I see new users "repackaging" existing answers instead of offering edits.
    – wim
    Commented Aug 8 at 19:41
50

Whether your answer is inferior to others is a red herring. If it would be a unique, good answer then post it, otherwise do not.

Regardless of whether you post an answer yourself, you should vote on posts that you find useful or not useful.

3
  • 3
    Yes, I guess this answers the question for me. Especially the 'unique' check is a good measurement to decide weather another answer/approach would be acceptable Commented Aug 6 at 12:49
  • I'm not sure I can get behind this. I've seen way too many uniquely bad implementations for any given problem. Uniqueness can be objectively determined. Whether a unique solution is "good" is a judgment call. If you have to ask this question you probably don't have enough experience to answer the latter. Commented Aug 7 at 16:28
  • When people ask question, they can get (hopefully useful) answers, which help them increasing their knowledge. If they post answers they think are valid, they can get (hopefully constructive) feedback, to improve and learn from errors. If no questions asked, out of fear of downvoting or blameful answers, nothing is learned at all.
    – fozzybear
    Commented Aug 8 at 7:42

You must log in to answer this question.

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