Feeds

Stroustrup on next-gen C++: I didn't want to let go of my baby

Badly taught, over-used... better than ever

Choosing a cloud hosting partner with confidence

Fuming frustration

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. ®

Security for virtualized datacentres

More from The Register

next story
Microsoft to bake Skype into IE, without plugins
Redmond thinks the Object Real-Time Communications API for WebRTC is ready to roll
Mozilla: Spidermonkey ATE Apple's JavaScriptCore, THRASHED Google V8
Moz man claims the win on rivals' own benchmarks
Microsoft promises Windows 10 will mean two-factor auth for all
Sneak peek at security features Redmond's baking into new OS
FTDI yanks chip-bricking driver from Windows Update, vows to fight on
Next driver to battle fake chips with 'non-invasive' methods
DEATH by PowerPoint: Microsoft warns of 0-day attack hidden in slides
Might put out patch in update, might chuck it out sooner
Ubuntu 14.10 tries pulling a Steve Ballmer on cloudy offerings
Oi, Windows, centOS and openSUSE – behave, we're all friends here
Apple's OS X Yosemite slurps UNSAVED docs into iCloud
Docs, email contacts... shhhlooop, up it goes
Was ist das? Eine neue Suse Linux Enterprise? Ausgezeichnet!
Version 12 first major-number Suse release since 2009
prev story

Whitepapers

Choosing cloud Backup services
Demystify how you can address your data protection needs in your small- to medium-sized business and select the best online backup service to meet your needs.
A strategic approach to identity relationship management
ForgeRock commissioned Forrester to evaluate companies’ IAM practices and requirements when it comes to customer-facing scenarios versus employee-facing ones.
Reg Reader Research: SaaS based Email and Office Productivity Tools
Read this Reg reader report which provides advice and guidance for SMBs towards the use of SaaS based email and Office productivity tools.
New hybrid storage solutions
Tackling data challenges through emerging hybrid storage solutions that enable optimum database performance whilst managing costs and increasingly large data stores.
Business security measures using SSL
Examines the major types of threats to information security that businesses face today and the techniques for mitigating those threats.