16

I've noticed a number of instances where a user will ask a question regarding PHP and MySQL using the deprecated mysql_ functions, and there will almost always be at least one other user who feels the need to point out that it is deprecated. They're not wrong. However, in my opinion, unless this is the actual cause of the problem the asker is facing, it's not adding anything constructive to the situation at all (and if it is the cause, it should be an answer not a comment).

I have reported these sorts of comments before and if my memory serves me correctly most were subsequently deleted, so I would guess that I am right in reporting them, however I'd just like an official word on it.

Should users be commenting "mysql_ functions are deprecated" on questions or is that considered not constructive? Or to go further, any question that involves a deprecated feature that is not supported but is still functional (such as the HTML tags deprecated in HTML5)?

12
  • 45
    After a lots of discussion on PHP chat and other area, all concluded to inform user about mysql_ deprecation with a simple message and nothing seems nonconstructive in it.
    – Rikesh
    Commented Jul 1, 2015 at 6:46
  • @Rikesh it might be just me but that question seems to be regarding old questions that users are coming to from search engines, not new questions. Commented Jul 1, 2015 at 6:52
  • 16
    On a similar vein, if someone's code looks like it's vulnerable to sql injection I tend to point it out, with a link to the wikipedia article and/or bobby-tables.com for follow up. Again, it's not necessarily the cause of their problem, but it's something they ought to know about. Commented Jul 1, 2015 at 9:19
  • 2
    For reference, the comment I see most often is this one:
    – Robert Harvey Mod
    Commented Jul 2, 2015 at 2:39
  • 15
    Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.
    – Robert Harvey Mod
    Commented Jul 2, 2015 at 2:39
  • 36
    ...which I find incredibly constructive and useful. So useful, in fact, that it's documented here. Don't discourage people from posting comments like these; folks need to know how to do it the right way.
    – Robert Harvey Mod
    Commented Jul 2, 2015 at 2:40
  • @Robert: Is there a good reason for that deluge of URL-shorteners in there? Commented Jul 2, 2015 at 16:58
  • 4
    @deduplicator probably too long for a single comment with unshortened links Commented Jul 2, 2015 at 17:05
  • 4
    If you flag a comment it's probably going to get deleted regardless of the validity of the flag. Mods delete comments with extreme prejudice; investigation/mercy is wholly optional. So, I wouldn't use the comment deletion as confirmation that those comments were actually unconstructive...
    – canon
    Commented Jul 2, 2015 at 17:10
  • 1
    I guess the only problem this could cause is on code where the user has no choice but to use old code in new code and the community refuses to answer because they see this comment on the question. As a PHP answerer myself I have seen this happen whereby people will not answer at all because of it.
    – Sammaye
    Commented Jul 2, 2015 at 19:15
  • Yesterday I came across a question about JSTL. One answerer set up some test data using scriptlets, then answered the question using JSTL. Somebody commented that scriptlets were evil and over 20 people upmodded the comment and downmodded the answer. The answerer was last seen on the site 7 days after his answer. These sorts of comments are useless and should be flagged.
    – Dexygen
    Commented Jul 3, 2015 at 13:53
  • 1
    I’m all for pointing out that the mysql_ functions are deprecated, just as I am for informing a user if their code is vulnerable to SQL injections like @JamesThorpe. It’s good to point these things out and make as many new (and old) developers aware as possible. Commented Jul 3, 2015 at 13:57

5 Answers 5

66

Such comments are generally constructive, if worded properly. They don't answer the question, which is why they get posted as comments rather than answers, but it's useful additional information for the OP and for other readers alike that may not know that the feature is deprecated.

Although I don't typically read PHP questions, the response on such comments in other tags that I do read is generally positive (something like "oh, didn't know that, what should I use instead?"), sometimes even getting the question changed in a way that allows for answers not using the deprecated feature.

Note the "if worded properly" though. "Oh FFS why are you still using this broken POS? It's been deprecated for years, switch already!" is not a good comment, no matter what the intentions of the commenter are.

