Saturday, May 9, 2009

C++/CLI versus unmanaged C++?

Is C++ / CLI popular with commercial software developers? or do many still work with unmanaged C++ code?

C++/CLI versus unmanaged C++?
Generally speaking, C++ is faster and more versitile than C#, although it tends to be less safe. But if you're planning to write code in a managed environment, C++/CLI is a pain in the neck. It's complicated, non-portable, and hard to read when you're done.





So why do it? Basically, there are times when you want to write in C++ for a variety of reasons (flexibility, speed, control, etc) but you need to write code that can interact directly with managed code. Let's say you're writing the bulk of your UI in C# or Visual Basic, but you have a somewhat low-level layer you're hoping to write in C++.





I wouldn't say it's "popular" among commercial software developers (I've been writing software professionally for 15 years) because nobody I know really *wants* to write C++ this way. But it's another tool in the toolbox that you can pull out and use when it's appropriate.





The vast majority of "shrink-wrapped" code these days is written in unmanaged C++, although C# is making big inroads. By shrink-wrapped, I mean code that isn't part of a web site or web service, or that isn't custom developped. If you're writing code and selling it to end users, it's likely unmanaged code.





Good luck.
Reply:The problems with C++/CLI come from a couple of different directions.





First, it is Windows only and that turns a good portion of developers off right from the start. Even something like Mono, basically .Net for linux, does not support C++/CLI as far as I know.





Second, and not so much important as irritating, is that managed C++ is in some respects non-standard. C++ is already difficult enough to learn and use properly without piling on a bunch of non-standard additions. (For fairness I would extend that criticism to things like gcc language extentions as well.)





Thrid, C++/CLI doesn't seem to have a genuinely compelling use case. There are some *very* minor things it can do that C# can't within the confines of .Net but on the whole C# is an easier language and if it can do 99% of what manage C++ can do it is stupid not to use it.


No comments:

Post a Comment