<<

PROGRAMMING and DotGNU

Comparing the free .NET implementations Mono and DotGNU LOTS OF DOTS

The projects Mono and DotGNU open ’s .NET platform to developers. This article investigates how well-suited these alternative implementations are for building simple GUI applica-

tions. BY MICHAEL TSCHATER

n 2002, Microsoft launched a new support has prompted two projects to gram written on Windows. This short system for platform-independent de- step into the gap: ’s sponsored example has all the major GUI elements, Ivelopment that they dubbed .NET Mono project [1] and the open source see Figure 1. The is avail- (pronounced “Dotnet”). The .NET pro- DotGNU [2] project. Both Mono and able on the Linux Magazine website at ject aims to simplify the development of DotGNU are aiming to provide as com- [3]. The only functionality this code ac- network and Internet applications. It plete an implementation of the .NET tually provides is that it logs user input supports object oriented programming platform as possible. The goal of both in a window specially designed for that and comes with a unique class projects is to allow developers to ex- purpose. suitable for use with multiple program- change across ming languages, such as # and VB boundaries. The Original by Microsoft .NET for example. In the course of Besides functionality such as One way of obtaining the original Micro- launching .NET, Microsoft has discontin- string manipulation, most projects need soft .NET is the free .NET runtime envi- ued support for its previous favorite, the widgets for graphical user interfaces to ronment and SDK (Software Develop- MFC library for Visual C++. All future help them cope with day-to-day tasks. ment Kit) download. The download Microsoft products will be based on the Microsoft offers the System.Windows. gives you all the command line tools new technology. Forms library for this purpose. The needed for software development on library has GUI objects, such as Main- Windows, just like the SDK. The csc Free .NET? Menu, ToolBar, Combobox, or Button. command compiles an application. The Despite the platform-independent ap- Listing 1 has a short code snippet as an results can be executed directly on Win- proach of the .NET framework, Micro- example. dows. soft is highly unlikely to release a Linux To compare the Mono and DotGNU The Integrated Developer Environ- implementation, and this lack of Linux implementations, we will be using a pro- ment (IDE) Visual Studio .NET is a com-

72 ISSUE 61 DECEMBER 2005 WWW.LINUX - MAGAZINE.COM Mono and DotGNU PROGRAMMING

Figure 1: The demo application includes all major GUI elements from Figure 2: Visual Studio .NET displaying the code from the sample the .NET System.Windows.Forms library. This figure shows the Win- project described in this article. The code in the figure draws graphi- dows version. cal elements. mercial alternative for .NET develop- speed. Mono uses GTK# (which is also to update documentation ment that includes a and dia- available for Windows) for graphical online from the Mono repository, is an- log editor (Figure 2). This package auto- user interfaces. GTK# is based on other useful feature. Besides distribution matically installs the .NET SDK. The free GTK+, which forms the basis of the specific binaries, there is an Sharpdevelop developer environment [4] Gnome Desktop on Linux. installer, which sets up all the required is an excellent alternative to the Visual packages. Studio .NET package. Sharpdevelop GUI with Windows.Forms After you download the 50MByte gives you a powerful IDE that only lacks The System.Windows.Forms library is package, a wizard walks you through the an integrated debugger. The features in- mainly implemented in C# and draws its installation procedure, which just in- clude the ability to toggle between the own controls [6]. The library requires a volves a few steps. Thanks to the wiz- Microsoft and Mono runtime environ- driver for each operating system: drivers ard, the installation problems that once ments and to import Visual Studio .NET for X11 and Windows are available at affected explicitly supported, but non- projects. this time of writing. The DotGNU project current, distributions (such as Fedora) has adopted this design after ditching a are a thing of the past. Some distribu- The Alternative: Mono -based implementation as impracti- tions – such as Suse 9.3 – include Mono The Mono environment [5] is available cable. by default, but distros such as Red Hat for Linux, Windows, and Mac OS. Be- Besides the mcs and the and Fedora tend to place their emphasis sides the .NET standard class libraries, mono runtime environment, the Linux instead on the Java platform. Mono has a few extensions, such as a version also has the devel- There are a number of websites, such variety of Gnome libraries. The virtual oper environment, which is based on a as the one at [5], that document the machine adds just-in-time and ahead-of- Linux port of Sharpdevelop. The progress of the Mono project in detail. time build techniques for improved monodoc help browser, which allows For example, you will find an overview of the controls in the System.Windows. Listing 1: GUI with System.Windows.Forms Forms library at [6]. 01 #using System; FirstApp()); A Sample Application with 02 #using System.Windows.Forms; 11 # } Mono 03 # 12 # Existing Visual Studio .NET projects 04 #namespace LinuxMagazin. 13 # public FirstApp() : such as our sample application can be FirstApp base() imported directly into Monodevelop. But 05 #{ 14 # { don’t forget to adjust the references for the new project. The context-based help 06 # public class FirstApp : 15 # this.Text = "First when editing source code is one thing System.Windows.Forms.Form Application with GUI"; that you immediately notice about the 07 # { 16 # } developer environment, but the environ- 08 # public static void Main() 17 # } ment lacks a GUI builder at this time of 09 # { 18 #} writing. When we tried to build the code by 10 # Application.Run(new giving the mcs -:System.Windows.

WWW.LINUX - MAGAZINE.COM ISSUE 61 DECEMBER 2005 73 PROGRAMMING Mono and DotGNU

