C++/CLI: a paradigm too far

Microsoft's new albino jumbo

Top three mobile application threats

No denigration without substantiation

To see why, let us a take a step back. C++ is notoriously complex. Whereas smaller computer languages have features designed into them, C++ is unusual in having a whole swathe of functionality discovered, like a tract of 19th century Africa. Nobody intended that C++ should support template metaprogramming, a wildly clever but visually dismal technique that allows the programmer to write a program within the program. One day it was noticed that it could be done, and now it is done.

Microsoft has taken this giant of a language, clamped it down on the target platform of their linguistic accelerator, and bombarded it with .NET fragments travelling at 10,000mph. The resulting 'tuple' (to use Stan Lippman's word, perhaps chosen because Boost doesn't yet offer a 'chimera') is the aesthetic equivalent of the monster in the original Quatermass - a man with one arm melted into a cactus plant.

Consider the issue of pointers. Pardon me while I instruct you briefly in ovoid evacuation by vacuum, Grandma. C++ offers two basic kinds: the common-or-garden kind, represented by a *, and the reference kind, that you aren't supposed to think of as a pointer until you must, represented by a &. Famously a source of confusion for novice programmers, and, cough, their elders can occasionally come unstuck too. One problem is: two kinds is really one too many. The superfluity steams up the lens.

But these constructs don't work in the safety-scissors-and-glitter .NET world, where ordinary pointers are usually concealed beyond reach. So with C++/CLI you get two more kinds in the packet, represented by ^ and %, which approximately map .NETty things on to the traditional * and &. So suddenly you've got parallel sets of pointy things, governed by different rules. Oh, great.

But it's not just pointers. There are special declarations for all the .NET classes and structs and interfaces. There is a new kind of generic mechanism. There are arrays that nearly behave like std::vectors... but not quite. If you are fond of destructors, there's now an extra one with a ! in front of it that your object gets long after death, when it has served its term in purgatory. And heaps extra - well, one heap anyway. Go look for yourself.

Another thing. Here are some demonstrative fragments of code from the same Lippman article, comparing C# and C++/CLI syntax for class declaration.

abstract class Shape { ... } // C#
ref class Shape abstract { ... }; // C++/CLI
struct Point2D { ... } // C#
value class Point2D { ... }; // C++/CLI

Notice anything? The C++/CLI version is just a little bit more wordy and clumsy than its C# equivalent; because its 'spaced' keywords have to be squeezed into the cracks. Use a .NET feature, you pay a cruft tax.

C++/CLI isn't a natural extension of C++; rather it is a dual gauge system. The detritus from two incompatible programming models is crammed uncomfortably into one space. The thing to remember about dual gauges is that, while any fool can do a straight bit, it's the points that will eventually put paid even to a Brunel.

Microsoft must run on its dual gauge system if it is to make a success of Windows Vista. But we don't.

If you need to write for .NET in a curly brackets language, may I suggest you try C#? It's focused and elegant and fits snugly into its design hole - just right for those webby-databasey back end apps that define, to Microsoft's irritation, the .natural .NET .niche.

And if you need to come back to something that runs a little edgier, and is more widely scoped, and lets you blow your leg off whenever you want, then C++ will still be there for you out here in the real world. Promise. ®

Top three mobile application threats

More from The Register

next story
OpenBSD founder wants to bin buggy OpenSSL library, launches fork
One Heartbleed vuln was too many for Theo de Raadt
Got Windows 8.1 Update yet? Get ready for YET ANOTHER ONE – rumor
Leaker claims big release due this fall as Microsoft herds us into the CLOUD
This time it's 'Personal': new Office 365 sub covers just two devices
Redmond also brings Office into Google's back yard
Patch iOS, OS X now: PDFs, JPEGs, URLs, web pages can pwn your kit
Plus: iThings and desktops at risk of NEW SSL attack flaw
Ubuntu 14.04 LTS: Great changes, but sssh don't mention the...
Why HELLO Amazon! You weren't here last time
Batten down the hatches, Ubuntu 14.04 LTS due in TWO DAYS
Admins dab straining server brows in advance of Trusty Tahr's long-term support landing
Red Hat to ship RHEL 7 release candidate with a taste of container tech
Grab 'near-final' version of next Enterprise Linux next week
Apple inaugurates free OS X beta program for world+dog
Prerelease software now open to anyone, not just developers – as long as you keep quiet
prev story


Securing web applications made simple and scalable
In this whitepaper learn how automated security testing can provide a simple and scalable way to protect your web applications.
3 Big data security analytics techniques
Applying these Big Data security analytics techniques can help you make your business safer by detecting attacks early, before significant damage is done.
The benefits of software based PBX
Why you should break free from your proprietary PBX and how to leverage your existing server hardware.
Mainstay ROI - Does application security pay?
In this whitepaper learn how you and your enterprise might benefit from better software security.
Combat fraud and increase customer satisfaction
Based on their experience using HP ArcSight Enterprise Security Manager for IT security operations, Finansbank moved to HP ArcSight ESM for fraud management.