

Ask HN: jumping back into C++ after 4 years, what did I miss? - yid

For the last 4 years or so, I&#x27;ve been mainly using dynamic languages after coming from a solid C&#x2F;C++ background. The last 4 years also have happened to be some of the most transformative years for C++. I&#x27;m starting a fresh project and want to know what people are using for their C++ ecosystem. In particular, I want to avoid re-inventing the wheel. Feel free to fill in the blanks below:<p>-- Compilers: g++, clang, anything else?<p>-- Build systems: do I still have to suffer through autotools?<p>-- C++11 features: which ones are production ready?<p>-- Package managers: anything decent at all yet?<p>-- Testing: unit tests, integration tests, profiling?<p>-- Debugging: still with gdb? Anything better than valgrind?<p>-- Threads: still with pthreads?<p>-- Documentation: anything better than doxygen?<p>-- Static analysis: anything FOSS out there?<p>-- RPC libraries: any de facto standard yet?<p>-- Async programming: still libuv?<p>-- HTTP client&#x2F;server libs: I hate cgicc, but have used it.
======
dmunoz
You're asking more specific questions that what I will cover, and they're good
ones. It will be interesting to read how others reply.

For the other people looking, Stroustrup's A Tour of C++ [0] is the guide for
getting quickly up to date with the "new C++", C++11 and onwards. It doesn't
specifically cover C++14, but if you understand C++11, the few things coming
in C++14 are for the most part minor enhancements to what is in C++11.

Scott Meyers should finish up the C++11/14 version of the Effective C++ series
this year, and many are waiting for this. For now, his notes Overview of the
New C++ (C++11/14) [1] are available for purchase.

If you like videos, there is a wealth of information from last years
GoingNative conference [2]. More recently, at this years Build conferece, Herb
Sutter gave a presentation on Modern C++: What You Need to Know [3].

Finally, come visit up over on reddit in /r/cpp [4]. Some heavyweights in the
C++ world participate there, and the larger portion of participants are
similarly knowledgeable in C++ as a whole.

[0] [http://www.amazon.com/Tour-In-Depth-Series-Bjarne-
Stroustrup...](http://www.amazon.com/Tour-In-Depth-Series-Bjarne-
Stroustrup/dp/0321958314)