Figure 3: The sample application running in Mono on Linux has diffi- Figure 4: The GUI-based .NET application has a few issues running in culty drawing the buttons at the top and the selection boxes on the DotGNU; for example, the radio buttons falsely trigger events multi- right. ple times.

Forms.dll sourcefile command, the stan- ing commands build and launch the instead it draws the controls itself, just dard System.Windows.Forms.Numeri- HelloWorld application: like the Java library. DotGNU does cUpDown control caused a problem, as it not implement an IDE of its own. is not completely implemented in Mono cscc -o HelloWorld.exe U as yet. After removing the offending HelloWorld.cs The Sample Project in code, we were able to build the applica- ilrun HelloWorld.exe DotGNU tion and launch it in the mono runtime DotGNU runs the generated on environment (Figure 3). The following command sequence Windows without any modifications. A number of errors occurred: for ex- builds a more complex project with a However, clicking on the RadioButton ample, the update mechanism, which graphical interface. The source code files controls initiated the event routine mul- handles redrawing in the application, are located in the src subdirectory: tiple times. This did not change when did not work properly when hidden by we rebuilt the source using DotGNU: another application. Additionally, the cscc -winforms -o U cscc --winforms -o DemoApp.exe *.cs. Ad- event mechanism had a some trouble Application.exe src/*.cs ditionally, we had to remove the Image- with the RadioButton and ComboBox ilrun Application.exe List handling code to get the application controls. to build. The implementation of the System.Win- Our tests managed to uncover another The Contender: DotGNU dows.Forms library is not based on a bug in the variant compiled with Dot- Based on the 0.7 version number as- graphical library such as GTK, but GNU (Figure 4). Our tests indictate that signed by the project, DotGNU is less mature than Mono. The core component Table 1: Comparing .NET Implementations of DotGNU is titled Portable .NET. It Project DotGNU Mono comprises three major components: Current Version 0.7.0 1.1.8 treecc (an aspect-oriented programming Copyright LGPL GPL or proprietary (selectable) tool), pnet (runtime environment, C# Operating systems Linux, Mac OS X, Windows Linux, Mac OS X, Windows compiler, programming tools), and Advantages pnetlib (C# system library with critical Standard package with Standard package with Suse 9.3 C# class libraries). Original Windows bytecode can Supported by full-time developers Source code and RPM packages are be launched without modifications at Novell available from the DotGNU website. The Disadvantages RPM variant did not require any tweak- System.Windows.Forms not System.Windows.Forms not ing to give us a fully functional environ- completely implemented completely implemented ment; the tools all worked at first asking. Event handling error Event handling error Current distributions such as Debian 3.1 No developer environment Installation packages (Wizard) not make things even easier by actually in- adequately tested; for example, the cluding the DotGNU environment by de- developer environment is missing in Mono 1.1.7 fault (in the pnet package). The follow-

74 ISSUE 61 DECEMBER 2005 WWW.LINUX - MAGAZINE.COM Mono and DotGNU PROGRAMMING

the event mechanism does not work pendent programming. The C# program- INFO properly: the GUI element RadioButton ming language is very similar to the Java triggered duplicate events. Numeric and C++ programming languages, and [1] Mono: http:// www. mono-project. com UpDown doesn’t work at all and is not that makes it easy for developers who [2] DotGNU: http:// www. . org displayed correctly. are familiar with these programming lan- [3] Listings online: http:// www. The GroupBox control changes color to guages to learn C#. Another advantage linux-magazine. com/ Magazine/ indicate the current focus. This behavior that C# gives you is ECMA standardiza- Downloads/ 2005/ 12/ dotNET/ does not conform to the standards. The tion. [4] Sharpdevelop homepage: ImageList control prevents the applica- The two open source implementa- http:// www. icsharpcode. net tion from being displayed. DotGNU will tions of the .NET framework, Mono and [5] Mono development status: display the executable created using DotGNU, both have impressive feature http:// www. go-mono. com/ Mono, but the icons in the control bar sets, but they do have some rough edges mono-roadmap. html buttons are faulty. too. The developers of these tools still [6] System.Windows.Forms develop- A clause in the Microsoft .NET license have a long way to go before they ment status at Mono: http:// svn. prohibits the publication of comparative achieve complete compatibility. This myrealbox. com/ mwf/ owners. html benchmarks for .NET implementations. said, both .NET and Mono succeed in [7] PNetmark: However, the DotGNU project provides providing support for .NET software de- http:// www. southern-storm. com. au/ the PNetmark tool [7] to help those of velopment on Linux. pnet_faq. html#q1_4 you interested in benchmark testing to We mainly experienced issues using create your own benchmarks. For more the System.Windows.Forms library, information on performing your own which provides graphical applications Linux, you can use GUI libraries such as benchmarks, check out Section 1.4 of on Windows. In other words, it is not GTK#, #, or WX#. Because all of these the DotGNU FAQ. trivially possible to migrate GUI-based libraries are also available for the Win- Windows .NET software to Linux right dows platform, cross platform applica- Summary now. tions are possible within limits, although Microsoft’s .NET framework provides an As an alternative to direct migration of these applications will not be .NET com- interesting approach to platform-inde- GUI-based Windows .NET software to patible. ■

Advertisement

WWW.LINUX - MAGAZINE.COM ISSUE 61 DECEMBER 2005 75