Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What advantages are there to developing a Win32 app in C++ over a .NET app in C#?

I learned windows programming using Visual C++, and the Win32 API. Nowadays, it seems most apps are being developed in .NET using C#. I understand that most of the time there isn't much performance difference between native code and managed code. So I'm wondering, if I were to start writing a new desktop app today, is there any reason (other than the fact that I'm more familiar with C++), that I might want to write it in non-managed C++ instead of .NET? Are there still some advantages to using C++ and native code? Or has that method been more-or-less replaced with .NET on the Windows platform?

Of course I know that people who are writing low-level device drivers and similar programs wouldn't do it in .NET. I'm asking with reference to typical client-facing apps that don't make direct hardware calls.

like image 807
Joshua Carmody Avatar asked Feb 18 '09 20:02

Joshua Carmody


4 Answers

IMO the most important one for small downloadable applications is that native code does not need the .NET runtime. While broadband becomes more and more common not nearly everybody has it yet.

Some people may be disappointed to see that your 2 MB application actually requires another 20MB of framework download and a bothersome installation process to run. If they are not sure whether or not they really need your application in the first place, they might just delete it before even giving it a try and turn to a competing product.

like image 116
Adrian Grigore Avatar answered Nov 11 '22 15:11

Adrian Grigore


  • Performance (certain situations, such as graphics)
  • Memory footprint (as Mancuso said)
  • Use of existing libraries
  • No need for a runtime
  • Finer control

To list a few.

However, you may also want to look at the question from the opposite angle to fairly evaluate which language to use.

Additionally, you could use C++/CLI to incorporate both native and .net code.

like image 39
Inisheer Avatar answered Nov 11 '22 14:11

Inisheer


If your application needs to be able to run without an installation (i.e. if you can't or shouldn't do something like install the .NET framework), you can't count on .NET being on a windows machine (pre-Vista). Lots of utility applications can fall in this category.

like image 8
Daniel LeCheminant Avatar answered Nov 11 '22 14:11

Daniel LeCheminant


I would recommend to write every desktop application in managed code. .NET/C# is a great platform to do so.

My reasons:

  1. Performance penalty is negligible. Google for benchmarks if you don't take my word. What matters more is the code itself. You can write O(n^m) algorithms in C++ or .NET/C#. JIT engines are very mature these days.
  2. Unmanaged C++ has major drawbacks when it comes to unit testing, mocking and refactoring. It's very cumbersome and inflexible. Reflection allows managed code to make such things very convenient.
  3. Deployment is a small issue. However, creating a setup which checks for the necessary .NET preconditions and installs them automatically is a no-brainer.
  4. Compilation is quicker, no linker! It even happens in the background when you edit the code.
  5. .NET library support is way better and cleaner than STL, MFC and boost.
  6. No header files and macros. They are just error prone.
  7. Security! Good bye buffer overflows, bad pointers, uninitialized variables...
  8. Exceptions. Clear exception hierarchy in .NET. C++ exceptions are messed up.
like image 7
olli-MSFT Avatar answered Nov 11 '22 15:11

olli-MSFT