
Why would you learn C++ in 2016? - ingve
http://itscompiling.eu/2016/03/10/why-learn-cpp-2016/
======
nostrademons
A big advantage of _learning_ C++ is so that you understand the concepts of
ownership and lifetime, along with type abstractions and using types to
enforce invariants in how your API is used.

I try to avoid using C++ for any pet projects if I can help it, but I've found
that being forced to use it for about 4 years really changed how I thought
about relationships between objects. My Java code c. 2005 was basically like
spaghetti; if I needed to operate on an object, I'd pass in a reference
somewhere and call whatever I needed, and then let the garbage collector
(maybe or maybe not) clean it up. In C++ this _doesn 't work_ \- you will have
an unmanageable mess of memory leaks and use-after-frees (or reference cycles
if you resort to shared_ptr). So I had to learn how common program
architectures (servers, compilers, distributed parallel programs) manage
memory and assign ownership to certain overall scopes. This in turn has
informed how I design my production Swift, Javascript, and Python code, or use
Java dependency-injection frameworks like Dagger.

I still appreciate being able to write spaghetti while prototyping, but I've
found that maintainable production programs seriously benefit from having
clear notions of object ownership and lifetime.

~~~
lossolo
I think Rust will teach you out of the box a lot more about concepts of
ownership and lifetime, i know i learned a lot from Rust.

~~~
AstralStorm
Sadly, it won't teach you what happens if you fail to consider something.

This means, long hours of tracing, debugging, leak checks etc.

The lesson is: never ever rely on compiler, framework, language or other
potentially buggy tools to think for you. Even with Rust's "hard" approach,
you can get complacent and hemorrhage performance and memory until there's no
turning back.

Those things were written by fallible people without hard mathematical proof
everywhere, after all. Rust and especially its libraries too.

Understand libraries, their implementation and design trade-offs if you're
using them.

~~~
pcwalton
> This means, long hours of tracing, debugging, leak checks etc.

But you don't have undefined behavior to debug, and that makes debugging
easier. Trying to reverse engineer from a corrupted memory dump from a
production system what the compiler did to your code and relate that back to
where it went wrong is something you will have to do in C++, given enough
time. You don't have to do that in Rust.

------
froh42
The target audience for the code I write is not the compiler but my coworkers
and the gals and guys who will maintain the stuff after I leave a project.

So I prefer to choose a language where I can nicely express the intent of what
I code. Java is a good compromise, because it's easy to follow (even if it's
quite verbose and mainly stuck in the world of nouns).

C++ is hard for that. It's an extremely complex language that got extended
over the years and it takes a quite long time to master, for example compared
to Java.

Yes I know, C++ is more "capable" than Java but it's not efficient in the
hours-spend-per-solved-problem way of things.

Yes I know, there are you C++ whiz kids out there who are insanely fast using
the language. But I experienced teams using it, and in a team C++ does not
scale well. Adding more and more features to it makes it a cool language, but
not one which I like to use in my day job.

And I'm not sure what I'd use it for. I use Java for the day-to-day boring
"enterprise" world, twiddle around with dynamic languages for the hobby (yay
to the recurrence of lisp!) and for close to the hardware stuff I'd use plain
C - which is a not so bad language at all. And it's hard to beat speed-wise,
writing C++ that keeps up with C is possible but not trivial.

And if I'd have to look forward I'd check out rust or go or even look at some
really mindbending stuff like erlang. Parallelism can't be evaded in the
modern world and using a language tailored to that is a great thing. (Yea, I'm
sure there also is a C++ library implementing the actor model).

~~~
userbinator
My preference is to use C++ like a C with some extra useful features, and not
"go full C++" by trying to "do everything the C++ way". C++ has a lot of
features and is growing but, contrary to what a lot of evangelism seems to
say, you are not obliged to use all of them. Use a feature when it makes the
code simpler and the effort reduced, don't try to use one and complicate
things just because it's a new feature that seems interesting.

