67

Some novices, unfortunately, write C++ in C-style, using C-style strings and IO, just to name a few things.

Unfortunately, users attack them with phrases like "This isn't C++" all the time, which is incorrect. Nevertheless, these comments are heavily upvoted. While most of them just use sloppy and misleading wording, there are occasionally commenters who seriously think that's the case.

How should these situations be handled and what would be the right wording we should promote?

When I try to raise attention, I usually get comments like "the code is actually C, not C++ even though you compile it as such".

17
  • 5
    I disagree. Most of the questions with these combined tags show any relevant c++ code. It's just tag spamming. Commented Feb 9, 2016 at 20:40
  • 3
    And when this actually happens? stackoverflow.com/questions/35301432/… Commented Feb 9, 2016 at 20:41
  • 26
    @KarolyHorvath: Ouch. There someone changed the language-tag, and than instead of correcting that blatant error he edited the code so it works in the language he kept tagged. That calls for both a rollback (well done btw.) and reminding the editor to marginally respect the authors intent. Commented Feb 9, 2016 at 20:52
  • 4
    This isn't [languages] :P Commented Feb 9, 2016 at 21:22
  • 2
    Where do the normal comment flag options not suffice? If you're looking to make other user see the (in your opinion) error in their ways ... yeah, don't hold your breath.
    – Bart
    Commented Feb 9, 2016 at 22:13
  • 2
    And yet, if someone tags "c" on their C-style C++ code (in addition to C++), people complain it shouldn't be tagged. You can't win. Commented Feb 9, 2016 at 23:21
  • Equally controversial: If a question is about something C and C++ have in common, and the asker happens to be using one or the other, should it be acceptable to tag the question with both C and C++? Some people like to insist that the question should only be tagged with the language the asker is actually using, even if both the question and the answers apply equally to both. Commented Feb 9, 2016 at 23:25
  • 3
    @immibis Not really that controversial. But it affects very few questions: most are specific to either language (if we want to encourage good code in answers, which was Stack Overflow’s goal last I looked). Hence the insistence. Incidentally, this also impacts the question here. Commented Feb 9, 2016 at 23:35
  • @KonradRudolph Questions about C APIs, for example, fall under that umbrella. Like "How do I <do something> with <some library>?" Commented Feb 9, 2016 at 23:41
  • @immibis Sure. I wasn’t really looking for (counter-)examples though: I know they exist. I’m saying that, contrary to your claim, tagging such questions as [c] and [c++] isn’t generally seen as controversial. It’s only “controversial” on questions where such tagging actually makes no sense. Commented Feb 9, 2016 at 23:43
  • @immibis: If no code is wanted, at all, sure, then it might make sense to tag with two of the languages you can use the API with. Or maybe not, are you really sure that there is no good answer in either of the languages which is completely inapplicable to the other one? Commented Feb 9, 2016 at 23:50
  • 1
    It is very important which tags are used. If you ask a question tagged [c++] that has to do with strings or arrays, you're going to get (correct) answers that suggest how to do it using std::string and std::vector. Most commenters I've seen are trying to nail down if there's an actual reason that you're avoiding the idiomatic C++ way of doing it, or if you're simply ignorant of it and would appreciate an enlightening answer.
    – Cody Gray Mod
    Commented Feb 11, 2016 at 11:31
  • 1
    C++ has a lot of this going around. It reminds me of the prevalent 'every raw pointer should be a shared pointer' comments. Commented Feb 12, 2016 at 16:11
  • 1
    I'd be curious if the same thing happens with jQuery and JavaScript.
    – krillgar
    Commented Feb 12, 2016 at 17:56
  • 2
    @krillgar Oh indeed it does. This is pedanticoverflow.com after all
    – AaronLS
    Commented Feb 12, 2016 at 19:38

3 Answers 3

63

I would suggest that you kindly remind them that although the minimal, complete, and verifiable example that the OP hopefully provided may not include any C++ features, there is a good chance that the rest of their code might. That suggests that the OP is open to C++ features in the answers.

Ultimately, it is the OP's decision on which tag to use in this case. Obviously a tag on a question with features is a mistake, but when in doubt, or if the OP seems confused on which tag they actually should be using, it never hurts to leave a comment requesting clarification.

4
  • So, instead of "This isn't C++" or "This is C", what should the commenters say to the OP? I fear the commenters are too lazy to write a valid, but long sentence, and will just keep using these expressions... Commented Feb 10, 2016 at 10:51
  • 12
    @KarolyHorvath As your question already states, and this answer appears to agree with, the commenters are just wrong. If they have no clue what they're talking about it, they should learn to refrain from commenting at all.
    – user743382
    Commented Feb 10, 2016 at 11:38
  • 18
    @hvd: I think it's mostly learnt behaviour. People come to SO, see what others do and they mimick it (eg.: never cast the result of malloc, in bold). In this case shouting silly phrases. I created this question so that instead of having an endless discussion I can simply use a link... but I would like to provide the correct phrasing there, so they can use that one next time. Maybe something like... "Your code is written in a C-style dialect of C++. Please confirm that you're actually using a C++ compiler." Commented Feb 10, 2016 at 11:56
  • 17
    @KarolyHorvath I do still think what they should do next time is not comment at all, but sure, if people can't control themselves, your proposed comment seems good when there's nothing in the question that already indicates that a C++ compiler is being used. A slightly more general comment might be "You've tagged this question C++, but what you've written looks like it's also valid C. Do you need answers to be acceptable to C compilers, or can C++ features be used in answers?"
    – user743382
    Commented Feb 10, 2016 at 12:07
14

It's probably a good bet that in most cases, the user is indeed compiling for (since they added the tag). Most of the time, the user is a fresh-faced novice and often won't even know there's a significant distinction between and .

In my experience, the best thing to do is either outright providing, or asking whether or not they are open to a C++ solution (using , etc.). Often, the user is delighted to find that the pure C++ implementation is significantly easier to understand and has less cruft.

2
  • But what to do with the comments? Ignore them? Answer them? Flag them?
    – anatolyg
    Commented Feb 11, 2016 at 8:30
  • 4
    Well, you can't really flag a comment because it's wrong, so you're left with "answer" and "ignore" options. Commented Feb 11, 2016 at 8:48
12

I think such retagging is not appropriate since it's conflicting with author's intent. If the code presented in the question is only valid in C, while C++ tag is used (or vice versa), the OP should be told that their code doesn't compile, and asked whether they want to fix the code or the tags.

If the code compiles in both C and C++, only the OP can know how he wants this code to compile. "This isn't C++" statement is outright wrong, because their code is actually both valid C and C++. There are actually valid reasons to use C-style IO in C++ (e.g. broken or bloated iostream implementation on an embedded target with no alternative compilers available, legacy code reused in C++ project, etc).

You must log in to answer this question.

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