C ++ MFC vs .NET?

My colleagues use Visual Studio 2002 and use C ++ MFC. I am developing in C #.

There were no problems before, but now we asked our customers whether we really should develop in different environments. My colleagues think (of course) that I should switch to C ++ MFC. I think they can use .NET instead of MFC.

Does it make sense to study MFC? Does it feel a bit outdated, or am I mistaken? What are the arguments against and for .NET compared to MFC?

Edit:

We develop process systems and ancillary applications for the nuclear industry. The main application is an emulator that emulates an old computer system and uses C ++ / MFC. Time is critical, perhaps the kernel should remain in native C ++. But the graphical interface for the emulator and all surrounding applications is not particularly critical.

And is there a real reason why you should replace an existing MFC application?

+41
c ++ c # visual-c ++ mfc
Oct 28 '09 at 14:24
source share
10 answers

I used MFC and Windows Forms for a very long time. I am from the video game industry, so for many years I had to write a lot of desktop applications, and before .net, MFC was extremely useful. Even before that, I wrote tools in pure Win32.

MFC definitely had its quirks, but overall it made life a lot easier. It was very easy to integrate OpenGL and Direct3D into custom views, and once you got stuck, writing custom controls was part of the cake. Best of all, I could just code in pure C ++, which just turned out to be my language of choice. Plus, I found MFC to be very efficient and fast.

Gradually, MFC began to gain support for an external management library, especially the docking / toolbar library, so my tools, such as 3D models and level editors, looked pretty sweet.

Most of the applications I wrote created the user interface programmatically, so the dialog / window design tool was more than enough for my needs.

MFC 9 is also very cool, especially with the ribbon / dock management library that Microsoft released as part of the Feature Pack. So, of course, life in an old dog! :)

When .net 1.0 came out, I found the transition quite simple because it supported managed C ++. It was ugly, but gave a relatively simple tilt to the .net frame. But the turning point for me was that I started writing tools that needed Windows Forms Designer, while .net 2.0. I decided to start again and learn C #, which I really liked, although I will never be used to having new () without delete ();). Then I began to write user controls, I find the whole experience is very beautiful and understandable. The .net structure was huge, well supported, and as a rule, it was easier for me to do almost everything in C # /. Net. In addition, the compilation was fast, and the refactoring ability in Visual Studio was awesome.

The beauty of C # /. NET - this does not limit you to just writing in managed code. You can still use unmanaged code if performance is a problem, for example, or if you need to use code between platforms. For example, my math libraries are written in C / C ++, which I put in libraries that allow C # to wrap / use the same code, although this is only temporary. I'm going to port these libraries to C # on time, so everything is clean .net.

The last experience I want to mention is that I spent the last few months programming a console game and wasted my time programming InterWeb. I used the Microsoft stack while programming in ASP.net/C#, and I have to say that it is very good, with all the knowledge about C # that may be applicable. The only learning curve was ASP.net, not the language and support libraries. With the advent of .net 3.5 (LINQ is sweet) life in .NET networks with C # is wonderful.

In any case, I do not want to turn this into my life story, but I just wanted to give a brief experience of the one who went through all the technology that you asked for. I would also like to mention that it is useful for you to try different languages ​​/ frameworks. I have been coding the iPhone for a year now and I really liked Objective-C. All this is programming, and all is good.

As for MFC / .net, both have their pros and cons, and I really don't mind MFC at all, but in terms of moving forward, I would probably stick with C # /. net, but please, please understand how this works. The only sermon I will say is to understand how memory works in .net, although "all this will take care of you";)

Your knowledge of C / C ++ should be completely independent of whether you use MFC or not, this is still a critical language (especially in console programming for video games), but it is becoming more and more difficult to program desktop applications on Windows argue with .net. It is fast, simple, has excellent tool support, excellent third-party libraries, a huge growing community, is now a cross-platform (Mono) and allows you to move between all current / new Microsoft technologies (ASP.net, WPF, Silverlight, WCF, etc.) d.).

