Steve Teixeira's Blog -- Thoughts on parallel computing, Microsoft, the industry, and life

C++ vs. C#

C++ vs. C#

  • Comments 24

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.

  • 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#.
  • 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 */
  • 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.

  • Type... when i said "c++ has 2+ years of development "
    i meant 20,  25 ++
  • 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.
  • Hi all,

    As said before, both languages have their own strengths. The key thing is to know what these strengths are.

    I worked on both C++ and C# and now on C++/CLI. C++/CLI is more pwerfull than C# as the constraints are less. Thats also the weakness of C++ as it is possible for bad programmers to screw up things more easily in C++/CLI. For example a programmer can still allocate memory on the CRT heap which is not garbage collected, so memory leaks are still a possiblity in C++. In C# all memory is garbage collected. But at the same time in many situations you might actually find it usefull that you can still allocate memory on the unmanaged heap (CRT).

    I like C++/CLI more because it gives me greater flexibility.
    However I might choose C# for a few small projects which need little development time. For big projects growing above 100,000 lines there is nothing like C++. Iam very thankfull to the C++/CLI team that .Net has been ported in a very elegant manner to C++.
  • PingBack from http://syyedwahab.wordpress.com/2007/12/11/c-vs-c/

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

  • PingBack from http://fixmycrediteasily.info/story.php?id=3094

Page 2 of 2 (24 items) 12