Choosing Between C++ and C#
During a recent Stackoverflow.com podcast, Jeff Atwood and Joel Spolsky discussed the question:
When is it correct to develop software (Windows software, in particular) in native C and/or C++?
Joel's response was basically "almost never". And while I wouldn't state it quite that strongly, the point he was trying to make is that, for most applications, there exists some language X which is a better (meaning: more appropriate) choice then C++ and especially, C.
Without getting embroiled in language wars, I can agree with this statement. C# is cleaner and more intuitive than legacy C/C++. The overwhelming consensus among Microsoft developers is that C# is the more productive language. And for all but the most intensive of applications, developer productivity trumps all other considerations.
However, as a long-time C++ and C# programmer myself, I have to say that even though C++ is often the wrong choice, there are still many, many situations in which it's the only choice:
- Cutting-edge 3D games.
- Graphical and audio workstation software.
- Large-scale productivity applications like Adobe Photoshop.
- Legacy codebases.
- Real-time systems of all sizes and descriptions.
- Anything involving extreme numerical computation.
- Large-scale data storage and retrieval.
- Device drivers.
- And so forth.
No other language offers the performance characteristics of C++ together with support for such a rich set of abstractions. Managed programs can get very fast, thanks to JIT compilation's ability to optimize for the native processor, but native C++ still outperforms managed C# across the board. And for any application where you need explicit control over large amounts of memory - for example, if you're building an RDBMS - C#'s garbage-collected approach is a deal-breaker.
Of course, most developers aren't sitting around coding 3D video games, or database engines. They're creating enterprise software, probably web-based. Or they're creating relatively lightweight desktop applications using WinForms. For these scenarios, C#, VB.NET, and or C++/CLI (also known as "managed C++") are the choices that will give an organization the most bang for its buck, in the long run.
In the non-Microsoft world, the story's a little different. If you want to program in C# for Linux, Unix, Solaris, et al., you'll probably end up using Mono. And the thing about Mono is it's open-source. Now, whatever your opinion on open-source development, one thing's certain: the future of Mono on *nix platforms is more uncertain than the future of .NET on Windows platforms. Don't get me wrong: Mono is supported by a thriving, vibrant developer community, and in all likelihood it'll be around...oh...approximating on forever.
But it doesn't have the weight of the Microsoft juggernaut behind it.
The thing about this particular question - I mean the question of C# vs. C++ - is that there just aren't that many borderline cases. Usually, some characteristic of the project will jump out at you, and it'll be obvious which language is appropriate. If you're doing hardcore systems or application development, C++ is probably for you. For everything else, C# is probably way to go. And in practice you'll find that it's something like 80% C#, and 20% C++, give or take 10%.
Now, as hardware continues to improve, expect this percentage to change. If you don't need the performance, there's very little reason to use C++ these days at all. Managed C# applications running on today's hardware are visibly faster than native C++ applications running on ten-year old hardware, and we can expect that trend to continue.
But as of right now: C++ is the only choice for hardcore application development. It's just a question of deciding what hardcore really means, in the face of ever-more-powerful hardware.
Use the form below to leave a comment.
- Of Gravatars and Robohashes
- Optimizing VP$IP
- A Question of VP$IP
- John Carmack: Script Interpreters Considered Harmful
- Movie Doppelgangers: B-Movie Ripoffs of Hollywood Blockbusters
- BROWSE ALL POSTS
Subscribe to Coding the Wheel over email or through any RSS reader. Coding the Wheel has been published since 2008.
- How I Built a Working Online Poker Bot, Part 1, 2, 3, 4, 5, 6, 7, 8
- Summoning the Harry Potter MMORPG
- Are Commercial Databases Worth It?
- 21 and the Monty Hall Paradox
- Online Poker and the Multi-Tabling Effect (34)
talia wrote: Ping G15 Fairway Wood Mizuno MP 53 Irons Mizuno MP 68 Irons Mizuno MX 1000 Irons ... - Online Poker and the Multi-Tabling Effect (34)
talia wrote: Ping G15 Fairway Wood Mizuno MP 53 Irons Mizuno MP 68 Irons Mizuno MX 1000 Irons ... - The Coin Flip: A Fundamentally Unfair Proposition? (92)
carla wrote: great post Thanks for sharing! [mutui][1] [1]: http://www.finmutui.it/ "mutui" ... - Summoning the Harry Potter MMORPG (1593)
AmberTheHarryPotterNumber1Fan wrote: Oh Does anyone know when it will come out? - Full Tilt Color Coding In Twenty Minutes or Less (34)
Timber Decking wrote: [url=http://www.deck-max.com.au/]Timber Decking[/url] [url=http://www.timberdeckingsydney.net.au/]Timber ... - Summoning the Harry Potter MMORPG (1593)
Tekken9 wrote: There is no game, at least not yet. - The Programming Aphorisms of Strunk and White (90)
parkeren wrote: So that we will follow and what shall be the first step to do so, because everyone will like this software ... - Online Poker and the Multi-Tabling Effect (34)
Anonymous wrote: This was an entirely new concept that Titleist Japan & Titleist US worked together on to create. They ... - Summoning the Harry Potter MMORPG (1593)
AmberTheHarryPotterNumber1Fan wrote: How do i play the Game? ;{ - The Coin Flip: A Fundamentally Unfair Proposition? (92)
maria wrote: i like this article and got info.this is very nice and popular site ,it site have informative and intrusting ... - The Coin Flip: A Fundamentally Unfair Proposition? (92)
Brian wrote: This is fascinating. I wonder if there's a similar bias vis a vis the coin flip during a football ... - Movie Doppelgangers: B-Movie Ripoffs of Hollywood Blockbusters (14)
Brian wrote: This is certainly not a hollywood blockbuster [dating site][1] [1]: http://www.basecandy.com/ ... - Movie Doppelgangers: B-Movie Ripoffs of Hollywood Blockbusters (14)
Brian wrote: Singles looking for [dating websites][1] can join now. [1]: http://www.basecandy.com/ ... - Full Tilt Color Coding In Twenty Minutes or Less (34)
Photo booth san diego wrote: Appreciate your making the effort to discuss this, I find myself strongly about this and love mind ... - Of Gravatars and Robohashes (20)
rake wrote: [rake][1] you provide the nice information , gravaters are amazing [1]: http://www.rakebackrage.com/ ... - The Programming Aphorisms of Strunk and White (90)
Steve Waters Vancouver wrote: A random act of kindness! - Movie Doppelgangers: B-Movie Ripoffs of Hollywood Blockbusters (14)
Bradly wrote: Battle: LA was a great movie (the new one that is). I have noticed a lot of very similar movies, mostly ... - Summoning the Harry Potter MMORPG (1593)
Shawn wrote: Haha, these photos are classic! I'm actually not a fan of the Harry Potter movies but I do play ... - A Word About Authenticity (57)
Shawn wrote: Being authentic is very important. If I'm playing poker against a bot and it goes all in on a 2, ... - Coding the Tweet: Building a Custom Branded Twitter Application (71)
Shawn wrote: Using Twitter to promote a business is extremely popular today. I actually found a place to train ...

8 comment(s)
I use C# for the long haul & have never noticed performance issues. MAYBE with bad hardware. And for game development there's XNA. .NET, C#, works fine.
"in which it's is the only choice"
=> "in which it's the only" or "in which it is the only"
I think that language choice depends heavily on the concrete project. I agree with you, that most performance critical applications have to rely on C/C++, but I have also written some high-performance applications with Java and the native SWT graphics toolkit. But of course these are exceptions.
How would you classify a web browser ?
So why for the botting series did you decide to mix C++ with C#? The reason I ask is that the botting project is a heavily computational beast, hand analyzing, looking up possible moves, monitoring the opposition etc. and giving a response all in real time? Yet you have chosen to use c++ only for communication and c# do do all the back end stuff! I know that there is a lot of C# AI libraries already written, was this the motivating force?
i considered using perl! :) but it seems to be hard to make changes to code, as the perl lacks static syntax checker, so i'm affraid of it.. and c/c++ - it's free of microsoft.
I did something similar with VB and it works just great
I'm with you, anyone spent time with MS's Singularity, which primarily uses C#, you'll find snippets of assembly. When your only tool is a hammer, everything looks like a nail!