-10

I know it is rather strange question, but I've been toying with this idea for last couple of days, and I am thinking if it might be reasonable?

I come from C++ (and C), but I am sure every programming language has it's no-no-no(s) when it comes to code. And yet those no-no-no(s) are duplicated in perpetuity (by the nature of people copying the code from bad examples, or CS teachers being less than stellar). What really alarms me, is that mere postings of such code on SO supports this perpetuation - more bad code can be found.

To give examples, following is seen multiple times a day in C++ tag:

using namespace std;

or

#include <bits/stdc++.h>

or, in sockets tag

bzero((char *)&serv_addr,sizeof(serv_addr)); 

All those examples are unequivocally bad, there is no dispute about them. There are SO duplicates to cover them. Yet they come back over and over again. On a lucky day there is a comment under the question, pointing out to those problems - but they do not seem to improve the sitatuion.

I have following suggestion. Would it be worth considering an automatic, tag-specific code verifier? Whenever a question is posted in a specific tag, and it contains well-known bad code, a popup will say that posted code is bad with link to a SO question explaining why it's bad? The question will not be accepted until bad code is fixed. I realize it is not that easy and general static code analyzer within SO is out of the question, but I suppose even if we cover easy cases (all above examples are covered by a single regexp, they are call copies from the same bad sources or copies of thereof) we could probably raise a bar a little bit?

12
  • "Would be worth considering an automatic, tag-specific code verifier? " That would be hard to be done from the engine, it's something easy for a background valued reviewer. May 27, 2016 at 14:29
  • 4
    I like the intent, but it will make it impossible to ask questions about the aforementioned no-nos. Likewise related questions where something like using namespace std; affects some sort of resolution ambiguity. Those are all valid questions. I think this is better left to comments.
    – Mysticial
    May 27, 2016 at 14:34
  • @Mysticial fair point! But. First, nowadays no one needs to ask a question about using namespace std. It would be a dupe of a dupe of a dupe. Really. And all the things I suggest to subject of such verification would be in the same category. As for the cases when such using is the cause of the problem, this is even better! Seeing that the code is bad, OP can try a solution before posting! Less noise on SO!
    – SergeyA
    May 27, 2016 at 14:39
  • I still think there are valid questions regarding using namespace std;. Furthermore, you'd need a topic expert on every tag to make such a judgement call. Also, I'm pretty sure such a block isn't going to do much. Everybody already finds ways to work-around filters anyway. And if people start using misspelled namespace or inserting ZWSP's into the code, that's just gonna piss off the people reading them.
    – Mysticial
    May 27, 2016 at 14:45
  • Why should the OP have to remove #include <bits/stdc++.h> or using namespace std; if it has no effect on the problem? We can comment to let them know it is a bad programming practice. I don't think we should require they be removed. May 27, 2016 at 14:48
  • @Mysticial, that would be clear violation and we'd just downvote them to non-existence. But I always feel bad about downvoting poor folks who just had a bad teacher (quite often the answer to 'why are you doing this' is 'our prof told us so').
    – SergeyA
    May 27, 2016 at 14:51
  • @NathanOliver, because it's a bad code, and it should not be popping up as a result of the search. And because OP needs to know it's bad unequivocally.
    – SergeyA
    May 27, 2016 at 14:52
  • And everybody, thanks for the unexplained downvotes.
    – SergeyA
    May 27, 2016 at 14:52
  • @SergeyA I'm not in favor of another cat-mouse game with the mods
    – Mysticial
    May 27, 2016 at 14:53
  • @SergeyA First votes are different on meta. They are a way to agree/disagree. Second why does the question have to have "good code". If they are coming her most of the time it is bad(ish) code. Then answers should have good code but we should not require question askers to abide by good coding practices when posting if it has no bearing on the problem. May 27, 2016 at 14:55
  • Alright, looks like my idea doesn't fly here. I will not remove the question, as I still like it :).
    – SergeyA
    May 27, 2016 at 14:56
  • @SergeyA So you agree that the "using namespace std;" question HAD value (the original one). So, if we get a new language and we have your code-verifier... those questions will never be asked for new language (not to mention how some of those "no-nos" actually HAVE places where they should be implemented (ok, maybe not the example you gave, but still)
    – Patrice
    May 27, 2016 at 17:31

1 Answer 1

0

I'm not an expert in C (or C++), but the first example is valid syntax, even if it is discouraged. I assume that's what you mean by a "no-no-no".

I think the major concern I have is that people will just remove the line and we'd be further away from an MVCE as ever.

But I do think that we might be able to prevent some problems if we would just promote some good online debuggers. I think that some syntax errors produce vastly unhelpful error messages, and I could probably write something that lexes a little and returns something that actually is helpful.

You must log in to answer this question.

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