How on earth do normal people learn C++?

I’m asking this seriously. How?

One dirty little secret around Microsoft is how little “real” C++ code is written around here. I think a lot of it has to do with the fact that when C++ was first coming into it’s own there were a number of high profile projects that enthusiastically adopted C++ but ran into a lot of problems. Some of those problems had to do with the immaturity of the tools (produced by Microsoft), some of them had to do with a lack of experience with C++ (since, of course, it was relatively new at the time), and some of them had to do with the “when you have a hammer…” effect. The end result is that although a lot of projects I’ve worked on have had “.cpp” file extensions on their source code, in many cases you could rename the extension to “.c” and it would compile with very few changes.

Lately, though, I’ve been having to do a lot more modern-ish C++ programming, and while I have an amazed respect for the sheer amount of power available to the C++ programmer nowadays, I am also baffled how anyone can actually understand what the hell they are doing half the time. Don’t get me wrong, I feel like I get by pretty well in C++, but then I spent a decade designing a OOP language, building a compiler for it, and debugging the whole thing. There are lots of times when I’ve been able to survive in C++ only because I can fall back on a mental type system model that was built up through a lot of blood, sweat, and tears. I wonder how people who haven’t had that particular experience actually grok a lot (sometimes, any) of what C++ does.

I’m guessing people just throw a lot of code at the wall until something sticks, or maybe just copy and paste from Stack Overflow. I don’t know. But, seriously, sometimes I think you should have a license before you should be allowed to attempt C++.

Either that, or I’m just being dense. Sadly, that’s always a possibility.

8 thoughts on “How on earth do normal people learn C++?

  1. not important

    My answer to your headline question ties to this comment from your post:

    “I am also baffled how anyone can actually understand what the hell they are doing half the time”

    I learned C++ by keeping myself to the “straightforward” half of C++. No multiple inheritance, no templates, no dynamic casting, and “no” to a few other things. Just basic OOP stuff. I try to avoid the “not straightforward” half of C++ as much as possible. I use/re-use “not straightforward” C++ code only when it comes from a reputable source. If the source is not reputable then, like your comment implies, there is a good chance the code has some subtle bugs. In this case I end up re-inventing the wheel and/or duplicating code.

  2. ZseliVojvodina

    Nothing special, I thing, just like a real-life-style of human race:
    “fast as you can to produce “something”, hoping there are no tree ahead …”
    You can win or lose… Nice blog, thanks.

  3. HMM

    Dear not important –

    I’ve heard your approach to C++ can be a problem with decent-sized teams, because not everyone instinctively agrees on which part of C++ is the part they’re not using.

  4. zeblonite

    HMM hit the nail on the head. Initially I was thinking the same thing as “not important” – I avoid the more esoteric elements. But then he listed a few features I don’t think of as esoteric. I think of templates and STL, for example, as core C++. You’re not going to get much consensus (instinctive or otherwise) on what is or isn’t “straightforward.”

  5. Blaisorblade

    But, seriously, sometimes I think you should have a license before you should be allowed to attempt C++.

    I’ve long thought the same, especially after learning how buggy the following can be:

    f( auto_ptr( new T1 ), auto_ptr( new T2 ) );

    compared to:

    auto_ptr t1( new T1 );
    auto_ptr t2( new T2 );
    f( t1, t2 );

    Fact: the first fragment can have a memory leak which the second doesn’t.*
    Point: those two fragments aren’t equivalent because of complex details of the language. If you aren’t a C++ guru, you won’t know about that**, but you might still end up introducing this bug. Hence, you can only use C++ if you’re a guru — or if you disable advanced features, possibly in your whole codebase.

    Using exceptions in any code called by T2’s constructor will trigger the problem. Are there other “advanced” features that have such a global effect as exceptions?

    * Guru of The Week #56:
    ** Evidence: Guru of The Week rates this with difficulty 8/10.

  6. Pingback: Top 10 | Links of the Week #3 | 02/21/2014 | The SoftFluent Blog

Leave a Reply

Your email address will not be published. Required fields are marked *