189
votes
Accepted
Should I stop using the term C/C++?
C was never a subset of C++. The most obvious example of this is int new;. This has been true since C89 and C++98, and the languages have only grown further from each other as new standards have come ...
75
votes
Accepted
Is passing arguments as const references premature optimization?
"Premature optimisation" is not about using optimisations early. It is about optimising before the problem is understood, before the runtime is understood, and often making code less readable and less ...
44
votes
Should I stop using the term C/C++?
Going against the flow I would say it depends on the context.
The term "C/C++" is usually not appropriate when saying something like "this is a C/C++ program", but this has been explored to depth in ...
31
votes
Should I stop using the term C/C++?
In general the SO users ask the person who is asking the question to choose a language: C or C++. Why?
There are many subtle differences between C and C++. For example, in C++, a const variable at ...
28
votes
Accepted
Is it ever bad to mark a C++ function constexpr?
This matters only if the function is part of a public interface, and you want to keep future versions of your API binary-compatible. In that case, you have to think carefully how you want to evolve ...
25
votes
Style guide for C++
The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++, you can find them here: https://github.com/isocpp/CppCoreGuidelines
They are written by, ...
21
votes
Accepted
Object lifetime invariants vs. move semantics
It's usually bad form in C++ to create zombie objects that explode if you touch them.
But that's not what you're doing. You're creating a "zombie object" that will explode if you touch it ...
21
votes
Is passing arguments as const references premature optimization?
TL;DR: Pass by const reference is still a good idea in C++, all things considered. Not a premature optimization.
TL;DR2: Most adages don't make sense, until they do.
Aim
This answer just tries to ...
20
votes
Accepted
Are all the objects in C++ mutable if not stated otherwise?
Immutability has been well-understood for some time. Python, Java, and C++ have different memory models that make direct comparisons difficult. The author of the article you originally cited (...
17
votes
Should I stop using the term C/C++?
I was always told that C is a subset of C++ or C++ is C with classes. And that was quiet true until the appearance of C++x0, C++11 (or the modern C++ 11/14/17 in general).
C has never been a subset ...
17
votes
Should I stop using the term C/C++?
Some programs are written in a mixture of C and C++
This is just a fact of life. You can compile object files from C and C++ and link them together. The result can quite reasonably be called "a C/...
16
votes
Is it ever bad to mark a C++ function constexpr?
Marking a function as constexpr also makes it an inline function §[dcl.constexpr]/1:
A function or static data member declared with the constexpr specifier is implicitly an inline function or ...
15
votes
Accepted
"The C++ Programming Language" confusion on Comparison
It's a little hard to be certain when you take such a short quote out of context, but I'd assume that he's pointing to the fact that comparisons of simple objects normally don't involve any function ...
14
votes
Should I stop using the term C/C++?
Should I stop using the term C/C++?
Absolutely. It is not clear what this construct is intended to express except, perhaps, confusion about what C and C++ are on behalf of the person who uses the ...
14
votes
Accepted
Is there any benefit to to define constant local variables as static ( c++)?
Beyond @Christophe's very good answer, the code generated for the static is most likely worse than the one for the local variable, so if you're interested the under-the-hood benefit, statics are worse ...
12
votes
Accepted
Is it possible to achieve Rust's ownership model with a generic C++ wrapper?
C++ has three ways to pass parameters to a function: by value, by lvalue reference, and by rvalue reference. Of these, passing by value creates ownership in the sense that the called function receives ...
12
votes
Accepted
Why did C++11 add find_if() instead of overloading find()?
Let's take a look at two of the relevant functions:
template <class InputIt, class T>
InputIt find(InputIt first, InputIt last, const T& value);
template <class InputIt, class ...
11
votes
Favored syntax for calling a function with parameters that another function returns
In most situations, it's about which version is most readable, which is often in the eye of the beholder. In simple cases, composition is very clear, but past a certain point, verbosity adds clarity. ...
11
votes
Are all the objects in C++ mutable if not stated otherwise?
Almost. The language itself treats everything as mutable unless you use const, but it's still possible to build immutable objects without telling the compiler they're immutable, by simply not ...
11
votes
Accepted
'Assigning' a base class to a derived class?
It all depends on what A and B are and mean.
Because base class subobjects can do things that member subobjects cannot (being empty not disturbing the layout of the type, automatically exposing their ...
11
votes
Is passing arguments as const references premature optimization?
In DonaldKnuth's paper "StructuredProgrammingWithGoToStatements", he wrote: "Programmers waste enormous amounts of time thinking about, or worrying about, the speed of noncritical parts ...
10
votes
What are R-value references used for?
A common use case is the “move constructor,” invoked when an object is being copied from a temporary that’s about to expire (a rvalue). An example is foo = bar + baz; where bar + baz is a temporary ...
10
votes
Will destructing a large list overflow my stack?
Late answer but since no one provided it... I ran into the same issue and solved it by using a custom destructor:
virtual ~node() noexcept {
while (next) {
next = std::move(next->next);
...
10
votes
Is the meaning of `const` still thread-safe in C++11?
The video you cited is for an advanced and expert audience. Herb Sutter tries to bring this audience to a consensus on how to best communicate the intent of these keywords to other people, in this age ...
9
votes
Accepted
What Design to choose for Parsing different files to populate different classes?
Classes should have a single responsibility. Presumably the responsibility of parsing a file to populate a class and the responsibilities of class itself are distinct and should not be combined. ...
9
votes
What Design to choose for Parsing different files to populate different classes?
If the parsing is more complex than a few lines of code, it is probably better to put it into separate classes, lets call them Class1Parser, Class2Parser and so on. If those classes contain similar ...
9
votes
Is passing arguments as const references premature optimization?
Passing by ([const][rvalue]reference)|(value) should be about the intent and promises made by the interface. It has nothing to do with performance.
Richy's Rule of Thumb:
void foo(X x); // ...
8
votes
Style guide for C++
The criticisms of Google's C++ style guide (and I agree some are justified) are not about Google's naming conventions or indentation style but rather about some of their other rules and policies. ...
8
votes
Accepted
How to properly deal with starvation
The scheduling mechanism you have described is Fixed-priority pre-emptive scheduling.
If you know there is a possibility the max priority queue is always full, then you are using the wrong mechanism, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
c++11 × 175c++ × 132
multithreading × 15
design × 13
design-patterns × 11
smart-pointer × 10
object-oriented-design × 9
c × 7
object-oriented × 5
performance × 5
polymorphism × 5
pointers × 5
lambda × 5
unit-testing × 4
programming-practices × 4
coding-style × 4
libraries × 4
reference × 4
boost × 4
c++14 × 4
algorithms × 3
inheritance × 3
class-design × 3
class × 3
queue × 3