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:Summary of the next 100 posts (Score:3, Insightful)
If you want cross-platform and (fairly) strong typing, use Java, if you want loose typing and want Linux or OS X, use Objective-C ( GNUStep/Cocoa respectively for UIs ), if you want M$, use Visual Studio C++ or flavor-of-the-moment C#, or flavor-of-the-last-moment VisualBasic, or ( somebody's favorite Wxyz windows-centric development platform here )...
But seriously ( for a moment ), without asking why not use Java, why use C# ? What's the benefit over *anything* else, other than Microsoft is pushing it hard ?
Re:Sweet Spot? (Score:3, Insightful)
I work specifically on 'fast path' software that is in the data path, and while we absolutely must be concerned with performance, a good C++ compiler will generate perfectly acceptable code from a speed standpoint. Any tweaks can be done in assembler. The benefits in extensibility and good code design are usually worth it in the log run (and better designed code is generally less buggy and often faster)
So, the point is that it's primarily memory footprint that has kept embedded engineers from using C++ (or other OO) in the past, but as that restriction has lessened, more and more of them are using C++ and OO design principles (even in 'fast path' processing).
Therefore, I (and many of my collegues) would like a language that is more OO than C++ (which frankly is a hack between C and strict OO languages), but still provides the direct system and memory access that a language like C provides. Not saying C# is it by any means, but there is a sweet spot between #1 and #2, and I'm living in it
Re:Objective-C (Score:3, Insightful)
Object-orientation is just a language feature, it's not a true indicator of the level at which a language exists, but typically it provides a boost to the level of a language. C, Objective-C, and C++ are each slightly higher-level than the last, but only slightly. It's other standard features (iostream, STL, etc.) that make the language truly higher-level.
The level of a language also depends on what you measure that level relative to. One way to look at it is to ask how far above the machine you are. In assembler, you aren't very far off the hardware. Every instruction is tailored to the hardware. But you can also measure relative to the OS. In C, you are farther from the hardware itself, but low-level to the operating system - you have to tailor your code to the OS it will run on.
Why bother? (Score:1, Insightful)
So, back to Mono -- why on earth should anyone care that there's something that's almost Java, only without anywhere near as much industry support, and many years less maturity? Sure, MS is scary and all, but so was Intel... now, if C# were substantially better than Java, it would at least be technically interesting, but so far the best argument I've heard for using C# instead of Java is that MS is promoting it. I can see why that would be important in an MS-only shop, but why on earth would anyone interested in cross-platform or open software care about, much less promote, Mono? Is it some twisted attempt to take control of C# from MS?
Re:Sweet Spot? (Score:5, Insightful)
It's a myth that C/C++ is particularly fast or efficient for those applications: in the absence of language-provided features like garbage collection, runtime safety, or dynamic typing, people end up reinventing those features over time, badly and less efficiently.
Both Gtk and Qt are actually sad examples of this: not only does their functionality suffer from their choice of language (each has invented their own object models), their resource requirements are embarrassingly bad.
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.
Languages like Python have other problems for the development of large systems, like the lack of static type checking. Python is great, however, for prototyping, extensions language uses, and for single programmer projects.
But, in any case, there is a lot of application software that requires much better performance than languages like Python can deliver: CAD systems, graphics systems, image encoders/decoders/editors, vector graphics renderers, typesetting and layout software (including web browsers and editors), audio encoders/decoders, GIS systems and mapping programs, speech recognition engines, and lots more. No, application developers have neither the time nor the resources to turn all the compute intensive core functionality in C/C++ code and then link that into Python. C# is a good middle ground.
let alone C# or Java, although we may be ready for it in 5 years or so.
The performance of Sun's Java implementation is excellent (although Java sucks for other reasons). The performance of C# implementations is quickly catching up with Java implementations.
Re:Summary of the next 100 posts (Score:5, Insightful)
The big advantage to
As for the patent stuff, I'm not aware of what patents cover
Oh hell, I'll bite (Score:5, Insightful)
Re:Sweet Spot? (Score:4, Insightful)
Huh? I typically find that I don't have the time not to do this. Programming in Python takes me about 5 to 10 less time than programming the same functionality in C, and in the rare cases something is too slow even with Psyco [sourceforge.net], I use Pyrex [canterbury.ac.nz] for the inner loop, typically a single function or class.
CAD systems: I am not familiar with those, what exactly is too performance-critical for Python in CAD systems?
graphics systems: Huh?
image encoders/decoders/editors: Image encoders/decoders are typically very small projects - small enough to write in C or other low-level languages.
vector graphics renderers: Probably true
typesetting and layout software (including web browsers and editors): Python is fast enough for these, on non-antique hardware.
audio encoders/decoders: Similar to image encoders/decoders, these are small and should be implemented in a low-level language.
GIS systems and mapping programs: What is time-critical about these?
speech recognition engines: I suspect there's a small algorithm running in an inner loop and a lot of higher-order code. Only the inner loop needs C, and that only if you want Real-Time behavior.
Ever since I turned to write nearly all my code in Python, my productivity was boosted by hundreds of percents, and I am less surprised with time that Python is fast enough in almost all cases when it is used right.
Re:No advantage of C# over Java (Score:3, Insightful)
To date Java has produced exactly two good desktop applications, Eclipse and Azureus. It's an abysmal failure, and the associated stigma won't disappear anytime soon.
Telling users to go to Windows update and pull down
Mono apps on Linux or Windows won't come in some funky
The JRE is an alien piece of software in Linux land. Even after you install the official RPM "java" produces a "java: command not found". Even as a developer I don't want to deal with that sort of shit these days if it can just be automated. There's just been no thought given to end user experience and it shows throughout the whole platform.
All these points make Java a horrible system for desktop Linux apps, and Mono on par with existing systems. Then when you add in all the niceties of working in a managed language, you've got to at least give Mono a good look when deciding what to use for your next Linux app.
Mono's 100% open source. Dismissing it right from the start just because it has its origins with MS is just stupid. The situation is completely analogous to MS SMB vs Samba. Even in an all Linux shop you're likely to find Samba in use because, frankly, NFS for the longest time has been a real piece of shit and is only recently worth using on Linux.
Re:Sweet Spot? (Score:2, Insightful)
I'm sorry, it's a myth? Apparently many millions of people, many far better programmers than you, have completely been deceived! Please back up this wonderfully baseless statement with some substance.
One of the core ideas behind the design of C++ is "if you don't use it, you don't pay for it". Do a quick look around at talk of the impending C++0x standard, and you'll see this mantra is alive and well to this very day... and the lack of some "language features", like forced garbage collection, don't exist it for this very reason.
To point to QT and GTK and somehow equate these very fine libs/toolkits was a "sad example" of how C/C++ forces people to "re-design things badly" reflects some serious ignorance. It only took one reply to another poster to totally contradict yourself and say GTK is in fact, a well designed toolkit. The fact you qualified it with "as well as could be done in C" shows you're a language war fanboy, and most fanboys are beginners who don't know any better.
Java/C# and even C++ really aren't wildly different languages. Fanatics claiming 500x speedups in their development time are immediately red flagged to me as ignorant.
Re:Sweet Spot? (Score:3, Insightful)
This is a debatable point. On the one hand, yes, it is dynamically typed. On the other hand, having easy access to an interpreter and zero compilation times leads to interactive testing and a more incremental approach to building large applications. In my experience, the latter far outweighs the former (as long as raw performance isn't the issue).