Partager via


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.

Comments

  • Anonymous
    June 02, 2005
    I've just switched from programming in C++ for 15 years, to C#, and I posted a response back to the original blog entry:

    http://grumpyoldprogrammer.myblogsite.com/blog/Grumps/_archives/2005/5/12/834859.html#302497

  • Anonymous
    June 02, 2005
    Great comment! Also glad to see another old VCL guy kicking around. :)

  • Anonymous
    June 02, 2005
    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.

    So Long live C#

  • Anonymous
    June 12, 2005
    I just read C++ vs. C# and thought it might be worthwhile to throw up a few thoughts.&amp;nbsp; I've been...

  • Anonymous
    July 15, 2005
    "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.

  • Anonymous
    July 18, 2005
    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.

  • Anonymous
    July 19, 2005





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

  • Anonymous
    July 19, 2005


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

  • Anonymous
    August 12, 2005
    The comment has been removed

  • Anonymous
    August 12, 2005
    >>I dont see why anyone would program c++ in .net<<

    Better runtime performance and better interop with native code are the two big reasons. I've blogged on this topic in the past:


    http://blogs.msdn.com/texblog/archive/2005/07/28/444553.aspx
    http://blogs.msdn.com/texblog/archive/2005/06/28/433718.aspx

  • Anonymous
    September 01, 2005
    Good blog

  • Anonymous
    November 16, 2005
    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.

  • Anonymous
    November 16, 2005
    Hi Gordon,

    I tried to answer your question here:

    http://blogs.msdn.com/texblog/archive/2005/11/16/493472.aspx

  • Anonymous
    December 12, 2005
    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.

  • Anonymous
    December 12, 2005
    Hi John,

    That's the theory, anyway. :) If you don't have a good experience mixing native and managed, please do let me know!

    -steve

  • Anonymous
    May 03, 2006
    I have to say I'm starting to question what I should be learning. You see, everything I've been hearing from people is still very mixed opinions. I don’t see a lot of people in my situation at all; most of the responses come from people who have a lot of experience while I am still simply learning the language.

    I've never been a fan of vb or java, and other languages are simply out of my time. Next year I'm starting my post secondary schooling and I have choice between to courses, the main difference is that the one I planned on taking was C++, while the other programming course focused on C#.

    Now I'm self-educated through books and online resources and I'm currently learning C++. Now I have to start to question what I should be learning, I mean I haven’t dove deep enough into the language yet to really be able to compare enough with C#. I just really want to know the pros and cons put simply. In my case, I do not plan to go into system programming but more software development, if not game development. This isn’t saying that later I might not have a career change, and through of all of this the choice seemed simpler as I always had the opinion that C++ was the most popular, powerful, and best choice in learning. Now I have to ask myself should I stay with C++, learn it and than learn C# if I have to? Do I have more work or have flawed programming technique because I chose C++ over C#? Will I loose a lot of the power C++ has if I was to move to C#, or will I miss out on something if I never chose to learn C#.

  • Anonymous
    May 15, 2006
    To Markus R.

    C++ is the staple of "from scratch" programming in all environments; meaning all Operating Systems.  There is a natural tendency to code anything that is going to reside deep in the founding layers of an application, like network code for multiplayer games, to be done in C++.  

    I have spent a few weeks learning about C# and my general feeling is that I do not wish to be stuck in a "Windows Only World" for my programming carreer.  I really like different environments because it reminds just how varied and wonderful the world of computing really is.

    Anyhow, the best advice I can give you is: to learn the more difficult language first (imo Logic).  Then anything after that will simply be gravy.  The more important aspect of analysis and design work is really being fluent in logic.  Precise and consice logic makes any languange choice appropriate according to your needs.  When you can apply good logical designs, derived from well understood analyses there are virtualy no obstacles left in the way to deliver the product on time.  Given enough experience, you too will notice that, the production schedule is still way more difficult a thing to manage vs. code.

    Remember: Logic 1st, Language 2nd.

    /* R.N.Rob */

  • Anonymous
    July 20, 2006
    How is it fair to compare the compiler for c# to c++?
    c++ has 2+ years of development and improvents on the compiler... c# has  maybe 5 or 6?

    I agree, that C++ as an unmanaged program will always be faster becuase there is no runtime, or intermediate layer... but i wonder if that argument still holds true for managed c++ ? Granted the compiler is still better... so you get a bit more optimization, but I imagine that in the comming years, you will see the c# compiler improve.

    Over the past 6 years, thousands and thousand have learned c#, and those people are not just going to up and learn c++ just becuase the compiled code might be faster. So in my opinino... no.. c# is not going to die anytime soon, and microsoft has made a huge comitment to support it for a good long while.

    I also think that in the "much longer" run... c# will continue to evovle much more just like c++ did... where as c++ at some point will begin to slow down... soley becuase of the generation gaps... people my age and younger are not keen on learning c++, perhaps it's easier in the 2005 version... but all in all... new devs are going to find the .net community huge and freindly, and that will lead them to c# (as said above a multitude of samples, apps, etec... ) and will not as easily push them to C++.

    With regards to vb.net being microsofts .net lanugauge... and why did they need c#... i think c# was the prefered first .net lanugage, andd vb.net came about, becuase microsoft realized they had a tremendous VB programer crew from before that they could more easily push to .NET by having the lanugage be similar. However, for example where i work, the manger mandated using c# over VB.net to inforce the thought that vb.net is not vb... it may look like it... but vb.net is a bonidfied .net oo lanugage, not like vb. So by forcing c# instead, the devs where forced to apprecaite that. Instead of coding new things the old way... code new things the new way.

  • Anonymous
    July 21, 2006
    Type... when i said "c++ has 2+ years of development "
    i meant 20,  25 ++

  • Anonymous
    September 14, 2006
    Oh, It is simply a comparision between two ends.
    I do not want to compare C# with vb.net. I workded on both and know that both are there because there are certain requirement where both fit at their place.

       Comparing to C++ , Really C# has taken the good things from C++ and also the general goodness of other theories.So naturally it is the current generation language.

  • Anonymous
    September 22, 2006
    The comment has been removed

  • Anonymous
    December 11, 2007
    PingBack from http://syyedwahab.wordpress.com/2007/12/11/c-vs-c/

  • Anonymous
    January 12, 2009
    PingBack from http://oweynge.com/2009/01/c-resources-for-c-developers/

  • Anonymous
    June 16, 2009
    PingBack from http://fixmycrediteasily.info/story.php?id=3094