Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
Programming Books Media Book Reviews Technology

Mono: A Developer's Handbook 301

vertigo writes "I am reasonably proficient in C and C++ as well as the more common scripting languages, but i always felt the lack of a sweet spot between the hard and fast low-level programming languages and the loosely typed scripting languages. Lately, my interest in the Mono project has been growing. The C# language appears to offer just that sweet spot between power and productivity I've been looking for, and its class libraries like Gtk# seem to provide the programmer with a very clean and intuitive API." Read on for vertigo's review of Mono: A Developer's Handbook from O'Reilly.
Mono: A Developer's Handbook
author Edd Dumbill and Niel M. Bornstein
pages 278
publisher O'Reilly Media, Inc.
rating 8
reviewer vertigo
ISBN 0596007922
summary An introduction to programming with Mono

When learning a new language such as C#, or working with a new development environment such as Mono, it usually takes some time before you get up to speed in developing programs. Wading through the reference documentation and reading other people's source code often provides much-needed information on how to do certain things. Both, however, are very time consuming and tedious.

Enter Mono: A Developer's Notebook. This book provides a series of task-driven chapters which are thin on theory, but rich on practical content and example code. The featured code snippets are, in contrast to ones in books that teach theory and concepts, not solely designed to illustrate a specific theoretical aspect of programming. Each one is designed to perform a useful task that is essential in day-to-day application programming. What sets this book apart from the multitude of .NET books already available on the market? In order to answer this question it is neccesary to provide a short introduction on Mono.

Mono is essentially an open source cross-platform implementation of Microsoft's .NET development framework and implements the API's which are standardized by ECMA. It is, however, not an exact clone. Besides providing a (partially implemented) stack that provides compatibility with Microsoft's .NET API's, Mono adds a whole new API-stack of its own, consisting of open source technologies such as the Gtk+ toolkit and the Gecko HTML rendering engine. This makes it possible to develop cross-platform applications based on open source technology while (mostly) compiling from a single code-base. In contrast to most .NET books available on the market, which focus primarily on Microsoft's API's in the context of Visual Studio.NET, this book concentrates on the basic ECMA API's and Mono's own open source stack. A complete coverage of .NET and the Mono architecture is outside of this review's scope, so for more information you are advised to check the Mono Project's website.

Before we dive deeper into the content of the book, a short introduction on the Developer's Notebook series by O'Reilly may be useful. The books in this series are styled to resemble the kind of notebooks college students carry around during their classes in which to take notes or, more commonly, draw caricatures of their teachers. The 'notebook' theme persists throughout the look-and-feel of the book. The 278-page thick paperback has a glossy blue cover, complete with faux post-it note and coffee-stains. Inside, the pages are not clean white but lined like the pages found in math notebooks. In the margin, useful comments are scribbled in a font that resembles handwriting. At first I suspected that the 'busy' look would distract from the content, but in practice this was no problem, thanks to the thick black typewriter font in which the bulk of the text is printed.

The chapters in this book are referred to as labs. Each of them focuses on a specific set of tasks and/or features and is divided into several paragraphs. Most paragraphs consist of a number of standard sections following a rigid formula that help you understand a certain aspect of working with Mono. The most common sections are:

  • How do I do that?: Often using a liberal amount of practical code, this section shows how to accomplish the task at hand, for example working with files.
  • How it works: In this section, the code and concepts involved in the previous section are explained more in depth, step by step.
  • What about...: Offers a short focus on more advanced topics or pitfalls.
  • Where to learn more: If you are craving more information after reading the previous sections, you are often offered a helping hand on where to find more information, providing url's to relevant documentation such as MSDN and other websites.

The first chapter, Getting Mono Running, describes how to get Mono up and running on Linux, Windows or Mac OS X, and how to compile from source on other platforms. The installation instructions for Windows only describe how to install Mono and Gtk#. Integration of Gtk# only in an existing Visual Studio.Net installation falls outside of the scope of the book, but a recent blog entry offers some hints on how to accomplish this. Besides installation, the first chapter offers a short description of the individual tools that make up the mono development. After installation, you will want some kind of editor or IDE to work with. Both the MonoDevelop IDE and several other ways of integrating Mono into your existing environment as a Java or Windows developer are covered. Finally, the community is an important aspect of every open source project. Ways of interacting with the community as well as a guide on how to submit bugs and links to some working Mono/C# applications are part of this chapter.