~~~
rjeli
This is how I feel. Even as a Unix/"Pure C" fanboy, just having the STL is a
huge time saver.

------
vvanders
Mostly spot on.

That said I can seriously see Rust giving C++ a run for it's money in about
2-3 years. All these things you have to learn the hard way(ownership, move
semantics, dangling pointers) are dealt with up-front in Rust. They really
aren't bolted on as an afterthought but a core part of the language(std::move
I'm looking at you!).

~~~
forbidden404
I've been looking Rust with good eyes and I want to be using it in my future
projects in College. But how easy would it be for developers to "give up" OOP
for a more safe and up-front language like Rust?

I mean this as a serious question, cause I see C++ being used instead of C
thanks to its multi-paradigm capability and I don't know how Rust could fight
that for now.

~~~
TillE
Rust is currently lacking plenty of "quality of life" features which even C++
has (eg, default parameters). Not to mention a good IDE. I do think it's the
first serious contender to eventually replace C++, but it's really not there
yet.

It's definitely worth trying and learning. I would've ditched C++98 in a
heartbeat to move to Rust, but C++ is a pretty exciting and productive place
to be ever since C++11.

~~~
Retra
I haven't needed an IDE in Rust. The auto-generated documentation is usually
good enough for all my needs. However, C++ is pretty awful without an IDE,
because you can easily end up with deep object hierarchies, usually with two
files per object.

It's also nice to just tab to your terminal and do `cargo run` and get your
code compiled out of the box. Writing a decent makefile (or whatever else you
plan to do) for C++ is comparatively quite a hassle.

------
fideloper
Almost everything is a crud app. Game developers are notoriously abused in
compensation and work hours.

I do think c++ provides an interesting area to program into but the part where
you do it to avoid places with business requirements would only speak to
programmers who don't yet realize that the business perspective of your code
is where your career growth and potential come from (not from learning more
and more advanced coding technique).

~~~
Aaronontheweb
> programmers who don't yet realize that the business perspective of your code
> is where your career growth and potential come from (not from learning more
> and more advanced coding technique).

Yes and no. I think programmers get the biggest lift, career-wise, from being
able to put themselves in the shoes of a stakeholder while coding and being
able to talk intelligently about what they produce to non-technical people.
But that's just the price of admission to work in an environment where you
don't get treated like shit usually.

Beyond that, if you want to work on problems that you really enjoy then
finding a technical specialization that gets you excited to go to work is a
must. Then find a job where your knowledge in that area translates to business
value. If that sounds hard, spend some more time socializing with other people
in your industry. Consulting or working on OSS projects helped me a ton in
this area.

That's the arc my career has taken at least, and I'm still early in it.

------
Paul_S
"Video game developer is considered to be one of the most rewarding jobs in a
software industry."

I would not agree with that. Unless you insert 'mistakenly' into that sentence
or replace 'rewarding' with 'underpaid and overworked'.

~~~
shinymark
I've been lucky in my career in games and have worked for some great people.
Now I'm my own boss and try to treat my employees fairly. It makes me sad to
hear about mistreatment in games.

I think working in games can absolutely be incredibly rewarding if you love
the medium and delighting players. On huge teams individual effort can be hard
to connect to player enjoyment but I've found it super fun to work on and lead
smaller teams where everyone can directly impact players and get concrete
immediate feedback on how your work is affecting player experience.

Unlike many other areas of software development most game features immediately
impact how players perceive your game. I love the immediacy of that
connection.

~~~
Joof
I would love to do game development / programming. The horror stories about
long hours, low pay, lots of crunch all have driven me away from it so far.
Gamasutra[0] did a nice article about how crunch makes games less likely to
succeed (among other things); I hope this kind of stuff changes the mindset of
the industry.

