2

I had a case when I needed to do something in code that I knew is a bad practice. But because of a unique situation and after considering the risks thoroughly decided that is worth it.

I cannot start explaining all my considerations that include business secrets over the internet but I do need technical assistance.

When I tried to ask at SO I got heated responses why it is a bad practice instead of answers to how to do this. People are so concerned about what is the right way to write code that they forget that there are other considerations as well.

How to correctly ask such a question in order to avoid "this is a bad practice" answers and get real answers?

  • 1
    You should at least state that you know that it's bad practice and give a short explanation of why you're forced to use that. – CodesInChaos Aug 21 '14 at 8:02
  • 3
    Probably this could be a topic for meta on SO (or here)... – Sebastian Dressler Aug 21 '14 at 8:12
  • @CodesInChaos the root of the problem is that event if I state this the tread keeps getting flamed by people who think they know better. – Nahum Aug 21 '14 at 8:38
  • first thing such a question need would be an explanation of why do you think that particular practice is bad (and no, "because this ${blog} said so" won't qualify). Also worth keeping in mind that serving it as how do I explain that ${this} is bad practice to ${someone}? won't fly at Programmers – gnat Aug 21 '14 at 9:20
4

It is a little difficult to reply without an example but I think there are a couple of things to consider.

Is the bad practice you are going to use actually bad practice (eg too many lines of code in a function) or is it a security threat (eg allowing SQL injection attacks)? If I see a security threat I feel honour bound to point it out.

Is the bad practice you are using making the code difficult to understand? I know that if I see 200 lines of badly structured code, I'll either ignore the question entirely or I may ask the questioner to try and break things down a bit and identify more precisely where the problem lies.

Finally, there are some responders who are a bit dogmatic or even "absolutist". All you can really do is not engage with them and hope somebody more pragmatic helps you.

  • I think the point of your second paragraph could be restated. If your bad practice is unethical (introducing a security flaw) you would point it out. If it is just a plain old bad idea (monolithic method) that might be acceptable. – user22815 Aug 22 '14 at 13:25
  • 1
    As far as I can know, the OP's "bad practice" is at the memory corruption level (use after free). – CodesInChaos Aug 22 '14 at 18:37
  • @CodesInChaos that the type of wrong I mean. – Nahum Aug 23 '14 at 10:32
3

Make your question very clear and objective. This is part of the reason why "best practice" questions are not ideal for this format. As you saw, you get a lot of answers that are not what you are looking for.

Examples:

  1. How do I frobnicate my widgets using technique X?
  2. I know technique X is a bad practice, but if I had to do it, how do you think I should frobnicate my widgets?

One of these is objective and concise. The other is subjective and verbose. Most questions like this unfortunately follow the second example.

Once you have a clear, concise question, the good and bad answers are clearly able to be judged. Unfortunately, these types of questions tend to attract the answers you are not looking for and they tend to get upvoted (people find them interesting, I guess), which exacerbates the problem.

All the more reason to keep your question clear and concise, remove any language about "yeah this is a bad idea but..."

  • 1
    If technique X is really a bad idea, you better state that using technique X is a hard constraint for you, or the large majority of answers will be of the form "don't do that, use technique Y instead". – Bart van Ingen Schenau Aug 22 '14 at 8:21
  • @BartvanIngenSchenau I have seen questions like that. While they do state X is a bad idea, they tend to be more concise. The wordy questions where the asker writes a novel before getting to the meat of the question tend to evoke bad answers even if the actual question is good. – user22815 Aug 22 '14 at 12:52
  • I think this is a combination of TL;DR and not being precise and concise in the actual question. – user22815 Aug 22 '14 at 12:53
  • The statement I was thinking about shouldn't take more than one or two lines. So we are not that far apart. – Bart van Ingen Schenau Aug 22 '14 at 13:03

You must log in to answer this question.

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