The C# introduction in the second chapter, Getting Started with C#, is tailored towards people who have at least some proficiency in using an object-oriented language such as C++ or Java. Some differences between C#, Java and C++ are discussed, as well as the differences between value- and reference types, the basics of error handling, working with assemblies and more. Concepts such as classes, methods, inheritance and namespaces are assumed to be known territory. If you have no previous programming experience, Mono: A Developer's Notebook is only useful in combination with a book that teaches programming with C# such as The C# Programming Language by Anders Hejlsberg.

An important part of any modern language is its class libraries. The third chapter, Core .NET, provides an introduction to the standard Framework Library Classes, which describes essential everyday tasks that are part of every program, such as working with files, strings, searching for text patterns and handling collections of data. Besides those basic functions, the chapter also dives deeper into the internals of a compiled assembly, the handling of processes and easy multitasking using threads. Finally, the last paragraph explains how to use a .NET version of the JUnit Java Unit testing framework, Nunit, to test your code.

Developing Gtk-applications with Mono and C# is remarkably easy. Chapter 4, Gtk#, describes the basics of writing Gtk# applications. First, it's neccesary to remark that Gtk# might be a bit of a misnomer. Besides the raw Gtk+ toolkit functionality, Gtk# also includes most of the Gnome libraries like gconf, the gnome canvas, libglade and more. Chapter 4 describes functionality available in the Gtk namespace, the basic Gtk+ toolkit. Gtk+ is a constraints-based toolkit, which means that widgets are not positioned using absolute pixel coordinates but rather on basis of their logical relation to each other. This can be a bit confusing for novices, but this chapter provides a good introduction to the basic principles of writing layouts using Gtk#. The authors provide descriptions of essential operations that almost every application needs, such as creating menus and drawing pixmaps (or more advanced things like using the treeview widget and drag-and-drop), assisted by easy-to-read code snippets.

While chapter 4 introduces basic Gtk# functionality, chapter 5, Advanced Gtk#, delves deeper into more advanced features of the Gtk# library which also include functionality outside of the basic Gtk-namespace, such as the Gnome libraries. Working with Gnome button toolbars, the Glade user interface designer, storing your application settings in Gconf, setting up some preferences through the use of a wizard/druid, asynchronous operations and threading to increase responsiveness of your application while performing background tasks, rendering HTML in your application using the Gecko rendering engine and internationalisation and translation of applications are all described in this chapter.

The use of XML is tightly integrated throughout the Mono framework. It is, for example, the underlying format of the messages that web services use to communicate using the SOAP and XML-RPC protocols. The 6th chapter, Processing XML, describes the XML functionality available in Mono. It starts off by simple operations, reading and writing to an XML-file using relevant examples such as RSS and Dashboard clue-packets. It then proceeds to describe how to modify XML in memory, how to navigate and transform XML using Xpath and XSLT, how to constrain XML in several ways and how to serialize and deserialize objects into and from their XML representation. As in previous chapters, the information density is very high so it might take several reads to grok everything explained. The code examples and accompanying text however are very clear and concise.

The 7th chapter called Networking, Remoting, and Web Services describes the networking functionality available in Mono. The chapter starts off with ASP.NET. Mono's stand-alone XSP webserver and Apache integration with mod_mono are discussed, as well as the basics of writing a web application using ASP.NET's code-behind functionality which enables web applications to completely seperate presentation from the underlying code. Communication using plain tcp/ip, remoting using binary serialized objects and invoking remote procedures using XML-RPC as an alternative to SOAP are also described in this chapter. You might want to encrypt the data you send over the network, so a basic description of the Mono cryptographic API is provided. Finally, a short introduction to database handling using ADO.NET concludes chapter 7.

The 8th and last chapter titled Cutting Edge Mono starts off with an introduction on how to use the GNU Automake, Autoconf and the pkg-config tools to create an easy to build source package of your project. It then proceeds to describe various pitfalls and considerations in case you want to write cross-platform applications using Mono, such as filesystem layout, configuration storage and the calling of native code using p/invoke. A particularly cool project is IKVM, which translates Java bytecode into the Common Intermediate Language bytecode Mono uses. This enables Mono to run Java applications and allows Java and Mono code to inter-operate. A short introduction on the use of IKVM is provided, as well as some code examples on how to call Mono assemblies from Java and use the Java class libraries from within Mono applications. The chapter ends with some other cutting-edge functionality, like how to run a development version of Mono, a preview of the Generics (templates in c++) implementation available as featured in C# 2.0 and how to write Mono programs in Basic.

