C#, Design, C++ – Migration from Complex C++ Application to C#

cdesignmigration

We currently have a complex VC++ software application, which uses a library like ObjectARX to build the dll. I feel there are many features in C# like Collections, Generics, and other libraries which can be used to build the current application in a better and efficient way.

I have been thinking about it, but I am not sure on how to present it to my supervisor and colleagues.

I would appreciate any help, to help me think in the right direction and highlight the points to bring it to the team.

Few points that I thought was;

  1. With some current examples, implementing it in C# with the features.
  2. Highlight the development time is comparatively lesser in C# than C++.
  3. Use a Design Architecture.

Best Answer

Short answer

You should consider that it's a very risky and costly idea that may not give you as many benefits as you think it might.

Long answer

You should consider the following:

C++ is a language that can be used at a very high level, that is cross platform (though that depends on how much you used the VC proprietary extensions) and for which many very mature tools exist. C++11 will add even more juicy bit to handle annoying use cases.

If you're thinking about a full rewrite, don't forget that rewriting fully debugged code is time you won't be implementing any new features. If you don't have a clear benefit for using C#, this is throwing money and time through the window.

If the team knows C++, then for a long time writing code in C# will be slower despite any advantage that C# brings.

You have two option for migrating your apps : restart from scratch (and see http://joelonsoftware.com/articles/fog0000000069.html , already posted), or add new features by maintaining a mapping layer between the C++ and C# code. While C# is quite good as far as calling native code go, it's still some pretty complex code to write. If you either use P/Invoke or C++/CLI, both will force you to know much deeper detail about the platform than would be required for a pure C# solution. Also, you'll spend an awful lot of time marshalling data between managed and native code. A better option may be COM, though I hope you like ATL programming.

The biggest benefits of C# are its simplicity and garbage collector that free you from thinking about a lot of corner cases. That mean it can be developed by developers that are less hardcore than what you need for C++. In your case, your team already know C++ so those benefit are much less present. If you use unique_ptr, shared_ptr, RAII and such, much of the dangerous part of C++ can be managed. Yes, you have more options to shoot yourself in the foot, but you avoid the dangerous parts.

But still...

If you're not talking about a full rewrite, yes, it could be possible to develop some part of the application in C#. But always keep it mind the cost of the mapping layer between C++ and C#. I would recommend exporting your C# parts as COM modules and calling that from C++. Be sure it bring a real advantage. If you must constantly convert vector<> to IList<> and must constantly convert your C++ type to C# one, any speed advantage of C# will be lost. You gain most of converting to C# and .NET when everything can stay inside the CLR. Getting everything inside the CLR mean a complete rewrite of a complex application and that is dangerous proposition.

All in all, I wouldn't recommend it.

Related Topic