
C++11 FAQ - Tomte
http://www.stroustrup.com/C++11FAQ.html
======
huhtenberg
I've been programming for money for over 20 years and I grew up professionally
writing C and then half-migrating to C++, because the latter very naturally
captured lots of C patterns and allowed for more succinct expression of the
same. It was lean, expressive and _elegant_. Just needed a bit of Lisp-y
closures and it would've been perfect.

And then things got completely out of hand. Elegance was nuked from the high
orbit in favor of "power features" and abstraction. Fucking Boost (I can't
tone it down, sorry), move semantics, ass-backwards closures, meta-template
programming - C++ that was _easy to understand_ became something that would
normally come out of self-indulgent academic research.

Again, I've been using C/C++ for all my professional life, so it pains me to
say this, but what it has become, it's... it's just horrible. Anything - C, D,
Python, Rust - is cleaner and more elegant than C++ and just as powerful. If
nothing else, I feel sorry for Bjarne. What could've been a gem of programming
languages became
[http://i.imgur.com/1oGHYqi.jpg](http://i.imgur.com/1oGHYqi.jpg)

~~~
spoondan
This is perhaps one of the more unexpected opinions on C++ I've encountered.
When I picked up C++ with Turbo C++ 3.0 in the early '90s, it was already
widely regarded as an over-complex behemoth. Donald Knuth said of it in 1993,
"Whenever the C++ language designers had two competing ideas as to how they
should solve some problem, they said 'OK, we'll do them both'. So the language
is too baroque for my taste." The last twenty years, there's no C++ that I
would call lean, expressive, and elegant. You give the example of template
meta-programming as something added more recently, but Erwin Unruh was
printing the primes in compiler error messages not long after Knuth was
knocking C++ as baroque. It makes me wonder if perhaps the issue isn't simply
that over time you've become more aware of how complex the language has always
been?

The language has continued to grow, but it's growing in a rather different
direction (or rather in a clear direction): towards a modern, preferred subset
that _is_ lean, expressive, and elegant. While C++ is still far from my
favorite language, I find C++ today to be far simpler, more expressive, and
more elegant than at any other point in the past.

~~~
cmrdporcupine
Arguably the std::move stuff and the semantics around it have added
uncomfortable complexity to the language, even if it might have been
necessary. Other than that I think other advances in C++11 and beyond have
made for a quite nicer language to work in.

I love C++11 and use it every day, but I think putting references in the
language was an 'original sin'. They should have stuck with C's model: it's
either a value or a pointer to a value. References just added a pile of
complexity and pontificating about whether something was being copied, moved,
or passed by reference.

~~~
JoeAltmaier
Surely references have intrinsic value to the programmer? They're a pointer
that can't be moved or rebased. Other languages have only references, and in
C++ you can use that convention and not have any extra confusion.

~~~
cousin_it
References are crazy. There's no simple guideline to use them safely. Check
this out:

    
    
        const string& s = max<string>("a", "b");
        cout << s;
    

Standard types and functions, const references, no warnings, everything by the
book. But it crashes.

There's a similar can of worms related to slicing (treating Derived* as Base*
is silently unsafe because arrays and copy constructors exist). C++ is scary.

~~~
qcoh
Works for me in both C++03 and C++14?
[https://ideone.com/KhfGaN](https://ideone.com/KhfGaN)

~~~
cousin_it
Your code is not the same as my code and you're probably new to C++. I suggest
trying two changes:

1) Replace max("a", "b") with max("b", "a"). Run it, look closely at the
result, and be enlightened.

2) Replace max("a", "b") with max<string>("a", "b"). Run it, look at the
result, and be enlightened in a different way.

As a small hint, your code invokes _unspecified_ behavior, while my code
invokes _undefined_ behavior.

If this exercise doesn't put the fear of C++ into you, then I don't know what
will :-)

~~~
qcoh
Sorry, can you clarify? Adding the template argument causes a crash on idone,
but I have no idea why that happens. Moreover, the output on my computer is
always b\n.

EDIT: Not sure if this is it, but after some digging I've found [0] on
lifetimes of temporaries. As for the lacking template argument, presumably
const char* is inferred and a temporary string is constructed in main?

[0] [http://stackoverflow.com/a/2784304](http://stackoverflow.com/a/2784304)

~~~
cousin_it
So first of all, max("a", "b") expands to max<const char*>("a", "b"). It
computes the maximum of two pointers, without looking at the characters at
all. Comparing two pointers to unrelated objects is unspecified behavior, but
in this case it usually returns the second pointer.

As for max<string>("a", "b"), it implicitly converts both arguments into
temporary strings, then returns a const reference to one of them. Since it's a
reference to a temporary, it becomes dangling when max returns, but you can
assign it to a const string& anyway. When you try to access it, you'll get
garbage or crash.

~~~
qcoh
Thank you for the explanation! I'll have to look out for that one...

------
72deluxe
Good stuff, I can also heartily recommend Scott Meyer's Effective Modern C++
book which covers idiosyncrasies and some unexpected behaviour (at least to
me).

Also Stroustrup's 4th edition of The C++ Programming Language is invaluable,
if not just for the more-readable sans-serif font compared to the 3rd edition!
And of course the coverage of all C++11 changes in it...

I can also recommend the Overload journal for interesting C++ articles
([https://accu.org/index.php/journals/c78/](https://accu.org/index.php/journals/c78/))

And cppcon videos on YouTube - there's a wealth of info there, free.

Also the ISO CPP FAQ (which I think supersedes Stroustrup's?):
[https://isocpp.org/faq](https://isocpp.org/faq)

~~~
cmrdporcupine
I need to figure out what to do with my expensive old hard cover addition of
the (C++98) C++ Programming Language. It just sits there looking sad. Not much
value in it anymore.

~~~
HelloNurse
It's a monument to progress; for maximum artistic and educational value, place
it where you see it every day on top of decorative obsolete hardware (I
recommend the Thinking Machines CM-2 for prettiness or SGI workstation for
historical value).

------
gumby
Interesting to see the love/hate. We are just starting a new blank slate code
base and decided to go straight to C++17. We need expressivity early on, high
performance later. And a model where someone can really get high performance
on the core and still let people prototype / experiment down the road. It's
pretty well supported by gcc & clang which are the compilers we care about.

I haven't really done much C++ programming in 20 years so approached it as a
brand new language (to me) that I'd never used before. It's a big but powerful
standard. I can't say I adore the syntax, but it's subject to path-dependent
constraints that you just have to put up with.

I'm still looking for good references to style and practice that are
appropriate to the latest C++. Books targeted at C++11 are pretty useful but
it's too early to have more than the standard to help with 1y features.

------
lossolo
Summary of C++17 changes:
[http://www.bfilipek.com/2017/01/cpp17features.html](http://www.bfilipek.com/2017/01/cpp17features.html)

Modern C++ Coding guidelines:

[https://github.com/isocpp/CppCoreGuidelines/blob/master/CppC...](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md)

