17

I'm only curious. I have already developed microcontroller software in C and Assembly. So, I can see an application for these languages.

As for today, I'm specialized in information and process systems and even though C++ is object-oriented and offers powerful development capabilities, we mostly develop in .NET C#.

So my question is this:

Which applications are best developed in C++ over C# in today's business?

Thanks for your serious responses!

15

Off the top of my head, anything low level such as drivers. C# doesn't provide a lot of lower level access, and anything relying on system APIs usually achieve this using dllimports anyway.

Also, anything that requires a low memory footprint is best done in C++ where the developer can manage the memory directly (in my opinion).

EDIT: If you do some searches for C++ vs C# performance, you'll find some hits. I found an article here, and though its a bit old, it's probably still relevant. C++ these days is still very good on embedded devices where resources are limited. You have to take execution environment into account. C# has a lot of checks in the runtime that aren't done in C++. C# is definitely safer and less error prone, but that comes at an overhead cost.

12

I disagree with some of the comments here. Given the state of the JVM and the .NET VM "performance" from run of the mill C++ programs are not going to be head over heels better. There will be very little difference (think 5%) unless you're building to the hardware. But...

  1. Any real-time systems where you can't afford a halt or slow down via the GC. That is, you absolutely need true deterministic response times.
  2. Any application which has to interface with hardware components.
11

Any kind of large data processing/manipulation (I've seen this with imagery, and stock market data) tends to be better done in C++ for the performance, plus there are tons of C++ libraries (like intel performance primitives) for doing high performance things.

9

PC Game dev is almost exclusively C++. Also, every application that needs to get the most out of the hardware at all costs, should better be developed in C++ than C#. E.g. physical processes modeling, cryptography, performance-critical web app modules etc.

9

Any application which cannot rely on the .NET framework existing on the target machine. The .NET Framework is a huge download (300MB+) (EDIT: Okay, there's the "Client profile" which is "only" 30MB, but when your application is 250k, that's still a huge amount of overhead) and is not supported on older operating systems. For anyone who needs to work when the Framework is not installed or damaged, or needs to support back to Win2k, C# really is not an option.

7

Portability issues aside, everything where performance is important.

I'm not talking pure number crunching or gaming. I'm talking applications that need to do things fast (relative to what the user expects) and/or with a decent memory footprint. There's a reason that Visual Studio is not written in dotNET. Or Photoshop. Or Internet explorer. Or MS Office.

dotNET/C# is great for creating GUIs, but if the application exceeds a certain size/complexity it seems that C++ GUI apps still are way ahead in responsiveness etc.

6

Numerics (ie. crunching numbers).

C# seems to be lacking libraries for doing numerical analysis, even if the language is really really great (I have colleagues who do C# exclusively). But there is a huge body of libraries for efficient numerical stuff in C++.

Moreover, C++ templates are superior to C# generics when it comes to building large code from little efficient pieces, which numerics require: interpolation, root finding, Richardson extrapolation, minimization, automatic differentiation, iterative generic algorithms,... all can be really well combined with templates + inlining from the compiler to yield efficient algorithms.

Howver I really miss covariance of template arguments (one great feature of C#) when I must express things like RandomVariable<T>.

5

games - I mean serious game (AAA), for Indie games C# + XNA is awesome ;-)

multiplatform - but here you have f.e java

4

That's a strange question. Since Linux and Mac OS don't readily support .Net, then you would not use C#.

If you want open-source software -- unencumbered by Microsoft licenses or patents -- you'd use C++.

4

Well, the tools that are needed to make C# work. The compiler, the JIT compiler and the CLR are written in C++. But that was more of a bootstrapping problem. Albeit that writing the CLR is a managed language would be close to impossible right now.

The next category are operating systems. But that's changing too, the .NET Micro Framework is fairly popular on embedded systems. But not the really resource constrained ones. And there's the super-secret Midori project at Microsoft. It is a continuation of the Singularity project, a managed operating system. Many of the team members that worked on .NET has joined that project. It's going to be interesting and a potential game changer. If it survives.

3

I think almost every program which has a gui and should run under windows only and do not rely very much on performance and lots of low level functionality would certainly have benefitted from C#.

I think this is true for most of todays business software.

I also see companies still developing webservices with plain C today, even if performance doesn't matter. They do it just because they have their unix and mainframe machines and they say that it would to too expensive to buy a new machine where Java or C# could be used.

3

The choice of language is orders of magnitude less important than the choice of developer.

In my experience, and outside the individual cases identified in other responses, somewhat non-intuitive factors can determine what gets used:

  • corporate or group policy
  • availability of programming expertise on the team
  • the need to integrate with some
    ancient library that's written in
    VC6.

These days on Windows, for new development the question is not so much "what would you use" as "why would you not use C#". The relative ease of development for all but the most specialized requirements makes C++ a harder sell.

Can't comment much on other platforms but my guess is that there the use of C# is a more uphill struggle, given the smaller population of C#-on-Linux (via Mono) experts, and my lack of conviction that one would prefer Mono to a truly platform-native solution.

3

I consider C++ over .NET when

  1. Portability is an issue.
  2. Deployment is an issue (.NET 3.5 for instance not readily available on all target machines).
  3. Startup performance is an issue.
  4. Memory footprint is an issue.

So for example, developing simple windows services for clinet OS in .NET I think is barking up the wrong tree as number 3 is important (Slow starting services may delay boot times which lowers overall user experience of the whole machine).

Personally I am not so concerned about running performance as that is usually good enough in .NET (and one can inject C code in those cases where's its needed).

2

Modern libraries have a tendancy to be written in C++ (It's just so much easier to work with than C). C++ provides an advantage here in that almost every newer language provides a way of linking with either C or C++ based shared object libraries, usually with fairly simple mappings.

EDIT: C# is not appropriate for library development, because that would artificially limit your userbase to a very small subset of what it would otherwise be.

2

C# is a very nice language, in Windows/.Net/Visual Studio/C#, programming is much more pleasant and efficient than with c++.

But the performance is a downside. Also in C# its difficult eficiently manipulate binary files or custom formats, you must use Win32 APi for that.

2

Applications best developed in C++ over C#:

Any system where memory management requires careful attention

  • Low memory devices
    • 32MB is the minimum for .NET (Mono)
  • Safety and critical systems, particularly where heap allocations are not allowed

Any system where storage is limited

  • The .NET framework is large and trimming it down is difficult
    • Even a 'small footprint' Mono install will be larger than the equivalent C++

Systems where high performance is of crucial importance

  • C# is very fast for the vast majority of applications...
    • ...but C++ will beat it given enough time and effort to optimise
  • Note: The number of system where performance really is that important is a very small niche
    • And remember that the majority of the system could be C#, using C++/CLI where necessary

Take care considering C#/.NET for platforms other than x86/Windows

  • Although Mono is a wonderful solution it isn't perfect
    • Some significant differences between platforms
    • Licensing concerns (even if you don't have them your users might)
  • C++ has it's own set of cross-platform issues but the problems are perhaps better understood
  • C++ can run on almost any hardware