[1]
[http://www.aristeia.com/Licensing/personalUse.html](http://www.aristeia.com/Licensing/personalUse.html)

[2]
[http://channel9.msdn.com/Events/GoingNative/2013?direction=a...](http://channel9.msdn.com/Events/GoingNative/2013?direction=asc#tab_sortBy_day)

[3]
[http://channel9.msdn.com/Events/Build/2014/2-661](http://channel9.msdn.com/Events/Build/2014/2-661)

[4] [http://www.reddit.com/r/cpp](http://www.reddit.com/r/cpp)

~~~
flohofwoe
Definitely take the time to watch the Herb Sutter video (number 3), the first
half is mainly about how modern C++ differs from old C++, and the second half
is all about how important control over the memory layout of your data is
(spatial locality, CPU caches, linear arrays vs lists, etc...). This is one of
the most interesting, and most relevant talks about C++ I've seen yet.

------
SamReidHughes
For most of your questions my answers are "I don't know" or "probably things
haven't changed much (but I haven't gone looking very hard)". I'm still under
the impression that valgrind, gdb, libuv, g++/clang, are tools of choice. You
didn't mention allocators: maybe try linking with a better malloc: tcmalloc or
jemalloc. But I think that was also true 4 years ago.

> C++11 features: which ones are production ready?

What compiler and which standard C++ library are you using?

Generally speaking, any your targeted compilers support. Rvalue references and
move semantics are the best and most important C++11 feature. Variadic
templates would be the second best, I'd say. Scoped enumerations are nice. And
being able to say std:: instead of boost:: in places, with std::bind,
std::unique_ptr<T> (not boost::scoped_ptr<T>), std::unique_ptr<T[]>.
nullptr_t. Stuff in
[http://en.cppreference.com/w/cpp/types](http://en.cppreference.com/w/cpp/types)
. Other boring C++11 features like new uses of the "using" keyword.

> Threads: still with pthreads?

You could use C++11 threading stuff, but I'm not inclined to do so.

------
cbab
On recent C++ projects, I used the TAP [0] test format. It's quite
minimalistic and does the job.

Debugging tools have improved quite a bit. I suggest you take a look at asan
[1] for memory related errors. Also, tsan [2] looks very promising for data
races detection. I think both tools have been integrated within
LLVM/Clang/GCC.

Also, you might want to take a look at tracing tools such as (shameless plug!)
LTTng [3] for userspace.

Static analysis tools are quite "en vogue" right now. IMO, nothing comes close
to Coverity Scan [4]. It's free for open source projects, but you will have to
fork (quite) a bit of money to run this tool on proprietary applications. On
the other hand, purely FOSS static-analyzer such as clang-analyzer and
cppcheck can catch nasty errors. I would suggest using a mix of all these
tools.

[0] - [http://testanything.org/testing-with-tap/c-plus-
plus.html](http://testanything.org/testing-with-tap/c-plus-plus.html)

[1] - [https://code.google.com/p/address-
sanitizer/](https://code.google.com/p/address-sanitizer/)

[2] - [https://code.google.com/p/data-race-
test/wiki/ThreadSanitize...](https://code.google.com/p/data-race-
test/wiki/ThreadSanitizer)

[3] - [http://lttng.org/ust](http://lttng.org/ust)

[4] - [https://scan.coverity.com/](https://scan.coverity.com/)

------
flohofwoe
Just to tick a few points off the list:

\- from my experience, gcc4.8, clang3.3 and VStudio2013 all have very solid
C++11 support, and it is definitely production ready

\- (meta-) build systems: cmake, premake, scons or similar meta-build-systems;
these create Makefiles or IDE project files and generally simplify managing
the build system for large multiplatform projects

\- std::thread, std::atomic and std::chrono are really helpful for multi-
platform development, since these areas hadn't been standardized before

\- clang/llvm has a nice static analyzer, which is also integrated into the
Xcode IDE on OSX (with a funky visualization of the "reasoning flow"),
VStudio2013 also has a static analyzer built in

\- I use UnitTest++ for unit testing, but I'm sure there are other choices,
UnitTest++ has a nice IDE integration both in Xcode and VStudio (basically,
the test failure messages are formatted so that they can be parsed by the IDE,
and you can simply click on them)

\- you can even get C++11 support on somewhat exotic platform like emscripten,
std::atomic and std::chronos work, std::thread not because of Javascript's
limited threading model

\- the new move-semantic is really useful for dynamic container classes, and
generally handing complex objects around, and you get these improvements "for
free" when using the standard containers

[edit: chronos -> chrono]

------
CJefferson
Compilers: visual studio is a very respectable C++ compiler nowadays. It lags
slightly behind clang and g++, but is the compiler of choice on windows. clang
is now the equal of g++. Unless you have a reason not to, use visual studio on
windows, clang on mac os x, and either clang or g++ on linux.

Build systems: cmake seems increasingly popular nowadays, but doesn't solve
all autotools related issues.

C++11: If you are willing to require a reasonably recent version of each
compiler, you can happily use almost every C++11 feature. auto and decltype
are the two which I use the most day to day, and greatly help simplify code.
If you are willing to use the very most recent version of clang or g++ (by
which I mean gcc 4.9, released a couple of days ago), there is almost complete
C++14 support. C++14 is mostly a cleanup, the only significant thing I have
been using is generic lambda functions (lambda functions are in C++11).

Debugging: on mac there is lldb, never tried running it on linux. clang and
g++ now have 'sanitizers' built in. I haven't use the g++ one, the clang
memory sanitizer catches several bugs which valgrind misses (as valgrind is
poor at detecting stack related issues).

Threads: C++11 has std::thread. It works fine for me but I don't do anything
super fancy.

~~~
kchoudhu
> use visual studio on mac

If only :(

~~~
CJefferson
Typo fixed :) (which now makes this comment make nos sense. I agree Visual
Studio is better than Xcode).

------
tdicola
For testing, I've used and like the googletest unit test framework:
[https://code.google.com/p/googletest/](https://code.google.com/p/googletest/)

For C++ features, definitely check out lambda functions and the STL
algorithms. With lambdas the standard algorithms are much, much easier to use.
Herb Sutter in a talk said something to the effect of just forget the whole
idea of function objects and use lambdas.

Will also be useful to familiarize yourself with the C++11 pointer types,
unique_ptr and shared_ptr. I try to never write code that invokes new/free
directly and instead just use those pointer types.

Also seconding picking up A Tour of C++ by Stroustrup. It's not a long read
and will get you up to speed on all the important changes. I think it's a very
exciting time to be using C++!

------
loumf
Clang has static analysis [http://clang-analyzer.llvm.org](http://clang-
analyzer.llvm.org)

Valgrind is still what I use and see recommended

Still using doxygen

C++11: lambdas

Kind of hoping people chime in on some of your questions.

------
pcvarmint
As for the core C++ language, rvalue references, lambdas and variadic
templates are probably the biggest additions.

Lambdas and variadic templates are optional, but you need to be aware of
rvalue references and move semantics, which enable optimizations previously
unavailable. If you write functions for which it might be advantageous to move
values rather than copy them, such as transferring ownership of dynamically
allocated memory from one instance of a class to another, then you should
consider using rvalue references.

------
jason_slack
I use Doxygen.

C++11 Lambda's, threads, auto, smart_ptr

C++14 shared mutex's look interesting.

~~~
yid
I have to say Doxygen has matured _considerably_ in the last 4 years. Color me
impressed.

~~~
jason_slack
Indeed. Coupled with "Dash" I have a lot of documentation at my finger tips...

------
cheepin
For HTTP, Microsoft recently opensourced a C++ Rest SDK called CasaBlanca [0].

For debugging, I'm still partial to the Visual Studio debugger when
appropriate, though it doesn't seem to be able to debug lambdas very well.

Also possibly missed the hype train for "replacement" languages like D, Go,
and Rust. We'll see where that goes. Some people are really excited.

[0]: [http://casablanca.codeplex.com/](http://casablanca.codeplex.com/)

------
blooberr
I'm also returning to C++ as well.

Throwing that out there - Will pay over $100 for books, videos, tutorials on
cutting-edge C++ tutorials to get back in the game.

~~~
jason_slack
well, maybe we could form a simple mailing list and we could just do an
ask/answer type situation. I spent the last year writing a game in C++ and
ready to start my second.

I run my own mail server, I could set something up. There a lot of
lists/forums out there but they all seem snooty and dont like obvious newb
questions.

EDIT: Here is a new group. Lets use it to help each other out so we all become
better: [https://groups.google.com/forum/#!forum/community-c-plus-
plu...](https://groups.google.com/forum/#!forum/community-c-plus-plus/)

~~~
jason_slack
OK, Here it is: [https://groups.google.com/forum/#!forum/community-c-plus-
plu...](https://groups.google.com/forum/#!forum/community-c-plus-plus/)

------
geekam
Jason created a group where everyone from here can ask and share
[https://groups.google.com/forum/#!forum/community-c-plus-
plu...](https://groups.google.com/forum/#!forum/community-c-plus-plus)

------
laxk
Maybe offtopic but did you try to look golang[1]?

[1] [http://golang.org](http://golang.org)

