Feeds

C++/CLI: a paradigm too far

Microsoft's new albino jumbo

Top 10 endpoint backup mistakes

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

Recommendations for simplifying OS migration

More from The Register

next story
PEAK LANDFILL: Why tablet gloom is good news for Windows users
Sinofsky's hybrid strategy looks dafter than ever
Leaked Windows Phone 8.1 Update specs tease details of Nokia's next mobes
New screen sizes, dual SIMs, voice over LTE, and more
POW! Apple smites Macbook Air EFI firmware update borkage
Fruity firm provides digital balm for furious fanbois
Call off the firing squad: HP grants stay of execution to OpenVMS
Startup to take over support for today's Itaniums and beyond
Fiendishly complex password app extension ships for iOS 8
Just slip it in, won't hurt a bit, 1Password makers urge devs
Mozilla keeps its Beard, hopes anti-gay marriage troubles are now over
Plenty on new CEO's todo list – starting with Firefox's slipping grasp
Apple: We'll unleash OS X Yosemite beta on the MASSES on 24 July
Starting today, regular fanbois will be guinea pigs, it tells Reg
Another day, another Firefox: Version 31 is upon us ALREADY
Web devs, Mozilla really wants you to like this one
prev story

Whitepapers

7 Elements of Radically Simple OS Migration
Avoid the typical headaches of OS migration during your next project by learning about 7 elements of radically simple OS migration.
Implementing global e-invoicing with guaranteed legal certainty
Explaining the role local tax compliance plays in successful supply chain management and e-business and how leading global brands are addressing this.
Consolidation: The Foundation for IT Business Transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.
Solving today's distributed Big Data backup challenges
Enable IT efficiency and allow a firm to access and reuse corporate information for competitive advantage, ultimately changing business outcomes.
A new approach to endpoint data protection
What is the best way to ensure comprehensive visibility, management, and control of information on both company-owned and employee-owned devices?