Miguel de Icaza Personal blog of Miguel de Icaza http://tirania.org/blog//index.html Miguel de Icaza miguel@gnome.org Thu, 19 Apr 2012 18:07:00 -0500 http://backend.userland.com/rss lb# XNA on Windows 8 Metro <p><img src="http://download.codeplex.com/Download?ProjectName=monogame&DownloadId=331456&Build=18696" align="right">The <a href="http://monogame.codeplex.com/">MonoGame Team</a> has been working on adding Windows 8 Metro support to MonoGame. <p>This will be of interest to all XNA developers that wanted to target the Metro AppStore, since Microsoft does not plan on supporting XNA on Metro, only on the regular desktop. <p>The effort is taking place on IRC in the #monogame channel on irc.gnome.org. The code is being worked in the <a href="https://github.com/mono/MonoGame/tree/develop3d">develop3d</a> branch of MonoGame. http://tirania.org/blog/archive/2012/Apr-19.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Apr-19.html Thu, 19 Apr 2012 22:07:00 -0500 Contributing to Mono 4.5 Support <p>For a couple of weeks I have been holding off on posting about how to contribute to Mono, since I did not have a good place to point people to. <p>Gonzalo has just updated our Status pages to include the differences betwee <a href="http://go-mono.com/status/">.NET 4.0 to .NET 4.5</a>, these provide a useful roadmap for features that should be added to Mono. <p>This in particular in the context of ASP.NET 4.5, please join us in <a href="http://lists.ximian.com/mailman/listinfo/mono-devel-list">mono-devel-list@lists.ximian.com</a>. http://tirania.org/blog/archive/2012/Apr-13.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Apr-13.html Fri, 13 Apr 2012 21:54:00 -0500 Modest Proposal for C# <p>This is a trivial change to implement, and would turn what today is an error into useful behavior. <p>Consider the following C# program: <pre> struct Rect { public int X, Y, Width, Height; } class Window { Rect bounds; public Rect Bounds { get { return bounds; } set { // Some code that needs to run when the property is set WindowManager.Invalidate (bounds); WindowManager.Invalidate (value); bounds = value; } } } </pre> <p>Currently, code like this: <pre> Window w = new Window (); w.Bounds.X = 10; </pre> <p>Produces the error: <pre> Cannot modify the return value of "Window.Bounds.X" because it is not a variable </pre> <p>The reason is that the compiler returns a copy of the "bounds" structure and making changes to the returned value has no effect on the original property. <p>If we had used a public field for Bounds, instead of a property, the above code would compile, as the compiler knows how to get to the "Bounds.X" field and set its value. <p>My suggestion is to alter the C# compiler to turn what today is considered an error when accessing properties and doing what the developer expects. <p>The compiler would rewrite the above code into: <pre> Window w = new Window (); var tmp = w.Bounds; tmp.X = 10; w.Bounds = tmp; </pre> <p>Additionally, it should cluster all of the changes done in a single call, so: <pre> Window w = new Window (); w.Bounds.X = 10; w.Bounds.Y = 20; </pre> <p>Will be compiled as: <pre> Window w = new Window (); var tmp = w.Bounds; tmp.X = 10; tmp.Y = 20; w.Bounds = tmp; </pre> <p>To avoid calling the setter for each property set in the underlying structure. <p>The change is trivial and wont break any existing code. http://tirania.org/blog/archive/2012/Apr-11.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Apr-11.html Wed, 11 Apr 2012 15:31:00 -0500 Can JITs be faster? <p>Herb Sutter discusses in his <a href="http://herbsutter.com/2012/04/02/reader-qa-when-will-better-jits-save-managed-code/">Reader QA: When Will Better JITs save Managed Code?</a>: <blockquote> In the meantime, short answer: C++ and managed languages make different fundamental tradeoffs that opt for either performance or productivity when they are in tension. <p>[...] <p>This is a 199x/200x meme that’s hard to kill – “just wait for the next generation of (JIT or static) compilers and then managed languages will be as efficient.” Yes, I fully expect C# and Java compilers to keep improving – both JIT and NGEN-like static compilers. But no, they won’t erase the efficiency difference with native code, for two reasons. <p>First, JIT compilation isn’t the main issue. The root cause is much more fundamental: Managed languages made deliberate design tradeoffs to optimize for programmer productivity even when that was fundamentally in tension with, and at the expense of, performance efficiency. (This is the opposite of C++, which has added a lot of productivity-oriented features like auto and lambdas in the latest standard, but never at the expense of performance efficiency.) In particular, managed languages chose to incur costs even for programs that don’t need or use a given feature; the major examples are assumption/reliance on always-on or default-on garbage collection, a virtual machine runtime, and metadata. </blockquote> <p>This is a pretty accurate statement on the difference of the mainstream VMs for managed languages (.NET, Java and Javascript). <p>Designers of managed languages have chosen the path of safety over performance for their designs. For example, accessing elements outside the boundaries of an array is an invalid operation that terminates program execution, as opposed to crashing or creating an exploitable security hole. <p>But I have an issue with these statements: <blockquote> Second, even if JIT were the only big issue, a JIT can never be as good as a regular optimizing compiler because a JIT compiler is in the business of being fast, not in the business of generating optimal code. Yes, JITters can target the user’s actual hardware and theoretically take advantage of a specific instruction set and such, but at best that’s a theoretical advantage of NGEN approaches (specifically, installation-time compilation), not JIT, because a JIT has no time to take much advantage of that knowledge, or do much of anything besides translation and code gen. </blockquote> <p>In general the statement is correct when it comes to early Just-in-Time compilers and perhaps reflects Microsoft's .NET JIT compiler, but this does not apply to state of the art JIT compilers. <p>Compilers are tools that convert human readable text into machine code. The simplest ones perform straight forward translations from the human readable text into machine code, and typically go through or more of these phases: <center> <img src="http://tirania.org/s/977fd53d.png"> </center> <p>Optimizing compilers introduce a series of steps that alter their inputs to ensure that the semantics described by the user are preserved while generating better code: <center> <img src="http://tirania.org/s/679d485f.png"> </center> <p>An optimization that could be performed on the high-level representation would transform the textual "5 * 4" in the source code into the constant 20. This is an easy optimization that can be done up-front. Simple dead code elimination based on constant folding like "if (1 == 2) { ... }" can also be trivially done at this level. <p>An optimization on the medium representation would analyze the use of variables and could merge subexpressions that are computed more than once, for example: <pre> int j = (a*b) + (a*b) </pre> <p>Would be transformed by the compiler into: <pre> int _tmp = a * b; int j = _tmp + _tmp; </pre> <p>A low-level optimization would alter a "MULTIPLY REGISTER-1 BY 2" instruction into "SHIFT REGISTER-1 ONE BIT TO THE LEFT". <p>JIT compilers for Java and .NET essentially break the compilation process in two. They serialize the data in the compiler pipeline and split the process in two. The first part of the process dumps the result into a <code>.dll</code> or <code>.class</code> files: <center> <img src="http://tirania.org/s/34c474f8.png"> </center> <p>The second step loads this file and generates the native code. This is similar to purchasing frozen foods from the super market, you unwrap the pie, shove it in the oven and wait 15 minutes: <center> <img src="http://tirania.org/s/62ebc31f.png"> </center> <p>Saving the intermediate representation and shipping it off to a new system is not a new idea. The <a href="http://en.wikipedia.org/wiki/TenDRA_Compiler">TenDRA C and C++</a> compilers did this. These compilers saved their intermediate representation into an architecture neutral format called <a href="http://en.wikipedia.org/wiki/Architecture_Neutral_Distribution_Format">ANDF</a>, similar in spirit to .NET's Common Intermediate Language and Java's bytecode. TenDRA used to have an installer program which was essentially a compiler for the target architecture that turned ANDF into native code. <p>Essentially JIT compilers have the same information than a batch compiler has today. For a JIT compiler, the problem comes down to striking a balance between the quality of the generated code and the time it takes to generate the code. <p>JIT compilers tend to go for fast compile times over quality of the generated code. Mono allows users to configure this threshold by allowing users to pick the optimization level defaults and even lets them pick LLVM to perform the heavy duty optimizations on the code. Slow, but the generated code quality is the same code quality you get from LLVM with C. <p>Java HotSpot takes a fascinating approach: they do a quick compilation on the first pass, but if the VM detects that a piece of code is being used a lot, the VM recompiles the code with all the optimization turned on and then they hot-swap the code. <p>.NET has a precompiler called NGen, and Mono allows the --aot flag to be passed to perform the equivalent process that TenDRA's installer did. They precompile the code tuned for the current hardware architecture to avoid having the JIT compiler spend time at runtime translating .NET CIL code to native code. <p>In Mono's case, you can use the LLVM optimizing compiler as the backend for precompiling code, which produces great code. This is the same compiler that Apple now uses on Lion and as LLVM improves, Mono's generated code improves. <p>NGen has a few limitations in the quality of the code that it can produce. Unlike Mono, NGen acts merely as a pre-compiler and tests suggest that there are very limited extra optimizations applied. I believe NGen's limitations are caused by .NET's Code Access Security feature which Mono never implemented [1]. <p>[1] Mono only supports the CoreCLR security system, but that is an opt-in feature that is not enabled for desktop/server/mobile use. A special set of assemblies are shipped to support this. <h2>Optimizing JIT compilation for Managed Languages</h2> <p>Java, JavaScript and .NET have chosen a path of productivity and safety over raw performance. <p>This means that they provide automatic memory management, arrays bounds checking and resource tracking. Those are really the elements that affect the raw performance of these languages. <p>There are several areas in which managed runtimes can evolve to improve their performance. They wont ever match the performance of hand-written assembly language code, but here are some areas that managed runtimes can work on to improve performance: <p>><b><A href="http://en.wikipedia.org/wiki/Alias_analysis">Alias analysis</a></b> is simpler as arrays are accessed with array operations instead of pointer arithmetic. <p>Intent: with the introduction of LINQ in C#, developers can shift their attention from how a particular task is done to expressing the desired outcome of an operation. For example: <pre> var biggerThan10 = new List<int>; for (int i = 0; i < array.Length; i++){ if (array [i] > 10) biggerThan10.Add (i); } </pre> <p>Can be expressed now as: <pre> var biggerThan10 = x.Where (x => x > 10).Select (x=>x); // with LINQ syntax: var biggerThan10 = from x in array where x > 10 select x; </pre> <p>Both managed compilers and JIT compilers can take advantage of the rich information that is preserved to turn the expressed intent into an optimized version of the code. <p><b>Extend VMs:</b> Just like Javascript was recently extended to support strongly typed arrays to improve performance, both .NET and Java can be extended to allow fewer features to be supported at the expense of safety. <p>.NET could allow developers to run without the CAS sandbox and without AppDomains (like Mono does). <p>Both .NET and Java could offer "unsafe" sections that would allow performance critical code to not enforce arrays-bounds-optimization (at the expense of crashing or creating a security gap, this can be done today in Mono by using -O=unsafe). <p>.NET and Mono could provide allocation primitives that allocate objects on a particular heap or memory pool: <pre> var pool = MemoryPool.Allocate (1024*1024); // Allocate the TerrainMesh in the specified memory pool var p = new pool, TerrainMesh (); [...] // Release all objects from the pool, all references are // nulled out // Assert.NotEquals (p, null); pool.Destroy (); Assert.Equals (p, null); </pre> <p><b>Limiting Dynamic Features:</b> Current JIT compilers for Java and .NET have to deal with the fact that code can be extended dynamically by either loading code at runtime or generating code dynamically. <p>HotSpot leverages its code recompiled to implement sophisticated techniques to perform devirtualization safely. <p>On iOS and other platforms it is not possible to generate code dynamically, so code generators could trivially devirtualize, inline certain operations and drop features from both their runtimes and the generated code. <p><b>More Intrinsics:</b> An easy optimization that JIT engines can do is map common constructs into native features. For example, we recently inlined the use of ThreadLocal&lt;T&gt; variables. Many Math.* methods can be inlined, and we applied this technique to <a href="http://tirania.org/blog/archive/2008/Nov-03.html">Mono.SIMD</a>. http://tirania.org/blog/archive/2012/Apr-04.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Apr-04.html Wed, 04 Apr 2012 15:53:00 -0500 Microsoft's new Open Sourced Stacks <p>Yesterday <a href="http://weblogs.asp.net/scottgu/archive/2012/03/27/asp-net-mvc-web-api-razor-and-open-source.aspx">Microsoft announced</a> that another component of .NET would be open sourced. The entire <a href="http://aspnetwebstack.codeplex.com/">ASP.NET MVC</a> stack is now open source, including the Razor Engine, System.Json, Web API and WebPages. <p>With this release, they will start accepting external contributions to these products and will be running the project like other open source projects are. <h2>Mono and the new Stacks</h2> <p>We imported a copy of the git tree from <a href="http://aspnetwebstack.codeplex.com/">Codeplex</a> into <a href="http://github.com/mono/">GitHub's Mono organization</a> in the <a href="https://github.com/mono/aspnetwebstack">aspnetwebstack</a> module. <p>The mono module itself has now taken a dependency on this module, so the next time that you run autogen.sh in Mono, you will get a copy of the aspnetwebstack inside Mono. <p>As of today, we replaced our System.Json implementation (which was originally built for Moonlight) and replaced it with Microsoft's implementation. <p>Other libraries like Razor are next, as those are trivially imported into Mono. But ASP.NET MVC 4 itself will have to wait since it depends on extending our own core ASP.NET stack to add asynchronous support. <p>Our github copy will contain mostly changes to integrate the stack with Mono. If there are any changes worth integrating upstream, we will submit the code directly to Microsoft for inclusion. If you want to experiment with ASP.NET Web Stack, you should do this with your own work and work directly with the upstream maintainers. <h2>Extending Mono's ASP.NET Engine</h2> <p>The new ASP.NET engine has been upgraded to support C# 5.0 asynchronous programming and this change will require a number of changes to the core ASP.NET. <p>We currently are not aware of anyone working on extending our ASP.NET core engine to add these features, but those of us in the Mono world would love to assist enthusiastic new developers of people that love async programming to bring these features to Mono. http://tirania.org/blog/archive/2012/Mar-28.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Mar-28.html Wed, 28 Mar 2012 20:20:00 -0500 Mono 2.11.0 is out <p>After more than a year of development, we are happy to announce Mono 2.11, the first in a series of beta releases that will lead to the next 2.12 stable release. <h2>Continuous Integration</h2> <p>To assist those helping us with testing the release, we have setup a new continuous build system that builds packages for Mac, OpenSUSE and Windows at <a href="http://wrench.mono-project.com/Wrench/">http://wrench.mono-project.com/Wrench</a>. <h2>Packages</h2> <p>To test drive Mono 2.11 head to our our <a href="http://www.go-mono.com/mono-downloads/download.html">downloads page</a> and select the "Alpha" section of the page to get the packages for Mac, Windows or Linux. <p>The Linux version is split up in multiple packages. <p>The Windows version ships with Gtk+ and Gtk# <p>The Mac version ships with Gtk+, Gtk#, F#, IronPython and IronRuby and comes in two versions: Mono Runtime Environment (MRE) and the more complete Mono Development Kit (MDK). <p>At this stage, we recommend that users get the complete kit. <h2>Runtime Improvements in Mono 2.11</h2> <p>There are hundreds of new features available in this release as we have accumulated them over a very long time. Every fix that has gone into the Mono 2.10.xx series has been integrated into this release. <p>In addition, here are some of the highlights of this release. <p><b>Garbage Collector:</b> Our SGen garbage collector is now considered production quality and is in use by Xamarin's own commercial products. <p>The collector on multi-CPU systems will also distribute various tasks across the CPUs, it is no longer limited to the marking phase. <p>The guide <a href="http://mono-project.com/Working_With_SGen">Working with SGen</a> will help developers tune the collector for their needs and discusses tricks that developers can take advantage of. <p><b>ThreadLocal&lt;T&gt;</b> is now inlined by the runtime engine, speeding up many threaded applications. <p><b>Full Unicode Surrogate Support</b> this was a long standing feature and has now been implemented. <h2>C# 5.0 -- Async Support</h2> <p>Mono 2.11 implements the C# 5.0 language with complete support for <a href="http://msdn.microsoft.com/en-us/vstudio/async.aspx">async programming</a>. <p>The Mono's class libraries have been updated to better support async programming. See the section "4.5 API" for more details. <h2>C# Backend Rewrite</h2> <p>The compiler code generation backend was rewritten entirely to support both IKVM.Reflection and System.Reflection which allowed us to unify all the old compilers (<code>mcs</code>, <code>gmcs</code>, <code>dmcs</code> and <code>smcs</code>) into a single compiler: <code>mcs</code>. For more information see <a href="http://www.mono-project.com/Release_Notes_Mono_2.12#C.23_Backend_Rewrite">Backend Rewrite</a>. <p>The new IKVM.Reflection backend allows the compiler to consume any mscorlib.dll library, instead of being limited to the ones that were custom built/crafted for Mono. <p>In addition, the compiler is no longer a big set of static classes, instead the entire compiler is instance based, allowing multiple instances of the compiler to co-exist at the same time. <h2>Compiler as a Service</h2> <p>Mono's Compiler as a Service has been extended significantly and reuses the compiler's fully instance based approach (see <a href="http://www.mono-project.com/Release_Notes_Mono_2.12#Instance_API">Instance API</a> for more details). <p>Mono's compiler as a service is still a low-level API to the C# compiler. The NRefactory2 framework --shared by SharpDevelop and MonoDevelop-- provides a higher level abstraction that can be -- used by IDEs and other high-level tools. <h2>C# Shell</h2> <p>Our C# interactive shell and our C# API to compile C# code can in addition to compiling expressions and statements can now compile class definitions. <h2>4.5 API</h2> <p><b>4.5 Profile</b> Mono now defaults to the 4.5 profile which is a strict superset of the 4.0 profile and reuses the same version number for the assemblies. <p>Although .NET 4.5 has not yet been officially released, the compiler now defaults to the 4.5 API, if you want to use different profile API you must use the -sdk:XXX switch to the command line compiler. <p>Because 4.5 API is a strict superset of 4.0 API they both share the same assembly version number, so we actually install the 4.5 library into the GAC. <p>Some of the changes in the 4.5 API family include: <ul> <li>New Async methods <li>WinRT compatibility API <li>Newly introduced assemblies: System.Net.Http, System.Threading.Tasks.Dataflow </ul> <p>The new System.Net.Http stack is ideal for developers using the C# 5.0 async framework. <h2>Debugging</h2> <p>The GDB support has been extended and can pretty print more internal variables of Mono as well as understanding SGen internals. <p>The soft debugger has seen a large set of improvements: <ul> <li>Single stepping is now implemented using breakpoints in most cases, speeding it up considerably. <li>Calls to System.Diagnostics.Debugger:Log()/Break () are now routed to the debugger using new UserLog/UserBreak event types. <li>S390x is now supported (Neale Ferguson). <li>MIPS is now supported. <li>Added new methods to Mono.Debugger.Soft and the runtime to decrease the amount of packets transmitted between the debugger and the debuggee. This significantly improves performance over high latency connections like USB. </ul> <h2>Mac Support</h2> <p>Mac support has been vastly extended, from faster GC by using native Mach primitives to improves many features that previously only worked on Linux to extending the asynchronous socket support in Mono to use MacOS X specific primitives. <h2>New Ports</h2> <p>We have completed the Mono MIPS port. <h2>Performance</h2> <p>As a general theme, Mono 2.11 has hundreds of performance improvements in many small places which add up. http://tirania.org/blog/archive/2012/Mar-22.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Mar-22.html Thu, 22 Mar 2012 14:33:00 -0500 Mono and Google Summer of Code <p>Students, get your pencils ready for an intense summer of hacking with the <a href="http://www.google-melange.com/gsoc/org/google/gsoc2012/mono">Google Summer of Code and Mono!</a> <p>Check out the Mono organization <a href="http://www.mono-project.com/Gsoc">Summer of Code Project site</a>. http://tirania.org/blog/archive/2012/Mar-16-1.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Mar-16-1.html Fri, 16 Mar 2012 19:41:00 -0500 Cross Platform Game Development in C# <p>If you missed the live session on Cross Platform Game Development in C# from <a href="http://altdevblogaday.com/2012/02/27/altdevconf-session-videos/">AltDevConf</a> you can now watch <a href="http://www.youtube.com/watch?v=qOnUog6WeUUour">presentation</a>. <p>You can also check <a href="http://altdevblogaday.com/2012/02/27/altdevconf-session-videos/">the videos for all the AltDevConf</a> presentations. http://tirania.org/blog/archive/2012/Mar-16.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Mar-16.html Fri, 16 Mar 2012 16:33:00 -0500 Working With SGen <p>As SGen becomes the preferred garbage collector for Mono, I put together the <a href="http://mono-project.com/Working_With_SGen">Working With SGen</a> document. This document is intended to explain the options that as a developer you can tune in SGen as well as some practices that you can adopt in your application to improve your application performance. <p>This document is a complement to the low-level implementation details that we had <a href="http://mono-project.com/Generational_GC">previously posted</a>. http://tirania.org/blog/archive/2012/Mar-05-2.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Mar-05-2.html Mon, 05 Mar 2012 19:18:00 -0500 Gtk+ and MacOS X <p>We have released a <a href="http://www.go-mono.com/mono-downloads/download.html">new build of Mono 2.10.9</a> (Beta) with the latest version of Gtk+2 containing dozens of bug fixes done by the <a href="http://www.lanedo.com/">Lanedo team</a> to improve the quality of Mono/Gtk+ apps on OSX. <p>This is still a beta release, please take it out for a spin, we are almost ready to graduate this as our stable Mono package. http://tirania.org/blog/archive/2012/Mar-05-1.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Mar-05-1.html Mon, 05 Mar 2012 16:20:00 -0500 Phalanger's PHP on Mono/.NET Updates <p>The <a href="http://www.php-compiler.net/">Phalanger developers</a> have published an updated set of <a href="http://www.php-compiler.net/benchmarks">benchmarks of their PHP compiler</a> running on top of .NET vs PHP and Cached PHP, and the results are impressive: <center> <img src="http://tirania.org/s/65a38d9f.png"> </center> <p>There are two cases on the language shootout where they are slower than PHP (out of eighteen cases) and they are also slower on eight of thirtyone microbenchmarks. <p>But in general with real applications like WordPress and MediaWiki, the performance gains are impressive. http://tirania.org/blog/archive/2012/Mar-05.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Mar-05.html Mon, 05 Mar 2012 16:18:00 -0500 C# for Gaming: Slides <p>You can now get the <a href="http://tirania.org/slides/AltDevConf-2012-Mono.pdf">Slides for my Mono for Game Development</a> talk. <p>Or you can go straight to the <a href="https://gist.github.com/1804402">resources</a> for the talk. http://tirania.org/blog/archive/2012/Feb-11.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Feb-11.html Sat, 11 Feb 2012 22:12:00 -0500 C# for Gaming: AltDevConf This Weekend <p>It is a great honor to participate this weekend on the online <a href="http://altdevconf.com/">AltDevConf conference</a>. This is an online <a href="http://altdevblogaday.com/2012/02/02/altdevconf-schedule/">two-day event</a> <blockquote> Our goal is twofold: To provide free access to a comprehensive selection of game development topics taught by leading industry experts, and to create a space where bright and innovative voices can also be heard. We are able to do this, because as an online conference we are not subject to the same logistic and economic constrains imposed by the traditional conference model. </blockquote> <p>I will be participating in the talk on <a href="http://altdevblogaday.com/2012/02/09/altdevconf-programming-laban/">Cross Platform Game Development</a> using C# with Matthieu Laban and Philippe Rollin. <p>You can <A href="https://www4.gotomeeting.com/register/729719079">register here</a> for our session on Saturday at 3pm Eastern Standard Time, noon Pacific Time, and 9pm Paris Time. <p>If you are located in the Paris time zone, that means that you get to enjoy the talk sipping a tasty hot chocolate with some tasty baguettes. http://tirania.org/blog/archive/2012/Feb-09.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2012/Feb-09.html Thu, 09 Feb 2012 19:59:00 -0500 Mono in 2011 <p>This was a very interesting year for Mono, and I wanted to capture some of the major milestones and news from the project as well as sharing a bit of what is coming up for Mono in 2012. <p>I used to be able to list all of the major applications and great projects built with Mono. The user base has grown so large that I am no longer able to do this. 2011 was a year that showed an explosion of applications built with Mono. <p>In this post I list a few of the high profile projects, but it is by no means an extensive list. There are too many <a href="http://xamarin.com/apps/all">great products</a> and amazing technologies being built with Mono, but a comprehensive list would take too long to assemble. <h2>Xamarin</h2> <p>The largest event for Mono this year was that the team working on Mono technologies at Novell was laid off after Novell was acquired. <p>We got back on our feet, and two weeks after the layoffs had taken place, <a href="http://tirania.org/blog/archive/2011/May-16.html">the original Mono team incorporated as Xamarin</a>. <p>Xamarin's goal is to deliver great productivity and great tools for mobile developers. Our main products are <a href="http://ios.xamarin.com">Mono on iOS</a> and <a href="http://android.xamarin.com">Mono on Android</a>. <p>These products are built on top of the open source <a href="http://mono-project.com">Mono project</a> and the <a href="http://monodevelop.com">MonoDevelop project</a>. We continue to contribute extensively to these two open source projects. <p>Launching Xamarin was a huge effort for all of us. <p>Xamarin would not have been possible without our great customers and friends in the industry. Many people cared deeply about the technology and helped us get up and running. <p>In July, we announced an agreement with <a href="http://www.itworld.com/mobile-wireless/184215/xamarin-attachmate-band-together-mono">Attachmate</a> that ensured a bright future for our young company. <p>A couple of days later, we were ready to sell the mobile products that had been previously developed at Novell, and we started to provide all existing Novell customers with ongoing support for their Mono-based products. <p>Half a year later, we grew the company and continued to do what we like the most: writing amazing software. <p>Meanwhile, our users have created amazing mobile applications. You can see some of those in our <a href="http://xamarin.com/apps">App Catalog</a>. <h2>C# Everywhere</h3> <p><b>On the Mobile Space:</b> This year Sony jumped to C# in a big way with the introduction of PS Suite (see the section below) and Nokia adopted Windows Phone 7 as their new operating system. <p>And <a href="http://xamarin.com">we got you covered</a> on Android and iOS for all of your C# needs. <p><b>On the Browser:</b> we worked with Google to bring you Mono to Native Client. In fact, every demo shown at the Google <a href="http://www.youtube.com/watch?v=g3aBfkFbPWk">Native Client event</a> on December 8th was powered by Mono. <p><b>On the Desktop:</b> this year we added MacOS X as a first-class citizen in the world of supported Mono platforms. We did this by <a href="http://tirania.org/monomac//archive/2011/Mar.html">introducing MonoMac 1.0</a> and supporting Apple's MacStore with it. <p><b>Games:</b> continue to take advantage of C# blend of performance and high-level features. Read more on my <a href="http://tirania.org/blog/archive/2011/Mar-07.html">GDC 2011</a> post. <p>It is a wild new world for C# and .NET developers that were used to build their UI using ASP.NET or Winforms only. It has been fascinating to see developers evolve their thinking from a Microsoft-only view of the world to a world where they design libraries and applications that split the presentation layer from the business logic. <p>Developers that make this transition will be able to get great native experiences on each device and form factor. <h2>Sony PSSuite - Powered by Mono</h2> <p>At GDC, Sony announced that PS Suite was built on top of Mono. PS Suite is a new development stack for cross-platform games and cross-platform applications to run on Android devices and Sony Vita. <p>The PS Suite presentation is available <a href="http://events.digitallyspeaking.com/gdc/online11/player.html?xmlURL=xml/201110202_1318362244736NUDW.xml&token=3c6c000ab0766078310c">in this video</a>. <center> <img src="http://tirania.org/s/51d6460d.png"> </center> <p>In particular, watch the game in <a href="http://www.youtube.com/watch?v=hUQk-tuPFmY">Video 2</a> to get a feeling for the speed of a 3D game purely written in managed code (no native code): <p>Some of the juicy details from the GDC announcement: <ul> <li>PS Suite will have an open appstore model, different than the traditional game publishing business. <li>Open SDK, available for everyone at launch time. <li>PS Suite supports both game development with Sony's 3D libraries as well as regular app development. <li>Cross-platform, cross-device, using the ECMA Common Intermediate Language. <li>Code in C#, run using Mono. <li>GUI Designer called "UI Composer" for non-game applications. <li>The IDE is based on MonoDevelop. <li>Windows-simulator is included to try things out quickly. </ul> <p>MonoDevelop on PSSuite: <center> <img src="http://tirania.org/s/b0510805.png"> </center> <p>PS Suite comes with a GUI Toolkit and this is what the UI composer looks like: <center> <img src="http://tirania.org/s/2ee3ec28.png"> </center> <h2>Google Native Client</h2> <p>Google Engineers ported Mono to run on the sandboxed environment of <a href="http://gonacl.com">Native Client</a>. Last year they had added support for Mono code generator to output code for Native Client using Mono's <a href="http://www.mono-project.com/AOT">static compiler</a>. <p>This year Google extended Native Client to support Just in Time Compilation, in particular, Mono's brand of JIT compilation. This was used by all three demos shown at the <a href="http://www.youtube.com/watch?v=g3aBfkFbPWk">Google Native Client</a> event a couple of days ago: <center> <img src="http://tirania.org/s/39e2119a.png"> </center> <center> <img src="http://tirania.org/s/952a94db.png"> <p>Unity Powered Builder </center> <p>This is another game built with Unity's Native Client code generator: <center> <img src="http://tirania.org/s/cb363aba.png"> </center> <p>To get the latest version of Mono with support for Native Client, download and build Mono from <a href="https://github.com/elijahtaylor/mono">Google's branch</a> on github. <h2>Mono 2.10</h2> <p>This was the year of <a href="http://www.mono-project.com/Release_Notes_Mono_2.10">Mono 2.10</a>. We went from a beta release for Mono 2.10 in January to making it our new stable release for Mono. <p>While the world is on Mono 2.10, we have started our work to get <a href="http://www.mono-project.com/Release_Notes_Mono_2.12">Mono 2.12</a> out in beta form in January. <h2>Mono on Android</h2> <p>This year we launched <a href="http://xamarin.com/monoforandroid">Mono for Android</a>, a product that consists of port of Mono to the Android OS, C# bindings to the native Java APIs and IDE support for both MonoDevelop and Visual Studio. <p>The first release came out in April, it was rough around the edges, but thanks to the amazing community of users that worked with us during the year, we solved the performance problems, the slow debugging, vastly improved the edit/debug/deploy cycle and managed to catch up to Google's latest APIs with the introduction of <a href="http://blog.xamarin.com/2011/12/05/mono-for-android-4-0-is-here/">Mono for Android 4.0</a>. <h2>Mono on iOS</h2> <p>Just like Android, we have <a href="http://blog.xamarin.com/2011/10/12/monotouch-5-with-ios-5-support/">been on a roll with MonoTouch</a>. <p>In short, this year: <ul> <li>We kept up with Apple's newly introduced APIs (UIKit, iCloud, Airplay, Bluetooth, Newstand, CoreImage). <li>Integrated XCode 4's UI designer with MonoDevelop< and added support for storyboards. <li>Added the option of using LLVM for our builds, bringing thumb support and ARMv7 support along the way. </ul> <p>We started beta-testing a <a href="http://ios.xamarin.com/Releases/MonoTouch_5/MonoTouch_5.1">whole new set of features</a> to be released early next year: a new unit testing framework, a heap profiler, integrating MonoTouch.Dialog in the product and improving the debug/deploy process.< <p>Mono for iOS has been on the market now for two years, and many products are coming to the market based on it. <h2>Phalanger</h2> <p><img src="http://tirania.org/s/c0573db7.png" align="right"><a href="http://www.php-compiler.net/">Phalanger</a> is a PHP compiler that runs on the .NET and Mono VMs and is powered by the Dynamic Language Runtime. <p>It is so complete that it can run both MediaWiki and WordPress out of the box. And does so by running faster than they would under PHP. <center> <img src="http://www.php-compiler.net/wp-content/uploads/2011/08/wordpress-phalanger-201109-performance.png"> </center> <p>This year the Phalanger guys released <a href="http://www.php-compiler.net/blog/2011/phalanger-3-0">Phalanger 3.0</a> which now runs on Mono (previously they required the C++/CLI compiler to run). <p>Phalanger's performance is impressive as it is just as fast as the newly announced Facebook HipHop VM for PHP. The major difference being that Phalanger is a complete PHP implementation and the HipHopVM is still not a complete implementation. <p>The other benefit of Phalanger is that it is able to <a href="http://www.php-compiler.net/blog/2011/pass-delegates-into-php">participate and interop</a> with code written in other .NET languages as well as benefitting from the existing .NET interop story (C, C++). <h2>CXXI</h2> <p>Our <a href="http://tirania.org/blog/archive/2011/Dec-19.html">technology to bridge C# and C++</a> matured to the point that it can be used by regular users. <h2>Compiler as a Service</h2> <p>This year our C# compiler was expanded in three directions: <ul> <li>We completed async/await support <li>We completed the two code output engines (System.Reflection.Emit and IKVM.Reflection). <li>We improved the compiler-as-a-service features of the compiler. </ul> <p>Our async/await support is scheduled to go out with the first preview of Mono 2.11 in early January. We can not wait to get this functionality to our users and start building a new generation of async-friendly/ready desktop, mobile and server apps. <p>One <b>major difference</b> between our compiler-as-a-service and Microsoft's version of the C# compiler as a service is that we support two code generation engines, one generates complete assemblies (like Microsoft does) and the other one is able to be integrated with running code (this is possible because we use System.Reflection.Emit and we can reference static or dynamic code from the running process). <p>We have also been improving the error recovery components of the compiler as this is going to power our new intellisense/code completion engine in MonoDevelop. Mono's C# compiler is the engine that is powering the upcoming NRefactory2 library. <p>You can read more about our <a href="http://tirania.org/blog/archive/2011/Feb-24.html">compiler as a service updates</a>. <h2>Unity3D</h2> <p><a href="http://www.unity3d.com">Unity</a> is one of Mono's major users. At this point Unity no longer requires an introduction, they went from independent game engine a few years ago to be one of the major game engine platforms in the game industry this year. <p>The Unity engine runs on every platform under the sun. From the Consoles (PS3, Wii and XBox360) to iPhones and Androids and runs on your desktop either with the Unity3D plugin or using Google's Native Client technology. The <a href="http://unity3d.com/gallery/made-with-unity/game-list">list of games</a> being built with Unity keeps growing every day and they are consistently among the top sellers on every app store. <p>Mono is the engine that powers the scripts and custom code in games and applications built with Unity3D and it also powers the actual tool that users use to build games, the <a href="http://unity3d.com/unity/editor/">Unity3D editor</a>: <center> <img src="http://download.unity3d.com/unity/editor/images/editor-small.jpg"> </center> <p>The editor itself it implemented in terms of Unity primitives, and users can extend the Unity3D editor with C#, UnityScript or Boo scripts dynamically. <p>One of my favorite games built with Unity3D is Rochard was demoed earlier this year on a PS3 at the GDC and is now also avaialble on Steam: <center> <img src="http://tirania.org/s/c50860ac.png"> </center> <h2>Microsoft</h2> <p>Just before the end of the year, Microsoft shipped <a href="http://itunes.apple.com/us/app/kinectimals/id482365195?mt=8">Kinectimals</a> for iOS systems. <p>Kinectimals is built using Unity and this marks the first time that Microsoft ships a software product built with Mono. <p>Then again, this year has been an interesting year for Microsoft, as they have <a href="http://www.zdnet.com/blog/microsoft/understanding-microsofts-big-picture-plans-for-hadoop-and-project-isotope/11466">embraced open source technologies</a> for Azure, <a href="https://github.com/WindowsAzure">released SDKs for iOS and Android</a> at the same time they ship SDKs for their own platforms and shipped various applications on Apple's AppStore for iOS. <h2>MonoDevelop</h2> <p><img src="http://xamarin.files.wordpress.com/2011/10/md-header1.png" align="right">We started the year with MonoDevelop 2.4 and we finished after two major releases with <a href="http://blog.xamarin.com/2011/10/05/monodevelop-2-8-released/">MonoDevelop 2.8.5</a>. <p>In the course of the year, we added: <ul> <li>Native Git support <li>Added .NET 4.0 project support, upgraded where possible to XBuild/MSBuild <li>MonoMac Projects <li>XCode 4 support for MonoMac, MonoTouch and Storyboards <li>Support for Android development <li>Support for iOS5 style properties <li>Major upgrade to the debugger engine <li>Adopted native dialogs on OSX and Windows </ul> <p>Our Git support was based on a machine assisted translation of the Java jGit library using Sharpen. <a href="https://github.com/slluis/sharpen">Sharpen</a> has proved to be an incredibly useful tool to bring Java code to the .NET world. <h2>SGen</h2> <p>Our precise collector has gotten a full year of testing now. With Mono 2.10 we made it very easy for developers to try it out. All users had to do was run their programs with the --sgen flag, or set MONO_ENV_OPTIONS to gc=sgen. <p>Some of the new features in our new Garbage Collector include: <ul> <li>Windows, MacOS X and S390x ports of SGen (in addition to the existing x86, x86-64 and ARM ports). <li>Lock-free allocation to improve scalability (we only take locks when we run out of memory). <li>Work stealing parallel collector and a parallel nursery collector, to take advantage of extra CPUs on the system to help with the GC. <li>Work on performance and scalability work, as our users tried things out in the field, we identified hot-spots in SGen which we have been addressing. </ul> <p>As we are spending so much time on ARM-land these days, SGen has also gained various ARM-specific optimizations. <p>SGen was designed primarly to be used by Mono and we are extending it beyond being a pure garbage collector for Mono, to support scenarios where our garbage collector has to be integrated with other object systems and garbage collectors. This is the case of Mono for Android where we now have a cooperative garbage collector that works hand-in-hand with Dalvik's GC. And we also introduce support for toggle references to better support Objective-C environments like MonoTouch and MonoMac. <h2>XNA and Mono: MonoGame</h2> <p><img src="http://tirania.org/s/2f9b5d8c.png" align="right">Ever since Microsoft published the XNA APIs for .NET, developers have been interested in bringing XNA to Mono-based platforms. <p>There was a MonoXNA project, which was later reused by projects like SilverXNA (an XNA implementation for Silverlight) and later XNAtouch an implementation of XNA for the iPhone powered by MonoTouch. Both very narrow projects focused on single platforms. <p>This year, the community got together and turned the single platform XNATouch into a full cross-platform framework, the result is the <a href="http://monogame.codeplex.com/">MonoGame project</a>: <center> <img src="http://tirania.org/s/62c8bebf.png"> <p>Platform Support Matrix </center> <p>Currently MonoGame's strength is on building 2D games. They already have an <a href="http://monogame.codeplex.com/">extensive list of</a> games that have been published on the iOS AppStore and the Mac AppStore and they were recently featured in Channel 9's <a href="http://channel9.msdn.com/coding4fun/blog/MonoGame-Write-Once-Play-Everywhere">Coding For Fun: MonoGame Write Once Play Everywhere</a>. <p>An early version of MonoGame/XnaTouch powers <a href="http://supergiantgames.com/">SuperGiantGame's</a> <a href="http://supergiantgames.com/?p=1231">Bastion</a> game on Google's Native Client. Which allows users of Windows, Mac and Linux desktop systems to run the same executable on all systems. If you are running Chrome, you can <a href="https://chrome.google.com/webstore/detail/oohphhdkahjlioohbalmicpokoefkgid">install it in seconds</a>. <center> <img src="http://tirania.org/s/39e2119a.png"> </center> <p>Incidentally, Bastion just won <a href="http://supergiantgames.com/?p=1261">three awards</a> at the <a href="http://en.wikipedia.org/wiki/Spike_Video_Game_Awards">Spike VGA awards</a> including Best Downloadable Game, Best Indie Game, and Best Original Score. <p>The MonoGame team had been relatively quiet for the most part of 2011 as they were building their platform, but they got into a good release cadence with the <a href="http://cocoa-mono.org/archives/400/monogame-goes-multi-platform-monogame-2-0-announced/">MonoGame 2.0</a> release in October, when they launched as a cross-platform engine, followed up with a tasty <a href="http://cocoa-mono.org/archives/452/monogame-takes-tentative-steps-into-3d-monogame-2-1-announced/">2.1 release</a> only two weeks ago. <p>With the addition of OpenGL ES 2.0 support and 3D capabilities to MonoGame, 2012 looks like it will be a great year for the project. <h2>Gtk+</h2> <p>Since MonoDevelop is built on top of the Gtk+ toolkit and since it was primarily a Unix toolkit there have been a few rough areas for our users in both Mac and Windows. <p>This year we started working with the amazing team at <a href="http://www.lanedo.com">Lanedo</a> to improve Gtk+ 2.x to work better on Mac and Windows. <p>The results are looking great and we want to encourage developers to try out our new <a href="http://www.go-mono.com/mono-downloads/download.html">Beta version of Mono</a>, which features the updated Gtk+ stack. <p>This new Gtk+ stack solves many of the problems that our users have reported over the past few months. <h2>Hosting Bills</h2> <p>I never tracked Mono downloads as I always felt that tracking download numbers for open source code that got repackaged and redistributed elsewhere pointless. <p>This summer we moved the code hosting from Novell to <a href="http://download.mono-project.com/archive/">Xamarin</a> and we were surprised by our hosting bills. <p>The major dominating force are binaries for Windows and MacOS which are communities that tend not to download source and package the software themselves. This is the breakdown for completed downloads (not partial downloads, or interrupted ones) for our first month of hosting of Mono: <ul> <li>39,646 - Mono for Windows (Runtime + SDK) <li>27,491 - Mono for Mac (Runtime) <li>9,803 - Mono for Windows (Runtime) <li>9,910 - Mono for Mac (Runtime + SDK) <br><br> <li>Total: 86,850 downloads for Windows and Mac </ul> <p>These numbers are only for the Mono runtime, not MonoDevelop, the MonoDevelop add-ins or any other third party software. <p>It is also worth pointing out that none of our Windows products (MonoDevelop for Windows, or Mono for Android on Windows) use the Mono runtime. So these downloads are for people doing some sort of embedding of Mono on their applications on Windows. <p>At this point, we got curious. We ran a survey for two days and collected 3,949 answers. These is the summary of the answers: <center> <img src="http://tirania.org/s/ca4988e1.png"> <p>What type of application will you run with Mono? </center> <p>This one was fascinating, many new users to the .NET world: <center> <img src="http://tirania.org/s/23a0c03a.png"> </center> <p>The best results came form the free-form answers in the form. I am still trying to figure out how to summarize these answers, they are all very interesting, but they are also all over the map. <h2>Some Key Quotes</h2> <p>When I asked last week for <a href="http://tirania.org/blog/archive/2011/Dec-15.html">stories of how you used Mono in 2011</a>, some of you posted on the thread, and some of you emailed me. <p>Here are a couple of quotes from Mono users: <blockquote> <p>I can't do without Mono and I don't just mean the iOS or Android dev with C# but MonoMac and Mono for *nix too. Thanks for everything; from the extraordinary tools to making hell turn into heaven, and thank you for making what used to be a predicament to effortless development pleasure. <p>I don't think we could have achieved our solutions without Mono in enterprise mobile development. It addresses so many key points, it is almost a trade secret. We extensively use AIR and JavaScript mobile frameworks too but ultimately we desperately need 1-to-1 mapping of the Cocoa Touch APIs or tap into low level features which determines our choice of development platform and frameworks. <p>That's where Mono comes in. <p>Gratefulness and paying polite respects aside, the key tenets of Mono we use are: <ul> <li>shared C# code base for all our enterprise solutions - achieving the write once, compile everywhere promise with modern language and VM features everyone demands and expects in this century <li>logical, consistent and self-explanatory wrapper APIs for native services - allows us to write meta APIs of our own across platforms <li>low latency, low overhead framework <li>professional grade IDE and tools <li>native integration with iOS tools and development workflow <li>existence of satisfactory documentation and support <li>legal clarity - favorable licensing options <li>dedicated product vision via Xamarin - commercial backing <li>community support </ul> </blockquote> <p>Koen Pijnenburg shared this story with me: <blockquote> <p>We've been in touch a few times before and would like to contribute my story. It's not really an interesting setup, but a real nice development for Mono(Touch). I've been developing app for iPhone since day 1, I was accepted in the early beta for the App Store. On launch day july 2008, 2 of the 500 apps in the App Store were mine, my share has decreased a lot in the past years ;) <p>I really, really, really like football(soccer), maybe you do also, I don't know. In september 2008 I created the first real soccer/football stats app for the iPhone called My Football. This was a huge succes, basically no competition at that time. In 2009 I released My Football Pro, an app with 800 leagues worldwide, including live data for more then 100 leagues. Since then I created lots of apps, all created with the iPhone SDK and with Objective-C. <p>Since the launch of MonoTouch, it merged the best of two worlds in my opinion. I've been a Mono/.NET developer for years before the iPhone apps, for me it was love at first line of code. <p>The last year I've increased my work with MonoTouch / Droid /MonoGame(Poppin' Frenzy etc ;)), and focused less on working with native SDK's only. Since our My Football apps are at the end of their lifecycle in this form, we are working on a new line of My Football apps. Our base framework supporting our data, is built with Mono, and the apps UI will be built with MonoTouch / MonoDroid / WP7 etc. <p>Included is the screenshot of our first app built with the framework, My Football Pro for iPad. It has a huge amount of data, stats / tables / matches / live data for more then 800 leagues worldwide. We think it's a great looking app! <p>Working with MonoTouch is fantastic and just wanted you to know this! </blockquote> <h2>Mono on Mainframes</h2> <p>This year turned out to show a nice growh in the deployment of Mono for IBM zSeries computers. <p>Some are using ASP.NET, some are using Mono in headless mode. This was something that we were advocating a few years ago, and this year the deployments went live both in Brazil and Europe. <p>Neale Ferguson from Sinenomine has kept the zSeries port active and in shape. <h2>Mono and ASP.NET</h2> <p>This year we delivered enough of ASP.NET 4.0 to run Microsoft's ASP.NET MVC 3. <p>Microsoft ASP.NET MVC 3 is a strange beast. It is licensed under a great open source license (MS-PL) but the distribution includes a number of binary blobs (the Razor engine). <p>I am inclined to think that the binaries are not under the MS-PL, but strictly speaking, since the binaries are part of the MS-PL distribution labeled as such, the entire download is MS-PL. <p>That being said, we played it safe in Mono-land and we did not bundle ASP.NET MVC3 with Mono. Instead, we provide <a href="http://www.mono-project.com/Release_Notes_Mono_2.10#ASP.NET_MVC3_Support">instructions on how users can deploy ASP.NET MVC 3 applications</a> using Razor as well as pure Razor apps (those with .cshtml extensions) with Mono. <h2>2012, the year of Mono 2.12</h2> <p>2012 will be a year dominated by our upcoming Mono release: Mono 2.12. It packs a year worth of improvements to the runtime, to our build process and to the API profiles. <p>Mono 2.12 defaults to the .NET 4.x APIs and include support for .NET 4.5. <p>This is going to be the last time that we branch Mono for these extended periods of time. We are <a href="http://tirania.org/blog/archive/2011/Oct-14.html">changing our development process and release policies</a> to reduce the amount of code that is waiting on a warehouse to be rolled out to developers. <h2>ECMA</h2> <p>We wrapped up our work on updating the <a href="http://www.ecma-international.org/publications/standards/Ecma-335.htm">ECMA CLI standard this year</a>. The resulting standard is now at ISO and going through the standard motions to become an official ISO standard. <p>The committee is getting ready for a juicy year ahead of us where we are shifting gears from polish/details to take on significant extensions to the spec. http://tirania.org/blog/archive/2011/Dec-21.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Dec-21.html Wed, 21 Dec 2011 19:47:00 -0500 CXXI: Bridging the C++ and C# worlds. <p>The Mono runtime engine has many language interoperability features but has never had a strong story to interop with C++. <p>Thanks to the work of Alex Corrado, Andreia Gaita and Zoltan Varga, this is about to change. <p>The short story is that the new <a href="http://github.com/mono/cxxi">CXXI</a> technology allows C#/.NET developers to: <ul> <li>Easily consume existing C++ classes from C# or any other .NET language <li>Instantiate C++ objects from C# <li>Invoke C++ methods in C++ classes from C# code <li>Invoke C++ inline methods from C# code (provided your library is compiled with -fkeep-inline-functions or that you provide a surrogate library) <li>Subclass C++ classes from C# <li>Override C++ methods with C# methods <li>Expose instances of C++ classes or mixed C++/C# classes to both C# code and C++ as if they were native code. </ul> <p>CXXI is the result of two summers of work from Google's Summer of Code towards improving the interoperability of Mono with the C++ language. <h2>The Alternatives</h2> <p>This section is merely a refresher of of the underlying technologies for interoperability supported by Mono and how developers coped with C++ and C# interoperability in the past. You can skip it if you want to get to how to get started with CXXI. <p>As a reminder, Mono provides a number of interoperability bridges, mostly inherited from the ECMA standard. These bridges include: <ul> <li>The bi-directional "Platform Invoke" technology (P/Invoke) which allows managed code (C#) to call methods in native libraries as well as support for native libraries to call back into managed code. <li><a href="http://www.mono-project.com/COM_Interop">COM Interop</a> which allows Mono code to transparently call C or C++ code defined in native libraries as long as the code in the native libraries follows a few COM conventions [1]. <li>A general <a href="http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject(v=VS.80).aspx">interceptor</a> technology that can be used to intercept method invocations on objects. </ul> <p>When it came to getting C# to consume C++ objects the choices were far from great. For example, consider a sample C++ class that you wanted to consume from C#: <pre> class MessageLogger { public: MessageLogger (const char *domain); void LogMessage (const char *msg); } </pre> <p>One option to expose the above to C# would be to wrap the Demo class in a COM object. This might work for some high-level objects, but it is a fairly repetitive exercise and also one that is devoid of any fun. You can see how this looks like in the <a href="http://www.mono-project.com/COM_Interop">COM Interop</a> page. <p>The other option was to produce a C file that was C callable, and invoke those C methods. For the above constructor and method you would end up with something like this in C: <pre> /* bridge.cpp, compile into bridge.so */ MessageLogger *Construct_MessageLogger (const char *msg) { return new MessageLogger (msg); } void LogMessage (MessageLogger *logger, const char *msg) { logger->LogMessage (msg); } </pre> <p>And your C# bridge, like this: <pre> class MessageLogger { IntPtr handle; [DllImport ("bridge")] extern static IntPtr Construct_MessageLogger (string msg); public MessageLogger (string msg) { handle = Construct_MessageLogger (msg); } [DllImport ("bridge")] extern static void LogMessage (IntPtr handle, string msg); public void LogMessage (string msg) { LogMessage (handle, msg); } } </pre> <p>This gets tedious very quickly. <p>Our <a href="http://tirania.org/blog/archive/2009/Jun-08.html">PhyreEngine#</a> binding was a C# binding to Sony's PhyreEngine C++ API. The code got very tedious, so we built a poor man's code generator for it. <p>To make things worse, the above does not even support overriding C++ classes with C# methods. Doing so would require a whole load of manual code, special cases and callbacks. The code quickly becomes very hard to maintain (as we found out ourselves with PhyreEngine). <p>This is what drove the motivation to build CXXI. <p>[1] The conventions that allow Mono to call unmanaged code via its COM interface are simple: a standard vtable layout, the implementation of the Add, Release and QueryInterface methods and using a well defined set of types that are marshaled between managed code and the COM world. <h2>How CXXI Works</h2> <p>Accessing C++ methods poses several challenges. Here is a summary of the components that play a major role in CXXI: <ul> <li><b>Object Layout:</b> this is the binary layout of the object in memory. This will vary from platform to platform. <li><b>VTable Layout:</b> this is the binary layout that the C++ compiler will use for a given class based on the base classes and their virtual methods. <li><b>Mangled names:</b> non-virtual methods do not enter an object vtable, instead these methods are merely turned into regular C functions. The name of the C functions is computed based on the return type and the parameter types of the method. These vary from <a href="http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B">compiler to compiler</a>. </ul> <p>For example, given this C++ class definition, with its corresponding implementation: <pre> class Widget { public: void SetVisible (bool visible); virtual void Layout (); virtual void Draw (); }; class Label : public Widget { public: void SetText (const char *text); const char *GetText (); }; </pre> <p>The C++ compiler on my system will generate the following mangled names for the SetVisble, Layout, Draw, SetText and GetText methods: <pre> __ZN6Widget10SetVisibleEb __ZN6Widget6LayoutEv __ZN6Widget4DrawEv __ZN5Label7SetTextEPKc __ZN5Label7GetTextEv </pre> <p>The following C++ code: <pre> Label *l = new Label (); l->SetText ("foo"); l->Draw (); </pre> <p>Is roughly compiled into this (rendered as C code): <pre> Label *l = (Label *) malloc (sizeof (Label)); ZN5LabelC1Ev (l); // Mangled name for the Label's constructor _ZN5Label7SetTextEPKc (l, "foo"); // This one calls draw (l->vtable [METHOD_PTR_SIZE*2])(); </pre> <p>For CXXI to support these scenarios, it needs to know the exact layout for the vtable, to know where each method lives and it needs to know how to access a given method based on their mangled name. <p>The following chart explains shows how a native C++ library is exposed to C# or other .NET languages: <center> <img src="http://tirania.org/s/3add594b.png"> </center> <p>Your C++ source code is compiled twice. Once with the native C++ compiler to generate your native library, and once with the CXXI toolchain. <p>Technically, CXXI only needs the header files for your C++ project, and only the header files for the APIs that you are interested in wrapping. This means that you can create bindings for C++ libraries that you do not have the source code to, but have its header files. <p>The CXXI toolchain produces a .NET library that you can consume from C# or other .NET languages. This library exposes a C# class that has the following properties: <ul> <li>When you instantiate the C# class, it actually instantiates the underlying C++ class. <li>The resulting class can be used as the base class for other C# classes. Any methods flagged as virtual can be overwritten from C#. <li>Supports C++ multiple inheritance: The generated C# classes expose a number of cast operators that you can use to access the different C++ base classes. <li>Overwritten methods can call use the "base" C# keyword to invoke the base class implementation of the given method in C++. <li>You can override any of the virtual methods from classes that support multiple inheritance. <li>A convenience constructor is also provided if you want to instantiate a C# peer for an existing C++ instance that you surfaced through some other mean. </ul> <p>This is pure gold. <p><img src="http://tirania.org/s/220882cf.png" align="right">The CXXI pipeline in turn is made up of three components, as shown in the diagram on the right. <p>The GCC-XML compiler is used to parse your source code and extract the vtable layout information. The generated XML information is then processed by the CXXI tooling to generate a set of partial C# classes that contain the bridge code to integrate with C++. <p>This is then combined with any customization code that you might want to add (for example, you can add some overloads to improve the API, add a ToString() implementation, add some async front-ends or dynamic helper methods). <p>The result is the managed assembly that interfaces with the native static library. <p>It is important to note that the resulting assembly (Foo.dll) does not encode the actual in-memory layout of the fields in an object. Instead, the CXXI binder determines based on the ABI being used what the layout rules for the object are. This means that the Foo.dll is compiled only once and could be used across multiple platforms that have different rules for laying out the fields in memory. <h2>Demos</h2> <p>The code on <a href="http://github.com/mono/cxxi">GitHub</a> contains various test cases as well as a couple of examples. One of the samples is a minimal binding to the Qt stack. <h2>Future Work</h2> <p>CXXI is not finished, but it is a strong foundation to drastically improve the interoperability between .NET managed languages and C++. <p>Currently CXXI achieves all of its work at runtime by using System.Reflection.Emit to generate the bridges on demand. This is useful as it can dynamically detect the ABI used by a C++ compiler. <p>One of the projects that we are interested in doing is to add support for static compilation, this would allow PS3 and iPhone users to use this technology. It would mean that the resulting library would be tied to the platform on which the CXXI tooling was used. <p>CXXI currently implements support for the GCC ABI, and has some early support for the MSVC ABI. Support for other compiler ABIs as well as for completing the MSVC ABI is something that we would like help with. <p>Currently CXXI only supports deleting objects that were instantiated from managed code. Other objects are assumed to be owned by the unmanaged world. Support for the delete operator is something that would be useful. <p>We also want to better document the pipeline, the runtime APIs and improve the binding. http://tirania.org/blog/archive/2011/Dec-19.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Dec-19.html Mon, 19 Dec 2011 13:28:00 -0500 2011: Tell me how you used Mono this year <p>I have written a summary of Mono's progress in the year 2011, but I want to complement my post with stories from the community. <p>Did you use Mono in an interesting setup during 2011? Please post a comment on this post, or email me the story and tell me a little bit about it. http://tirania.org/blog/archive/2011/Dec-15.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Dec-15.html Fri, 16 Dec 2011 00:55:00 -0500 Porto Alegre <p>We are traveling to Porto Alegre in Brazil today and will be staying in Brazil until January 4th. <p>Ping me by email (miguel at gnome dot org) if you would like to meet in Porto Alegre to talk hacking, Mono, Linux, open source, iPhone or if you want to enlighten me about the role of scrum masters as actors of social change. <p>Happy holidays! http://tirania.org/blog/archive/2011/Dec-14.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Dec-14.html Wed, 14 Dec 2011 14:30:00 -0500 Farewell to Google's CodeSearch <p>It seems that part of Steve Jobs' legacy was to give Larry Page some advise: focus. This according to Steve Jobs' recently published biography. <p>So Larry Page took the advise seriously and decided to focus. His brand of focus is to kill projects that were distracting to their goals. One of them, -and the one I cared the most about- was <a href="http://googleblog.blogspot.com/2011/10/fall-sweep.html">CodeSearch</a>.. <h2>What did CodeSearch do for programmers?</h2> <p>The CodeSearch service was a unique tool as it indexed open source code in the wild. <p>Codesearch is one of the most valuable tools in existence for all software developers, specifically: <ul> <li>When an API is poorly documented, you could find sample bits of code that used the API. <li>When an API error codes was poorly documented, you could find sample bits of code that handled it. <li>When an API was difficult to use (and the world is packed with those), you could find sample bits of code that used it. <li>When you quickly wanted to learn a language, you knew you could find quality code with simple searches. <li>When you wanted to find different solutions to everyday problems dealing with protocols, new specifications, evolving standards and trends. You could turn to CodeSearch. <li>When you were faced with an obscure error message, an obscure token, an obscure return value or other forms of poor coding, you would find sample bits of code that solved this problem. <li>When dealing with proprietary protocols or just poorly documented protocols, you could find how they worked in minutes. <li>When you were trying to debug yet another broken standard or yet another poorly specified standard, you knew you could turn quickly to CodeSearch to find the answers to your problems (memories of OAuth and IMAP flash in my head). <li>When learning a new programming language or trying to improve your skills on a new programming language, you could use CodeSearch to learn the idioms and the best (and worst practices). <li>When building a new version of a library, either in a new language, making a fluent version, making an open source version, building a more complete version you would just go to Codesearch to find answers to how other people did things. </ul> <p>It is a shame that Google is turning their back on their officially stated mission <a href="http://www.google.com/about/corporate/company/">"To organize the world‘s information and make it universally accessible and useful".</a> It is a shame that this noble goal is not as important as competing with Apple, Facebook, Microsoft, Twitter and Yelp. <h2>Comparing Search Engines</h2> <p>While writing this blog entry, I fondly remembered how Codesearch helped me understand the horrible Security framework that ships with iOS. Nobody informed the Apple engineers that "Security through obscurity" was not intended for their developer documentation. <p>In this particular case, I was trying to understand the semantics of <tt>kSecReturnData</tt>. How to use this constant and how it interacts with the keyring system is both tricky, and poorly specified in Apple's docs. Sometimes things fail without any indication of what went wrong, other than "error". So I used CodeSearch to figure this out (along with some other 30 constants and APIs in that library that are just as poorly documented). <p>These are the results of looking for this value in three search engines as of this morning. <h3>First Contender: GrepCode</h3> <p><a href="http://www.grepcode.com">GrepCode</a> shows absolutely nothing relevant. But shows a bunch of Java packages with no context, no code snippets and if you make the mistake of drilling down, you wont find anything: <center><img src="http://tirania.org/s/668f579c.png"> </center> <p>Not useful. <h3>Second Contender: Codease</h3> <p><a href="http://www.codase.com">Codase</a> is indexing 250 million lines of code, usually it takes minutes to get this page: <center> <img src="http://tirania.org/s/ab8ab54f.png"> </center> <p>Maybe the server will come back up. <h3>Third Contender: Koders</h3> <p><A href="http://www.koders.com">Koders</a> is part of Black Duck, and searching for the term renders a bunch of matches. Not a single one of the results displayed actually contain a single use of the kSecReturnData constant. And not a single one of the snippets actually show the kSecReturnData constant. It is as useful as configuring your browser to use StumbleUpon as your search engine: <center> <img src="http://tirania.org/s/e1bffde7.png"> </center> <p>Not useful. <h3>Google's CodeSearch</h3> <p>And this is what Codesearch shows: <center> <img src="http://tirania.org/s/20e4f136.png"> </center> <p>The big innovation on Google's search engine is that it actually works and shows real matches for the text being searched, with a relevant snippet of the information you are looking for. <p>We are going to be entering the dark ages of software research in the next few months. <h2>Is there a hacker White Knight out there?</h2> <p>Running a service like Codesearch is going to take a tremendous amount of resources. There are major engineering challenges involved and hosting a service like this can not be cheap. It is probably not even profitable. <p>Larry Page's Google has already dropped the project. We can only hope that in a few years Sergey Brin's Google or Eric Schmidt's Google will bring this service back. <p>Microsoft is too busy catching up to Google and wont have any spare resources to provide a Bing for code search. And if they did, they would limit the search to Win32 APIs. <h2>Thanks!</h2> <p>I should thank Google for funding that project for as long as they did as well as the Google engineers that worked on it as long as they could. Over the years, it helped me fix problems in a fraction of the time and helped me understand complicated problems in minutes. <p>The Google engineers whose projects just got shutdown for in the name of strategy and focus are probably as sad as all of us are. <p>On the plus side, I get to share this rant on Google Plus with a dozen of my friends! http://tirania.org/blog/archive/2011/Nov-29.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Nov-29.html Wed, 30 Nov 2011 04:44:00 -0500 Updated Documentation Site <p>Jeremie Laval has upgraded our Web-based documentation engine over at <a href="http://docs.go-mono.com">docs.go-mono.com</a>. This upgrade brings a few features: <p><b>New Look:</b> Base on Jonathan Pobst's redesign, this is what our documentation looks like now: <center> <a href="http://docs.go-mono.com/?link=N%3aMonoTouch.CoreImage"><img src="http://tirania.org/s/25d86560.png"></a> </center> <p><b>Better Links:</b> Links to pages on the site will now properly open the left-side tree to the documentation you linked to. This has been an open request for about six years, and it got finally implemented. <p><b>Search:</b> the search box on the web site uses Lucene to search the text on the server side, and shows you the matching results as you type: <img src="http://tirania.org/s/2f2389f0.png"> <p><b>Easier to Plug:</b> MonoDoc/Web now easily supports loading documentation from alternate directories, it is no longer limited to loading the system-configured documentation. <p><b>No more frames:</b> For years we used frames for the documentation pages. They had a poor experience and made the code uglier. They are now gone. <p><b>Powered by Mono's SGen:</b> We have reduced the memory consumption of our web documentation by switching to Mono's <a href="http://mono-project.com/Generational_GC">Generational GC</a> from Boehm's. The load on the server is lower, responses are faster and we scale better. <p>The source code changes are now on GitHub in the <a href="https://github.com/mono/mono-tools/tree/master/webdoc">webdoc</a> module. <p>We have also added Google Analytics support to our web site to help us determine which bits of documentation are more useful to you. http://tirania.org/blog/archive/2011/Nov-22.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Nov-22.html Tue, 22 Nov 2011 15:34:00 -0500 Hiring Mono Runtime Hackers <p>As Mono grows on servers, mobile and desktop platforms, we are looking to hire programmers to join our Mono Runtime team. <p>The Mono Runtime team owns the code generator, the just-in-time and ahead-of-time compilers, the garbage collector, the threadpool and async layers in the runtime and mostly works in the C-side of the house. <p>If you are a developer with low-level experience with virtual machines, just in time compilers or love garbage collection, real time processing, or you read every new research paper on incremental garbage collection, hardware acceleration, register allocation and you are interested in joining our young, self-funded and profitable startup, we want to hear from you. <p>Send your resumes to jobs@xamarin.com http://tirania.org/blog/archive/2011/Oct-18.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Oct-18.html Tue, 18 Oct 2011 15:25:00 -0500 Upcoming Mono Releases: Change in Policies <p>We have historically made stable releases of Mono that get branched and maintained for long periods of time. During these long periods of time, we evolve our master release for some four to five months while we do major work on the branch. <p>Historically, we have had done some of these large changes since we have rewritten or re-architected large parts of our JIT, or our garbage collector, or our compilers. <p>There were points in the project history where it took us some 9 months to release: seven months of new development followed by two months of beta testing and fixing regressions. With Mono 2.6 we tried to change this, we tried to close the release time to at most six months, and we were relatively good at doing this with 2.8 and 2.10. <p>We were on track to do a quick Mono 2.12 release roughly around May, but with the April bump in the road, this derailed our plans. <p>Since 2.10.0 was released two things happened: <ul> <li><b>On Master:</b> plenty of feature work and bug fixing. <li><b>On our 2.10 branch:</b> bug fixes and backporting fixes from master to 2.10 </ul> <p>Now that things have settled at Xamarin and that we are getting Mono back into continuous integration builds we are going to release our first public beta of the upcoming Mono, it will be called Mono 2.11.1. We will keep it under QA until we are happy with the results and we will then release Mono 2.12 based on this. <p>But after Mono 2.12, we want to move to a new development model where we keep our master branch always in a very stable state. This means that new experimental features will be developed in branches and only landed to the master branch once they have been completed. <p>Our goal is to more quickly bring the features that we are developing to our users instead of having everyone wait for very long periods of time to get their new features. <h3>New Features in Mono 2.11</h3> <p>These are some of the <a href="http://www.mono-project.com/Release_Notes_Mono_2.12">new features availalable in Mono 2.11</a>: <ul> <li>We refactored our C# compiler to have two backends one based on Cecil, one based on Reflection.Emit. Fixing some important usability properties of our compiler. <li>Implemented C# 5 Async. <li>Our C# compiler has TypedReference support (__refvalue, __reftype and __makeref). <li>Our compiler as a service can compile classes now and has an instance API (instantiate multiple C# compiler contexts independently). <li>Added the .NET 4.5 API profile and many of the new async APIs to use with C# 5. <li>Improved our new Garbage Collector: it is faster, it is more responsive and it is more stable. It has also gained MacOS/iOS native support. <li>We made System.Json available on every profile. <li>We added <a href="http://msdn.microsoft.com/en-us/library/gg597391.aspx">Portable Class Library</a> support. <li>We added tooling for Code Contracts <li>We added a TPL Dataflow implementation <li>We added fast ThreadLocal<T> support <li>We brought our ASP.NET implementation to the year 2011 and it now sports a new enormously cute error page as opposed to that error page that we have which transports you mind back to 1999. <li>Mono's debugger now supports attaching to a live process (deferred support) <li>Our socket stack is faster on BSD and OSX, by using kqueue (on Linux it uses epoll already). </ul> http://tirania.org/blog/archive/2011/Oct-14.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Oct-14.html Fri, 14 Oct 2011 15:31:00 -0500 WinRT and Mono <p>Today Joseph mentioned to me that some of our users got the impression from my previous post on WinRT that we would be implementing WinRT for Linux. We are not working on a WinRT UI stack for Linux, and do not have plans to. <p>WinRT is a fabulous opportunity for Mono, because Microsoft is sending a strong message: if you want your code to run in multiple scenarios (server, desktops, sandboxed environments), you want to split your UI code from your backend code. <p>This is great because it encourages developers to think in terms of having multiple facades for the same code base and the direction that we have been taking Mono on in the last few years. <p>Use the native toolkit on each platform to produce an immersive user experience, and one that leverages the native platform in the best possible way. <p>These are the APIs that we envision .NET developers using on each platform: <ul> <li>Windows: WinRT, Winforms, WPF (fallbacks: Gtk#, Silverlight) <li>MacOS: MonoMac (fallback: Gtk#, Silverlight) <li>Linux: Gtk# <li>Android: MonoDroid APIs <li>iOS: MonoTouch <li>Windows Phone 7: Silverlight <li>XBox360: XNA-based UI </ul> <p>Even if a lot of code could be reused from Moonlight, WinRT is a moving target. It is not clear that the Linux desktop, as we know it today, is keeping up with the growth of other consumer environments. I <a href="http://www.itwriting.com/blog/4925-miguel-de-icaza-talks-about-windows-8-and-the-failure-of-linux-on-the-desktop.html">talked to Tim</a> about this at Build. <h2>Head-less WinRT</h2> <p>There are some GUI-less components of WinRT that *do* make sense to bring to Mono platforms. There is already an <a href="https://github.com/ermau/WinRT.NET">implementation of some bits</a> of the headless WinRT components being done by Eric. <p>The above effort will enable more code sharing to take place between regular .NET 4 apps, WP7 apps, Mono apps and WinRT apps. http://tirania.org/blog/archive/2011/Sep-26.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Sep-26.html Tue, 27 Sep 2011 01:04:00 -0500 WinRT demystified <p>Windows 8 as introduced at Build is an exciting release as it has important updates to how Microsoft envisions users will interact with their computers, to a fresh new user interface to a new programming model and a lot more. <p>If you build software for end-users, you should <a href="http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1004">watch Jensen Harris</a> discuss the Metro principles in Windows 8. I find myself wanting to spend time using Windows 8. <p>But the purpose of this post is to share what I learned at the conference specifically about WinRT and .NET. <h2>The Basics</h2> <p>Microsoft is using the launch of Windows 8 as an opportunity to fix long-standing problems with Windows, bring a new user interface, and enable a safe AppStore model for Windows. <p>To do this, they have created a third implementation of the XAML-based UI system. Unlike WPF which was exposed only to the .NET world and Silverlight which was only exposed to the browser, this new implementation is available to C++ developers, HTML/Javascript developers and also .NET developers. <p>.NET developers are very familiar with P/Invoke and COM Interop. Those are two technologies that allow a .NET developer to consume an external component, for example, this is how you would use the libc "system (const char *)" API from C#: <pre> [DllImport ("libc")] void system (string command); [...] system ("ls -l /"); </pre> <p>We have used P/Invoke extensively in the Mono world to create bindings to native libraries. Gtk# binds the Gtk+ API, MonoMac binds the Cocoa API, Qyoto binds the Qt API and hundred other bindings wrap other libraries that are exposed to C# as object-oriented libraries. <p>COM Interop allows using C or C++ APIs directly from C# by importing the COM type libraries and having the runtime provide the necessary glue. This is how Mono talked with OpenOffice (which is based on COM), or how Mono talks to VirtualBox (which has an XPCOM based API). <p>There are many ways of creating bindings for a native library, but doing it by hand is bound to be both tedious and error prone. So everyone has adopted some form of "contract" that states what the API is, and the binding author uses this contract to create their language binding. <h2>WinRT</h2> <p>WinRT is a new set of APIs that have the following properties: <ul> <li>It implements the new Metro look. <li>Has a simple UI programming model for Windows developers (You do not need to learn Win32, what an HDC, WndProc or LPARAM is). <li>It exposes the WPF/Silverlight XAML UI model to developers. <li>The APIs are all designed to be asynchronous. <li>It is a sandboxed API, designed for creating self-contained, AppStore-ready applications. You wont get everything you want to create for example Backup Software or Hard Disk Partitioning software. <li>The API definitions is exposed in the ECMA 335 metadata format (the same one that .NET uses, you can find those as ".winmd" files). </ul> <p>WinRT wraps both the new UI system as well as old Win32 APIs and it happens that this implementation is based on top of COM. <h3>WinRT Projections</h3> <p>What we call "bindings" Microsoft now calls "projections". Projections are the process of exposing APIs to three environments: Native (C and C++), HTML/Javascript and .NET. <li>If you author a component in C++ or a .NET language, its API will be stored in a WinMD file and you will be able to consume it from all three environments (Native, JavaScript and .NET). <p>Even in C++ you are not exposed to COM. The use of COM is hidden behind the C++ projection tools. You use what looks and feels like a C++ object oriented API. <p>To support the various constructs of WinRT, the underlying platform defines a basic set of types and their mappings to various environment. In particular, collection objects in WinRT are mapped to constructs that are native to each environment. <h2>Asynchronous APIs</h2> <p>Microsoft feels that when a developer is given the choice of a synchronous and an asynchronous API, developers will choose the simplicity of a synchronous API. The result usually works fine on the developer system, but is terrible when used in the wild. <p>With WinRT, Microsoft has followed a simple rule: if an API is expected to take more than 50 milliseconds to run, the API is asynchronous. <p>The idea of course is to ensure that every Metro application is designed to always respond to user input and to not hang, block or provide a poor user experience. <p>Async programming has historically been a cumbersome process as callbacks and state must be cascaded over dozens of places and error handling (usually poor error handling) is sprinkled across multiple layers of code. <p>To simplify this process, C# and VB have been extended to support the F#-inspired await/async pattern, turning async programming into a joy. C++ got a setup that is as good as you can get with C++ lambdas and Javascript uses promises and "then ()". <h2>Is it .NET or Not?</h2> <p>Some developers are confused as to whether .NET is there or not in the first place, as not all of the .NET APIs are present (File I/O, Sockets), many were moved and others were introduced to integrate with WinRT. <p>When you use C# and VB, you are using the full .NET framework. But they have chosen to expose a smaller subset of the API to developers to push the new vision for Windows 8. <p>And this new vision includes safety/sandboxed systems and asynchronous programming. This is why you do not get direct file system access or socket access and why synchronous APIs that you were used to consuming are not exposed. <p>Now, you notice that I said "exposed" and not "gone". <p>What they did was that they only exposed to the compiler a set of APIs when you target the Metro profile. So your application will not accidentally call File.Create for example. At runtime though, the CLR will load the full class library, the very one that contains File.Create, so internally, the CLR could call something like File.Create, it is just you that will have no access to it. <p>This split is similar to what has been done in the past with Silverlight, where not every API was exposed, and where mscorlib was given rights that your application did not have to ensure the system safety. <p>You might be thinking that you can use some trick (referencing the GAC library instead of the compiler reference or using reflection to get to private APIs, or P/Invoking into Win32). But all of those uses will be caught by AppStore review application and you wont be able to publish your app through Microsoft's store. <p>You can still do whatever ugly hack you please on your system. It just wont be possible to publish that through the AppStore. <p>Finally, the .NET team has taken this opportunity to do some spring cleaning. mscorlib.dll and System.dll have been split in various libraries and they have moved some types around. <h2>Creating WinRT Components</h2> <p>Microsoft demoed creating new WinRT components on both C++ and .NET. <p>In the .NET case, creating a WinRT component has been drastically simplified. The following is the full source code for a component that adds 2: <pre> public sealed class AddTwo { public int Add (int a, int b) { return a + b; } public async IAsyncOperation<int> SubAsync (int a, int b) { return a - await (CountEveryBitByHand (b)); } } </pre> <p>You will notice that there are no COM declarations of any kind. The only restriction is that your class must be sealed (unless you are creating a XAML UI component, in that case the restriction is lifted). <p>There are also some limitations, you can not have private fields on structures, and there is not Task&lt;T&gt; for asynchronous APIs, instead you use the IAsyncOperation interface. <b>Update to clarify: the no private fields rule is only limited to structs exposed to WinRT, and it does not apply to classes.</b> <h2>UI Programming</h2> <p>When it comes to your UI selection, you can either use HTML with CSS to style your app or you can use XAML UI. <p>To make it easy for HTML apps to adhere to the Metro UI style and interaction model, Microsoft distributes Javascript and CSS files that you can consume from your project. Notice that this wont work on the public web. As soon as you use any WinRT APIs, your application is a Windows app, and wont run in a standalone web browser. <p>.NET and C++ developers get to use XAML instead. <p>There is clearly a gap to be filled in the story. It should be possible to use Microsoft's Razor formatting engine to style applications using HTML/CSS while using C#. Specially since they have shown the CLR running on their HTML/JS Metro engine. <p>Right now HTML and CSS is limited to the Javascript use. <h2>In Short</h2> <p>Microsoft has created a cool new UI library called WinRT and they have made it easy to consume from .NET, Javascript and C++ and if you adhere by their guidelines, they will publish the app on their appstore. <h2>Xamarin at BUILD</h2> <p>If you are at build, come <a href="http://tirania.org/blog/archive/2011/Sep-14.html">join us tonight at 6:30</a> at the Sheraton Park hotel, just after Meet the Experts. Come talk about Mono, Xamarin, MonoTouch, MonoDroid and MonoMac and discuss the finer points of this blog over an open bar. <h2>Comments</h2> <p>There is a long list of comments in the moderation queue that are not directly related to WinRT, or bigger questions that are not directly related to WinRT, .NET and this post's topic, so I wont be approving those comments to keep things on focus. There are better forums to have discussions on Metro. http://tirania.org/blog/archive/2011/Sep-15.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Sep-15.html Fri, 16 Sep 2011 01:03:00 -0500 Xamarin and Mono at the BUILD Conference <center> <img src="http://xamarin.files.wordpress.com/2011/09/flyer-web.jpg?w=700&h=295"> </center> <p>Continuing our tradition of getting together with Mono users at Microsoft conferences, we are going to be hosting an event at the Sheraton Hotel next to the conference on Thursday at 6:30pm (just after Ask the Experts). <p>Come join us with your iOS, Android, Mac and Linux questions. http://tirania.org/blog/archive/2011/Sep-14.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Sep-14.html Wed, 14 Sep 2011 16:07:00 -0500 MonoDevelop 2.6 is out <p>Lluis just released the final version of MonoDevelop 2.6. <p>This release packs a <a href="http://monodevelop.com/Download/What's_new_in_MonoDevelop_2.6">lot of new features</a>, some of my favorite features in this release are: <ul> <li>Git support. <ul> <li>It not only provides the regular source code control commands, it adds full support for the various Git idioms not available in our Subversion addin. <li>Based on Java's JGit engine <li>Ported to C# using db4Object's sharpen tool. Which Lluis <a href="https://github.com/slluis/sharpen">updated significantly</a> <li>Logging and Blaming are built into the editor. <center> <img src="http://monodevelop.com/@api/deki/files/308/=md26-ChangesView.png" width="540"> </center> </ul> <li>Mac support: <ul> <li>Our fancy <a href="http://www.mono-project.com/MonoMac">MonoMac</a> support lets you build native Cocoa applications. If you have not jumped into this Steve Jobs Love Fest, you can get started with our built-in templates and our <a href="http://docs.go-mono.com/index.aspx?link=root:/monomac-lib">online API documentation</a>. <li>Native File Dialogs! We now use the operating system file dialogs, and we even used our own MonoMac bindings to get this done. <li>You can also check my <a href="http://tirania.org/monomac">Mac/iOS-specific blog for more details</a>. </ul> <li>Unified editor for Gtk#, ASP.NET, MonoTouch and MonoDroid: we no longer have to track various forks of MonoDevelop, they have all converged into one tree. </ul> <p>The above is just a taste of the new features in MonoDevelop 2.6. There are <a href="http://monodevelop.com/index.php?title=Download/What's_new_in_MonoDevelop_2.6">many more</a> nominate your own! <p>Congratulations to the MonoDevelop team on the great job they did! <p>And I want to thank everyone that contributed code to MonoDevelop, directly or indirectly to make this happen. http://tirania.org/blog/archive/2011/Sep-07.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Sep-07.html Wed, 07 Sep 2011 21:11:00 -0500 Learning Unix <p>As I meet new Unix hackers using Linux or Mac, sometimes I am surprised at how few Unix tricks they know. It is sometimes painful to watch developers perform manual tasks on the shell. <p>What follows are my recommendations on how to improve your Unix skills, with a little introduction as to why you should get each book. I have linked to each one of those books with my Amazon afiliates link, so feel free to click on those links liberally. <p>Here is the list of books that programmers using Unix should read. It will only take you a couple of days to read them, but you will easily increase your productivity by a whole order of magnitude. <h3>The Basics</h3> <iframe align="right" src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=tiraniaorg-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=013937681X" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> <p>The <a href="http://www.amazon.com/gp/product/013937681X/ref=as_li_ss_tl?ie=UTF8&tag=tiraniaorg-20&linkCode=as2&camp=217145&creative=399369&creativeASIN=013937681X">Unix Programming Environment</a> by Kernighan and Pike is a must-read. Although this is a very old book and it does not cover the fancy new features in modern versions of Unix, no other book covers in such beauty the explanation of the shell quoting rules, expansion rules, shell functions and the redirection rules. <p>Every single thing you do in Unix will use the above in some form or shape, and until you commit those to memory you will be a tourist, and not a resident. <p>Then you will learn sed and basic awk, both tools that you will use on a daily basis once you become proficient. You do not have to ever be scared of sed or regular expressions anymore. <p>Save yourself the embarrassment, and avoid posting on the comments section jwz's quote on regular expressions. You are not jwz. <p>It will take you about a week of commuting by bus to read it. You do not have to finish the book, you can skip over the second part. <h3>Unix Boot Camp</h3> <iframe align="right" src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=tiraniaorg-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=0201823764" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe> <p>While Kernighan's book is basic literacy, you need to develop your muscles and you need to do this fast and not buy a book so thick and so packed with ridiculous screenshots that you will never get past page 20. <p>Get <a href="http://www.amazon.com/gp/product/0201823764/ref=as_li_ss_tl?ie=UTF8&tag=tiraniaorg-20&linkCode=as2&camp=217145&creative=399369&creativeASIN=0201823764">UNIX for the Impatient</a>. This book is fun, compact and is packed with goodies that will make you enjoy every minute in Unix. <h3>Learn Emacs</h3> <p>Emacs has had a strong influence in Unix over the years. If you learn to use Emacs, you will automatically learn the hotkeys and keybindings in hundreds of applications in Unix. <p>The best place to learn Emacs is to launch Emacs and then press Control-h and then t. This is the online tutorial and it will take you about two hours to complete. <p>The knowledge that you will gain from Emacs will be useful for years to come. You will thank me. And you will offer to buy me a beer, which I will refuse because I rather have you buy me a freshly squeezed orange juice. <h3>Tooting my own horn</h3> <p>Learn to use the Midnight Commander. <p>The Midnight Commander blends the best of both worlds: GUI-esque file management with full access to the Unix console. <p>The Midnight Commander is a console application that shows 2 panels listing two different directories side-by-side and provides a command line that is fed directly to the Unix shell. <center> <a href="http://www.gnu.org/s/mc/images/mc-panels.png"> <img src="http://www.gnu.org/s/mc/images/mc-panels.png" width="640"> </a> </center> <p>The basics are simple: use the arrow keys to move around, Control-S to do incremental searches over filenames, Control-t to tag or untag files and the F keys to perform copy, move or delete operations. Copy and Move default to copy to the other panel (which you can conveniently switch to by pressing the tab key). <p>There is no better way of keeping your file system organized than using my file manager. <h3>Becoming a Power User</h3> <p><iframe src="http://rcm.amazon.com/e/cm?lt1=_blank&bc1=000000&IS2=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=tiraniaorg-20&o=1&p=8&l=as4&m=amazon&f=ifr&ref=ss_til&asins=0596003307" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" align="right"></iframe> If you can not quench your thirst for knowledge there is one last book that I will recommend. This is the atomic bomb of Unix knowledge. <p><a href="http://www.amazon.com/gp/product/0596003307/ref=as_li_ss_tl?ie=UTF8&tag=tiraniaorg-20&linkCode=as2&camp=217145&creative=399369&creativeASIN=0596003307">Unix Power Tools</a> is a compilation of tricks by some of the best Unix users that got compiled into a huge volume. This is a book of individual tricks, each about a page long, ideal to keep either on your bedside or in the restoom to pick a new trick every day. <h3>Mavis Beacon</h3> <p>At this point you might be thinking "I am awesome", "the world is my oyster" and "Avatar 3D was not such a bad movie". <p>But unless you <a href="http://en.wikipedia.org/wiki/Touch_typing">touch-type</a>, you are neither awesome, nor you are in a position to judge the qualities of the world as an oyster or any James Cameron movies. <P>You have to face the fact that not only you are a slow typist, you do look a little bit ridiculous. You are typing with two maybe three fingers on each hand and you move your head like a chicken as you alternate looking at your keyboard and looking at your screen. <p>Do humanity a favor and learn to touch type. <p>You can learn to touch type in about three weeks if you spend some two to three hours per day using <a href="http://www.amazon.com/gp/product/B003MU9CPY/ref=as_li_ss_tl?ie=UTF8&tag=tiraniaorg-20&linkCode=as2&camp=217145&creative=399369&creativeASIN=B003MU9CPY">Mavis Beacon Teaches Typing</a>. <p>Mavis Beacon costs seventeen dollars ($17). Those seventeen dollars and the sixty three hours you will spend using it will do more to advance your carreer than the same sixty three hours spend reading editorials on Hacker News. <h3>Classics</h3> <p>All of the books I list here have stood the test of time. They were written at a time when books were designed to last a lifetime. <p>Unlike most modern computer books, all of these were a pleasure to read. http://tirania.org/blog/archive/2011/Sep-06.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Sep-06.html Tue, 06 Sep 2011 13:45:00 -0500 And we are back: Mono 2.10.3 <p>This is Xamarin's first official Mono release. <p>This is a major bug fix release that addresses many of the problems that were reported since our last release back on April 25th. <p>The <a href="http://www.mono-project.com/Release_Notes_Mono_2.10.3">detailed release notes</a> have all the details, but the highlights of this release include: <ul> <li>MacOS X Lion is supported: both the Mono runtime and Gtk+ as shipped with Mono have been updated to run properly on Lion. This solves the known problems that users had running MonoDevelop on MacOS X. <li>Vastly improved WCF stack <li>Many bug fixes to our precise garbage collector. </ul> <p>Major features continue to be developed in the main branch. Currently we are just waiting for the C# 5.0 Asynchronous Language support to be completed to release that version. <p>Mono 2.10.3 also serves as the foundation for the upcoming Mono for Android 1.0.3 and MonoTouch 4.1. <p>You can get it from <a href="http://www.go-mono.com/mono-downloads/download.html">Mono's Download Site</a>. <p>Currently we offer source code, Windows and MacOS packages. We will publish Linux packages as soon as we are done mirroring the contents of the old site that contains the Linux repositories. <h3>On C# 5.0</h3> <p>Our new compiler, as you might know, has been rewritten to support two backends: a System.Reflection.Emit backend, and the brilliant IKVM.Reflection backend. <p>The C# 5.0 support as found on <a href="http://github.com/mono/mono">master</a> contains the C# 5.0 support as shipped by Microsoft on their latest public release. <p>To try it out, use -langversion:future when invoking the compiler. You can try some of our samples in mono/mcs/tests/test-async*.cs http://tirania.org/blog/archive/2011/Aug-04.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Aug-04.html Thu, 04 Aug 2011 17:00:00 -0500 MonoDevelop on Lion <P>We here at Xamarin are as excited as you are about the release of Lion. But unfortunately we're not quite ready to support you on Lion yet, and MonoDevelop doesn't work quite right. We're working around the clock to make MonoDevelop work perfectly on Lion, and we'll let you know as soon as it's ready. <p><b>Update on July 29th:</b> We have most of the fixes in place for Mono and will issue a build for testing on the Alpha channel soon. http://tirania.org/blog/archive/2011/Jul-20.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Jul-20.html Wed, 20 Jul 2011 17:16:00 -0500 Novell/Xamarin Partnership around Mono <p>I have great news to share with the Mono community. <p>Today together with SUSE, an Attachmate Business Unit, <a href="http://www.novell.com/news/press/2011/7/suse-and-xamarin-partner-to-accelerate-innovation-and-support-mono-customers-and-community.html?utm_source=twitterfeed&utm_medium=twitter">we announced</a>: <ul> <li><a href="http://xamarin.com">Xamarin</a> will be providing the support for all of the existing <a href="http://ios.xamarin.com">MonoTouch</a>, <a href="http://android.xamarin.com">Mono for Android</a> and Mono for Visual Studio customers. <li>Existing and future SUSE customers that use the Mono Enterprise products on their SLES and SLED systems will continue to receive great support backed by the engineering team at Xamarin. <li><a href="http://xamarin.com">Xamarin</a> obtained a perpetual license to all the intellectual property of Mono, MonoTouch, Mono for Android, Mono for Visual Studio and will continue <a href="http://store.xamarin.com">updating and selling</a> those products. <li>Starting today, developers will be able to purchase MonoTouch and Mono for Android from <a href="http://store.xamarin.com">the Xamarin store</a>. Existing customers will be able to purchase upgrades. <li>Xamarin will be taking over the stewardship of the <a href="http://www.mono-project.com">Mono open source</a> community project. This includes the larger Mono ecosystem of applications that you are familiar with including MonoDevelop and the other Mono-centric in the <a href="http://github.com/mono/">Mono Organization</a> at GitHub. </ul> <center> <img src="http://tirania.org/images/xamarin-cat.jpg"> </center> <p>We are a young company, but we are completely dedicated to these mobile products and we can not wait to bring smiles to every one of our customers. <h3>Roadmaps</h3> <p>Our immediate plans for both MonoTouch and Mono for Android is to make sure that your critical and major bugs are fixed. We have been listening to the needs of the community and we are working to improve these products to meet your needs. You can expect updates to the products in the next week. <p>In the past couple of months, we have met with some of our users and we have learned a lot about what you wanted. We incorporated your feature requests into our products roadmaps for both the <a href="http://ios.xamarin.com/Roadmap">MonoTouch</a> and the <a href="http://android.xamarin.com/Roadmap">Mono for Android</a> products. <p>Another thing we learned is that many companies need to have a priority support offering for this class of products, so we have introduced this. It can be either be <a href="http://store.xamarin.com">purchased</a> when you first order MonoTouch or Mono for Android, or you get an upgrade to get the priority support. <h3>Next Steps</h3> <p>Our goals are to delight software developers by giving them the most enjoyable environment, languages and tools to build mobile applications. <p>We are thankful to everyone that provided feedback to us in our online form that we published a month ago. Please keep your feedback coming, you can reach us at <a href="mailto:contact@xamarin.com">contact@xamarin.com</a>. We are reading every email that you send us and you can use my new miguel at new company dot com email address to reach me. <p>We will be at the <a href="http://monospace.us/">Monospace conference</a> this weekend at the <a href="http://microsoftcambridge.com/Default.aspx">Microsoft NERD Center</a>, hope to see you there! <p>Remember to <a href="http://store.xamarin.com">purchase early and often</a> so we have the resources to bring you the best developer tools on the planet. http://tirania.org/blog/archive/2011/Jul-18.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Jul-18.html Mon, 18 Jul 2011 15:27:00 -0500 Update on Mono <p>I have a posted an <a href="http://lists.ximian.com/pipermail/mono-list/2011-July/047311.html">update on Mono</a> and the upcoming release of Mono 2.12. http://tirania.org/blog/archive/2011/Jul-06.html miguel@gnome.org (Miguel de Icaza) http://tirania.org/blog/archive/2011/Jul-06.html Wed, 06 Jul 2011 15:45:00 -0500