For all this, I still configured Visual Studio as a C ++ environment. Some habits never die;)

+69
Oct 28 '09 at 17:29
source share

MFC and .NET are at almost opposite extremes, each of which is completely crappy in its own way.

Using the MFC roughly corresponds to the order of life in the decaying wreck of an excess building of World War II. There are no warnings about hazardous areas, and it is probably not immediately clear where to find running water, electricity or a toilet that works, although they all exist if you know how to find them. Like any collapsing building, there are many holes in the walls, so you can leave anytime you want as much as you want. Similarly, dragging things from the outside world is pretty easy, although pretty much you can do “drag and drop” to get it there.

Using .NET is like living on the set of a Truman show. This is in line with the idea of ​​one person about how real life should look. Within it, life may seem utopian. In the end, however, it is little more than a pleasant accoutered prison cell, and nothing that it portrays as life is real. All your interaction with the outside world is subject to the whims of the director, whose goals are mainly aimed at improving his own ratings; your welfare is only considered to the extent that it affects it.

Unlike most prisons, .NET has a well-defined evacuation route (marked as "P / Invoke"). However, like the escape route from any good prison, it is a mile-long sewage pipe. Most residents are aware of its existence, but almost the only ones who go there are adolescents proving their masculinity. Those few who put them to real use do so only in urgent need. Those of us who considered this necessary too often realized that it was better to stay outside and not return.

Edit: since some people need circles and arrows and a paragraph on the back of each of them, which will be used as evidence in court: the strength and weakness of MFC is that it’s basically a pretty thin shell around the API. This is a weakness, because there are quite a lot of holes in its coverage, but because it relatively little "smooths out" places that the API itself does not mix very well. For example, if something is implemented using COM, which is usually displayed directly in the code that uses it. This is strength, because it is fairly easy to extend MFC to handle areas that it isn’t by default, and just bypass it and work with the API directly when you need it. It has also been updated relatively rarely, therefore, although it can currently create reasonably “modern” applications, this is not always the case. Given its history, it would be difficult to predict that this would continue.

The strength and weakness of .NET is that it is a much thicker shell around the API. It greatly expands the ability to “smooth out” differences in APIs, therefore (for example) the parts that are implemented in COM do not look / noticeably differ from the parts that are implemented as direct calls to C functions. Inside .NET, the differences disappear..NET (currently ) Microsoft prefers technology, so it is updated much more often and does a much better job of ensuring that your user interface follows the latest guidelines. I guess this is much more likely than the MFC to continue to do this for some time.

The weakness of .NET is that it is much more difficult to circumvent or extend. Basically, your only way to the outside world is through P / Invoke. Even for small excursions, it is ugly and painful. Trying to use it very often or for something approaching a major expansion is an exercise in masochism.

If (almost) everything you write can fit into what .NET supports, then this is a clear choice. It is much cleaner and smoother as long as you stay within its borders.

If you write code that often needs to go beyond what the environment supports, MFC will probably work a lot better for you. With .NET, the .NET model applies to your entire program. With MFC, it is relatively easy to write programs that use MFC for their user interface, and do anything you want for something else that MFC does not support.

+37
Oct 28 '09 at 16:11
source share

I think the value is in knowing C ++, as the language will last a long time. You never know when C ++ programming might be required, and in today's job market, having more languages ​​under your belt improves your resume.

As for the MFC , I try my best to get away from it. It is outdated by calculating standards (I think, I think, 20 years), but Microsoft still sees value in supporting it with new releases and feature packages. From this point of view, I doubt that the MFC will leave in the near future. But this does not mean that I want to program with her. The flexibility and ease with which you can program in C # knock down pants with MFC / C ++ every day of the week. Threading, sockets, string manipulation, etc. - All this is easier to do in C # than in C ++. In addition, C # /. NET is the main technology focus for Microsoft, and I would rather be on this edge than the MFC backburner when it comes to career development.

+23
Oct 28 '09 at 14:34
source share

