In Stack Overflow, there are some code patterns that many of us recognize as problematic, and we reflexively post comments about them (they're usually unrelated to the actual question being asked). For example, in C code

while (!feof(variable)) {

is an anti-pattern, and I automatically post a link to Why is “while ( !feof (file) )” always wrong? when I see it (most recent example being File Handling and Functions in C).

I wonder if this kind of thing is common enough to warrant an automated mechanism for it. So there could be a table of regular expressions that map to comments. As soon as the question is posted, the automated comment would be added.


2 Answers 2


You can use the pro forma comments script: AutoReviewComments - Pro-forma comments for SE

It adds an "auto" link next to every comment box from which you can select one of your pre-made comments. You can set your own templates, have different comments for questions and answers, edit the comment before posting it and it will even auto-fill usernames for you. Simple!

As for implementing this as a part of the sites proper; there are so many different sites, covering so many topics with so many different issues within those sites (think how many of these comments you'd need on Stack Overflow per tag, and then think about the other ~160 or whatever it is now sites). I don't think it's feasible to come up with and agree on the patterns to match and the comments that would go with them.

So just use the script with the few comments that you personally use. There's a useful list of some here: Repository of useful pro-forma comments


I feel like such peremptory judgments on code is not always right. Sometimes, something that looks wrong is not. To make my point clearer and relate to your specific example, I fully agree with this answer to the post you linked to.

For C/C++ code, when you see a "goto", will the algorithm automatically post a link to Dijkstra's paper? Some people don't fully agree with Dijkstra (quoting Jeff Atwood himself: "GOTO isn't all bad, though. It still has some relevance to today's code."). And even if I never use goto myself, I understand people can disagree with the assumption "goto is always bad".

So, although I agree it is generally a good thing that some users inform OP that a part of his code is using an antipattern and is likely wrong, I think it is not good that a simple algorithm run by a machine makes that decision.

Moreover, who would decide on what patterns should trigger the mechanism? Moderators? Should users vote to decide?

  • Indeed, there could occasionally be exceptions -- I once saw a code post where there was an initial read of the file before the loop, so the test was OK. But do we have to make perfect the enemy of the good? I'm not suggesting something for which a rare false positive is that harmful (it's not going to close the question).
    – Barmar
    Commented Jan 25, 2017 at 16:39
  • As for who decides, how do we decide other automated mechanisms, like tag suggestions (which occasionally cause posters to add the mysql tag to any SQL question)?
    – Barmar
    Commented Jan 25, 2017 at 16:41

You must log in to answer this question.

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