A few weeks back I read Mono: A Developer’s Notebook to learn about about Mono, a bit about .Net through mono tinted glasses. I don’t know what I was expecting, but it was interesting to find out how reality compared to it.
OK, so I pretty much messed up my previous post on how to describe the difference programming languages. Essentially what I was trying to get at was that it isn’t enough to say that a language is object oriented, or that it has an extensible syntax, but how the how the language designer translates a concept like “object oriented” into the particular semantics of their language. (This is sort of reminding me of the book Long Dark Teatime of the Soul when an accident is considered an Act of G-d and Dirk Gently wants
to find out which god and why) The most obvious comparison C# has is to Java, and if I’m going to do that, I shouldn’t be comparing to two variables. So let me say that Java seems to be a language that was originally designed to be a “consensus” language. It had the features that were widely common across many OO languages, and avoided features that would have cause derision. Between a C++ style class definition being a “fully complete static definition” and a smalltalk style “initial specification”, pick the safer static one. Between open class definitions that can be added to and closed classes, pick closed. Between single inheritance and multiple (and then seeing MI would turn into arguments like depth first and diamond inheritance) pick single but the pull in interfaces to cover a common use case. Avoid things like metaclass protocols, but give escape hatches like reflection, etc. It might just be that as the technology matured, certain ideas would sort of mesh be the standard, default choices, and if Java didn’t come around to cover them, something else would have.
So if Java is a consensus language, C# seems similar to Java because its starting from those same obvious answers to similar questions. (well, that and the C-like syntax, and the platform independent bytecode, and that it was the first thing that Microsoft came up with after being forced to stop distributing Java) C# as a language has a different set of design goals, and so has some interesting features.
As an initial laundry list, having both reference and value objects and optional non-polymorphic methods like C++. It has a properties syntax for giving a getter/setter implementation around what looks like simple member variable access to its clients. (like languages such as Python, common lisp, and dylan) It has class and method attributes for metadata. (which dynamic languages tend to take care of with special runtime object member (Zope’s security and Interface additions to Python are an example) and static languages have done with odd preprocessor hacks (like lint’s /* NOTREACHED */, or Java’s javadoc.) or just odd language quirks (like Python’s “if the first statement is a constant string in a void context it is a docstring) C#’s “delegate methods” (essentially language level support of things like the strategy and Observer patterns) is an interesting addition as a language primitive.
I guess what I found the most interesting were which pieces were part of the core language, the standard library, and how they interact. Some of them are language primitives that depend on interfaces in the standard library (like foreach loops needing IEnumerable interfaces or the “using ( object ) { block } ” needing an object implementing IDisposable. (This form of “using” is interesting because it takes care of some of the use cases of Perl’s immediately called destructors.) So its not exactly a barebones set of language primitives, but not the kitchen sink of Perl.
The .net architecture in general is relatively interesting, and these are some of the where Mono matches the architecture directly. Classes get compiled to an bytecode format, and put into “assemblies” (which can be applications or libraries) libraries that are designed to be shared can be cryptographically signed, versioned, and put into the global assembly cache (sort of like /usr/lib of unix) Some of the origins of the platform are visible here, and the Mono macros for Autoconf are set up so that small shell scripts are put in $prefix/bin/$program that call out “exec mono $prefix/lib/$package/$program.exe”
Actually, maybe this demonstrates the core issues with Mono. The .net platform isn’t written to be platform independant, unless you view WindowsCE, through Windows XP desktops, to Windows 2003 Servers to be the full spectrum of platforms. Mono tries its best to fit what it can of .net into a Unix-like mold, and then tries to fit Gnome into .net. Most of the OS neutral pieces have been copied over. The OS dependent pieces that are required (like spawning another process) are done in an Windows-centric way. Some of the OS dependent pieces that can’t be ported easily (like Windows.Forms, a UI library, which only runs under Mono in conjunction with Wine on x86 Linux) are replaced with Gnome components like Gtk#.
Despite the windows-centric quirks, I can see why the Mono team decided to create a system based on .net technologies. They can piggyback onto a development economy on par with Java. But Java’s method of platform independence is as much ignoring the underlying system’s unique advantages as it is creating a common interface to the features that are supported across all host platforms. I can see developing desktop applications under Gtk# might give more “native” feeling applications than a Java/Swing one.
OK, now let me give at least an initial rundown of some of the things covered in the book. Like the other books in the “A Developer’s Notebook” series, its essentialy a series of examples with a small amount of explanatory material in between. (Essentially a series of “How do I …” passages, then the solution, followed by a “What just happened?” passsage) It goes over how to install Mono, then either existing free IDEs (like SharpDevelop or the Gtk port of MonoDevelop) or how to fit Mono into an existing development environment (Emacs and Vim modes, using Make or NAnt to build, etc.) Then it goes over enough C# in order to work through the examples (teaching basic class construction syntax, and delegates since they are used with Gtk) Then it goes through making desktop applications with Gtk# and Gnome assemblies.
The book does a fair amount to cover server-side use of Mono, including making SOAP based web services, and Using mod_mono under Apache to develop ASP.NET applications. Around this part, it covers XML processing (since Microsoft is so invested in XML, you can imagine they want their common runtime to have robust XML libraries in it.
The last chapter, “Cutting Edge Mono” is a mishmash of things, but probably the things that are too small to cover in their own chapter, but too interesting to ignore. This is where the Autotools info is, and some cross-platform hints. It also covers IKVM, a system to have Java code run under Mono or .Net. A the rest of the chapter is some “not ready for prime time” pieces still under development in Mono. Mono implements most of version 1 of C#, and has some of the version 2 features, but the development version of Mono has some of the newer features like support for generics. They also have a VB.Net compatible compiler under development.