[0][http://www.gamasutra.com/blogs/PaulTozour/20150120/234443/Th...](http://www.gamasutra.com/blogs/PaulTozour/20150120/234443/The_Game_Outcomes_Project_Part_4_Crunch_Makes_Games_Worse.php)

------
lossolo
I agree 100% with second point. I enjoy writing c++11/14 and it's not my
primary language. 10 years ago i would say no to c++ but today it's like
writing in different language.

Qt is another huge argument why i use C++, there is no alternative (or i don't
know any other cross-platform framework as good and mature as Qt is).

~~~
truncate
How about Qt bindings to other languages? Last I checked for Python (like 4
years) ago, the biggest problem I had was with licence (GPL). But yeah,
compared to Python, using C++ also gives me system threads which might come
handy every now and then for CPU intensive stuff.

~~~
zanny
The problem with the Python Qt bindings, in my experience, is that PyQt is
not... pythonic. I like Pythonic things, like Flask, over less-Pythonic
alternatives, like Django. At least in principal. And yes, I know Django has
gotten better about it over the years. I need to try a new project in it at
some point, especially considering Flask's atrophy.

But PyQt is not so much a binding layer as just Qt in Python, literally. It
has to be some kind of semantic offense though, since I have no problem
writing Qt C++ to begin with. It is just the language and style of the API
itself favors C++ because thats what it is made for.

QML and Python, on the other hand? Lovely. If it didn't depend on all of PyQt
to just start up a QML program and signaling into / out of it, I'd be all over
that idea.

Which is probably where I am super interested on the Rust front. qmlrs showed
a lot of promise last year, and while the project seems to be suffering from a
lack of contributions as of late, someone will eventually pick up the reigns -
I do not think any other GUI framework is even close to appropriate for Rust
to begin with anyway.

------
Animats
I tend to think that the C++ standards committee went off into template la-la
land a few years back. Everything has to involve templates, "metaprogramming",
and excessive gyrations within the type system. If you want to compute at
compile time, C++ templates are a terrible way to do it.

The fundamental problem with C++ is that it has hiding ("abstraction") without
safety. No other major language does that. In C, there's no memory safety but
everything is explicit in source. In memory-safe languages, there's memory
safety even if there's lots of abstraction.

Rust has a brilliant idea in the borrow checker, but the type system is kind
of weird, the attempt to bolt on functional programming is marginal, and error
handling involves hacks such as "try!()". But with enough use, those aren't so
bad. Maybe. Personally I would have preferred Python-type "with" clauses and
exception handling to RAII. If anything goes wrong in a destructor, Rust
cannot help you.

~~~
GFK_of_xmaspast
> If you want to compute at compile time

I assume you're not up to speed on all the constexpr work.

~~~
Animats
I didn't realize that as of C++14, you can now execute loops at compile time.
Does that work in many compilers?

~~~
hellofunk
Wouldn't any fully standards compliant compiler for c++14 support that
feature?

------
akuma73
When Moore's Law ends (imminently), performance and performance/watt will be
harder and harder to come by.

In the long term, there may be a reversal in the trend towards "easy"
languages.

~~~
tachyonbeam
There already is a "reversal", to some extent, in that statically typed
languages are making a comeback.

However, the performance of dynamically typed languages has also improved a
ton. It's not unrealistic to think that you could write simple JS code and get
about 50% of the performance of an equivalent C function, possibly more.

~~~
Klathmon
you are already there for some admittedly contrived situations.

Things like simple loops that work on typed arrays in javascript can really
give C/C++ a run for their money right now.

------
RivieraKid
I don't know why anyone would think C++ is dead. If you need top-notch
performance, there's often no reasonable alternative.

~~~
ljk
stupid question: why do people prefer C++ over C? is _C_ considered dead?

~~~
santaclaus
I miss generics and RAII when I have to use C.

~~~
PeCaN
RAII is nice—I hope GCC's __attribute__((cleanup)) gets included in C2x.

Templates though... are nice, I guess, but the cost in compile time, ABI, code
size, and ease of debugging is a lot to swallow.

Besides, with the preprocessor and M4 you can get many of the benefits of
templates, albeit with most of the downsides (and a few more to boot).

~~~
ant6n
well, santaclaus wrote 'generics', not 'templates'. So presumably that means
containers like std::vector, or std::unordered_map. Those are pretty easy to
deal with.

------
madengr
I'm in the middle of C++ For Engineers and Scientists, learning about STL and
vectors. Though I'm an EE and learning it for software defined radio,
specifically GNU Radio.

Seems like all the really high performance stuff is in C++, C, or Fortran.

Recently learning Python, and knowing some basic C for microcontrollers, I can
see how OOP is really handy, thus C++.

------
niccaluim
I'm surprised to find no mention of embedded development. C++ seems to have a
foothold there.

~~~
kszatan
You're right, but I just couldn't realistically enumerate all the places where
C++ is used. There will always be something missing.

------
bradford
I haven't used C++ in about... 12 years. I'll admit ignorance about the
updates that have occurred in recently, so I've got a general question: How is
the compatibility between different versions? Specifically, would a C++ 11
compiler be able to compile legacy code written for C++ 03?

~~~
AstralStorm
Yes in 99.9% of cases. The main trouble could come from the angle of
accidental move (rvalue cast) somewhere invoking a broken/wrong move
constructor or assignment.

Of course, crusty old code can be buggy yet originally working - e.g. relying
on implementation defined or undefined behavior. (or even bugs in compiler or
standard library implementation)

------
wmu
The worst thing in modern C++ is metaprogramming. It's powerful technique, but
the syntax is awful _, programs are unreadable & unmaintainable. Moreover,
compilers don't help with debugging such code, diagnostics messages rarely
tell anything useful. Not to mention frequent ICEs, at least in MSVC. :)

