10 May 2013

Cross platform eh?

Total change of track from usual ramblings. This time as a result of trying to develop a simple cross platform GUI application on a Windows machine. Here's what we learned!

I started with Mono as the platform of choice. It has a neat opensource development IDE for Windows called SharpDevelop. It uses Windows Forms for it's GUI design. That's Windows as in windows on the screen, not windows as in Microsoft, so it does indeed run Windows Forms apps fairly happily in Linux land.

First problem. Don't bother checking to see how your creation looks on a Windows machine using Mono instead of .Net. It'll look really terrible and have fun graphical glitches and bugs. You really do need a Linux box or a virtualbox with Linux on it to test your creation.

Now it gets fun.

To begin with I was disappointed with what could be done with Windows Forms, so I had a look around and found Monodevelop appears to have had some updates since I last tried it. So much so that it's now called Xamarin Studio instead. It uses GTK for it's GUI design which is a much richer toolkit than WinForms. It's also open source and in theory lets you target mobile phone apps as well. Sounds fantastic! Except .. just like my last attempt to use Monodevelop in Windows, it's still buggy as hell. Sometimes it will refuse to let you click and put your cursor back in the edit window. I gave up telling it I wanted a Mono target because if I did that, every so often it would break the Posix library. Uninstall library. Reinstall library. Recompile. Ok. Go back to code. Can't edit code. Quit. Restart. Posix library breaks again. Reinstall Posix library. Edit code. Run. Edit code. Run. Edit .. oh it crashed. Give up on Monodevelop. It might work fine as a Linux development platform, but that's not what the original plan was.

So I look around and decide Python with GTK might be the way to go. Uh. No. Back in the good old days of Python 2.6/2.7, it seemed relatively easy to get a whole Python system running on Windows including ERIC, Python's own IDE with GUI designer. Now you have two choices. Try and install 2.7 and hunt for the now obsolete dependencies for it, or go for 3.x and face the fact most people are still on 2.7. I'm not an idiot when it comes to computers, but I gave up after about the fifth time around of "ERIC should run now!" ... Oh no it doesn't. Complete uninstall. Clean registry. Carefully recheck all stated requirements, try again. Once again. It probably works fine on Linux.

Fine. Have another look around. Well. There's Eclipse with SWING / SWT or Netbeans! JAVA! Java will save the day! Surely! ... Er. Not exactly. For a fairly long time now, Sun java hasn't been supported on many Linux distributions. And who can blame them? It's a security nightmare of a product. But if you accept that most Linux users will be on OpenJDK, you have a problem. Most of the fancy Netbeans applications (ok, all of them). Will fail to run without Sun Java. Even the fairly simple Eclipse + Swing app I tried died with AWT errors when I tried to run it on Linux. So it's not cross platform. You can either jump through hoops to stuff all the SWT libraries in with your creation (manually, Eclipse won't do it for you), or reduce yourself to a GUI so basic, that actually, WinForms back on SharpDevelop looks at least as good if not nicer with a lot less hassle.

The other side to that problem is I can't actually justify telling people it's "Linux compatible", if that means they have to go through a long relatively complex process to get Sun Java (a big security risk) installed before they can run it. Once again. If I did my Java application development on a Linux box, it would almost certainly work on a Windows machine.

Then there's dependencies. If I want to get fancy and use GTK for a Mono application, I can ... but I have to bundle in a bunch of DLL's for distribution that Linux doesn't need. That or point people at GTK runtime bundles for Windows. Again. Not exactly out of the box cross platform.

So basically ... If you really want to write cross platform applications, you have to write them from inside a Linux environment. If you want to be a pain like me and insist on a Windows development platform, then Mono looks like the best bet. Mono isn't perfectly cross platform tolerant (you do have to add code to cope with some things Linux does differently), but it does work in the main if you don't do anything too fancy. Java should be a great idea, but since Sun is no longer welcome in Linux land, it's not any more. Python seems to me to be slowly dying. I don't think the jump to version 3+ went very well. Windows support for the 2.x versions vanished yet most people still seem to prefer to code for 2.7 on Linux. So even though most of the development time has gone in to 3.x, less people use it simply because more people still use 2.7. Oh and Python guys & gals? Having install instructions on the webpage that differ from the readme that came with the download that point to no longer available requirements is a bit of a killer on Windows.

End result? I'm back on SharpDevelop using WinForms. It's not perfect by a long shot, but it's stable, fast, and what it spits out can actually run on Linux and look pretty darn similar to how it did on Windows without a lot of additional messing around.

I also learned you can waste most of a week trying other possible "better" solutions to a problem when the one you started with was actually a pretty good bet.

Just thought I'd share! :-)