The Register® — Biting the hand that feeds IT

Feeds

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

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

Agentless Backup is Not a Myth

C++ 11 is “far better than previous versions”, says the inventor of the language Bjarne Stroustrup. He was speaking at an online event marking the launch of Embarcadero's C++ Builder XE3, a rapid application tool targeting Windows and Mac OS X.

C++ Builder XE3 is a promising but curious product. Delphi and C++ Builder were successful because the tools offered fast native code performance and high productivity on Windows. Embarcadero is now striving to make them cross-platform tools, via a new framework called FireMonkey that supports Windows and OS X, with iOS and Android promised in 2013. To keep pace with C++ changes, Embarcadero has adopted a new 64-bit compiler front-end for XE3, based on the open source compiler front end Clang.

C++ is an ISO standard, first ratified in 1998 with C++ 11 completed in 2011, but Stroustrup revealed he was initially resistant to standardisation efforts.

“It took some arm-twisting to get me to realise that it was time to start a standards effort," he said. "People pointed out that you couldn’t have a language used by millions controlled by a single guy in a single company. Even if you could trust the guy, you can’t trust the corporation. I was a bit sad, because the things I wanted to do would take years instead of months, because you have to build up consensus, and then you have to wait for five compilers to catch up.

“On the other hand the fundamental argument is correct. If you want something that is really widely used, you need some kind of standard. As languages grow, if they’re owned by a single organisation, sooner or later they start taking on peculiar twists to support that organisation’s business plan. The allies of that corporation are favoured.

“A lot of the languages that are seen as competitors to C++ are owned by a single corporation, but they do tend to fight with all the other corporations, and portability is a really hard thing to achieve. It has always been difficult, but it is not getting any easier, and I think portability across platforms is a very big deal.

“When people get into these stupid language wars like what’s best C++ or Java, I can’t be that rude, since most of the major Java implementations are C++. Same with C#. Same with the browsers and such. It’s a big world and many languages are useful.”

Despite its wide usage, C++ is among the most complex programming languages and hard to learn. Stroustrup says the solution is not to attempt to learn everything, and that C++ 11 is easier than before.

“A lot of people look at C++ and want to understand every dark corner. This is what you do if you want to be a compiler writer, but most people should look at what is the easiest way to write a good solution for their problem," said Stroustrup.

“I try to focus on things that lead to correct programs fairly easily. I emphasise the use of constructors to establish invariance, to acquire resources, destructors for cleaning up, copy operations, and the new [C++ 11] move semantics that allow you to move an object out of one scope and into another one very cheaply," he added.

"One of the things that was limiting C++ 98 [the previous standard] was that you could build really good resource handles - like vector, or istream, or thread - but they are hard to move around because this is computers and everybody knows that you copy things. In the real world you don’t copy things.

"If I lend you my phone, I don’t make a copy of my phone, I move it. We can do the same in C++ now. If I make a 10,000 by 10,000 matrix in a function, I can hand it over to you at the cost of two pointer assignments. We are talking picoseconds. That is a huge difference in the way I can write code today.”

Stroustrup does not favour a "dumbing down" of the language. “People always want to simplify the language to do exactly what they want, but to be part of a huge global and multi-industry community the language has to support things you would never do in your field. I see the language as a general purpose tool, and coding standards as specifying what you can do in a specific domain,” he says.

Regcast training : Hyper-V 3.0, VM high availability and disaster recovery

Next page: Fuming frustration

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.

20
7

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.

19
7

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.

12
1

More from The Register

SCO vs. IBM battle resumes over ownership of Unix
Zombie lawsuit back and wants to suck the brains out of Linux
Bjarne Again: Hallelujah for C++
Plus: Now officially OK to admit you never used STL algorithms
Interwebs taunt Sir Jony over Apple eye candy makeover
Hey Ive, Ive... add more unicorns, willya?
Apple: iOS7 dayglo Barbie makeover is UNFINISHED - report
Plus: You don't like the icons? Blame marketing
Red Hat to ditch MySQL for MariaDB in RHEL 7
So long, Oracle! Don't let the door hit you on the way out
Shy? Socially inadequate? Fiddling with your phone could help
App 'tells the brutal truth' about social inadequates' chatup lines
Java EE 7 melds HTML5 with enterprise apps
New release arrives with GlassFish, NetBeans support
 breaking news
'Office Facebook' firm Tibbr wants you to PAY for mobe-meetings app
Great idea. Punters won't cough for it though
 breaking news
The only Waze is Google: Ad giant tipped to gobble map app 'for $1.3bn'
Pac-Man-satnav-ish upstart in bidding war with Apple, Facebook
 breaking news
PM Cameron calls for modern, programmable computers! (We think)
IT education musings to G8 chiefs to mystify IT industry