3
  • 2
    agreed. but at some point you have to wonder how beginners still find tutorials reference this old, broken deprecated for more than half a decade ... thing. not to mention that all of mysql_ documentation has this big red warning that it is deprecated, and will you stop using that, please! Positive comments require fortitude and patience.
    – njzk2
    Commented Jul 2, 2015 at 0:04
  • 11
    Most of the tutorials were written years ago. And the authors generally aren't interested in recoding them.
    – Barmar
    Commented Jul 2, 2015 at 0:06
  • 3
    @njzk2: Tutorials on the internet don't magically disappear weeks after they are written. It's not hard to find outdated content. In fact it's often easier thanks to the many links they have attracted in the meantime... Commented Jul 3, 2015 at 14:05
13

I find those kind of comments ("X is deprecated; consider using Y") very helpful.

I am relatively new to the software world and I'm also a lone developer. I find that almost any technology is subject to the whiff of rumour that it is about to topple, so it can be hard to work out what is opinion and what is fact. I appreciate Stack Overflow's aversion to opinion-based/incorrect comments, which makes it far more reliable than most sites.

Therefore, comments are helpful if:

  • they are polite
  • they don't assume the OP is an idiot
  • they are supported by evidence (i.e. link to documentation)
  • they point the user towards the new and correct way of doing it, rather than just stating "don't do that"
8

When I come across a "not constructive" comment flag I generally try to consider the question "on the balance of probabilities was the commenter likely to be trying to help or does the comment read as flippant".

Warnings about security issues or deprecation usually fall into the former question, so are unlikely to get deleted by me unless they're open to misperception or contain excessive snark.

Such warnings contribute to the net value of the question, even if the OP themselves can't heed the advice for whatever reason, because it's highly unlikely that the OP will be the only one interested in this particular function.

6

There is a big difference between:

X is a bad idea (because reasons).

And:

X is a bad idea (because reasons) but here is a solution using Y to accomplish a similar goal.

In the real world, developers don't always have a clean slate, and so may well find they're stuck with some awful legacy cruft that the only real answer is 'kill it with fire' but they're somehow left bodging it into life each day because it's too expensive to start over.

One day this might be you. It's ok to point out that something is a bad idea - and why it'd be a bad idea - but it's not constructive to do so unless you also offer a solution/workaround or other answer to the question at hand (even if you did have to broaden the scope of the question slightly).

4
  • 3
    I disagree. You appear to be suggesting that it's non-constructive to write these comments unless you also write an answer to the question. But why does one person need to do both? Commented Jul 3, 2015 at 14:06
  • @LightnessRacesinOrbit Otherwise, they would just continue to use the awful solution. Like the case with regex and HTML, or regex with JSON.
    – nhahtdh
    Commented Jul 3, 2015 at 15:49
  • I am suggesting that, yes. Because ... it doesn't help the supplicant with answering their question. I wouldn't say you have to answer the specific question as asked merely that without supplying an alternative approach, you haven't contributed to the solution in any way.
    – Sobrique
    Commented Jul 3, 2015 at 15:55
  • @nhahtdh: Right, so it's great that there's an answer to the posed question. But somebody else can post that. Commented Jul 3, 2015 at 16:36
2

I think it depends on the context of the question, or rather the skill level of the questioneer.

If OP seems to be a professional programmer working in an (old) system that was built on mysql_ functions, I assume they know that those functions are deprecated. If they are not migrating yet, they probably have a good reason for that, and they don't need a bunch of people telling them that their code is deprecated.

However, many questions are from users who say, "I am just starting with PHP and MySQL and this [Hello-World level piece of code] doesn't work".

In those cases, I tend to respond that when learning PHP, it's a good thing to not learn about those deprecated functions. I also refer to the big red box on PHP.net on the help pages of each of those functions.

And I usually also mention that I feel people who just started with PHP should have read those pages in the first place before asking a question. I don't do that to be hateful, but to indicate that it's a good idea to check the official documentation for PHP functions. After all, PHP is very popular and the internet is crowded with numerous examples and tutorials. Many of those are poorly written or incomplete, and many others (or sometimes the same) are just outdated and are based on features that are now deprecated or at least rendered obsolete by better alternatives. So, it's very easy to find incorrect information about PHP (and some other languages as well).

In our office, we even had a saying that if you google for information about PHP, the first answer you get is bound to be incorrect. Anyway, it's not (at least not always) OP's fauls that they based their first steps on outdated information, but it's still a good idea to show them the right path.

So yes, I think that -especially for beginners- such comments are helpful.

You must log in to answer this question.

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