_ As a programmer who already knew functional programming and have some
experience in SML and Ocaml, I found C++-functional-programming really
annoying.

------
wcrichton
If you're going to write a compiler, please, for the love of Bjarne
Stroustrup, don't write it in C++. There are so many better modern languages
for writing a compiler: OCaml, Haskell, Rust, and Terra to name a few. You
really want features like algebraic data types and a sane package manager in
your language of choice. In my mind, the only use case for C++ is interfacing
with existing C++ libraries/codebases. All other tasks can be better relegated
to superior languages.

~~~
copperx
Golang's compiler was originally written in C++, so people are actively
avoiding your advice.

~~~
f2f
no, it wasn't. the go compilers initially came from Plan 9, which hasn't seen
any C++ code ever :)

~~~
copperx
"Came from Plan 9". What does that mean?

~~~
holmak
Plan 9 was a research OS that was sort of intended to be a "next generation"
Unix. The Golang project is led by at least one person who worked on the Plan
9 OS, and overall it seems to be heavily inspired by Plan 9's design.

[https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs](https://en.wikipedia.org/wiki/Plan_9_from_Bell_Labs)

~~~
copperx
Yes, I know that. But I don't understand the implication that Go came
magically from Plan 9. I recall reading Kernighan stating that the first Go
compiler was written in C++ before bootstrapping.

~~~
holmak
Sorry, I misunderstood your comment. I think the original poster was referring
to the Plan 9 team's strong preference for C over C++. Plan 9 was written with
a modified version of C, and the developers seemed to be very interested in
evolving the C language. As far as I can tell, they never used C++.

> In the presentation before the awarding of the Japan Prize today, you were
> quoted on the distinction between research and development. [The former,
> Thompson stated, was directionless, whereas development had a specific goal
> in mind.] So in that context, is Go experimental? > Yes. When the three of
> us [Thompson, Rob Pike, and Robert Griesemer] got started, it was pure
> research. The three of us got together and decided that we hated C++.
> [laughter] [1]

It looks like you were half-right about the early Go compiler being partly
written in C++: There were two compilers, and "gccgo" had a C++ front-end,
while their homemade compiler "gc" was written entirely in C. [2]

[1] [http://www.drdobbs.com/open-source/interview-with-ken-
thomps...](http://www.drdobbs.com/open-source/interview-with-ken-
thompson/229502480)

[2]
[https://golang.org/doc/faq#What_compiler_technology_is_used_...](https://golang.org/doc/faq#What_compiler_technology_is_used_to_build_the_compilers)

------
ant6n
I think C++ was dead from like 2005 to 2011, then it started respawning (to
deliberately borrow a term from fps-shooters ;-).

------
brutopia
Can't read on ios due to social media buttons overlapping the text.

~~~
capote
Get yourself some content blockerz, yo.

~~~
capote
Oops… they're showing up on mine too with the blockers ️

~~~
capote
Haha, you guys really hated these two comments.

------
gozur88
You learn pretty much any skill because it's in demand and people will pay you
to do it. Of course there are some things you'd rather do or not do
independent of money, but it's a good place to start.

A better question would really be "What factors would lead me to believe C++
is right tool for a particular task?" Which, I think requires a bit more depth
than you'll find in this article.

~~~
kszatan
As the author of the article, I can only say that I agree with you but I just
wanted to write a little bit longer version of "Hey, look, C++ is alive and
there are still interesting jobs involving using it!". Your question is
something absolutely different, and yes, it should be given much more in-depth
thinking.

------
overgard
I entirely agree with this -- in a lot of ways C++ is truly awful (though it's
getting much better); but! It's the only practical solution for a lot of
interesting work. I think when people are doing something hard they always
reach for the pragmatic solution rather than the principled one, and C++ is
nothing if not pragmatic.

------
maxxxxx
I think with C/C++ you learn how the machine really works (you could argue
that Assembler would be better but C/C++ hits a sweet spot for me) . A lot of
of people who have grown up with GC languages don't seem to be aware that
under the hood there is still some C code that allocates and releases memory.
There is no magic.

------
p0nce
> The appearance of GPGPUs along with parallel computation frameworks such as
> CUDA and OpenCL created demand for C++ programmers with this kind of
> expertise.

This is a bit ironic because using accelerated APIs means the host language
could be anything and it would still be 99% as fast.

~~~
Joof
Maybe many of the problems they work with are also CPU bound? C++ programmers
also tend to be somewhat more familiar with how memory is transferred to
graphics cards, but anyone could potentially learn in any language. AoS or
SoA?

------
nickpsecurity
I'd consider learning it to work on a critical FOSS projects already done in
C++, make money with it, or write language analysis/transformation tools to
make C++ apps safer automatically. Little reason to use it in a new project
without legacy C++ code.

~~~
hga
Any insight into why Genode went with C++? That, plus swearing to never
program in it again after doing so for a decade, rather curb my enthusiasm
towards it.

~~~
nickpsecurity
Jesus... No I didn't know. So, add that to the list of reasons I might
grudgingly learn C++.

------
sprite
As someone who hasn't programmed much C++ in the last 10 years, what's a good
book to get caught up with all the new stuff?

~~~
zig
I like both "A Tour of C++" by Stroustrup and "Effective Modern C++" by Scott
Meyers. Though, the latter is a bit dense if you are unfamiliar with c++.

------
ftclausen
What are some good resources for learning C++ with an eye to these modern
practices?

~~~
MattHarrington
Try Kate Gregory's Pluralsight courses.

------
joshsyn
D is a better language than C++.

~~~
capote
Pff, E is better than D any day of the week. Trust me; I'm a programmer.

------
joshsyn
I will take a look at C++ when they get rid of header files.

~~~
rileymat2
I actually kind of like header files. I find that they can nicely separate
external interfaces from internal interfaces. They also can summarize an
interface nicely.

They are not without problems. Complete template definitions, default circular
includes. Not supporting partial classes. Ect.

~~~
srean
Compared to modules I don't think header files have even a single redeeming
quality. They are a historical artifact.

------
partycoder
_insert citizen kane slow clap gif here_

