Migrating from C# to C++, and from Windows.Forms to wxWidgets

During the last 4 weeks, I started to write a small 3D editor. I started it in C#, using Irrlicht.NET and Windows.Forms for the UI. But three days ago, I decided that it would be better to stop development and restart it with C++ and wxWidgets, before it would be too advanced. The main reason behind this decision was that it would be simpler to improve Irrlicht simultaneous with the Editor, and easier to try out different approaches to new features, because writing everything in C++ removes the need to write and use wrapper code in managed C++. So I sat down and ported - or better - completely rewrote the editor from scratch. This is the result:

A simple 3D editor, with nearly the same functionality, once written in C# and once in C++

There are small differences between these two versions, for example some toolbar icons or menu entries are still missing, and the docking controls look a bit different due to the completely unrelated used docking frameworks, but everything works and is usable. It is quite interesting to compare the results of this work. For example, the common myth (which I believed too, until now) that you are developing applications faster with C# is now dead for me. You cannot compare the development time of these editors (about 32 hours for the C# version and about 5 for the C++ version) because a lot of user interface research went into the first one. But you can compare amount of code: The C#/windows.forms editor needs about 70 KB of code, while C++/wxWidgets only needs 36 KBytes. Thats quite a difference. And interestingly, the code does exactly the same on both sides, I'm using libraries for the same stuff in both versions.

And there is another interesting thing: The C++/wxWidgets version is way faster. The C++ application starts up instantly (C# version always needs some seconds), all views and trees update faster, moving of windows is faster (repainting 3D stuff) and I even have the subjective impression that clicking buttons is presenting results faster. So now, where is the advatage of C# again? I'm a C# fan, but now a bit disillusioned. But who knows, maybe C# just is a bit slower when it works with mixed mode assemblies.

21 comments, already:

hm, quite interesting
lxguy - 01 05 06 - 22:48

C# is extremely wrist unfriendly, tons of casting and braces. Boo is far better, a wonderful CLR language.

I’m scared, just tell me this doesnt mean Irrlicht.net is going to fall further behind. Having the editor in C# gave me hope Irrlicht.NET would start staying more up to date.
rektide () (link) - 02 05 06 - 00:03

Niko,

any chance you could post a tutorial on integrating wxWidgets and irrlicht? Like a hello world with a File…Exit Menu or something?
RabidLockerGnome - 02 05 06 - 00:22

Good move Niko. And nice to see less c#/.net and more portable code.
Sharpfish () (link) - 02 05 06 - 02:24

Hmm… I hope this wouldn’t lead to freezing Irrlicht.NET development. I agree with rektide that editor in C# gives us hope on faster irr.net improvement :p

And some words on C# speed and code size: – are you using 2.0 framework? Generics and other improvements, as well as much better vs2005 ui really push up development :) – C# is my main language and therefore i often see that code written by me in csharp is smaller and faster than cpp, when it should be slower :)
Wizzard - 02 05 06 - 02:31

man why does everybody hate on .NET? seriously its a great platform…
buhatkj - 02 05 06 - 04:21

Owww…I’ve heard of wxWidget before. But I’ve never tried it because it has a linux/unix tie for some reason in my mind. I have nothing against linux/unix. It just conjures up images of balding, morbidly obese old programmers who are both anal and emotionless. I don’t want to associate myself with such images. :)

Then I read this blog post. Before you know it, I’ve downloaded and installed wxWidget on my ‘puter. I’ve skimmed through the hello world tutorial and tried out the gui demo in the bin folder. It’s not bad.

I’ve programmed gui apps on windows using visual c++ 6, MFC, VB, VB.NET, window forms with C#, WSH, and with pure win32 api(!).

Fantastic, niko! I love your blog posts!
lug - 02 05 06 - 07:04

I don’t think anyone here “hates” .NET (I know I don’t). However, just because I do not hate something does not mean that it is perfect for all tasks.

.NET is basically Microsoft’s Java (or more accurately – CLR is Microsoft’s JVM). It has it’s uses, but when it comes to speed, cross-platform compatibility, and memory consumption – it pales compared to C++. It is easier to debug than C++ due to the lack of “memory leaks” (as .NET is garbage collected), but memory consumption/turnover is still an issue for anything larger than a “test demo” (trust me, there are some .NET garbage collection issues that can really trash an application’s performance!)

Personally, I prefer C++ and am kind of interested in seing Niko’s wxWindows based “Irrlicht Editor”. I have found wxWindows very easy to use and the idea of embedding Irrlicht within it makes me smile :)
—EK
Eternl Knight () - 02 05 06 - 07:46

Yeah, and C++ is that wonderful god which can do everything and takes you to wonderland … looks-at-the-most-software-which-have-lots-of-security-leaks
Maverick - 02 05 06 - 08:01

