tags:

views:

271

answers:

5

I am working on a project which talks to SQL server and most of the back end code is in C++. This is an application which controls flow of few fluids while loading them into carriers. Some of the back end modules which talk to controllers which in turn control flow of fluids are in C++. Since they have memory leaks and some other bugs, there has been attempt to migrate them to .Net. What I understand is, performance comes down when we use .Net for back end modules. So my opinion was NOT to convert these back end modules to .Net but to fix the issues in C++ itself. The code in discussion is an application which interacts with firmware of controllers. It basically takes some commands and gets response from controllers. This code does not have UI and the same code interacts with SQL as well to update the data. Both are part one exe. .Net is believed to be good when performance is not expected to be rigorous. It would have been suitable if new code had to be written and especially when it involves design of UI. Another school of thought is, .Net is good for higher layers but not for lower layers in a multi tier architecture. I would like to know opinions of others from different perspective. Some of the aspects to consider are speed, maintainability of code, migration related risks in future etc. Please comment from angle of rewriting existing code. It will be one to one C++ line conversion to C# if we decide to go for it.

A: 

every language is special in its own way, you should find out which language suits best for the scenario

Searock
But that is exactly what I want to know. I would like to know what are different aspects which we need to consider.
PlatformPerformanceResourcesand many morenow if you are going to create app for diff OS than you cant use C# unless you use some kind of software like Monowell if you are designing it for windows for system interaction then VC++ is the best option
Searock
I dont see any other operating system coming into picture in near future. It will be only on Windows(XP and future versions).
well if you have to interact with database .net is best because it has a huge set of classes that support database interaction but if you want to interact with system i think of c++even production time required in .net is less
Searock
Could you please clarify what you mean by 'even production time required in .net is less'? Do you mean time taken to write code in .net is less compared to C++. This aspect will not matter as code is there in C++. I am trying to find is there any additional advantage of writing in .net.
yes it takes less time and is easy, i am not comparing two languagesnow1. Wpf (Windows presentation foundation) looks are good2. Gui (if you are not using Vc++)and there are lots of feature,try searching in googlewell i think if you have already an application in c++ it will not be a good idea to start from scrap to write it in .netc++ is not a bad languagebut .net is customized for modern needsif you are going to use it for controllers use VC++.net rather than C# or Vb.netits upto you,people find vc++ for system programing but i use vb6
Searock
+1  A: 

Apparently the only problem with existing C++ code is memory leaks.

That seems to me an insufficient reason to rewrite it all in C#.

Instead I'd suggest running memory leak detection software to find the leaks.

ChrisW
+2  A: 

Quick Answer:

If you have capable C++ programmers who can use debuggers and understand their application domain and how to use the controllers, it would probably be easier to do a careful review and fix the memory bugs and issues. After all, time and effort has already been spent on the code, and unless it is trivial code, rewriting in C# could introduce new logic errors.

Questions for the OP:

The code in discussion is driver code which interacts with firmware of controllers. It basically takes some commands and gets response from controllers. This code does not have UI and the same driver code interacts with SQL as well to update the data

Are you talking about user-mode software that you have named the "driver", or are you talking about a kernel-mode device driver?

It would help if you could provide more information about these controllers running firmware that control fluid flow. Does the C++ back-end connect to the controllers through RS232 (Serial)? Ethernet? USB? TCP/IP? PCI?

If you're connecting to the controller hardware via TCP/IP or RS232 (Serial), C#/.NET is well equipped to handle the task. For anything else like USB, PCI, Ethernet, etc., you're going to need a device driver which has to be programmed in C or C++ depending on the requirements of the driver. Of course you can encapsulate the user-mode part that is in C++ or encapsulate direct calls to Win32, but it will add more development tasks to your project.

Dr. Watson
The word 'driver' may be misleading. Let me correct it. The code in question is 'application which talks to firmware of controller on RS485 port'. The controller is proprietary and not sold in open market. The exact question would be, we need to send lots of commands to firmware and get back responses. The latency of network will be certainly involved. But will .Net add to slowness?
With RS485, .NET is certainly an option. It shouldn't really add any overhead or make the I/O slower than with C++. I've used C#/.NET to control machinery via RS485 and it was certainly up to the job.If you're worried about speed, then as with any type of I/O, asynchronous I/O (perhaps with callbacks) will enable your application to be more efficient, but the trade off is that it will also add significantly to the complexity of your code.Before deciding to rewrite in C#, I think you judge why the memory leaks are happening. Is it a design error? Or was it just programmer error?
Dr. Watson
A: 

Don't rewrite a whole program in a different language because of a few bugs -- there will just be different ones in the new product, and the Q&A cycle will have to be restarted. I'd fix the bugs in the C++ program. If the issue is memory management, I'd strongly look into std::auto_ptr or std::tr1::shared_ptr, which will automatically delete memory for you when finished. If that's not an option, I'm sure that running something through valgrind or even paying for commercial memory checkers would be cheaper than rewriting the whole thing (in both time and money).

MighMoS
A: 

"language is special in its own way" man I need a hug, for real. Don't change languages because code is not written well...write better code and use resources available to you.