According to Stroustrup, there are so many poor C++ tutorials out there that he decided to write his own, Programming Principles and Practice using C++. "For about three weeks I was looking through C++ textbooks and had smoke coming out of my ears, muttering things like, 'If that’s C++ I don’t like it either.'"
"The quality of teaching C++ has gone down over the last 10 or 15 years. It's gone away from how to write a good program, to here is this long list of features you should understand. It is easy to teach a list of features, but hard to teach good programming.”
So what are programmers doing wrong? One thing is too much use of inheritance. "It is obviously hugely overused," he says. "There are languages where you can’t express yourself without inheritance - they fit everything into a hierarchy and it doesn’t make any sense. Inheritance should come from the domain, from the problem. It is good where there is an 'is a' or 'kind of' relationship in the fundamental domain. Shapes fit into this, there is something natural there. Similarly device controllers have natural hierarchies that you should exploit. If you forget about programming languages and look at the application domain, the questions about deep or shallow inheritance answer themselves.
He also takes care to distinguish "implementation inheritance, where in some sense you want a deep hierarchies so that most of the implementation is shared, and interface inheritance - where you don’t care, all you want to do is to hide a set of implementations behind a common interface. I don’t think people distinguish that enough."
Another bugbear is protected visibility. "When you build big hierarchies you get two kinds of users [of the classes]: the general users, and the people who extend the hierarchy. People who extend the hierarchy often need protected access. The reason I like public or private is that if it is private, nobody can mess with it.
"If I say protected, about some data, anybody can mess with it and scramble my data. That has been a problem. It is not such a problem if the protected interface really is functional, a set of functions that you have provided as support for implementers of new classes... The ideal is public or private, and sometimes out of necessity we use protected,” he said.
Macros are another issue. "For most uses of macros, there is something better in C++. The exceptions are source code control using #if and #ifdef. This will stay that way until we get some kind of module system. But I am not so worried about simple #ifdefs. I am worried about real macros that expand into code. They don’t follow any rules of C++ or any other language, they are text manipulation features. They make tool building harder, and they have delayed progress in C++."
Since code that includes thousands of macros is so difficult to maintain, Stroustrup suggests attempting to remove them from applications, automatically where possible, and manually where necessary. ®
Re: C++ put me off programming
C++ put me off C++. I read the books, I played with the language, I knocked things up and they worked. But it wasn't until I had to read someone else's C++ code that I realised what an horrendous mess there is to be made with perfectly good code, and how hard it can be to turn that back into something you can understand.
I loved learning about OOP, back in the day, and loved the concepts presented therein. But I've yet to find a usable and suitable syntax for expressing the ideas contained there. As such, I've stuck with C99 - which does everything I want and ever need, integrates with C++ libraries if I really need it to, allows me to *choose* how to program (hell, with a lot of compilers, I can mix and match C99 and C++ code and not even notice), is standardised across compilers (C++ was, historically, a mess - and may still be for all I know), is blindingly fast still, doesn't need interpreters or virtual machines, and can even be read by C++ programmers with ease (which is something that I can't claim works the other way round).
I find it quite interesting just how many libraries are actually still C99-or-similar, under the hood, and how easy it is to work with everything still just using C99 instead of C++. C++ hasn't become the major takeover of the language that I expected to come for years, and C++11 doesn't look like that will be either. You can still teach someone the entire C language and the standard library in a matter of hours. You could waste that just explaining how to use some of the more complex features like variadic templates correctly.
Yes, I grew up in an era of what is now referred to as procedural programming (it was called functional programming back in my day, but that's been subverted for something now related to mathematics more than programming, but I think that both "procedural" and "functional" were originally an accurate description - you're providing procedures, like NASA space operation procedures, to the computer to have it perform a function), and that almost certainly colours my view but the fact is that at the end of the day I want to give my computer a set of instructions that it carries out as I've told it to. The OOP overhead removes a lot of control which, if you're happy to give up, is fine. I don't like it, though.
As such, almost everything I write is in C99, can be read by any half-decent programmer, used by any half-decent programmer, extended by any half-decent programmer and get the most out of the machine even if it means I have to organise my code a little more carefully. It interfaces with everything, compiles quickly and without surprises and ports to any platform I like. And almost certainly the first compiler for any new platform will be a C compiler, not a C++ one (even though that can then follow quite quickly).
Call me old-fashioned, but C99 was where decent programming standards stopped as far as I'm concerned (which is probably another reason that C++ implementations are rarely completely compatible, and why it's taken so long to standardise the language, whereas C has been through several standardisations and added decent functionality that you can *see* and *use* each time, and which quickly find their way into compilers). Everything since then has been syntactic sugar that makes code unreadable, and sometimes unpredictable, and still has to be (pretty much) C99 compatible once you take that sugar away, and for which you need to have learnt C syntax to start.
Re: C++ put me off programming
No - programming put you off programming. All C++ does is try to do it 'properly' from pretty much just above machine code to the top.
Other languages to varying degrees do what MS does to IT in general - pretend its easy so they can sell it to you but when push comes to shove in the long run you have to re-thing and re-factor and re-write everything to fit in with the reality you hid from for years. To the point that many get stuck in, shall we call it the sme environment emphasis on the s), where you have made progress on the flat but not got any strength to climb the hills.
Programming is NOT easy - its a mathematical mapping of almost all of reality onto a computer - bit of it can be easy but the end game is never simple. Computer SCIENCE is difficult in any language. MS Office gave you the excuse to write voluminous documents to hide behind - code itself cant do that. .
Visual studio moving to C++11 might be portrayed as that excuse. But learn your trade and don't blame the language for containing concepts you haven't got a clue about yet.
Re: Sounds good
You can do it in old C++ too. The point is YOU have to do it. Every time the developer is responsible for memory, an opportunity for an error is introduced.