Pages

Tuesday, January 25, 2011

Going Mono

Going Mono

I have decided that all of my open source projects and the internal ones (that I make to help a team when working on a project) will be cross compatible with mono, and also will be one click deployable via build script. This is due that I feel that Mono is mature enough and in some time will become more mainstream then it is now, besides it has got some great tools that VS doesn't, like live console etc, IL debugger (my fav), and a migration tool from .Net C# to Mono C#.

Things to consider

Let's be honest here, mono has bugs, but they are not so annoying when say 3 years ago, it was a mine field back then, now the bugs are minimal for the most part and the performance is on par with Windows, but there are still a few thing to consider when going mono, as the existing codes from Windows may work differently or a little buggy, consider this:

When I imported some of my projects I have noticed that they do compile and run but don't work as they should (tested on Ubuntu Linux).

if (targetType.GetInterfaces().FirstOrDefault(x => x.GetGenericTypeDefinition() == typeof(IList<>)))
            { //code }

this works on Windows, but not in mono, I haven't decompiled the code but my gut tells me that windows version internally checks if the type is generic wheres mono does not, so it is more strict, so the code needs to be modified like this:

if (targetType.GetInterfaces().FirstOrDefault(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IList<>)))
            { //code }

but it still had some problems picking up the lambda code and it failed to work so for safety I ended up writing the code in an old fashioned way, that's faster btw:

foreach (var item in targetType.GetInterfaces())
            {
                if (item.IsGenericType)
                {
                    var result = item.GetGenericTypeDefinition();
                    if (result == typeof(IList<>))
                    {
                        return true;
                    }
                }
            }
            return false;

This code worked without any problems so I was happy with it.

The interresting thing is that MSDN states that in order for this to work one needs to check if a type is generic but the compiler does not enforce it, so it turns out that mono plays by the book :-).

Mono still struggles with performance in some framework areas, but the most painful are the regex matchings as the execution is based around code interpreter, the net version can produce IL compiled assembly, so having a regex heavy matches can bring down performance, and there is also a consideration to take that the platform itself uses the regex classes so even when not using regexes some parts of the framework can be slow (like ASP.NET for e.g or string matching), the only good solution I see for this is to rewrite the regex class to use DynamicMethods (or dynamic assemblies if you will), or skip the framework features that use the build in regex class and just use some external library for your own application, or ... just wait for a new release when this will be resolved once and for all ;-).

IDE

MonoDevelop is the primary IDE for mono and since version 2.2 it's an awesome powerhouse, the debugger and Intelisence is just great (much better then in eclipse), and it has some great tools out of the box to speed up the development.

One little rant: I had some issues with version 2.2 (2.4 is the newest one) as all of the breakpoints didn't work, this is a known issue and the recommended fix is to just reinstall (purge) and in most cases it works, but I updated to 2.4 and since then I have no problems at all.

Summary

I fell that mono is great now and it's going to be awesome in a few years if the development will continue and chances are that it will become a top solution for the Enterprise (would love to see that :-) ).

No comments:

 
ranktrackr.net