Feeds

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

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

Internet Security Threat Report 2014

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

Choosing a cloud hosting partner with confidence

More from The Register

next story
Netscape Navigator - the browser that started it all - turns 20
It was 20 years ago today, Marc Andreeesen taught the band to play
Sway: Microsoft's new Office app doesn't have an Undo function
Content aggregation, meet the workplace ... oh
Sign off my IT project or I’ll PHONE your MUM
Honestly, it’s a piece of piss
Do Moan! MONSTER 6-day EMAIL OUTAGE hits Domain Monster
Customers freaked out by frightful service
Return of the Jedi – Apache reclaims web server crown
.london, .hamburg and .公司 - that's .com in Chinese - storm the web server charts
NetWare sales revive in China thanks to that man Snowden
If it ain't Microsoft, it's in fashion behind the Great Firewall
prev story

Whitepapers

Forging a new future with identity relationship management
Learn about ForgeRock's next generation IRM platform and how it is designed to empower CEOS's and enterprises to engage with consumers.
Why cloud backup?
Combining the latest advancements in disk-based backup with secure, integrated, cloud technologies offer organizations fast and assured recovery of their critical enterprise data.
Win a year’s supply of chocolate
There is no techie angle to this competition so we're not going to pretend there is, but everyone loves chocolate so who cares.
High Performance for All
While HPC is not new, it has traditionally been seen as a specialist area – is it now geared up to meet more mainstream requirements?
Intelligent flash storage arrays
Tegile Intelligent Storage Arrays with IntelliFlash helps IT boost storage utilization and effciency while delivering unmatched storage savings and performance.