Mono: A Developer's Handbook 301
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.
Re:Objective-C (Score:3, Informative)
Sidenote #2, IronPython, which runs on Mono, has been shown to perform better (on average, 1.7x better) under most performance tests than standard Python v2.3. (this is not a troll or flame-incitation, just a FYI). See IronPython.com [ironpython.com], or this paper from PyCon 2004 [python.org].
Re:What about java? (Score:5, Informative)
Mono is Novell's implementation of this standard [ecma-international.org].
On the other hand,
Same standard, 2 different implementations of the standard.
Before anyone starts trolling... (Score:5, Informative)
Mono with the
Mono with GTK#, Gnome, Mozilla and other libraries doesn't have that problem because the only thing that it uses from Microsoft is the ECMA standard C# language implementation.
Why Mono and not Java? Mono is 100% open source.
Why Mono and not Python? Mono uses a virtual machine environment that is faster than an interpreted language. Some people prefer the Java and C++ similarities that C# offers. Mono is cuasi language independent. You can use Python in Mono (See Iron Python).
"Miguel de Icaza is wasting his time..." Miguel works on Mono because he likes it, he is not employed by you (except if you are Novell) so he spends his time as he sees fit. He owes you nothing.
Cheers,
Adolfo
Re:What about java? (Score:3, Informative)
For the uninitiated (Score:4, Informative)
There's an RSS feed [mono-project.com] for the newest news, updates, etc. on Mono, too.
Re:Objective-C (Score:4, Informative)
To each their own, but I suspect you are in a small minority. Garbage collection, safe modules, type-safe linkage, and runtime code generation are all important modern language features that C# has and Objective C lacks.
Re:Before anyone starts trolling... (Score:3, Informative)
Well.. if you're going to be "educated and informed", you should at least trouble yourself with considering the fact that there are open-source implementations of Java.
JBoss, gcj, kaffe...
And it's also fair to remember that there are indeed two different
Re:Mono vs .NET Framework (Score:4, Informative)
The mono c# compiler allows you to create CIL (common intermediate language) code, which is analygous to java byte-code, except for just-in-time compilation. The mono implementation of the
The whole point about the
When Mono's Windows.Forms implementation is complete, you should be able to do this same thing with complete GUI applications, however in the mean time that's what GTK# and other linux-based APIs are for.
Re:Cobol (Score:4, Informative)
Re:Summary of the next 100 posts (Score:2, Informative)
Re:Objective-C (Score:5, Informative)
It was a little less than a year ago that I first started investigating the Common Language Runtime (CLR). My plan was to do a little work and then write a short pithy article called, "Why
The more time that I spent with the CLR, the more excited I became about its potential. At the same time, I was becoming more frustrated with the slow pace of progress that I was able to make working on this project in my spare time. After exploring many alternatives, I think that I've found the ideal way to continue working to realize the amazing potential of the vision of the CLR. I've decided to join the CLR team at Microsoft beginning on August 2.
At Microsoft I plan to continue the work that I've begun with IronPython to bring the power and simplicity of dynamic/scripting languages to the CLR. My work with Python should continue as a working example of a high-performance production quality implementation of a dynamic language for the CLR. I will also reach out to other languages to help overcome any hurdles that are preventing them from targeting the CLR effectively. I welcome any and all feedback about how to best accomplish this. You can reach me at jim@ironpython.com.
Lesson to be learned, if you think something from MS sucks, only to find out it doesn't, you might just get hired.
Re:Mono vs .NET Framework (Score:5, Informative)
Personally, I disagree. Visual Studio is still a phenomenal IDE, and its GUI tools are some of the best on the market. But I think as we see Mono stabilize and mature past 1.0, the GUI tools for Gtk#, ASP.net, and the new Managed.Windows.Forms implemenation will be quite impressive.
(Disclaimer: This isn't a knock at Glade. Glade is good at what it does, but with the advent of Mono it's time for a replacement.)
Re:What, no VB? (Score:2, Informative)
Re:Sweet Spot? (Score:2, Informative)
The same is true for C#, using the platform invoke mechanism, it's even simpler.
Re:Mono vs .NET Framework (Score:3, Informative)
But, in addition, Mono also offers bindings to the Gtk+/Gnome APIs, and that makes software development a lot easier for Gnome developers. There are some GUI builders you can already use with those Mono bindings, and a new GUI builder will be integrated into Monodevelop, giving you a VisualStudio.NET-like experience developing applications for Mono and Gnome.
So, in short, yes, Mono "captures the simplicity of the
Argh! (Score:5, Informative)
Java/C# = Strongly statically typed
Python/Ruby = Strongly dynamically typed
"Loose" typing is another way of saying "weak" typing. Meaning the system doesn't enforce type safety. In almost all scripting languages, type safety is strongly enforced.
Here is somthing funny (Score:3, Informative)
Re:Objective-C (Score:2, Informative)
Re:Argh! (Score:3, Informative)
Re:Summary of the next 100 posts (Score:3, Informative)
That's assuming you don't count Rotor [c-sharpcorner.com], Microsoft's reference implementation of the ECMA-standardize bits of .NET (the C# language, the CLR, etc, but not bits like WinForms), which at least works on various BSD platforms, and is licensed such that you can safely port it to other platforms, or use it as the basis for a reimplimentation (think BSD's network stack, for instance).
Also keep in mind that Microsoft has a 10 year support plan for each new version of the .NET framework. Tha means that 1.0 will be supported for another 7-8 years, 1.1. will be supported for another 9, and 2.0 will be supported for 10 years from release (which should be sometime next year?). That means that even if Microsoft does make breaking changes in a new version of the platform, you can still build applications against older versions that Mono does support. As well, each framework has some amount of backwards- and forwards-compatibility (for instance, it's possible to run 1.1-targeted .NET apps on the 1.0 framework, with a few exceptions). Microsoft generally does a good job of listing backwards [gotdotnet.com] and forwards [gotdotnet.com] breaking changes between versions of the framework. (Yes, GotDotNet.com is a Microsoft property.)
patented libs in different part of build tree (Score:3, Informative)
Mono with GTK#, Gnome, Mozilla and other libraries doesn't have that problem because the only thing that it uses from Microsoft is the ECMA standard C# language implementation.
And the beaut think about that is the *potentially encumbered* libraries are in a different part of the build tree, ready to be pulled if a MS (FUD) patent does get served.
Re:Argh! (Score:3, Informative)
You *don't* have strongly-typed collections in C++. You've got *statically* typed collections in C++. They are, however, still *weakly* typed.
The difference between weak and strong typing is in that a strongly typed language, the compiler enforces the type system.
The difference between static and dynamic typing is that in a dynamically typed language, some type information may not be known until runtime.
Maybe you should read one of those textbooks...
Re:Summary of the next 100 posts (Score:3, Informative)
Personally, I like it. Throwing everything together in a huge registry is a can of worms just asking for trouble.
Re:Why bother? (Score:2, Informative)
C# is better than Java in almost every way:
You may hear about these "features" from pro-CLR people:
The only advantages the Java language has (that I can think of) are:
It's true that C# is mostly copied from Java. They didn't add any novel ideas. They just improved it incrementally (and screwed up a little too). But after everything is accounted for, it's clearly a better language. You can talk about "maturity" and "industry support" all you want, but some people are just happy to be using a superior language.
BTW, both "maturity" and "industry support" wont be problems for C#. It's not hard to design a mature language and set of class libraries when you have a working example to learn from. Also, Microsoft has mature designers working on the CLR and that counts for something too. As for "industry support", you have got to be joking. When they make the CLR come pre-installed on Longhorn, it will instantly become an industry standard. Even now it's available directly through Windows Update. The whole XAML/Avalon thing is not even ready yet but Amazon.com has already used it to build a prototype. It's depresing, but true: anything that comes out of Microsoft will have a completely unfair advantage over any competing products. Macromedia is next [infoworld.com].