Phu! Does this mean your .NET Wrapper development won’t continue..? Okay, it does not affect our C#(!!) RPG Toolset Development as we use our own MixedMode Assembly for ‘communication’ with the Irrlicht Engine – but I think this is bad news for the .NET Irrlicht Community… – let’s hope, that irrlicht# will make its way!

I can hardly understand your reasons for switching over to wxWidgets – particularly etcaptor is writing an Irrlicht Editor in C++ and the Irrlicht .NET Community needs more ‘support’ – so your .NET Editor would have been a valuable tool…

just my 2 cents!
[Duncan Mac Leod] (link) - 02 05 06 - 16:11

.NET is pretty cool… but I have to favor the C++ version right now until .NET sees more improvement and more cross-platform distribution. I mean Niko can do it in C++ and wxWidgets and get it to how many platforms very stable and quickly… but .NET, not quite as much. Don’t get me wrong, it’s great and all, but I think for THIS particular application, c++ is the way to go.
RabidLockerGnome - 02 05 06 - 16:35

Dissapointed… I was hoping for some real progress on the .NET side, Irrlicht.NET is badly lagging behind C++ and the switch back to (unmanaged) C++ adds to the lag…

“because writing everything in (unmanaged) C++ removes the need to write and use wrapper code in managed C++. ” ..please don’t forget the wrapper is desperatly needed for everyone wanting to develop in Irrlicht.NET and many people have that need.
Braneloc - 03 05 06 - 03:56

I still don’t get why people are so hooked on .NET, I’ve messed with it at work and I think it provides no enhancement to C++ at all.

Some big things I didn’t like were the major differences between classes and structs in C#, as well as the inability to use multiple case statements in a switch for a single result.
spintz () (link) - 03 05 06 - 13:53

Well, the good news is, http://irrlichtsharp.sf.net is still going strong for people who need a .NET solution (that is, if Irrlicht.NET is discontinued)
riktor - 03 05 06 - 20:28

Ah, come on, no, Irrlicht.NEt won’t suffer from this. :) BTW: looking for irrlichtsharp to make progress, would be interesting to compare both implementations. :)
niko - 03 05 06 - 21:59

Whoa! Looks like alot of the .NET’ers have issues with C++. Nobody said C++ was the best langauge/library-set out there. Simply that we prefer it for the task of graphics engine development.

And for those criticising Niko for deciding how t best spend HIS freetime (i.e. complaining because he is using wxWindows rather than .NET) – remember that it is HIS right to determine what he does, not yours. It always annoys me when people complain about the direction of development they are not paying for.
—EK
Eternl Knight () - 04 05 06 - 04:12

I completely agree with Eternl Knight.

Besides I hope Irrlicht development (in C++) won’t lag, because of the development of .NET version…
omgz0r () - 05 05 06 - 01:56

it seems like there is almost a linux-vs-windows style flamewar brewing between .NET and C++ users…
I suppose we all have our preference, but i think id have to be on the .NET side…
I like c++, but .NET is a lot easier to use/more programmer friendly.
buhatkj - 05 05 06 - 21:47

I remember that Borland made Kylix for linux based on their visual library, but they was stopped development and this software don’t works with new kernels. Two years ago they made their C++BuilderX with wxWidgets RAD based preview. I was happy to compile Irrlicht with it. Despide cross compilers support, development of this product was stopped too. But this is a trace, that Borland likes wxWidgets ;-)
I suggest that Codeblocks team works on RAD system based on wxWidgets. So, every choice have own strong and weeks features.
But in both cases we can learn something in addition.
etcaptor () (link) - 06 05 06 - 07:48

Hi Niko,

this is good news, as i have fumbled around with wxWidgets myself. Did i miss something, or is IrrEdit not available (yet?). Would be cool to open it up for others to contribute to the development… I’d like to take a shoot at C++/wxWidget development, seems pretty straightforward.
Christophe Leske () (link) - 15 05 06 - 22:15

I am quite puzzled by the assumptions made by this “experiment”.
To be exact: if the slowness and chubbyness of the implementation is caused exlusively by Windows.Forms?
I think this is the cause.

I am not pro-managed neither pro-native, but it’s difficult to found valuable experiments of managed/native comparison.
I only found two applications: Jake 2 and Quake2.NET, both derived from Quake2, which showed that state-of-the-art programming in managed code lost about 15% compared to state-of-the-art native code (which, by the way, was C++ AND assembler).

I think it would be very interesting only the comparison of C# and C++ both using WxWidgets, and not C#/W.Forms and C++/WxWidgets.
Saverio () - 13 08 06 - 15:54


Name:  
Remember personal info?
yes
no
Email (optional):
URL (optional):
Enter "layered" (antispam):
Comment:Emoticons / Textile

  ( Register your username / Log in )

Notify: Yes, send me email when someone replies.  

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Note: If you type in your email adress above, it will be visible to other visitors, although it will be hidden for bots using javaScript.