-18

In answering the question pointer array of structure I was reminded of a couple of other questions.

A solution to the sorting 1 million 8 digit numbers in 1 MB of RAM requires a deep understanding of data structures and their representations. As a community, we continually discourage the use of the raw C heritage of the C++ language.

I feel we are splitting the language into the user language - with containers and std::strings, shared_ptr for the masses, and a leaving the ability to understand the underlying memory layout of things, and the ability to answer the sort 1 million things question in C++ to a significantly smaller set of library writers.

I think it is correct for us to guide people into using these high quality features of the C++ language, but we should not be downvoting people for using the more basic language, so we continue to get a vibrant new set of people who can help maintain and enhance the C++ language.

Should the C++ tag limit questions and answers applicable coding styles allowed by the standard library since C++11?

Is downvoting a question/answer because it describes memory layouts, or uses new/delete the mechanism we agree upon to shape the answers on Stack Overflow?

Using a std::string for a struct of name/number would be inefficient if millions were being stored.

Using a fixed array for strings of wildly different lengths would also be inefficient.

15
  • 2
    Abstracting away the machine is rather the point of C++. The community in general insists on wearing [java] like pants. The OP is writing code in the fictional C/C++ language, made worse by using Turbo C++. You'll have to consider whether your answer really helps him when he's so lost. Commented Nov 2, 2017 at 8:28
  • 2
    I'm not sure what exactly you want here? Is this a call out to the C++ tag community to stop downvoting questions and answers that encourage mixing C and C++?
    – Magisch
    Commented Nov 2, 2017 at 8:31
  • 3
    new/delete is not C. What he wants to say is: "Is it a good idea to force new C++ questions to be answered in the C++11/C++17 style instead of older C++". For example, by using smart pointers instead of memory allocations with new/delete. Other example: Using std::vector everywhere instead of a heap array.
    – BDL
    Commented Nov 2, 2017 at 9:49
  • 2
    As one who is teaching C++ for game programmers, I'm still not sure what the better idea is. I see that students in general are less aware of what the code they write really does in the background. As a result I get more questions of the style: "My code is slow what can I do to improve this". BUT: Since I encourage using smart pointers and vectors instead of new/delete, the amount of questions regarding the classical memory issues (double deletions, memory leaks, accessing wrong memory) drastically decreased.
    – BDL
    Commented Nov 2, 2017 at 9:55
  • 1
    As said, I'm not sure yet which way is better, but I tend to lean in the direction of using modern C++. It might be better to first have working code without errors and than dig into the few sections where performance is a problem.
    – BDL
    Commented Nov 2, 2017 at 9:56
  • 7
    Citation required for smart pointers and std::vector leading to performance problems. This is almost certainly a myth. These abstractions are intentionally and painstakingly designed to get comparable performance to the equivalent code written in C. I do believe strongly in understanding what goes on under the hood, but that's very different than not being able to take advantage of battle-tested abstractions that eliminate entire categories of bugs when writing code, and it's not even in the same ballpark as writing relevant answers to a simple Stack Overflow question about C++.
    – Cody Gray Mod
    Commented Nov 2, 2017 at 10:07
  • 7
    Obviously if the question is tagged with an older version of the C++ language standard, then you should not use modern C++ features (or at least offer backwards-compatible alternatives). If you want to add a discussion of what goes on behind the scenes and performance implications, then this can only improve your answer. But writing a C answer to a C++ question is not really a good idea, any more than writing a Rust answer under the assumption that Rust is a "better" C++. The edit to this question didn't help much, BTW. Where did that quotation come from? What does it have to do with anything?
    – Cody Gray Mod
    Commented Nov 2, 2017 at 10:09
  • @CodyGray: Yes, the container itself are not a performance problem (that's why I teach them nowadays), but only if you use them correctly. Common things I see is: Inserting 100.000 objects in a vector without reserving the size beforehand. Or copying a shared_ptr inside a loop to a temporary variable. But in order to know how to use this things correctly one has to know whats going on under the hood.
    – BDL
    Commented Nov 2, 2017 at 10:18
  • I believe what mksteve wanted to start was a discussing if anwers to c++ questions (without a specific version) should be downvoted/commented on when they do not use the most up-to-date standard. I also saw some comments lately telling someone to rewrite their answer just because they used new[] instead of a vector.
    – BDL
    Commented Nov 2, 2017 at 10:22
  • I think I have asked a clear question now. Can we reopen?
    – mksteve
    Commented Nov 2, 2017 at 10:40
  • 1
    Your question is more narrow now, but I don't follow the thought. If you want C++ 11 answers, you can just tag with c++11. If you only want to give and read C++ 11 answers because you feel they're superior, you can follow that tag.
    – Erik A
    Commented Nov 2, 2017 at 11:06
  • 1
    @ErikvonAsmuth: It's not about the question. It's about non-c++11 answers to questions that are just tagged with c++. A lot of these answers get comments and downvotes because they are not using c++11. Following that logic, every c++ questions is a c++11 question unless it is specifically tagged with c++98.
    – BDL
    Commented Nov 2, 2017 at 12:30
  • 4
    They were ruined when they decided to start coding c++ in the first place, so I don't understand the point of this question :/ VTRO for lols.
    – user1228
    Commented Nov 2, 2017 at 14:31
  • Ignoring my downvote, I seem to have less up votes, than someone making a cheap joke about people who use C++
    – mksteve
    Commented Nov 2, 2017 at 20:03
  • 1
    If the question does not contain a version tag, the most recent version should be assumed. Other than that, the only hard requirement is only that the answer attempts to answer the question. Anything on top of that is gravy. How much gravy is entirely up to the answerer.
    – user4639281
    Commented Nov 2, 2017 at 21:36

2 Answers 2

10

Caveat lector.

It's important for someone who is reading answers here on Stack Overflow to be sure that they have the prerequisite foundation to understand the solution being presented to them. It is not our responsibility to provide that foundation.

Fundamentally, this is the same issue with users who copy code verbatim from the site without understanding what it does or what it means. That sucks, and I totally get it, but there's little we can do from that angle except either pray they don't get hired where we work, or if we catch them doing that, we break them of that habit quickly.

1
  • 3
    Good answer, but you really need to expand the scope of your prayers. Also pray that they don't get hired where we bank, where we trust our information, to oversee critical safety systems, etc.
    – Cody Gray Mod
    Commented Nov 3, 2017 at 5:39
7

If you disagree with an answer and wish there was an answer for people only wanting to use lower level constructs, I suppose you should could just write one.

If the question itself has performance concerns built into it, answers should address this, but otherwise I see no reason to arbitrarily limit what can be posted in an answer like you suggest.

If the question doesn't have performance concerns built into it, I don't believe you should downvote feasible answers just because they don't use the code style you prefer. However, you could certainly point out performance concerns in a comment on that answer.

You must log in to answer this question.

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