It is neither one nor the other. Starting with version 1.1, Windows Forms supports hosting on native clients, such as the IE or MFC dialog. MFC 8.0 wrapped the necessary hosting code in its Windows Forms support classes, so you do not need to write it yourself. Choose the right library based on your current project requirements.

MFC is bigger than its GDI shell classes. At one time, it was developed as a replacement for OOP for the core Win32 API, much like .Net today. However, MFC did not stop the Win32 API, and now I can say that win32 APIs are growing out of what MFC can support. Over the past ten years, the number of APIs has increased tenfold.

Windows Forms, on the other hand, was intended to be a replacement only for Windows GDI. These are the other .NET Framework libraries intended to replace the rest of Win32, such as WPF and XNA for DirectX and System.Speech for SAPI. However, I can see that win32 APIs are growing out of the fact that .Net can keep up without increasing the download size over several years.

Therefore, Windows Forms cannot do everything that MFC can do; it is designed to simplify GDI + -based RAD and may include what MFC cannot do. However, Windows Forms based on GDI + goes down as Microsoft reorients to WPF and MFC to consumer demand. If you are developing for future applications, you can take this into account.

+2
Oct 28 '09 at 2:30 p.m.
source share

What is the problem you want to solve? Suppose you know both C ++ / MFC and C # /. NET the same way. What set of tools will allow you to build and maintain better? (Better subjectively, but again, which depends on your goals)

If I do not do much work with my own APIs that are not available in .NET, I will continue to work with .NET. C ++ is a great language and nothing prevents you from coding in managed C ++ to preserve the .NET structure and memory management.

In comparison, my observation is the MFC infrastructure, which is very complex and cumbersome compared to .NET Windows forms.

+2
Oct 28 '09 at 15:59
source share

One good feature that MFC provides is the Document / View framework (a single document or multiple documents), which does not yet have equivalence in .NET. This feature can be very useful and convenient when you need to create an application that works like Microsoft Word. This helps to separate the data model from the presentation that you want to present to users. I think that most people will jump to the side of .NET forever, as soon as this function is implemented. (Is Microsoft working on this, or at least planning to work on it?)

+2
Sep 18 '13 at 3:47 on
source share

There are many pros and cons to this choice. MFC is an old position, it has existed for ages and shows its age. On the other hand, it is still pretty well supported, and MS continues to update it to remain valid.

The .Net Framework has better support, as it has a large team that supports it and is seen as something to create new parts of Windows.

MFC, on the other hand, is a large part of the Windows ecosystem. If you are programming on the platform, then it’s worth having at least a working knowledge of what MFC does and how it happens when you provide support to an MFC application (and don’t worry, someday you will do it) have a good justification where to start .

+1
Oct 28 '09 at 15:58
source share

I switched from C ++ / MFC to C # / WinForms a little over a year ago (late bloomer, I know;)).

Unlike language differences, switching from MFC to WinForms is much easier than vice versa. I think there is some value in knowing MFC if you intend to work effectively with legacy applications. However:

Would I learn MFC from scratch (given existing technologies)? No, probably not.
Would I write new applications in MFC? No, probably not.

The benefits of MFC are far outweighed by the support, flexibility and ease of use of .NET. For this, MFC is excellent, and I am grateful for the opportunity to work with it - it taught me a lot. Ultimately, however, he went out.

+1
Oct 28 '09 at 17:51
source share

Unmanaged code is not necessarily faster, it depends on the code written and the one that writes the code. I read several complex test reports (source, Code Project), and in some cases C # beat C ++, and in others C ++. It depends on your field: I am writing software for Flight Simulators, so you need an unmanaged environment. If you are building a GUI application, C # might be the best choice. For low-level socket programming, C ++ can give better results. I did not notice a serious speed difference between C ++ and C # in normal operations, but I am a fan of C ++ for its native portability and C # for its ease.

0
May 05 '12 at 7:13
source share

.NET uses managed code. MFC uses unmanaged code. I read that unmanaged code runs faster than managed code. Therefore, if you are developing soft code in real time, you can use unmanaged code.

-3
Oct 28 '09 at 15:50
source share



All Articles