10

I see a lot of answers on Stack Overflow that include deprecated functions, for example the mysql_query function. The code is correct but the usage of a deprecated function shouldn't be encouraged.

Should those answers be voted down? Should I add comments to the answers and ask for a non-deprecated method to be used?

19
  • 6
    Look at the time stamp on the answers. Were they posted before or after the function was deprecated? – Cody Gray Aug 21 '13 at 13:04
  • they are recent, so the function was deprecated when the answer was given, for example check this: stackoverflow.com/questions/6236371/… last answer – jnhghy - Alexandru Jantea Aug 21 '13 at 13:06
  • 4
    If it was recent, and the question didn't seem to require that usage, a down vote (with comment, if you are brave!) seems appropriate. And, of course, your own answer, if you like. – Andrew Barber Aug 21 '13 at 13:06
  • 1
    Incidentally; that particular question is old, so that might qualify as it 'requiring' that usage. Perhaps just a comment suggesting an update. And, kudos for caring about quality answers and how to properly go about improving them! – Andrew Barber Aug 21 '13 at 13:08
  • 1
    I don't know any PHP or MySQL, so I can't comment on the validity of the approach. But I agree with Andrew: if there's no particular reason for the answers to be using bad code, downvote it. Also leave a comment explaining that the function is deprecated and what the risks are of using it. If you have time, you should post a better answer of your own. Or you can skip the song and dance and just fix their code, if it's a simple fix. – Cody Gray Aug 21 '13 at 13:09
  • 2
    @CodyGray He can't just fix their code - it's a recurring discussion here whether you should change code in answers, and given what I've gotten rejected I've personally given up on changing any kind of code except for obvious formatting. – user213634 Aug 21 '13 at 13:16
  • Don't all the answers in the question link provided by OP use the same depreciated function? – gitsitgo Aug 21 '13 at 13:29
  • @gitsitgo lot of them were posted back when the function wasn't deprecated, the issue is with the new answer that is written when the function is deprecated. Also I don't think answering with deprecated function to a question that includes a deprecated function is ok. First correct the question and then give the correct answer – jnhghy - Alexandru Jantea Aug 21 '13 at 13:32
  • @alexalex Oh I see, sorry... still early in the morning for me so I misunderstood. The way I see it though, any answer regardless of when it was written is irrelevant for "today" if it contains a depreciated function. – gitsitgo Aug 21 '13 at 13:42
  • 1
    @gitsitgo That assumes that everyone in the world has upgraded to the newest version of that language/library. That's a false assumption. If people are still using older versions of a library where the functionality isn't deprecated, then the information is useful to them. – Servy Aug 21 '13 at 13:54
  • @Servy: even if the code is working, such an answer can cause vulnerabilities and needs to be discouraged in my opinion – jnhghy - Alexandru Jantea Aug 21 '13 at 13:56
  • @alexalex So people not using the newest version of a language aren't allowed to use SO? – Servy Aug 21 '13 at 13:56
  • @Servy I think that this can cause more harm then good, promoting a vulnerability as the correct answer is not the way to go, if the OP specifies it's version and why he/she needs a deprecated function then I don't see an issue but if they are not specified then 1)vulnerability might be created 2) the code might not work on recent versions. But I see your point also and I need to give it a 2nd thought. – jnhghy - Alexandru Jantea Aug 21 '13 at 14:02
  • 1
    @CodyGray It's been a while since I last tried, but take a look at this edit: stackoverflow.com/review/suggested-edits/1778349#./… - I changed the variable names to be consistent with OPs question and included one line of code from the question to clarify the context implied as the OP hadn't understood that part of the answer. I've had some other, similar, answer-edits rejected as well, so I've stayed away from those edits for quite some time. It's just not worth it. – user213634 Aug 21 '13 at 14:48
12

If the OP's code uses the same deprecated library, don't vote down answers that do so, too. If you feel so inclined, add a comment that the library is deprecated - or even edit a notice into the answer.

4
  • If the OP's code uses a deprecated function an answer with a deprecated function is still wrong in my opinion.Lets take for example the safe_modefunction, an OP's code including this function won't work on all php versions, so an answer with the same function is very bad. – jnhghy - Alexandru Jantea Aug 21 '13 at 13:53
  • 8
    @alex you don't know the asker's context. If they are working on a huge legacy project, there is no point in going "OMG you need to use PDO right away". Just comment and point out the situation. Now if the OP is not using a specific deprecated library, and an answer suggests they do so, that is a different situation. That I find fair to downvote anytime. – Pekka Aug 21 '13 at 14:06
  • @alexalex not quite - if it works for OP, is part of a question and is not a cause of the problem, it should stay. Do not change what does not need to be changed to solve a problem. Removing it might confuse future readers and give them impression it was part of the problem when it wasn't. Of course it's good if answer contains notice about other things in code to improve, like deprecated functions, but that's it. – Mołot Aug 21 '13 at 14:06
  • @alexalex, I agree with Pekka, unless you're 100% sure of the context you need to tread carefully. Either that or you update the entire 'thread', and leave a prominent note to explain why. UNLESS your deprecated function really IS a security problem (you seem to equate the two in your comments, but I don't think they are equivalent), and even then, I'd be inclined to leave a comment, so future readers can see the context and decide for themselves. – Benjol Aug 23 '13 at 7:44

You must log in to answer this question.

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