Original URL: https://www.theregister.com/2006/05/05/cplusplus_cli/

C++/CLI: a paradigm too far

Microsoft's new albino jumbo

By Verity Stob

Posted in Columnists, 5th May 2006 08:12 GMT

Stob Microsoft has been firing off some big guns in support of something called 'C++/CLI'.

The Softies would really like to lure C++ users into the suburban programming world of .NET - the .NETscape if you wish. But their previous attempt in this direction, a system called 'Managed Extensions to C++' that was composed mostly of __underscore characters, has been universally deemed resistible.

So now they've had another try, and Redmond is doing all it can to convince us that C++/CLI is the real goods. Few stops have been left in. For example:

(As an aside, this last effort briefly looked like it might not come off, when a British delegation from the heavier-weight ISO C++ committee objected to the name.

'The proposed name of C++/CLI will cause unnecessary and harmful confusion' they said crossly. 'We therefore request that Ecma withdraw this document from fast-track voting and if they must re-submit it, do so under a name which will not conflict with Standard C++.'

I love that 'if they must re-submit it' bit, treating ECMA/Microsoft like a naughty child that has handed in '2/10 - see me' quality homework. And of course 'C++/CLI' will get abbreviated to 'C++'. Why else would Microsoft's marketing department sanction such an unwieldy name for a core, strategic product?

In the event, ECMA rapidly and politely told the Brits to get knotted, and that was that. At least the interlude affords us a pleasant insight into how standardisation works.)

Elsewhere on the Net, C++/CLI has sent various eyebrows northwards. You can Google as well as I can, but I commend this wasp's nest of a thread in the dusty attic of the comp.lang.c++.moderated newsgroup, which features a good selection the world's most senior C++ pundits chewing the matter over.

However, I can reveal that all this effort - the broodings of comp.lang.c++, the deliberations of the ECMAnites, the boastings of Microsoft itself - is all to no purpose. All these clever people have overlooked one point.

C++/CLI is a dud.

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