214 points · by joboccara · 9y ago · 172 comments
Just replace that Josuttis's C++ standard library with C++11 version and throw in Mayers new effective book for good measure and you're all set
And I'm completely serious. I've earned my living with C++ for over a decade, am considered a valuable contributor and still... so clueless towards so many details.
If after a decade there are so many details still obscured from you, then that's pretty much again a fault of the overly-engineered and tacked on language called C++.
Other mainstream language work fine and allow you to still write clean and modern code without having literally dozens of subsets and implementations. So why is it that C++ feels the need to have so many?
I'm not kidding.
I've got several linear feet of C++ books on my bookshelf, have read most of those books, and I consider myself an average C++ programmer, not a language guru by any means.
It's easily one of the most complex mainstream languages and one with the most pitfalls which is why higher level languages are preferable when feasible.
I also wouldn't bother with Effective STL or More Effective C++. They're ancillary to the main books of that series and are somewhat outdated.
I don't know if you know the meaning of "proficiency", but if you are trying to argue that it takes work to become an expert in a subject then it seems you aren't aware of what being an expert actually entails.
Moreover, Those books appear to be a lot mainlyl because the subjects covered by half of them actually overlap.
Jonathan Blow's upcoming language?
In C++, structs are just classes whose members are public by default.
I might be extremely biased about this, but I can't not recommend to follow Folly as well (https://github.com/facebook/folly). There is some very good C++ there (and some bad C++ too), and it is generally more readable than Boost. Some ex-Boost people work on it too.
The implementation of Function (https://github.com/facebook/folly/blob/master/folly/Function...), for example, is mindblowing. I learned lots of tricks from it that I ended up using in a bunch of places.
There's also a lot of interesting things happening in concurrent data structures under experimental/ (and the widely used MPMCQueue and LifoSem are also excellent).
I studied C and C++ back in university (I was in the wave of students that came through after they switched from Pascal as the teaching language, and before they switched to Java). And my first job or two back in the early-2000's was using C++ in HP-UX servers, to talk to other systems via CORBA.
But that was ages ago, and once I stumbled into a Java job I never left. Every so often decide to scrape off the rust and check out C++ again, but the ENVIRONMENT setup scares me off.
Should you use GCC or LLVM? If you're on a Windows box, do you try one of those? (there's at least three different distributions of MINGW available) Or do you use Microsoft's compiler? (VS has potential licensing issues, while the freeware build tools are pretty arcane and it's hard to even find an installer or know which exact thing to install) Or Cygwin? (I'm not 100% sure on the current state of its licensing)
I've tried to build the wxWidgets library at least 100 times. It gives you dozens of options for compiler and environmental setup, and yet I've never found a choice that successfully built all the sample apps.
Once you have a compiler setup, what about an IDE? (Don't even start with the "just use Vim or Emacs" crap, I'm not an animal!) I love IntelliJ in the Java world, but don't want to pay for JetBrains CLion just for hobby/personal use. The last time I tried Eclipse's C++ support it felt pretty half-baked. Qt Creator is actually really nice IDE (a C++ IDE should be written in C++!), but it feels very specific to writing Qt apps.
What about build tools? It's hard enough for Java newbies to wrap their heads around Maven or Gradle. But makefiles and "configure" scripts are far more arcane, and which flavor of make should you be using in 2017? It's hard enough to build a project that uses one of these large frameworks with opinionated build systems. I wouldn't even know where to begin in combining two opinionated build systems as dependencies of a single project, or creating a new build system from scratch for a greenfield large project.
Once you have a compiler, IDE, and build system and are ready to start coding, what about a standard library? Is Boost still the thing everyone uses? STL? Something else?
I really can't imagine that learning C++ syntax is THAT challenging in comparison to Java/C#, Rust, D, or anything else. But I'd love to see an "Effective C++ Environment" book.
As for standard libraries, the STL is the standard library and you 'should' use that where possible. Boost is a mix of potential features for C++, a few modules that lots of people rely on (e.g. json, timers, asyncio), and a whole lot of undocumented and unmaintained code. I get by without it most of the time.
Qt Creator is pretty decent even if you don't use Qt. You can use the qmake system which does lock you in somewhat, but it's easier to configure than cmake for a newcomer. You still get debugging/profiling and intelligent autocomplete/linting.
If you don't mind the large library overhead, you can use Qt for a lot of brick-and-mortar code like dealing with filesystems, sockets/serial comms, parsing XML, etc. It's very well documented, updated often and it's GPL which is nice. Or you could statically link it. Personally I've found the Qt GUI framework much more intuitive than the native Windows stdafx stuff.
I recommend starting a blank C++ console project and adding files as you go, otherwise you risk getting confused (e.g. "what the hell is stdafx.h and why is it included by default in my main file") and trapped by Microsoft's ecosystem.
> What about build tools? It's hard enough for Java newbies to wrap their heads around Maven or Gradle.
You don't have to worry, Visual Studio has everything integrated. There is a build system (MSBuild? last time I checked) that you could theoretically use outside of Visual Studio, but you probably don't even need to be aware of its existance.
Also, if you do Android development, Visual Studio abstracts Gradle away, which is basically the way development is supposed to be done.
No, I just use Visual Studio.
If you don't want to pay for it, there is the Visual Studio Community edition available for free for personal use, which is basically Visual Studio Professional re-branded with a different license.
No it is not, I use QtCreator 99% of times with CMake projects. QtCreator with ClangCodeModel is the best you can get. Nothing even comes close to this combination.
I have to say I am obsessed with IDE's, and I have tried all of IDE's you mentioned, nothing can even come close to QtCreator.
The only drawback is when you use ClangCodeModel in Windows. It seems there is problem of Clang Parser in windows (there was a serious discussion with Clang developers on their mailing list). Parsing and Autocompletion are slow in Windows platform. But it is completely fine in *nix, OS X.
Resist the temptation to switch tools a lot, or tweak things continually with plugins or code generators or whatever. I've seen people do this; they get distracted by tooling and tend to learn more slowly.
All you really need to do is sit your butt in a chair in front of a good C++ compiler/debugger, and stock VS without any tweaks fits that perfectly.
On the other hand, the Whole Tomato refactoring tools are pretty awesome, and most of my cow-orkers have them installed. They make large projects a lot easier to deal with (near instantaneous search across a large project is a wonderful thing). But you don't need them, especially when you're starting out.
My basic principle is, when learning a language, doing stuff that isn't involved in learning that language is, well, not learning the language. It's like the aspiring writer who just needs to find the right laptop, the right software, the right printer / coffeeshop / corner of the house . . . it's all excuses and procrastination, just sit down and write.
GCC still compiles faster and produces faster binaries for me. But I like to swap to clang once in a while since it has better compiler messages (always use -Wall -Wextra).
> If you're on a Windows box, do you try one of those? (there's at least three different distributions of MINGW available) Or do you use Microsoft's compiler? (VS has potential licensing issues, while the freeware build tools are pretty arcane and it's hard to even find an installer or know which exact thing to install) Or Cygwin? (I'm not 100% sure on the current state of its licensing)
Instead of Cygwin you should check out MSYS2: http://www.msys2.org/ It has a package manager which can install both GCC and LLVM.
> I've tried to build the wxWidgets library at least 100 times. It gives you dozens of options for compiler and environmental setup, and yet I've never found a choice that successfully built all the sample apps.
Check out this wxWidgets project of mine: https://github.com/jhasse/pwcalculator It should build on all operation systems, if not please create an issue and I will take a look :)
> Once you have a compiler setup, what about an IDE?
I'm using Visual Studio Code with the C++ extension (on both Linux and Windows).
> What about build tools?
I'm using Waf (and SCons for older projects), mostly because I also like Python. In my experience you should avoid qmake, most others are fine.
> Once you have a compiler, IDE, and build system and are ready to start coding, what about a standard library? Is Boost still the thing everyone uses? STL?
Yes, both are pretty popular. Nowadays the STL covers most of the older Boost stuff (e.g. shared_ptr, thread, regex, ...).
Don't use gcc or clang on Windows as I have had been bitten by their bugs for a lot times. Always use the native tool on that platform or you will face constant headaches (VS on Win, GCC on Linux and Clang on macOS).
Don't do this to yourself, just stick with regular Visual Studio and its build system. Nowadays you can even use it to build Linux binaries, so why put yourself through the hassle of using stone age text files to configure your build when Microsoft has been providing a perfectly usable solution for almost two decades?
https://www.theregister.co.uk/2016/03/31/microsoft_visual_st...
My life got so much when I just worked in Linux, then used CMake to hide all the visual studio grossness. My software all still builds over there and my unit tests still pass, but I get an environment that works and is understandable. I started with visual studio too, I never understood what the hell it was doing or why, there was always one more corner case or one more confusing exception to a rule or one more thing that wasn't standard C++ but msvc wanted.
I think windows and visual studio was designed to be impossible to understand intentionally, and this gets confirmed every time I ask some MCSE or or other cert holder "why" or "how" to some specific feature. I am fine with them not knowing, but they don't even know how to look it up of use technical tools to inspect it. With any other OS it is pretty easy to follow technical stuff all the way down to the bare metal and back up if that is what solving a problem takes and you can do this through the documentation or through the inspection tools like debuggers profilers. I have tried with MSVC on windows and get blocked the first time some "feature" I have never heard of and didn't ask for gets in the way. Now that understand some of what the older versions are doing I still don't understand why they do it, there is no clear technical reason to do much of the non-sense they do.
One last gripe, why does the installed thing fill like 20GB and take an hour to install when QtCreator, gcc and clang takes 3GB with all their dependencies and like 2 minutes to install from apt-get?
That's what I'm talking about. VS works great out of the box using the Wizard, but the learning curve gets real steep right after that.
I'll stick to C++, IDEs and BUILD files.
Before any project, it was Turbo/Borland Pascal and TPU files. No real projects, but it was very easy to use a module, no header files, just "Use Something;" done. C# carried that in there, and Java too.
Then for C++ it was first a simple text files with what to compile, later Makefiles (I still love them), .vcproj, .vcxproj/.sln, scons, cmake, qmake, qbs, custom tailored makefiles, etc. I've never found any of these good, until I used Blaze (Bazel on the outside) at Google (alternatively generate-ninja (gn) for Chromium/Fuchsia, close but not the same).
So what do I like about BUILD files, Bazel and WORKSPACES? It's simply this:
cc_library(
name = "my_lib",
srcs = [ "one.cc", "two.cc" ] # has glob() too
hdrs = [ "one.h", "two.h" ]
deps = [ "//base/something:project" ], # // is like a root for all projects.
)
No transitive dependencies, e.g. if A depends on B, B on C, A can't use "C" just because B did. A also needs to declare it. It takes a while to convince yourself, but then it becomes clear why this is done so.Bazel (blaze) gets a little bit harder to use if you target different platforms (say ps2, ps3, ps4, xbox, wii, pc, etc.), but there is way to declare that, in this respect GN is much easier, just use "if (is_pc) {}" in the declarations (they are BUILD-like), and you are done.
I just bought the IntelliJ package /yearly, got CLion, also some other things, and started using it for home projects. It comes with bazel support (plugin), so that helps.
--
On the other hand there is QtCreator, Visual Studio (the current free version is almost like professional except CodeLens), then some more experimental ones like the Juce's Projucer, and plenty more.
https://giantfublog.wordpress.com/2016/10/15/portability-in-...
mingw32-make -f makefile.gcc BUILD=release SHARED=1 MONOLITHIC=1 UNICODE=1 USE_OPENGL=1 CXXFLAGS=-fno-keep-inline-dllexport
works on multiple machines for me, I write openGL GUI apps.
Given your post, I'm assuming Windows.
There's BloodShed Dev-C++ which has Mingw-GCC bundled but you can use another. [1]
Then there's Code::Blocks, which has a Mingw-GCC bundled version - [2]
One IDE that impressed me recently was CodeLite [3]. It doesn't come with a compiler, but its support for GCC is very good, especially gdb. You mention wxWidgets and IIRC it has built-in tools for that as well.
[1] - http://www.bloodshed.net/devcpp.html [2] - http://www.codeblocks.org/ [3] - https://codelite.org/
I could see how mixing templates with other C++ paradigms could quickly get messy in the wrong hands, since it's very powerful.
Otherwise, great article--that's a lot to dive into over a single summer though!
Of course not all hobby projects need to be "practical" or directly useful - but time is a valuable resource and I at least would like to have an actual non-toy project goal in mind when choosing to better grok a language. What is C++ uniquely good for in 2017?
edit :
Useful answers to this question -
* extending libraries for higher level languages
* embedded devI find that when someone's made up their mind about me based on little to no data, there's not much point trying to prove them wrong.
> C++ is one of the most widely used languages for application development
What kind of applications?
It's a little like saying what are some good modern uses for Java? Then you remember that millions of people use Android every day.
I work in computer vision and deal with hardware a lot, both embedded (micros) and 'higher level' (cameras, random optomechanics). You get drivers in C/C++, often dot net, and occasionally other languages. Sometimes you get lucky and someone's written a Python wrapper already, but most of the time it's faster just to use the C++ (otherwise now you have another library to maintain and keep up to date with the vendor - someone else can do that!).
If you work in web development, it's easy to forget that you can't just write a backend in Python and then make it look snazzy with CSS and Javascript. It's one of the few areas where C++ doesn't have much penetration. That said, browsers are written in C++ (Firefox and Chrome, for example) and of course the web servers themselves (plus some C).
The combination of C++ and Python is very powerful. Modern C++ is very easy to read and if you use the STL, you can write surprisingly compact code. I'm also a big fan of Qt for GUI development (plus the other bits you get with it).
"sounds like" is very much the opposite of that.
> What kind of applications?
All of them, except web pages.
Remove C++ from software development and check what is still working...
Are you asking about the ROI in terms of learning and personal growth? Then it's tremendous. The language that you probably are using (Java or C#) was written because most average programmers couldn't handle the power and flexibility of C++, so industry developed those languages as lookalikes with training wheels. If you've ridden a bike with training wheels your whole life, then aren't you at least curious at some point to see what it's like with them taken off?
If nothing else, then you'll learn why decisions were made the way they were in derivative languages, and become a better programmer overall. It gives you certain amount of confidence to have experience in a language that most people are afraid of.
If you're asking me to be specific, then I'd like to compare the ROI of developing greater C++ intuition vs. developing better machine learning intuition.
> If you've ridden a bike with training wheels your whole life, then aren't you at least curious at some point to see what it's like with them taken off?
Like just about everyone here, I've spent years of my life writing C in systems and OS classes. Are the OO abstractions that Cpp layers on top of C really that important for my personal growth? I don't see it unless I have something practical I can use it for.
> If nothing else, then you'll learn why decisions were made the way they were in derivative languages, and become a better programmer overall. It gives you certain amount of confidence to have experience in a language that most people are afraid of.
This is the definition of hand-wavy, and sounds a lot like the reasons the people on HN give for learning functional languages like Lisp and Haskell that you deride so much.
I'm a seasoned C++ developer; I can confidently apply for any job that requires years of C++ experience.
I don't find much intellectual satisfaction in that work.
If you're able to self-actualize with C++, good for you; it doesn't work for everyone.
Universities are a much longer and unfortunately financially inaccessible route for me. Going to try the "build-a-portfolio-and-start-freelancing" approach.
From http://www.ensisoft.com/temp/cplusplus_stack.png (why is this a PNG and not a JPEG?), Modern C++ Design and C++ Template Metaprogramming are likely to be the most challenging. Don't get me wrong, they are fantastic works, but are probably not what you need right now.
C++ Primer, C++ Common Knowledge, and API Design for C++ are books that I think you should consider that are not listed in the post above. If you have never studied computer architecture it is an important subject to understand. There are good books like Computer Systems: A Programmer's Perspective, but others may have different opinions.
I understand your reservations but keep in mind that the blog post is intended for an audience that has already bought into C++ programming and therefore, may want to improve their baseline C++ skills.
It's not an an evangelism article to convince those not using C++ right now.
That said, to answer your question directly... I think that programmers who require high-performance code with low-to-zero cost abstractions will self-select into C or C++ ecosystems. In other words, a programmer thinking about writing a web app to track food recipes isn't going to be perplexed about choosing "C++? vs Ruby? vs COBOL?". Like you hinted at, the domain of the app constrains what the programming languages will be realistically chosen.
I get that. Maybe I should have added a disclaimer to that end.
> In other words, a programmer thinking about writing a web app to track food recipes
You're maybe the 5th person who's made thinly veiled barbs about me being one of those despised subhuman web developers, so I'll just answer this once and for all :
Though I have written web apps in the past, I'm not really a web developer. What I am is a developer who builds shit that people use - be it desktop apps, mobile apps, games or web-apps. I don't give two shits if I'm using RubyScript or a goddamn magnetized needle : if I need the tool I'll happily learn it. My only problem here is I can't find a good reason to learn C++. That's all.
C++ is special because it combines two big ideas:
- Zero-cost abstractions (you only pay for what you use)
- High-level abstractions (OOP, lambdas, code-generation, etc. )
I would jump straight to C++ 17. It looks completely different to early 2000s C++ and makes functional programming easier (type inference, lambdas, constexpr, etc. ).
If you learn to use C++ well, you will be able to write faster code faster.
I'd love to, but there are simply no (accessible?) resources. I'd love a "how to write C++17 with no baggage" book, but it simply doesn't exist. (please, correct me if I'm wrong?)
I really want to get to know C++, it looks like it's become a fantastic language, but in all seriousness, I could write fast, performant robust Go within a weekend, I'm proficient in half a dozen other languages, and C++ programmers still unironically suggest a stack of books the height of a small table to beginners.
True in theory and essentially because C++ still remains mostly a superset of C, but unfortunately the majority of C++ programmers I've met tend to overabstract and not realise it, making this claim not really true in practice.
High-level abstractions (OOP, lambdas, code-generation, etc. )
On the other hand, this is definitely true in practice.
I think this notion is out-of-date. Have a look at this slide: https://youtu.be/_wzc7a3McOs?t=21m37s It shows how C++ has evolved away from just "C with Classes".
I agree that many C++ programmers over-abstract things.
I wouldn't say that C++ is _uniquely_ good for this (C could be used as well as any compiled language that can expose a compatible C ABI which includes Go, Haskell, etc.), but I do feel like the addition of RAII and exceptions matches the Python paradigm quite well.
I'm currently taking Udacity's Self-Driving Car Engineer Nanodegree. Currently I'm on the 2 week "break" between term 2 and 3, which starts on July 6th.
Anyhow, term 1 used Python (and various libraries of course) exclusively. When I signed up, I knew that at some point they were going to use C++ - so I was concerned if my system would need an upgrade (I use Ubuntu 14.04 LTS); but I was assured it would work ok. I was also concerned because I hadn't touched C++ since VS4 (ie - ages ago!) - and I was thinking "will I be able to do this - rusty isn't the word for my skillset in C++".
Term 2 came around, and that's when reality hit - C++ was to be used almost exclusively thru the entire term. Fortunately, Udacity (as part of one of the lessons) gave us a free "preview" of a course they are developing to teach C++ (not sure if it will be free or paid) - and so I went thru that, and found that it was fairly easy! I suppose that my skills in other languages since I had last played with C++ (ie, PHP, Python, Java, Go, Javascript, etc) all worked to make it seem that C++ was "just another syntax". Granted, there are some things which I only barely grok (templates, for instance - but there are several others), but overall, I got things, and was able to successfully finish my projects and complete the term.
Oh - and I had to upgrade my gcc compiler, and a host of other things - because the version of gcc wasn't C++ 11 - which of course is what they were using mostly. So I got to do some unspeakable things to my workstation (and basically fubar'd it so bad I can't do an upgrade any longer - not without some serious work, but I'll leave that to the end of term 3)...
I guess what I'm saying here is that the experience on the Udacity course led me to the agreement with your premise; C++ isn't really that difficult to pick up the basics of if you already have Python (and maybe some other languages) under your belt.
That said - I am looking forward to seeing what Jai brings, if it is ever released to the public...
I don't think that's true. Go only has a FFI to the platform's C ABI (cgo).
https://blog.filippo.io/building-python-modules-with-go-1-5/
As long as you specify the correct interface, Python will happily load your modules.
I disagree. Most desktop apps are written with some kind of bytecode language (like my code editors and IDEs) with a few being written in C++ for very specific reasons (like my web browsers).
> When you add C
I wasn't asking about C
That's maybe true for your Dev tools but not for general purpose apps. MS Office, Adobe products, video players and other stuff regular people use are written in C++.
C++, along with C, which you should also know if you know C++ is also used in the embedded software industry. Because it C++ is still essentially C, you write code for these tiny, bare metal embedded systems and still take advantage of some advanced features like classes, templates, etc...
Where I live, C++ coders are in high demand in various fields, just to let you know.
What fields, aside from embedded? I'm genuinely curious.
* Graphics
* Infrastructure (web servers and browsers, OS's, drivers, etc)
* Any desktop apps that are CPU/memory intensive. think image processing, video editing, even office applications
* Finance
* Games
* AI. GPUs are becoming more popular for training machine learning models, and C and C++ are pretty much dominating this space with OpenCL, CUDA, etc.
You mentioned in previous comments that browsers and stuff don't really count because you're not going to be implementing a browser that competes with the big four. But people have to work on maintaining those browsers. Same with MS office, Photoshop, etc.
The world pretty much runs on C and C++. From the steering column in your car to the computational fluid dynamics models that predict hurricanes and save lives, to the telephone switches that route your cell phone calls. Until pretty much every important piece of digital technology, small or large, switches over to a new language, there will be a need for C and C++ developers.
Personally, I mostly work around embedded/industrial systems and everything that goes with it such as test and simulation tools. I know some people who work in scientific computing and C++ is used in this domain too.