[Answering the follow-up question:]
Pranit Kothari wrote:
Hi Sir, Thanks for your answer. But here my question is why one should prefer C++/CLI over C# or VB.Net. Will C++/CLI also score more on performance than C#.
Good question. I would estimate the relative values like this:
VB.NET: Honestly, forget it. Yes, it's a decent language right now, but the social structure around it looks like this: it has never been a standard and I'm almost sure it will never be, in contrast to C# and C++/CLI. Main role of it is: to former keep VB users at work and keep sales of .NET due to having established market driven by VB users, no more. Also, the real-life attitude of professionals to VB.NET programmers is usually very arrogant, like VB people are not true. Even if such attitude can be considered wrong, it's a big negative factor to the people selecting the language. In real life, when you are looking, for the help in .NET, most likely the good solution will be C#. If you look for developers, you can find VB.NET people much easier, but when you need quality, the situation is directly opposite. VB.NET developer, please don't get offended, it has nothing to do with your personal skills, but on average this is just a medical fact, by all observation. Even Microsoft is not so serious about VB.NET — some features always go behind C#.
C#: Maybe the best and most effective language from all the standard languages of .NET. It has some inherent problems though. For example, I feel devastating about lack of inheritance or simple type definition for primitive types. At least C++ has
typedef
. The idea of inheritance of primitive types is very well-proven (thing Ada), but C++ legacy cut out the approach. But with C# it's worse: if I need to delay the decision of concrete primitive type and make it changeable, I can only declare alias in
using
clause, which I have to repeat in all files involved — so ugly. Most of other problems are problems of .NET, and there are very few of them. And of course, compromised readability of code inherited from C, like curly brackets barely different from round brackets would be a curse (fans of C-like language, please keep silence: we do understand you, but it's just your imprinting), but Intellisense and other, folding editors and other things compensate for such problems very well. However, C# has some limitations which can be removed by using of C++/CLI. Or IL, for that matter :-). The language is standardized under ECMA and ISO.
C++/CLI: So, what limitation of C#, etc., can be overcame? C++/CLI is the unique language (not counting IL) where even so called reference type can use
value semantic. So, the instances of classes can be placed totally on stack, or memory usage can be combined: the instance of the class on stack, one member is on heap, another on stack, and so on. This is very important feature! It may safe some memory, but this is not the most important thing. For example, stack is much easier and safer with multithreading as all threads have separate stacks. Another powerful thing very practical in real-life situation: mixed mode. The ability to mix managed and unmanaged code is amazing, compared to legacy "managed C++". This is a way to avoid massive P/Invoke. C++ has better performance. In Microsoft implementation, this is the only .NET language I know which uses its own more advances optimizer, not just generic .NET optimizer. However, the real-life performance improvement will heavily depend on application.
At the same time C++ has some impossibly outdated features, such as "include". I really do not understand how it's possible to keep such archaic and non-robust technique in XXI century. Compatibility with the legacy, one would answer. Well…
Also, it's generally considerably more difficult to code using C++/CLI compared to C#. Visual Studio Intellisense, refactoring (is there any?) are well behind that of C# projects.
The language is standardized under ECMA and ISO, so major C# and C++ codes alike can really run on many platforms, not just C++
IL: Most powerful thing in .NET, ever. Best thing: fully standardized under ECMA and ISO. The major problem is: lack of good documentation except the standard, not easy to use.
I only pointed out what I find most important myself. As to comprehensively correct and objective comparison, not only this is very difficult, but theoretically impossible. Please consider this as my personal notes.
—SA