11

I've answered a question recently that solved the issue for the OP: Update using case statement

But I would never want to use this code.

There was another answer, which was better then my own (according to my opinion) in this post of @ConradFrix with a better design.

Should I avoid answers that show bad design? Shouldn't answers (like @ConradFrix's) with better design get more recognition?

  • I don't know much SQL, so I'm wondering: is your answer bad design, or is his answer just better design? – thegrinner Oct 11 '13 at 17:42
  • My answer was (on my humble opinion) very bad design, ~70 case statements is a very long, non-readable code, and there are better alternatives – Yosi Dahari Oct 11 '13 at 17:44
  • 4
    So the problem is your answer isn't scalable? If that's it, I'd think calling it out in an edit would be enough - something like "This will work, but will not scale well as you'll need one case for each blah blah." – thegrinner Oct 11 '13 at 17:46
  • @thegrinner - The problem is scale, but in any scale more than a few statements, which makes it a bad code for the given problem (which is update according to a given mapping..). – Yosi Dahari Oct 11 '13 at 18:03
15

That's something that readers need to determine on their own, and can vary on a case by case basis. You simply need to use your own judgement.

Sometimes the person asking the question is under constraints that others aren't, or that may seem very unusual or suspect to you, but sometimes there really is a reason for the constraints, even if they aren't explained. Sometimes something that seems bad when looked at in isolation really is appropriate when looking at the larger context.

In other cases a refactor of the entire code base may be considered as simply out of scope of the question. Something that might be mentioned in a comment, but that wouldn't require an answer to address.

You need to take into consideration the possibility, and probability, that there's a good reason for what's being done, consider the cost or problems with not fixing it (i.e. leaving a SQL injection vulnerability is very serious, and I personally would downvote an answer for not addressing it; leaving poor variable names isn't terrible, and I wouldn't downvote for not changing it, but fixing them is still nice), consider the cost of the refactor, and whether your refactor is distracting from the real answer to the question or enhancing it.

Another option to consider, in some cases, is mentioning the problem without actually fixing it. State at the end of the answer that some section seems much less efficient than it could be, or that the variable names are unclear, or that using such and such a construct isn't encouraged. This ensures that these side issues don't overwhelm the body of your answer and detract from the actual question while giving the OP the opportunity to address the potentially worrisome practice. You can always expand on such a section in the event that there are comments about such a notation.

There will be cases where one option or the other is better, cases where people disagree, cases where either is acceptable, and so on.

As I said before, just use your best judgement, and use the feedback that you get from the community (in the form of both comments and votes) to help you.

|improve this answer|||||
  • 1
    The issue is, that sometimes the OP's just wants an ad hoc solution, and such is given more quickly since it's more easy. The OP accepts this answer, viewers upvote to this answer, and other answers, which comes later and might be better doesn't get the notability that it should. – Yosi Dahari Oct 11 '13 at 18:21
  • 1
    @Yosi Which is something that they have every right to do. If there really is that much of a problem with that answer, even though the OP accepts it, other members of the community will be able to downvote/comment as well as upvote the preferable answer. The OP is not the sole evaluator of the answers of a question, and that is by design. – Servy Oct 11 '13 at 18:23
1

Should I avoid answers that show bad design?

No you should go ahead and answer anyway. Personally I like as many tools in my toolbox as possible. Your answer had value mapping via CASE which is a tool I've used for a variety of reasons. There's also no hard reasons like performance or correctness issues with it so I don't see any problems with answering in a way that you wouldn't personally use.

However as you noted this can create the problem where a better answer, in your opinion, exists then the one you gave but yours is the highest voted and accepted. If you answer enough questions this is bound to happen.

When it does I usually just reference the other answer with a link and explain why I think it's better

Here's an example in my answer to Using AVG() in Oracle SQL

enter image description here

|improve this answer|||||

You must log in to answer this question.

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