C++ vs. C#

C++ vs. C#

A few of my more C++-centric friends and colleagues have sent me pointers to Grumpy Old Programmer's "Has C# lost its point?" grump. While I naturally enjoy seeing VC++ portrayed in a positive light, I think it's a bit silly to suggest that C# has lost the very impetus for its existence simply because CLR has been elegantly folded into the C++ language. It's clear Grumpy Old Programmer is a C++ fan (not unlike many other grumpy old programmers I know), and that's great! However, Grumpy's grump seems to be a classic case of the old "my programming language is better because I like it better" argument that always comes down to the unarguable issue of personal preference. I'd like to pull a few quotes out of the grump because I think it's important to make the point that I truly believe that C++ and C# are and will continue to be useful languages in their own right.

>>The truth is that this new development in C++ seriously undermines the justification for C# as a language. C++ programmers yet to learn C# simply don’t need to now.<<

I agree with the latter part of this statement but disagree with the first. If the justification for C# as a language were to simply get C++ developers using .NET, then, yes, the new CLR features in VS 2005 would undermine C#. However, C# isn't about migrating C++ developers to .NET. C# incorporates lessons learned from C++, Java, Delphi, and other languages and focuses them into a very productive, expressive, readable, and manageable language. That said, with VS2005 it's true that if you're a C++ developer today, you need not feel compelled to learn C# simply because you're interested in targeting the .NET platform -- VC++ 2005 enables you to target .NET in a way that feels natural from a C++ standpoint.

>>What’s the point? They will find the full productivity of Visual Studio 2005 right there at their fingertips supporting the language they know and love. Why should they move to something that is slower and less feature rich?<<

Indeed, C++ developers tend to find C++ productive. :) For C++ developers, there is no need to jump onto the far left side of a new learning curve in order to reach the .NET platform. However, many developers *want* to take the time to learn C#, and that's okay too. In fact, one of the hallmarks of C++ developers is they're generally capable and willing to jump into another language and use it when it suits their needs for a particular task.

However, I have trouble buying the argument that C# is slower and less feature rich. It's true that from a runtime performance standpoint, C++ tends to be superior (even for some managed code, due to some optimizations we can perform in the compiler front-end). However, I would argue that C# is speedier in terms of design-time performance, as the faster compiler tends to lend itself toward more productive use of code->compile->debug->repeat cycles. Where changes can be made and tested in smaller increments. And feature rich? Well, it's definitely true that C++ developers have a massive arsenal of language features and libraries at their disposal to attack whatever problem they need to solve. But let's say you want to design a web form in the IDE... well, you can't do that in C++. Rather than trying to claim that one language is more feature rich than the other, I would simply say that each language experience is optimized for a different set of scenarios.

>>It will be interesting to see how many ex C++ programmers slip back to C++ now that it is fully .NET enabled.<<

Here, Grumpy and I are in agreement. We would love to bring back into the fold, those C++ developers that would prefer to do their .NET coding in C++. Because of the easy mixing of native and CLR bits in C++, .NET can effectively become just one more library among the many that C++ developers already enjoy. But some folks will still prefer to do their .NET coding in C# because it has its own advantages in .NET elegance and productivity, and that's okay too.

>>Of course, Microsoft will continue to promote C# as the native .NET language – they simply can’t afford to admit that they have foistered a brand new language on the programming world that is broadly feature-identical to other languages, and cannot pretend to be a replacement for C++. <<

Again, C# was never intended to be a "C++ for .NET" -- it's a differnt language with a different different philosophy and a different set of priorities. It's also worth pointing out that there continues to be some real language innovation coming out of the C# team, some of which won't be visible outside of Microsoft for a couple of years. C# is a bit more free to innovate within the language than we are in C++ because compatibility and conformance are major issues for our user base. However, those C# innovations that make sense for C++ will be folded into the language.

>>C# acolytes will no doubt be pampered with IDE features that are denied to other developers (for no technical reason)<<

We're talking about software here, where everything is possible, so there is rarely a technical reason why some feature or other shows up in one language but not another. More often it's things like scheduling priorities or targeted scenarios. For example, C# has webforms development, whereas C++ does not, because that's important to C# developers. However, C++ allows for transparent mixing of native and CLR modules, which C# does not, because that's important to C++ developers.

In summary, C++ and C# are both great languages that fulfill different needs, and the success of one need not come at the expense of the other.

Ada you forgot Ada in there as some of the best of the languages C# was made from.

Seriously though I have been programming for about 25 years. Somehow I managed to never get into Fortran or Cobalt so I can't really speak from those languages. However, I have done Ada, Java, C++, VB, Basic, etc and I really must say I switched to C# and I haven't looked back you can see all the different languages in there, but it is like the best of.

"C++ and C# are both great languages that fulfill different needs, and the success of one need not come at the expense of the other."

I agree with this, and also with you assertion that C# is a bit freer to test out new ideas (such as C-omega).

And yes, there is also a large amount of "personal preference" in this.

However, I think the crux of the argument is that with Visual Studio 2005, C# and C++ are MUCH more the same than they were before C++/CLI.

If C++/CLI was available from day one with .NET 1.0, I think it's questionable how much traction C# would have gotten. If I needed GUI WebForms design, I could use VB.NET (or the stronger C++/CLI support that would have been there absent C#). See http://spaces.msn.com/members/jdanielsmith/Blog/cns!1pRjebUoVh0bNLSJvrecmAEg!147.entry

Does C# have advantages over C++/CLI? Sure. But are those advantages enough to warrent a brand new language, especially when there is already a Microsoft-specific .NET language in VB.NET?

C# isn't going away now, but I think with C++/CLI it will be a lot less interesting.

Wil

18 Jul 2005 11:18 PM

To what extent will MS now support VC++ as a "real" .Net language, instead as just a tool for interop with legacy COM code? I note that the forthcoming Visual Studio 2005 Toolkit for Office (or whatever it's called) that is intended for programming using Word and Excel will allow you to use only C# and VB.Net. In spite of MS's hype that all CLI languages are equal (just like Sun's "Write once, run anywhere!" nonsense), some languages are in fact far more equal than others. I was hoping that would change with the introduction of C++/CLI, but I'm still looking for evidence of that.

Wil asks a good quesiton on the &quot;C++ vs. C#&quot; blog thread...
&amp;nbsp;
&quot;To what extent will MS now...

Graham

12 Aug 2005 11:18 AM

I dont see why anyone would program c++ in .net
I program heavily in both c# and c, but i use win32 as my api for c/c++.
I dont see the point in writing "managed" c++ code....kind of defeats the purpose of using a high-powered low(er) level language.

I just got VS 2005 C++ Express. I have been looking for comprehensive examples of C++ code and it seems to me there are a great many more C# examples. This is making me wonder if C# isn't a better choice for someone getting started.

The appeal of C++.net for new, as opposed to legacy, applications is down to how much faster it is.
I am converting a project from Access to .NET. I liked Delphi (who doesn't), but went for .NET as the future. Its starting to dawn on me that C# is going to be slow, however. I just can't see it doing any optimisations and it seems to me to be VB in different clothes.
And so the answer may be ... my first love, C++. It does the .NET UI stuff and yet you have a real compiler and hopefully the ability to mix unmanaged and managed code easily to get best performance.