<p>I've been tasked with updating a series of applications which are performance critical VB.NET apps that essentially just monitor and return networking statistics. I've only got three requirements: <em>convert it to C#, make it fast, and make it stable</em></p>

<p>One caveat is that we <em>"may"</em> migrate from a .NET platform to linux <em>"soon"</em></p>

<p>I will be responsible for maintaining these apps in the future so I'd like to do this right. I have decided to refactor these apps according to the MVP pattern so that I can properly unit test the hell out of this bad boy. But I was also thinking since I was using MVP that I could also do the computationally expensive stuff in native C/C++ code while the GUI would be done with .NET forms, or Qt or whatever.</p>

<p>questions: </p>

<ol>
<li><p>does it make sense to do a GUI in winforms but the expensive stuff in native, unmanaged C/C++ ?</p></li>
<li><p>any recommendations for a good cross platform windowing kit that would fit for the scenario described above?</p></li>
</ol>

[{'answer_id': 9872, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>1) Premature optimization is evil.  Implement your "expensive stuff" in C# and see if you need to refactor it.  Or, at least set up a test that will allow you to determine this.</p>\n\n<p>2) Yowch.  Cross platform UI.  I wouldn\'t put up with the "may" stuff.  Nail the weasels down; how can you possibly make design decisions without knowing what you\'re designing?  If you go with a pure .NET implementation, will they complain if you have to (at a minimum) refactor it to work in Mono?  If you create it in Java, will they be annoyed that it looks ugly as hell and users complain that they can\'t find their .exe file amongst all those .jars?  </p>\n'}, {'answer_id': 9880, 'author': 'rjzii', 'author_id': 1185, 'author_profile': 'https://Stackoverflow.com/users/1185', 'pm_score': 2, 'selected': False, 'text': '<p>For the first question, it is really hard to say if it would make sense as it would likely depend upon what sort of performance you need to be getting. I personally haven\'t seen any system wide slow downs due to the GUI in properly designed GUIs using WinForms so I don\'t see why it would should cause any problems, and in all likelihood it would make your life easier in regards to the GUI.</p>\n\n<p>As for your second question, if you are going to be moving to another platform at some point - you want to take a look at the libraries that have been implemented by Mono (<a href="http://www.mono-project.com/Main_Page" rel="nofollow noreferrer">http://www.mono-project.com/Main_Page</a>), this should also cover most of your needs in regards to cross platform windowing as it supports WinForms and GTK#.</p>\n'}, {'answer_id': 9884, 'author': 'Stu', 'author_id': 414, 'author_profile': 'https://Stackoverflow.com/users/414', 'pm_score': 2, 'selected': False, 'text': '<p>No, it does not make sense to do the "expensive stuff" in C/C++. The potential (and most likely minor) performance improvements never, ever outweigh your productivity being an abject, sick joke when compared to C#. Really. It\'s not even close.</p>\n\n<p>Read through this (and all posts referenced within):\n<a href="http://blogs.msdn.com/ricom/archive/2005/05/10/416151.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/ricom/archive/2005/05/10/416151.aspx</a></p>\n'}, {'answer_id': 9887, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 2, 'selected': False, 'text': '<p>1) Not necessarily. I think it would be more correct to say that it\'s probably worthwhile writing your backend code in C++, regardless of the performance implications. Even though you can\'t tie your higher-ups down on the platform switch, it would be prudent of you to make preparations for that eventuality, since management types tend to change their mind alot without good reason (or warning); even if they decide not to switch now, that doesn\'t mean that they won\'t decide to switch six months from now. Writing your logic in C++ now, knowing that it\'s a possibility, though more difficult, may make your life significantly easier later.</p>\n\n<p>2) Not really. There are "solutions" like wxWindows and GTK#, but often they\'re buggy, or difficult to get working properly, or they lack something important on one platform or another. They also usually lock you into a lowest-common-denominator UI (ie, general controls work fine but you can forget about ever doing something interesting -- WPF, for example -- with it). UIs are easy to write, so I think if you write your logic in something that\'s portable, it should be a trivial matter to knock together several platform-specific UIs.</p>\n'}, {'answer_id': 9894, 'author': 'Donny V.', 'author_id': 1231, 'author_profile': 'https://Stackoverflow.com/users/1231', 'pm_score': 2, 'selected': False, 'text': '<p>You might want to look into using <a href="http://www.mono-project.com" rel="nofollow noreferrer">Mono</a>. This is a open source version of .NET that runs on many plateforms...Linux,Mac, Solaris, Windows, etc..</p>\n\n<p>Now about coding your expensive stuff in C/C++. Here\'s an article that does a very good\njob explaining the differences between <a href="http://www.codeproject.com/KB/cs/CSharpVsCPP.aspx" rel="nofollow noreferrer">C/C++ &amp; C# performance</a>.</p>\n'}, {'answer_id': 10254, 'author': 'rjzii', 'author_id': 1185, 'author_profile': 'https://Stackoverflow.com/users/1185', 'pm_score': 1, 'selected': False, 'text': '<blockquote>\n  <p>And again, let me emphasize, the C++ stuff is veerrrryyyy expensive. Would it make sense to do what I mentioned above? (.NET forms hiding heavy lifting C++)</p>\n</blockquote>\n\n<p>As noted before, I personally haven\'t noticed any system wide slow downs due to WinForms in applications written in both VB.NET and C#. However, if the application is truly performance intensive then you might notice a slight slow down if you wrote everything in C# due to it being complied into CIL (<a href="http://www.cl.cam.ac.uk/research/srg/han/hprls/orangepath/timestable-demo/" rel="nofollow noreferrer">http://www.cl.cam.ac.uk/research/srg/han/hprls/orangepath/timestable-demo/</a>). As such, writing the GUI in a language such as C# will likely make that part of the development a bit easier which would give you more time to work on the critical parts of the code. The only catch-22 here is might notice some slow downs due to the calls to the C/C++ code from the C# code; however, this is likely very unlikely.</p>\n'}, {'answer_id': 10285, 'author': 'Patrik Svensson', 'author_id': 936, 'author_profile': 'https://Stackoverflow.com/users/936', 'pm_score': 0, 'selected': False, 'text': '<p><strong>I might be misunderstanding the issue</strong>, but if it is a network monitoring system, why isn\'t it written as a "dedicated" Windows service? </p>\n\n<p>VB.NET shouldn\'t be much slower than C#. I\'m not 100% certain if there is any big differences in the generated IL-code, but the only advantage (and justifiable reason to rewrite it in C#) I could think of (except that C# have a nicer syntax and some other goodies) is the use of unsafe code block that could speed things up a little.</p>\n'}, {'answer_id': 10301, 'author': 'Derek Park', 'author_id': 872, 'author_profile': 'https://Stackoverflow.com/users/872', 'pm_score': 4, 'selected': True, 'text': '<p>First off, I would put some time into trying out a few <a href="http://www.google.com/search?q=VB.NET+to+C%23+converter&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:en-US:official&amp;client=firefox-a" rel="nofollow noreferrer">VB.NET to C# converters</a>.  You\'re basically porting syntax, and there\'s no reason to do that by hand if you don\'t have to.  Sure, you might have to clean up what comes out of the converter, but that\'s way better than a by-hand conversion.</p>\n\n<p>Now, as for your questions:</p>\n\n<blockquote>\n  <p>1) does it make sense to do a GUI in winforms but the expensive stuff in native, unmanaged C/C++ ?</p>\n</blockquote>\n\n<p>Not yet.  Wait until you\'ve done the conversion, and then find out where you\'re actually spending your time.  There\'s no reason to jump into mixing C/C++ with C# until you find out that it\'s necessary.  You may find that dropping into unsafe C# is sufficient.  Even that may be unnecessary.  You might just need to optimize algorithms.  Find out what your bottlenecks are and <em>then</em> decide how to fix them.</p>\n\n<blockquote>\n  <p>2) any recommendations for a good cross platform windowing kit that would fit for the scenario described above? </p>\n</blockquote>\n\n<p>I\'d be looking into <a href="http://www.mono-project.com" rel="nofollow noreferrer">mono</a> for sure.  That\'s really the best you can do if you\'re going with C#.  It\'s pretty much either mono or another rewrite in another language when/if you move to Linux.</p>\n'}, {'answer_id': 10339, 'author': 'Orion Edwards', 'author_id': 234, 'author_profile': 'https://Stackoverflow.com/users/234', 'pm_score': 1, 'selected': False, 'text': "<blockquote>\n  <p>1) does it make sense to do a GUI in winforms but the expensive stuff in native, unmanaged C/C++ ?</p>\n</blockquote>\n\n<p>Most likely not. Unless you're communicating with a lot of other native C dlls or so on, C# is likely to be between 5% slower to 5% <em>faster</em> than C++ (std::string really kills you if you're using it)</p>\n\n<blockquote>\n  <p>2) any recommendations for a good cross platform windowing kit that would fit for the scenario described above? </p>\n</blockquote>\n\n<p>If it's just some simple forms with buttons, mono will likely be able to run them unmodified. It's support for .NET WinForms is pretty good these days. It is however, butt ugly :-)</p>\n"}, {'answer_id': 83957, 'author': 'Jacksonh', 'author_id': 6803, 'author_profile': 'https://Stackoverflow.com/users/6803', 'pm_score': 0, 'selected': False, 'text': '<p><a href="http://www.mono-project.com/GtkSharp" rel="nofollow noreferrer">gtk-sharp</a> is a pretty nice cross platform toolkit.</p>\n\n<blockquote>\n  <p>Gtk# is a Graphical User Interface Toolkit for mono and .Net. The project binds the gtk+ toolkit and assorted GNOME libraries, enabling fully native graphical Gnome application development using the Mono and .Net development frameworks.</p>\n</blockquote>\n'}, {'answer_id': 159825, 'author': 'Andrew Cowenhoven', 'author_id': 12281, 'author_profile': 'https://Stackoverflow.com/users/12281', 'pm_score': 0, 'selected': False, 'text': '<p>The c/c++ stuff may end up being a good idea, but right now YAGNI. Same with the Linux stuff. Ignore it, <a href="http://en.wikipedia.org/wiki/You_Ain&#39;t_Gonna_Need_It" rel="nofollow noreferrer">you ain\'t gonna need it</a> until you need it.  Keep it <a href="http://www.xprogramming.com/Practices/PracSimplest.html" rel="nofollow noreferrer">simple</a>. Unit test the hell out of it, as you say.  Get the code working and <a href="http://martinfowler.com/articles/designDead.html" rel="nofollow noreferrer">evolve the design</a> from there.</p>\n'}, {'answer_id': 1699827, 'author': 'Raptor', 'author_id': 205030, 'author_profile': 'https://Stackoverflow.com/users/205030', 'pm_score': 0, 'selected': False, 'text': '<p>I had similar dilemma some time back, while trying to find out a best way to develop a PC based H/W Testing tool (which obviously means "with UI options") that interacts with an embedded hardware (via PCMCIA interface).</p>\n\n<p>The bottleneck was that the testing should run at maximum deviation of 10ms from the intended time specified by the tester.</p>\n\n<p>E.g: If the tester creates the following test sequence:</p>\n\n<ol>\n1. Remotely activate the H/W<br>\n2. Wait for 50ms delay.<br>\n3. Read an H/W information.<br>\n</ol>\n\n<p>the delay mentioned in step 2 should not be > 60ms.<br></p>\n\n<p><br> I chose C++ WIN32 application as my back-end and VC++ 2005 Winform (.NET platform) for UI development. Detailed information on how to interface these two is available in <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx" rel="nofollow noreferrer">msdn</a> <br>\nI segregated the system like this:<br>\nIn VC++ .NET:</p>\n\n<ol>\n1. UI to have complete information about the H/W (read via back-end application) and to control the H/W on demand. (Buttons, combo-box etc.. etc..)<br>\n2. UI to run time critical test sequences (as mentioned in the above example).<br>\n3. Gathering these information and building a stream (File-stream) in a Time-linear format (i.e, in the precise order of steps in which it has to be performed).<br>\n4. Triggering and hand-shaking mechanism (by redirecting standard input and standard output) with WIN32 back-end application. The common resources will be the File-streams. \n</ol>\n\n<p>In C++ WIN32:</p>\n\n<ol>\n1. Interpreting the Input File-Stream.<br>\n2. Interaction with H/W.<br>\n3. Gathering information from H/W and putting it in its Output File-Stream.<br>\n4. Indication of test completion to UI (via redirected standard output).<br>\n</ol>\n\n<p>The complete system is up and running. It seems to be pretty stable. (Without the timing deviation mentioned above).\n<br> \nNote that, the testing PC we use is solely for the H/W Testing purpose (it had just the UI running on it, with no auto-updates, virus scan etc.. etc.. ).</p>\n'}]
['https://Stackoverflow.com/questions/9846', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/750/']