What is missing? The book doesn't contain a reference section on any of the described API's. If you need detailed information on the C# language specification or an API reference you will need to consult external resources such as the documentation provided with Mono, MSDN, or a separate book covering the topic to make optimal use of the information contained in this book. Fortunately, the book kindly provides pointers on where to find those. The information-density is much higher than you would expect from a book this size. This means the information contained in it is terse. Many topics are treated in a only a couple of pages and the book doesn't take time to explain a lot of programming concepts. The information gets you 'on the road' quickly however, which is exactly what this book is supposed to do.

The strength of this book is that it fills the gap between the earlier-mentioned reference documentation and the need to go out and try to read sourcecode to find out how a particular thing is done. The writing style is clear, concise and neutral. Some topics are clarified by the use of screenshots, which is especially useful in the chapters dealing with Gtk# widgets. All in all, if you are a developer with previous experience in object-oriented programming, Mono: A Developer's Notebook will provide you with an excellent introduction into many of the aspects of working with Mono, its associated libraries and programs.

More information and a sample chapter can be found at the book's homepage.


You can purchase Mono: A Developer's Handbook from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.

This discussion has been archived. No new comments can be posted.

Mono: A Developer's Handbook

Comments Filter:
  • Objective-C (Score:4, Interesting)

    by remahl ( 698283 ) on Wednesday September 29, 2004 @03:20PM (#10386603)
    For me, Obj-C combined with Cocoa (*Step), is that same sweet spot. And sometimes Python, when a really high-level language is required. Naturally still together with Cocoa through PyObjC.
  • by aminorex ( 141494 ) on Wednesday September 29, 2004 @03:29PM (#10386709) Homepage Journal
    I can't imagine why anyone would use Mono when it can be ripped out from under you by Microsoft's patent attorneys at any moment, and the alternatives are so superior. For example, gcj, or
    Ruby's GTK and Gnome or QT and KDE bindings.

    While C# and dotnet get enormous amounts of PR hype, they really don't amount to much in the real world, where the platform lock-in and enormous bloat that dotnet entails spell doom.

  • What, no VB? (Score:1, Interesting)

    by Nom du Keyboard ( 633989 ) on Wednesday September 29, 2004 @03:32PM (#10386739)
    If Mono doesn't support Visual Basic .NET, I'm not interested.

    Even if VB.NET really is nothing more than VC++ in VB sheep's clothing.

  • by Nick of NSTime ( 597712 ) on Wednesday September 29, 2004 @03:32PM (#10386742)
    One thing I still haven't been able to figure it is how Mono compares to developing .NET applications on Windows with the Microsoft toolset. Does Mono capture the simplicity of the .NET Framework in building Windows (GUI-based) applications?
  • Sweet Spot? (Score:4, Interesting)

    by Freedom Bug ( 86180 ) on Wednesday September 29, 2004 @03:32PM (#10386743) Homepage
    Sweet spot? I call it uninteresting void. It seems to me that most programming is either:

    1) operating system kernel or core library, embedded or high-performance programming. This niche only finished moving from assembly to C a few years ago. C++ is usually too slow & big & unwieldy for this niche, let alone C# or Java, although we may be ready for it in 5 years or so.

    2) application programming. Here development speed is more important than execution speed. Python and kin provide 'good enough' execution speed when coupled with proper libries (QT, etc) with the fastest development speed.

    What kind of code falls between the 2? Sure there is some, but is it interesting?

    Bryan
  • by Dante Shamest ( 813622 ) on Wednesday September 29, 2004 @03:33PM (#10386756)
    An important part of any modern language is its class libraries. C# beats C++ only in the size of it's standard library. (Managed C++ doesn't count). If only the ANSI/ISO dudes would include a standard GUI library (even a very simple one) and stop spending so much time on generics and algorithms...
  • by iezhy ( 623955 ) on Wednesday September 29, 2004 @03:34PM (#10386774) Homepage
    I can't imagine why anyone would use Mono when it can be ripped out from under you by Microsoft's patent attorneys at any moment..

    and it will be ripped out by evil M$ attorneys, as soon as it spreads enough. M$ is only waiting till enogh open-source project migrates to mono.
  • Re:Sweet Spot? (Score:5, Interesting)

    by tcopeland ( 32225 ) * <tom AT thomasleecopeland DOT com> on Wednesday September 29, 2004 @03:44PM (#10386896) Homepage
    > Here development speed is more important
    > than execution speed. Python and kin

    Right on. And with Ruby/Python/etc you can always dip down into a C library for bits that turn out to be performance-critical. With Ruby, this is usually as simple as something like:
    require 'dl/import'

    module Curl
    extend DL::Importable
    dlload "/usr/local/lib/libcurl.so"
    extern "char *curl_version()"
    end

    puts Curl.curl_version
    Hard to beat...
  • C# without .NET? (Score:3, Interesting)

    by Animats ( 122034 ) on Wednesday September 29, 2004 @04:09PM (#10387235) Homepage
    Can you use C# without .NET or some replacement for it? Is it possible to use it with POSIX alone? Or perhaps with OpenGL?
  • Re:Sweet Spot? (Score:2, Interesting)

    by bushidocoder ( 550265 ) on Wednesday September 29, 2004 @04:25PM (#10387441) Homepage
    The problem is that alot of people don't think Python/Ruby/Perl fits appropriately into 2) because of the language bindings. One of the advantages of managed frameworks (particularly .NET/Mono) is that once somebody somewhere wrote a .NET library to do something, that library is available immediately for use in any language which compiles to IL or has an IL runtime built into it.

    Projects like IronPython give you all the advantages of working in Python, all the advantages of working on top of the CLR framework and toss in the added benefit of every other .NET/Mono application being able to take advantage of your Python libraries.

    btw - Being able to run stored procedures written in Python on the SQL Server 2005 beta is pretty cool. I still can't find a good reason to write a stored procedure in any language other than T-SQL, but its still kind of fun.
  • Re:Sweet Spot? (Score:3, Interesting)

    by bushidocoder ( 550265 ) on Wednesday September 29, 2004 @04:37PM (#10387575) Homepage
    The performance of C# implementations is quickly catching up with Java implementations.

    That depends. For single processor 32bit x86 environments, I've found .NET to be significantly faster than Java. It helps to be able to inline short non-virtual methods, perform allocations for simple non-native-typed objects on the stack, etc. The gap will probably only widen as the two camps release their very different implementations of generics.

    Java clobbers .NET in the 64 bit world and in the multi-processor world. .NET also doesn't really appear in a non-x86 architecture and probably wouldn't perform as well - Not surprisingly .NET IL looks to be pretty biased to the x86 architecture. But for every runtime optimization the Java world can build, the .NET CLR team can match it and build in another option the Java camp can't without a pretty drastic change to some of the core internals.

    (note that when I talk about .NET, I'm referring to the Microsoft .NET CLR - the Mono CLR is still pretty slow to my experience, but getting better by the day

  • Re:What, no VB? (Score:1, Interesting)

    by Anonymous Coward on Wednesday September 29, 2004 @05:25PM (#10388150)
    You should really read up on what youre talking about before posting

    He develops in VB...what else did you expect? They just point and click and type in a database source, assume all is well with the world and think they are Top Coders. I'm not trying to flame here, but my experience with VB developers has been that VB is all they know, and no matter how proficient they are with it, they dont ever truly get a grasp on how a computer, compiler, or any of the related, really work. Also (keep in mind this is my personal experience with VB developers), VB Developers often only know one language (VB of course) and still call themselves programmers. I'm sorry but no real programmer only knows one language, sure you may only typically use one language, but anyone who takes coding seriously knows *at least* one other language and perhaps a few scripting languages too. What I'm getting at is that just to be a programmer and be good at programming, you need a good understanding of many things, VB coders typically don't know much beyond point and click and occasional typing of an "if" statement. I've met many VB coders who had no idea that a gui was generated by code, honest to God, they thought it just kind of magically appeared after being dragged and dropped and you made your exe, probably because they never saw the code for the gui. One guy saw me coding up some C++ in vim and was not only confused by the syntax, but was also amazed to see a window appear when I ran my program, he asked me how I did that without designing one, he thought I was using an activex control or something to do it for me (BTW, I was on linux, and apparently alot of things in VB are done with activex). I almost went insane. Then I explained how you can do all that without a little form designer, simply by coding it. He was shocked and I still don't think he fully understood.
    Regards,
    Steve
  • Re:Sweet Spot? (Score:1, Interesting)

    by Anonymous Coward on Wednesday September 29, 2004 @06:08PM (#10388683)
    It's a myth that C/C++ is particularly fast or efficient for those applications

    No, its not a myth. Language implementation benchmarks, like http://shootout.alioth.debian.org/ [debian.org] prove this. Not only is C/C++ the fastest option but also the most memory friendly one. C++ in particular offers nice abstractions that those "modern" VM languages still lack or provide only half-hearted (eg. templates). Anyone who claims that Java or C# is suitable for embedded environments does not know what she is talking about.
  • by omicronish ( 750174 ) on Wednesday September 29, 2004 @09:14PM (#10390077)

    Assuming that is true, the only real worry for Mono is that Microsoft would change .NET enough to break what compatibility they have, but the Mono project has already explained why this doesn't worry them.

    I just wanted to clarify this part in case people are wondering why. Basically Microsoft can't break .NET compatibility in old versions of the Framework because it'll break all the programs that use those versions. So versions 1.0 and 1.1 can be considered unchangeable right now (except for fixes probably), and it's safe from a coding standpoint for Mono to make an equivalent implementation without worrying about breaking changes.

    Microsoft can extend and modify .NET with newer versions, such as the currently-beta 2.0, but .NET versions can and are designed to be installed side-by-side, so applications that use 1.0 or 1.1 still need the respective version of the framework installed. If you want to check this for yourself, take a look at the C:\Windows\Microsoft.NET\Framework directory. I currently have the subdirectories v1.0.3705, v1.1.4322, and v2.0.40607

  • by iggymanz ( 596061 ) on Wednesday September 29, 2004 @09:14PM (#10390080)
    no elite or FUD here, but if you read the specs for the java vm found in pre-1.4 it indeed uses a 32 bit address space for its internal pointers. IBM and Sun have released the 64 bit (internal) JVM, but I've yet to hear they are production grade. You might also be interested to know that while Sun boxes with UltraSparc 1 chips were 64 bit capable, the Solaris 2.5 and 2.6 were not true 64 bit OS (I have an Ultra 170e which triple boots 2.6, 7 and 8, btw). Not until Solaris 8 (which includes both 32 and 64 bit kernel you have the choice of booting) did they get *most* of the 64 bit issues ironed out, and you can read all about the remaining problems in their online doc site.
  • C# Rocks (Score:3, Interesting)

    by Pedrito ( 94783 ) on Wednesday September 29, 2004 @10:00PM (#10390403)
    I have to say it. C# does rock and I'm so happy about Mono doing so well.

    There are mistakes in how the C# language has been designed that really bug me at times, but I've been developping in C# for about 2 years now and I've never been so productive in my life.

    It has a lot of the advantages of Java, but with a better UI (and by better, I mean better looking AND better performance. The Java ones seem to be one or the other: Fast and Ugly or Slow and Pretty, and maybe even some slow and ugly ones).

    I really hope Mono can keep up with the Longhorn development because I really expect the library design to be better. There are a lot of aspects of the .NET framework that are clearly hacked together just to make it work. Others were clearly designed by developers with very little understanding of object oriented development principles.

    But complaints aside, overall it's excellent and as I said, I've never been so productive! As an independent contractor, that means a lot to me.
  • Re:Sweet Spot? (Score:0, Interesting)

    by Anonymous Coward on Thursday September 30, 2004 @06:29AM (#10392534)
    dlload "/usr/local/lib/libcurl.so"

    Yeah, I guess that's hard to beat... if your code will never be used on another machine. In the real world, we have to deal not only with different machines (where libcurl might be in /usr/lib, or /opt/lib, or /home/foo/lib), but different operating systems (where it might be C:\Program Files\Common Files\cURL\libCURL 7.12.1\dllcurl.dll). Assuming it's available for Windows, which it might not be.

    This is what we mean by "scripting languages don't scale".

    The advantage of Mono or CLR development - or Java for that matter - is that the huge standard library guarantees that most of the functionality you need will be present on any supported operating system, and gives a standard way to access it through standard names. Dipping down into a C library from Ruby just isn't as good. Sorry.

Solutions are obvious if one only has the optical power to observe them over the horizon. -- K.A. Arsdall

Working...