Friday, January 31, 2014

Still Kicking

For those who track this stuff, Mono will turn 10 years old this summer. Since June 30th 2004, the Mono team has been relentlessly trailing the ever evolving CLR (Microsoft’s implementation of the CLI), and hasn’t seemed to stop or get bored with the idea. At time of writing, they still trail a little bit here and there, but for the most part, have near feature parity with .NET 4.5.

It’s Prolific

One of the interesting thing about Mono is that even though it may not be used as often as Microsoft’s implementation of the CLI (the CLR, which just runs on Windows), Mono has brought .NET to arguably more platforms including:

Linux

Windows

OS X

BSD

Solaris

Nintendo Wii

PS 3

iOS

Android

And architecture wise, Mono runs on more instruction sets too:

x86

x64

IA64

PowerPC

Sparc

ARM

Alpha

S390/x (32/64)

How It Works

Although the details vary from platform to platform (especially for iOS/Android) effectively your application when executed is hosted and run inside the Mono runtime (just like apps are hosted within the CLR in the Windows world), and your code makes .NET calls against that runtime. Since Mono is a implementation of the CLI, you get all the things you’d expect from a .NET Framework implementation like:

Embedding

Turns out you can even embed .NET applications into C/C++ applications by hosting the Mono runtime (in your C application) and loading regular .NET assemblies into that runtime. Furthermore once loaded, those .NET assemblies and the C codes can interoperate, being able to both make and receive calls from each other.

In a nutshell it looks like the below.

Hosting a .NET Managed Assembly in C a Application

This is often used in scripting scenarios, allowing you to author applications that benefit from both low level and very fast code for scenarios that need it, while still allowing your team to write less mission critical code in highly productive languages like C#, Ruby, Perl, etc… (all of which are .NET enabled languages).

iOS/Android/OSX

Mono has always had the ability to run on Linux, but getting good integration (how do I call native APIs) and UI building tools has always been challenging on increasingly exotic platforms. Xamarin aims to fix this. Although the tools are pretty spendy, Xamarin is one of the only solutions that allows you to author cross platform code that calls against native APIs for iOS, Android, and OS X. They do this by hosting your code in a Mono Runtime, and providing a set of native APIs that you can call against (which in turn call against those native APIs.

Since .NET runs natively on Win Phone/Surface it’s also included in the cross platform reach.

Summary

When Microsoft created the CLI as an open specification, I doubt they dreamed that their idea of a platform agnostic runtime would end up on so many systems. Even though “write once, run anywhere” paradigm never really materialized completely for the CLI or the JRE, they continue to cover an incredibly large array of device profiles. With tools like Xamarin and Mono continuing to close the gap, a world of ever emerging devices doesn’t seem as daunting as it did a couple of years ago.

About Me

Tyler Holmes is a Solutions Architect working in Portland, Oregon. He lives mostly in the MS tech stack and is currently treading the waters of Communication/Collaboration and Business Intelligence with off the shelf/open source technologies.