Miguel de IcazaPersonal blog of Miguel de Icazahttp://tirania.org/blog//index.html
Miguel de Icazamiguel@xamarin.comWed, 18 Jan 2017 13:21:00 -0500http://backend.userland.com/rsslb#Creating .NET Bindings for C Libraries with ObjectiveSharpie
<p>We created
the <a href="https://developer.xamarin.com/guides/cross-platform/macios/binding/objective-sharpie/">ObjectiveSharpie</a>
tool to automate the mapping of Objective-C APIs to the .NET
world. This is the tool that we use to keep up with Apple
APIs.
<p>One of the lesser known features of ObjectiveSharpie, is
that it is not limited to binding Objective-C header files.
It is also capable of creating definitions for C APIs.
<p>To do this, merely use the "bind" command for
ObjectiveSharpie and run it on the header file for the API
that you want to bind:
<pre>
sharpie bind c-api.h -o binding.cs</pre>
<p>The above command will produce the <tt>binding.cs</tt> that
contains the C# definitions for both the native data
structures and the C functions that can be invoked.
<p>Since C APIs are ambiguous, in some cases ObjectiveSharpie
will generate some diagnostics. In most cases it will flag
methods that have to be bound with the <tt>[Verify]</tt>.
This attribute is used as an indicator on your source code
that you need to manually audit the binding, perhaps checking
the documentation and adjust the P/Invoke signature
accordingly.
<p>There are various options that you can pass to
the <tt>bind</tt> command, just invoke <tt>sharpie bind</tt>
to get an up-to-date list of configuration options.
<p>This is how I quickly bootstrapped
the <a href="https://github.com/migueldeicaza/TensorFlowSharp">TensorFlowSharp</a>
binding. I got all the P/Invoke signatures done in one go,
and then I started to do the work to surface an idiomatic C#
API.
http://tirania.org/blog/archive/2017/Jan-18.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2017/Jan-18.htmlWed, 18 Jan 2017 18:21:00 -0500TLS 1.2 Comes to Mono: Update
<p>Short version: the master branch
of <a href="http://www.github.com/mono/mono">Mono</a> now
has support for TLS 1.2 out of the box. This means that
SslStream now uses TLS 1.2, and uses of HttpWebRequest for
HTTPS endpoints also uses TLS 1.2 on the desktop.
<p>This brings TLS 1.2 to Mono on Unix/Linux in addition to
Xamarin.{Mac,iOS,tvOS} which were already enabled to use TLS
1.2 via the native Apple TLS stack.
<p>To use, install your fresh version of Mono, and then either
run the <cc>btls-cert-sync</cc> command which will convert
your existing list of trusted certificates to the new format (if you used
<tt>cert-sync</tt> or <tt>mozroots</tt> in the past).
<h2>In Detail</h2>
<p>The new version of Mono now embeds
Google's <a href="https://boringssl.googlesource.com/boringssl/">Boring
SSL</a> as the TLS implementation to use.
<p>Last year, you might remember that we completed
a <a href="http://tirania.org/blog/archive/2015/Aug-27.html">C#
implementation of TLS 1.2</a>. But we were afraid of
releasing a TLS stack that had not been audited, that might
contain exploitable holes, and that we did not have the
cryptographic chops to ensure that the implementation was
bullet proof.
<p>So we decided that rather than ship a brand new TLS
implementation we would use a TLS implementation that had been
audited and was under active development.
<p>So we picked Boring TLS, which is Google's fork of
OpenSSL. This is the stack that powers Android and Google
Chrome so we felt more comfortable using this implementation
than a brand new implementation.
<h2>Linux Distributions</h2>
<p>We are considering adding
a <tt>--with-openssl-cert-directory=</tt> option to the
configure script so that Linux distributions that package Mono
could pass a directory that contains trusted root certificates
in the format expected by OpenSSL.
<p>Let us discuss the details in the
mono-devel-list@lists.dot.net
http://tirania.org/blog/archive/2016/Sep-30.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2016/Sep-30.htmlSat, 01 Oct 2016 01:07:00 -0500Asset Previewer
<p>Mobile developers are working with all kinds of graphics
assets and until now, to preview them, we would use an
external tool to browse them.
<p>We have developed a plug-in for both Visual Studio and
Xamarin Studio that will provide live previews of various
assets right into the IDE. It works particularly well for
UrhoSharp projects.
<p>The previewer can display in the IDE previews of the
following asset types.
<a href="http://content.screencast.com/users/Egorbo/folders/Default/media/0a78618c-e18f-43cd-b34f-a7b3679baf40/Untitle1111d.mp4">
<img src="http://tirania.org/pictures/us-asset.png">
<br>
<img src="http://tirania.org/pictures/us-asset-2.png">
</a>
<ul>
<li>Static Models (*.mdl files)
<li>Materials, Skyboxes, Textures (*.dds)
<li>Animations (*.ani)
<li>2D and 3D Particles (*.pex)
<li>Urho Prefabs (*.xml if the XML is an Urho Prefab)
<li>Scenes (*.xml if the XML is an Urho Scene)
<li>SDF Fonts (*.sdf)
<li>Post-process effects (*.xml if the XML is an Urho RenderPath)
<li>Urho UI layouts (*.xml if the XML is an Urho UI).
<li>
</ul>
<p>For Visual Studio, just download the previwer from
the <a href="https://visualstudiogallery.msdn.microsoft.com/22f52371-92c4-450a-a524-393666f4cfe8">Visual
Studio Gallery</a>.
<p>For Xamarin Studio, go to <tt>Xamarin Studio > Add-ins</tt>
go to the "Gallery" tab, and search for "Graphics asset
previewer" and install.
http://tirania.org/blog/archive/2016/Jul-28.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2016/Jul-28.htmlThu, 28 Jul 2016 22:18:00 -0500The Evolution of Interactive C#
<h2>The Early Days</h2>
<p>Years ago, in 2008
<a href="http://tirania.org/blog/archive/2008/Sep-08.html">we
introduced an interactive C# shell</a>, at the time a
challenge was to adjust the syntax to be suitable for
interactive use, to provide
a <a href="http://tirania.org/blog/archive/2008/Aug-26.html">usable
decent command line editing</a> API for .NET and to turn our
<a href="http://tirania.org/blog/archive/2011/Feb-24.html">compiler
as a service</a> into a tool that could provide code
completion.
<p>A few months later, we added
a <a href="http://tirania.org/blog/archive/2008/Nov-02.html">UI
shell</a> for this on Linux and used Gtk's text widget to add
support for embedding rich content into the responses. It
was able to render images inline with the responses:
<center>
<img src="http://tirania.org/tmp/xpoyxg.png">
</center>
<p>This was inspired at the time by the work
that <a href="http://blog.fishsoup.net/">Owen Taylor</a> at
Red Hat had done
on <a href="http://fishsoup.net/software/reinteract/">Re-interact</a>.
You can still watch
a <a href="https://people.gnome.org/~otaylor/reinteract-demo.html">screencast</a>
of what it looked like.
<p>Like Owen, I added a plot command:
<center>
<img src="http://tirania.org/tmp/xlawtm.png">
</center>
<p>At the time, Re-interact took some ideas
from <a href="http://ipython.org/">IPython</a> and it seems
like they are both inspired to some extent by Mathematica's
interactive window.
<p>Re-interact in particular introduced a brilliant idea, which was
that users could go back in history, edit the previous
expressions and the entire buffer would be re-evaluated.
This idea lives on in Apple's Playgrounds for Swift.
<p>In the meantime, the IPython project grew and they added
one of my favorite features: it was now possible to blend
text, explanations and code into workbooks. You can see a
sample of this <a href="https://try.jupyter.org/">here</a>.
For years, I have desired an IPython for C#.
<h2>The Xamarin Years</h2>
<p>In the meantime, at Xamarin, we experimented with the idea
of bringing sometehing like Re-interact/Playgrounds to Xamarin
Studio and we
shipped <a href="https://developer.xamarin.com/guides/cross-platform/sketches/">Sketches</a>:
<center>
<img src="https://developer.xamarin.com/guides/cross-platform/sketches/introduction/Images/Overview001.png">
</center>
<p>But while these were interesting for trying out ideas and
learning C#, they are not very useful for day to day work.
We found that what our developers needed was a full C# REPL
that was connected to the application they were running on, so
they could experiment with their UI live. This is when we
introduced Xamarin's Inspector. We took the existing engine
and changed the way you interacted with C#.
<p>The inspector was originally planned as a debugging aid,
one that you could use to attach to a live Android/iOS/WPF
process and use to examine:
<center>
<img src="https://developer.xamarin.com/guides/cross-platform/inspector/Images/mac-inspector-repl-small.png">
</center>
<p>We wrote several backends to provide some visual
representation of the running app:
<center>
<img src="https://developer.xamarin.com/guides/cross-platform/inspector/Images/mac-3d-view-small.png">
</center>
<p>While Sketches used the IDE editing surface and a custom
renderer view for results, with the Inspector we took a
different route. Our interactive surface was an HTML canvas,
and our results are rendered using HTML. This allowed us to
do some pretty visualizations for results.
<p>We have only started to explore what is possible in this
space, and our last release included various data renderers.
In particular, we added support for pretty printing
collections and a handful of native Android and iOS results.
<p>Up until now, we had been powered by Mono's C# compiler and
while it has served us well for many years, it pales in
comparison with the services that we could get out of
Microsoft's Roslyn. Our code completion and error reporting
were limited and the model did not translate too well to F#.
<p>We recently
<a href="https://forums.xamarin.com/discussion/61024/inspector-0-6-0-released">switched
the inspector</a> to use Roslyn:
<center>
<img src="https://developer.xamarin.com/releases/inspector/preview/inspector-0.6.0/Images/inspector-0.6.0-repl.gif">
</center>
<p>With this release, we ended up with an Inspector that can
now be used either to debug/analyze a running app (very much
like a web inspector), or one that can be used to experiment
with APIs in the same spirit as other shells.
<h2>Continuous</h2>
<p>In the meantime, Frank Krueger took the iOS support that we
introduced for the compiler as a service, and
wrote <a href="https://github.com/praeclarum/Continuous">Continuous</a>,
a plug-in for Xamarin Studio and Visual Studio that allowed
developers to live-code. That is, instead of using this as a
separate tool, you can modify your classes and methods live
and have your application update as you change the code:
<center>
<video controls width="800">
<source src="https://pbs.twimg.com/tweet_video/CXb1RaBU0AAEldo.mp4" type="video/mp4">
</video>
</center>
<p>Frank also added support for evaluating values immediately,
and showing some values in comments, similar in spirit to his
<a href="http://calca.io/">Calca</a> app for iOS:
<p>
<center width="800">
<video controls>
<source src="https://pbs.twimg.com/tweet_video/CWr0DepUEAAVrCK.mp4">
</video>
</center>
<h2>The Glorious Future</h2>
<p>But now that we have a powerful HTML rendering engine to
display our results and we upgraded our compiler engine, we
are ready to take our next steps.
<p>One step will be to add more visualizers and rendering
capabilties to our results in our Inspector.
<p>The second step is to upgrade Sketches based on this work.
We will be changing the Sketches UI to be closer to IPython,
that is, the ability of creating workbooks that contain both
rich HTML text along with live code.
<p>To give you a taste of what is coming up on our next
release, check out this screenshot:
<center>
<img src="http://tirania.org/images/csharp-workbook.png"/>
</center>
<p>Developers will still have a few options of richly
interacting with C# and F#:
<ul>
<li>With our inspector experiment with APIs like they
do with many other interactive shells, and to poke and
modify running apps on a wide spectrum of
environments.
<li>With Frank
Krueger's <a href="https://github.com/praeclarum/Continuous">Continuous</a>
engine to see your changes live for your C# code.
<li>With our revamped Sketches/workbook
approach to use it for creating training, educational
materials.
</ul>
http://tirania.org/blog/archive/2016/Feb-17.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2016/Feb-17.htmlWed, 17 Feb 2016 20:51:00 -0500Shared Projects or PCL?
<p>My colleague Jason Smith has
shared <a href="http://xfcomplete.net/general/2016/01/19/pcl-or-shared-project/">his
views</a> on what developers should use when trying to share
code between projects. Should you go with a Shared Project or
a Portable Class Library (PCL) in the world of Xamarin.Forms?
<p>He hastily concludes that you should go with PCLs
(pronounced Pickles).
<p>For me, the PCL is just too cumbersome for most uses. It
is like using a canon to kill a fly. It imposes too many
limitations (limited API surface), forces you to jump through
hoops to achieve some very basic tasks.
<p>PCLs when paired with Nugets are unmatched. Frameworks
and library authors should continue to deliver these, because
they have a low adoption barrier and in general bring smiles
and delight to their users.
<p>But for application developers, I stand firmly on the
opposite side of Jason.
<p>I am a fan of simplicity. The simpler the technology, the
easier it is for you to change things. And when you are
building mobile applications chances are, you will want to
make sweeping changes, make changes continously and these are
just not compatible with the higher bar required by PCLs.
<p>Jason does not like #if statements on his shared code.
But this is not the norm, it is an exception. Not only it is
an exception, but careful use of <tt>partial</tt> classes in
C# make this a non issue.
<p>Plugging a platform specific feature does not to use an #if
block, all you have to do is isolate the functioanlity into a
single method, and have each platform that consumes the code
implement that one method. This elegant idea is the same
elegant idea that makes the Linux kernel source code such a
pleasure to use - specific features are plugged, not #ifdefed.
<p>If you are an application developer, go with Shared Projects
for your shared code. And now that we support this for F#,
there is no reason to not adopt them.
http://tirania.org/blog/archive/2016/Jan-22.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2016/Jan-22.htmlFri, 22 Jan 2016 16:49:00 -0500getline.cs update: Partying like it is 1992
<p>Back in 2008, I wrote about <tt>getline.cs</tt>, a
single-file command line editor for shell application. It
included Emacs key bindings, history, customizable completion
and incremental search. It is equivalent to GNU's readline
library, except it is implemented in
a <a href="https://github.com/mono/mono/blob/master/mcs/tools/csharp/getline.cs">single
C# file</a>.
<p>I recently updated getline.cs to add a popup-based
completion and C# heuristics for when to automatically trigger
code completion. This is what it looks like when using in
<a href="http://www.mono-project.com/docs/tools+libraries/tools/repl/">Mono's
C# REPL</a> in the command line:
<img src="http://tirania.org/images/getline2.png"/>
http://tirania.org/blog/archive/2016/Jan-14.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2016/Jan-14.htmlThu, 14 Jan 2016 14:27:00 -0500Mono's Cooperative Mode for SGen GC
<p>Mono's master tree now contains support for a new mode of
operation for our garbage collector, we call this the
cooperative mode. This is in contrast with the default mode
of operation, the preemptive mode.
<p>This mode is currently enabled by setting
the <tt>MONO_ENABLE_COOP</tt> environment variable.
<p>We implemented this new mode of operation to make it
simpler to debug our GC, to have access to more data on the
runtime during GC times and also to support certain platforms
that do not provide the APIs that our preemptive system
needed.
<h1>Behind Preemptive Mode</h1>
<p>When we started building Mono back in 2001, we wanted to
get something up and running very quickly. The idea was to
have enough of a system running on Linux that we could have a
fully self-hosting C# environment in a short period of time,
and we managed to do this within eight months.
<p>We were very lucky when it came to garbage collection that
the fabulous <a href="http://www.hboehm.info/gc/">Boehm
GC</a> existed. We were able to quickly add garbage
collection to Mono, without having to think much about the
problem.
<p>Boehm is fabulous because it does not really require the
cooperation of the runtime to work. It is a garbage collector
that was originally designed to add garbage collection
capabilities to programs written in C or C++. It
performs garbage collection without much developer
intervention. And it achieves this for existing code:
multi-threaded, assembly-loving, low-level code.
<p>Boehm GC is a thing of beauty.
<p>Boehm achieves its magic by pulling some very sophisticated
low-level tricks. For example, when it needs to perform a
garbage collection it relies on various operating system
facilities to stop all running threads, examine the stacks for
all these threads to gather roots from the stack, perform the
actual GC job then resume the operation of the program.
<p>While Boehm is fantastic, in Mono, we had needs that would
be better served with a custom garbage collector. One that
was generational and reduced collection times. One fit more
closely with .NET. It was then that we built the current GC
for
Mono: <a href="http://www.mono-project.com/docs/advanced/garbage-collector/sgen/">SGen</a>.
<p>SGen has grown by leaps and bounds and has been key in
supporting many advanced scenarios on Android and iOS as well
as being a higher performance and lower latency GC for Mono.
<p>When we implemented SGen, we had to make some substantial
changes to Mono's code generator. This was the first time
that Mono's code generator had to coordinate with the GC.
<p>SGen kept a key feature of Boehm: most running code was
blissfully unaware that it could be stopped and resumed at any
point.
<p>This meant that we did not have to do too much work to
integrate SGen into Mono <a href="#note1">[1]</a>. There are
two main downsides with this.
<p>The first downside is that we still required the host
platform to support some mechanism to stop, resume and inspect
threads. This alone is pretty obnoxious and caused much grief
to developers porting Mono to strange platforms.
<p>The second downside is that code that runs during the
collection is not really allowed to use many of the runtime
APIs or primitives, because the collector might be running in
parallel to the regular code. You can only use reentrant
code.
<p>This is a major handicap for development and debugging of
the collector. One that is just too obnoxious to deal with
and one that has wasted too much of our time.
<h2>Cooperative Mode</h2>
<p>In the new cooperative mode, the generated code is
instrumented to support voluntarily stopping execution
<p>Conceptually, you can think of the generated code as one
that basically checks on every back-branch, or every call site
that the collector has requested for the thread to stop.
<p>The supporting Mono runtime has been instrumented as well to deal
with this scenario. This means that every API that is
implemented in the C runtime has been audited to determine
whether it can run in a finite amount of time, or if it is a
blocking operation and adjusted to participate accordingly.
<p>For methods that run in a finite amount of time, we just
wait for them to return back to managed code, where we will
stop.
<p>For methods that might potentially block, we need to add
some annotations that inform our GC that it is safe to assume
that the thread is not running any mutating code. Consider
the internal call that implements
the <a href="https://github.com/mono/mono/blob/a7317980f5f682301a662138585d26126ef4e799/mono/metadata/file-io.c#L272">CreateDirectory</a>
method. It now has been decorated
with <tt>MONO_PREPARE_BLOCKING</tt>
and <tt>MONO_FINISH_BLOCKING</tt> to delimit blocking code.
<p>This means that threads do not stop right away as they used
to, but they stop soon enough. And it turns out that soon
enough is good enough.
<p>This has a number of benefits. First, it allows us to
support platforms that do not have enough system primitives to
stop, resume and examine arbitrary threads. Those include
things like the Windows Store, WatchOS and various gaming
consoles.
<p>But selfishly, the most important thing for us is that we
will be able to treat the garbage collector code as something
that is a first class citizen in the runtime: when the
collector works, it will be running in such a state that
accessing various runtime structures is fine (or even using
any tasty C libraries that we choose to use).
<h2>Today</h2>
<p>As of today, Mono's Coop engine can either be compiled in
by default (by passing <tt>--with-cooperative-gc</tt> to
configure), or by setting the <tt>MONO_ENABLE_COOP</tt>
environment variable to any value.
<p>We have used a precursor of Coop for about 18 months, and
now we have a fully productized version of it on Mono master
and we are looking for developers to try it out.
<p>We are hoping to enable this by default next year.
<a name="note1">[1] Astute readers will notice that it still took
years of development to make SGen the default collector in Mono.
http://tirania.org/blog/archive/2015/Dec-22.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Dec-22.htmlTue, 22 Dec 2015 18:57:00 -0500David Brooks, Op-Ed for All Trades, Master of None
<p>I first heard about David
Brooks' <a href="http://www.nytimes.com/2015/10/16/opinion/schools-for-wisdom.html">article</a>
criticizing <a href="http://www.thefutureofschool.us/">Most
Likely to Succeed</a> from a Mom at school that told me it was
a rebuttal to the movie, and I should check it out.
<p>I nodded, but did not really expect the article to change
my mind.
<p>David Brooks is an all-terrain commentator which dispenses
platitudes and opinions on a wide range of topics, usually
with little depth or understanding. In my book, anyone that
supported and amplified the very fishy evidence for going to
war with Iraq has to go an extra mile to prove their worth -
and he was specially gross when it came to it.
<p>Considering that the best part about David Brook's writing
is that they often
prompt <a href="https://www.google.com/search?q=matt+taibbi+david+brooks&oq=matt+taibbi+david+brooks&aqs=chrome..69i57.5523j0j7&sourceid=chrome&es_sm=119&ie=UTF-8">beautiful
take downs</a> from Matt Taibbi and that his columns have
given rise to a cottage industry of bloggers that routinely
point out
just <a href="https://www.google.com/search?q=david+brooks+is+wrong&oq=david+b&aqs=chrome.0.69i59l3j69i57j69i59j0.31386j0j7&sourceid=chrome&es_sm=119&ie=UTF-8">how
wrong he is</a>, my expectations were low.
<p>Anyways, I did read the article.
<p>While the tone of the article is a general disagreement
with novel approaches to education, his prescription is bland
and generic: you need some basic facts before you can build
upon those facts and by doing this, you will become a wise
person.
<p>The question of course is just how many facts? Because it
is one thing to know basic facts about our world like the fact
that there are countries, and another one to memorize every
date and place of a historic event.
<p>But you won't find an answer to that on Brooks piece. If
there is a case to be made to continue our traditional
education and continue relying on tests to raise great kids,
you will not find it here.
<p>The only thing that transpires from the article is that he
has not researched the subject - he is shooting from the hip.
An action necessitated by the need to fill eight hundred words
a short hour before lunch.
<p>His contribution to the future of education brings as much
intellectual curiosity as washing the dishes.
<p>I rather not shove useless information into our kids.
Instead we should fill their most previous years with joy and
passion, and give them the tools to plot their own destinies.
Raise curious, critical and confident kids.
<p>Ones that when faced with a new problem opt for the more
rewarding in-depth problem solving, one that will have them
research, reach out to primary sources, and help us invent the future.
<p>Hopefully we can change education and raise a happier,
kinder and better generation of humans. The road to get there
will be hard, and we need to empower the teachers and schools
that want to bring this change.
<p>"Most Likely to Succeed"
represends <a href="http://www.userland.com/whatIsStopEnergy">Forward
Motion</a>, and helps us start this discussion, and David's
opinions should be dismissed for what they are: a case of
sloppy
<a href="http://www.userland.com/whatIsStopEnergy">stop
energy</a>.
<p>Do not miss Ted
Dintersmith's <a href="http://www.edu21c.com/blog/2015/10/game-on-mr-brooks/">response
to the article</a>, my favorite part:
<blockquote>
<p>I agree with Brooks that some, perhaps even many, gain
knowledge and wisdom over time. We just don’t gain it in
school. It comes when we’re fully immersed in our careers,
when we do things, face setbacks, apply our learning, and
evolve and progress. But that almost always comes after our
formal education is over. I interview a LOT of recent college
graduates and I’m not finding lots of knowledge and
wisdom. Instead, I find lots of student debt, fear of failure,
and formulaic thinking. And what do I rarely see? Passion,
purpose, creativity, and audacity.
<p>So, game on, David Brooks and others defending the 19th
Century model of education.
</blockquote>
http://tirania.org/blog/archive/2015/Oct-19.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Oct-19.htmlMon, 19 Oct 2015 17:01:00 -0500Roslyn in MonoDevelop/XamarinStudio
<p>As <a href="http://tirania.org/archive/2015/jul-21.html">promised</a>,
we now have a version of
our <a href="http://developer.xamarin.com/guides/cross-platform/xamarin-studio/">IDE
powered by Roslyn</a>, Microsoft's open sourced C# compiler as
a service
<p>When we did the port we found various leaks in the IDE that
were made worse by Roslyn, so we decided to take the time and
fix those leaks, and optimize our use of Roslyn.
<h2>Next Steps</h2>
<p>We want to get your feedback on how well it works and to
let us know what problems you are running into. Once we feel
that there are no regressions, we will make this part of the
default IDE.
<p>While Roslyn is very powerful, this power comes with a
memory consumption price tag. The Roslyn edition of Xamarin
Studio will use more memory.
<p>We are working to reduce Roslyn's and Xamarin Studio memory
usage in future versions.
http://tirania.org/blog/archive/2015/Sep-21.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Sep-21.htmlMon, 21 Sep 2015 21:50:00 -0500Mono and LLVM's BitCode
<p>This past June, Apple announced that WatchOS 2 applications
would have to be submitted using LLVM BitCode. The idea
being that Apple could optimize your code as new optimizations
are developed or new CPU features are introduced, and users
would reap the benefits without requiring the developer to
resubmit their applications.
<p>BitCode is a serialized version of
the <a href="http://llvm.org/docs/BitCodeFormat.html">low-level
intermediate representation</a> used by LLVM.
<p>WatchOS 2 requires pure BitCode to be submitted. That is,
BitCode that does not contain any machine code blobs. iOS
supports mixed mode BitCode, that is, BitCode that contains
both the LLVM intermediate representation code, and blobs of
machine code.
<p>While Mono has had
an <a href="http://www.mono-project.com/docs/advanced/mono-llvm/">LLVM
backend</a> for a long time, generating pure BitCode posed a
couple of challenges for us.
<p>First, Mono's LLVM backend does not cover all the generated
code. There were some corner cases that we handled with
Mono's old code generator. Also, Mono uses hand-written
assembly language code in various places (lots of small
optimizations involving generics code sharing, method dispatch
and other things like that). This poses a problem for
WatchOS.
<p>Secondly, Mono uses a modified version of LLVM that adds
support for many .NET idioms. In particular, our changes to
LLVM produce the necessary information to support .NET-style
exception handling <a href="#mono-llvm-notes">[1]</a>.
<p>We spent the summer adapting Mono to produce Vanilla LLVM
bitcode support. This includes the removal of our hand-tuned
machine code, as well as devising a new system for exception
handling that works in this context. Sadly, the exception
handling is not as efficient as the one that we got with our
modified LLVM.
<p>Hopefully, we will be able to upstream our changes for
better exception handling for .NET-like languages to LLVM in
the future and get some of the performance back.
<a name="mono-llvm-notes" />
<h2>Notes</h2>
<p>[1] Vanilla LLVM exception support requires exceptions to
be explicit. In .NET some exceptions happen implicitly, for
example, when dereferencing a null pointer, or dividing by
zero.
http://tirania.org/blog/archive/2015/Sep-02.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Sep-02.htmlWed, 02 Sep 2015 21:41:00 -0500Xamarin Release Cycles
<p>There are four major components of Xamarin's platform
product: the Android SDK, the iOS SDK, our Xamarin Studio IDE
and our Visual Studio extension.
<p>In the past, we used to release each component
independently, but last year we realized that developing and
testing each component against the other ones was getting too
expensive, too slow and introduced gratuitous errors.
<p>So we switched to a new style of releases where all the
components ship together at the same time. We call these
cycles.
<p>We have been tuning the cycle releases. We started with
time-based releases on a monthly basis, with the idea that
any part of the platform that wanted to be released could
catch one of these cycles, or wait for the next cycle if they
did not have anything ready.
<p>While the theory was great, the internal dependencies of
these components was difficult to break, so our cycles started
taking longer and longer.
<p>On top of the cycles, we would always prepare builds for
new versions of Android and iOS, so we could do same-day
releases of the stacks. These are developed against our
current stable cycle release, and shipped when we need to.
<p>We are now switching to feature-based releases. This
means that we are now waiting for features to be stable, with
long preview periods to ensure that no regressions are
introduced.
<p>Because feature based releases can take as long as it is
needed to ship a feature, we have introduced Service Releases
on top of our cycles.
<h2>Our Current Releases</h2>
<p>To illustrate this scenario, let me show what our current
platform looks like.
<p>We released our Cycle 5 to coincide with the Build
conference, back in April 29th. This was our last timed
release (we call this C5).
<p>Since then we have shipped three service releases which
contain important bug fixes and minor features (C5-SR1, SR2
and SR3), with a fourth being cooked in the oven right now
(C5-SR4)
<p>During this time, we have issued parallel previews of
Android M and iOS 9 support, those are always built on top of
the latest stable cycle. Our next iOS 9 preview for example,
will be based on the C5-SR4.
<p>We just branched all of our products for the next upgrade
to the platform, Cycle 6.
<p>This is the cycle that is based
on <a href="http://www.mono-project.com/docs/about-mono/releases/4.2.0/">Mono
4.2.0</a> and which contains a major upgrade to our Visual
Studio support for iOS and plenty of improvements to Xamarin
Studio. I will cover some of my favorite features in Cycle 6
in future posts.
http://tirania.org/blog/archive/2015/Sep-01.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Sep-01.htmlTue, 01 Sep 2015 14:47:00 -0500State of TLS in Mono
<p>This is an update on our efforts to upgrade the TLS stack
in Mono.
<p>You can <a href="#skip-summary">skip to the
summary</a> at the end if you do not care about the sausage
making details.
<p>Currently, TLS is surfaced in a few places in the .NET
APIs:
<ul>
<li>By the <code>SslStream</code> class, which
is a general purpose class that can be used to turn
any bidirectional stream into an TLS-powered stream.
This class is what currently powers the web client in
Mono.</li>
<li>By the <code>HttpWebRequest</code> class, which
provides .NET's HTTP client. This in turn is the
foundation for the modern <code>HttpClient</code>, both the WCF and
WebServices stacks as well as the quick and
dirty <code>WebClient</code> API.</li>
</ul>
<p><code>HttpClient</code> is in particular interesting, as it
allows for different transports to be provided for it. The
default implementation in .NET 4.5 and Mono today is to use
an <code>HttpWebRequest</code>-based implementation. But on
Windows 10, the implementation is replaced with one that uses
WinRT's HTTP client.
<p>Microsoft is encouraging developers to
abandon <code>HttpWebRequest</code> and instead
adopt <code>HttpClient</code> as it both async-friendly and
can use the best available transport given on a specific
platform. More on this in a second.
<H2>Mono's Managed TLS</h2>
<p>Mono currently only supports TLS 1.0.
<p>This is the stack that powers <code>SslStream</code>
and <code>HttpWebRequest</code>.
<p>Last year we started an effort to bring managed
implementations of TLS 1.2 and TLS 1.1. Given how serious
security has become and how many holes have been found in
existing implementation, we built this with an extensive test
suite to check for conformance and to avoid common exploits
found in implementation mistakes of TLS. This effort is
currently under development and you can see where it currently
lives
at <a href="http://github.com/mono/mono-tls">mono-tls</a>
module.
<p>This will give us complete TLS support for the entire
stack, but this work is still going to take a few months to
audit.
<h2>Platform Specific HttpClients</h2>
<p>Most of the uses for TLS today is via the HTTP protocol,
and not over custom TLS streams. This means that it is more
important to get an HTTP client that supports a brand new TLS
stack, than it is to provide the <code>SslStream</code> code.
<p>We want to provide native <code>HttpClient</code> handlers
for all of Mono's supported platforms: Android, iOS, Mac,
Linux, BSD, Unix and Windows.
<p><b>On iOS:</b> Today Xamarin.iOS already ships a native
handler,
the <a href="http://tirania.org/monomac//archive/2013/Jun.html"><code>CFNetworkHandler</code>.
This one is powered by Apple's CFNetwork stack. In recent
years, Apple has improved their networking stack, and we now I
strongly recommend using Paul Bett's
fantastic <a href="https://components.xamarin.com/view/modernhttpclient">ModernHttpClient</a>
which uses iOS' brand new NSUrlSession and uses OkHttp on
Android.
<p><b>On Android:</b> in the short term, we recommend adopting
ModernHttpClient from Paul Betts (bonus points: the same
component works on iOS with no changes). In the long term,
we will change the default handler to use the Android Java
client.
<p>In both cases, you end up with HTTP 2.0 capable clients for
free.
<p>But this still leaves Linux, Windows and other assorted
operating systems without a regular transport.
<p>For those platforms, we will be adopting the CoreFX
handlers, which on Unix are powered by the libcurl library.
<p>This still leaves <code>HttpWebRequest</code> and
everything built on top of it running on top of our TLS
stack.
<h2>Bringing Microsoft's SslStream and HttpWebRequest to Mono</h1>
<p>While this is not really TLS related, we wanted to bring
Microsoft's implementations of those two classes to Mono, as
they would fix many odd corner cases in the API, and address
limitations in our stack that do not exist in Microsoft's
implementation.
<p>But the code is tightly coupled to native Windows APIs
which makes the adoption of this code difficult.
<p>We have built an adaptation layer that will allow us to
bring Microsoft's code and use Mono's Managed TLS
implementation.
<h2>SslStream backends</h2>
<p>Our original effort focused on a pure managed
implementation of TLS because we want to ensure that the TLS
stack would work on all available platforms in the same way.
This also means that all of the .NET code that expects to
control every knob of your secure connection to work (pinning
certificates or validating your own chains for example).
<p>That said, in many cases developers do not need this
capabilities, and in fact, on Xamarin.iOS,
we can not even provide the functionality, as the OS does not
give users access to the certificate chains.
<p>So we are going to be developing at least two
separate <code>SslStream</code> implementations. For Apple
systems, we will be implementing a version on top of Apple's
SSL stack, and for other systems we will be developing an
implementation on top of Amazon's new SSL library, or the
popular OpenSSL variant of the day.
<p>These have the advantage that we would not need to maintain
the code, and we benefit from third parties doing all the hard
security work and will be suitable for most uses.
<p>For those rare uses that like to handle connections
manually, you will have to wait for Mono's new TLS
implementation to land.
<a name="skip-summary"/>
<h2>In Summary</h2>
<p>Android, Mac and iOS users can get the latest TLS for HTTP
workloads
using <a href="https://github.com/paulcbetts/ModernHttpClient">ModernHttpClient</a>.
Mac/iOS users can use the
built-in <code>CFNetworkHandler</code> as well.
<p>Soon: OpenSSL/AppleSSL based transports to be available in
Mono (post Mono 4.2).
<p>Soon: Advanced .NET SSL use case scenarios will be
supported with Mono's new mono-tls stack
<p>Soon: <code>HttpWebRequest</code>
and <code>SslStream</code> stacks will be replaced in Mono
with Microsoft's implementations.
http://tirania.org/blog/archive/2015/Aug-27.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Aug-27.htmlThu, 27 Aug 2015 16:07:00 -0500Roslyn and Mono
<p>Hello Internet! I wanted to share some updates of Roslyn and Mono.
<p>We have been working towards using Roslyn in two
scenarios. As the compiler you get when you use Mono, and as
the engine that powers code completion and refactoring in the
IDE.
<p>This post is a status update on the work that we have been
doing here.
<h2>Roslyn on MonoDevelop/XamarinStudio</h2>
<p>For the past year, we have been working on replacing
the IDE's engine that gives us code completion, refactoring
capabilities and formatting capabilities with one powered by Roslyn.
<p>The current engine is powered by a combination of <a
href="https://github.com/icsharpcode/NRefactory">NRefactory</a>
and the Mono C# compiler. It is not as powerful,
comprehensive or reliable as Roslyn.
<p>Feature-wise, we completed the effort, and we now have a
<a href="https://github.com/mono/monodevelop/tree/roslyn">Roslyn-powered
branch</a> that uses Roslyn for code completion, refactoring,
suggestions and code formatting.
<p>In addition, we ported most of the refactoring
capabilities from NRefactory to work on top of Roslyn. These
were quite significant. Visual Studio users can try them out
by installing the <a
href="https://visualstudiogallery.msdn.microsoft.com/68c1575b-e0bf-420d-a94b-1b0f4bcdcbcc">Refactoring
Essentials for Visual Studio</a> extension.
<p>While our Roslyn branch is working great and is a pleasure
to use, it also consumes more memory and by extension, runs a
little slower. This is not Roslyn's fault, but the side
effects of leaks and limitations in our code.
<p>Our original plan was to release this for our September
release (what we internally call "Cycle 6"), but we decided to
pull the feature out from the release to give us time to fix
the leaks that affected the Roslyn engine and tune the
performance of Roslyn running on Mono.
<p>Our revisited plan is to ship an update to our tooling in
Cycle 6 (the regular feature update) but without Roslyn. In
parallel, we will ship a Roslyn-enabled preview of
MonoDevelop/XamarinStudio. This will give us time to collect
your feedback on performance and memory usage regressions, and
time to fix the issues before we make Roslyn the default.
<h2>Roslyn as a Compiler in Mono</h2>
<p>One of the major roadblocks for the adoption of Roslyn in
Mono was the requirement to generate debugging information
that Mono could consume on Unix (the other one is that our C#
batch compiler is still faster than Roslyn).
<p>The initial Roslyn release only had support for generating
debug information through a proprietary/native library on
Windows, which meant that while Roslyn could be used to
compile code on Unix, the result would not contain any debug
information - this prevented Roslyn from being useful for most
compilation uses.
<p>Recently, Roslyn <a
href="https://github.com/dotnet/roslyn/pull/3891">got
support</a> for <a
href="https://github.com/dotnet/roslyn/blob/master/docs/specs/PortablePdb-Metadata.md">Portable
Program Database</a> (PPDB) files. This is a fully documented, open,
compact and efficient format for storing debug information.
<p>Mono's master release contains now support for using
PPDB files as its debug information. This means that Roslyn
can produce debug information that Mono can consume.
<p>That said, we still need more work in the Mono ecosystem to
fully support PPDB files. The <a
href="https://github.com/jbevain/cecil">Cecil library</a> is
used extensively to manipulate IL images as well as their
associated debug information. Our Reflection.Emit
implementation will need to get a backend to generate PPDBs
(for third party compilers, dynamic code generators) and
support in IKVM to produce PPDB files (this is used by Mono's
C# compiler and other third party compilers).
<p>Additionally, many features in Roslyn surfaced bloat and
bugs in Mono's class libraries. We have been fixing those
bugs (and in many cases, the bugs have gone away by replacing
Mono's implementation with implementations from Microsoft's <a
href="http://github.com/microsoft/ReferenceSource">Reference Source</a>).
http://tirania.org/blog/archive/2015/Jul-21.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Jul-21.htmlTue, 21 Jul 2015 15:53:00 -0500In Defense of the Selfie Stick
<p>From the sophisticated opinion of the trendsetters
to <a href="http://www.forbes.com/sites/kashmirhill/2014/06/24/the-selfie-stick-backlash/">Forbes</a>,
the Selfie Stick is the recipient of scorn and ridicule.
<p>One of the popular arguments against the Selfie Stick is
that you should build the courage to ask a stranger to take a
picture of you or your group.
<p>This poses three problems.
<p><b>First,</b> the courage/imposition problem. Asking a
stranger in the street assumes that you will find such a
volunteer.
<p>Further, it assumes that the volunteer will have the
patience to wait for the perfect shot ("wait, I want the
waves breaking" or "Try to get the sign, just on top of me").
And that the volunteer will have the patience to show you the
result and take another picture.
<p>Often, the selfista that has amassed the courage to
approach a stranger on the street, out of politeness, will
just accept the shot as taken. Good or bad.
<p>Except for a few of you (I am looking at you Patrick),
most people feel uncomfortable imposing something out of the
blue on a stranger.
<p>And out of shyness, will not ask a second stranger for a
better shot as long as the first one is within earshot.
<p>I know this.
<p><b>Second,</b> you might fear for the stranger to either take your
precious iPhone 6+ and run, or even worse, that he might sweat
all over your beautiful phone and you might need to disinfect
it.
<p>Do not pretend like you do not care about this, because I
know you do.
<p><b>Third,</b> and most important, we have the legal aspect.
<p>When you ask someone to take a picture of you, technically,
they are the photographer,
and <a href="http://blog.kenkaminesky.com/photography-copyright-and-the-law/">they
own the copyright</a> of your picture.
<p>This means that they own the rights to the picture and are
entitled to copyright protection. The photographer, and, not
you, gets to decide on the terms to distribute, redistribute,
publish or share the picture with others. Including making
copies of it, or most every other thing that you might
want to do with those pictures.
<p>You need to explicitly get a license from them, or purchase
the rights. Otherwise, ten years from now, you may find
yourself facing a copyright lawsuit.
<p>All of a sudden, your backpacking adventure in Europe
requires you to pack a stack of legal contracts.
<p>Now your exchange goes from "Can you take a picture of us?"
to "Can you take a picture of us, making sure that the church
is on the top right corner, and also, I am going to need you
to sign this paper".
<p>Using a Selfie Stick may feel awkward, but just like a
condom, when properly used, it is the best protection against
unwanted surprises.
http://tirania.org/blog/archive/2015/Jan-22.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2015/Jan-22.htmlFri, 23 Jan 2015 00:07:00 -0500.NET Foundation: Advisory Council
<p>Do you know of someone that would like to participate in
the .NET foundation, as part of the .NET Foundation Advisory
Council?
<p>Check <a href="http://forums.dotnetfoundation.org/t/advisory-council-proposal/63">the
discussion</a> where we are discussing the role of the
Advisory Council.
http://tirania.org/blog/archive/2014/Dec-01.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Dec-01.htmlMon, 01 Dec 2014 22:47:00 -0500Microsoft Open Sources .NET and Mono
<p>Today, Scott Guthrie announced that Microsoft is open
sourcing .NET. This is a momentous occasion, and one that I
have advocated for many years.
<p>.NET is being open sourced under
the <a href="https://github.com/dotnet/corefx/blob/master/LICENSE">MIT
license</a>. Not only is the code being released under this
very permissive license, but Microsoft is providing
a <a href="https://github.com/dotnet/corefx/blob/master/PATENTS.TXT">patent
promise</a> to ensure that .NET will get the adoption it
deserves.
<p>The code is being hosted at
the <a href="https://github.com/dotnet">.NET Foundation's
github</a> repository.
<p>This patent promise addresses the historical concerns that
the open source, Unix and free software communities have
raised over the years.
<h2>.NET Components</h2>
<p>There are three components being open sourced: the .NET
Framework Libraries, .NET Core Framework Libraries and the
RyuJit VM. More details below.
<h3>.NET Framework Class Libraries</h3>
<p>These are the class libraries that power the .NET framework
as it ships on windows. The ones that Mono has historically
implemented in an open source fashion.
<p>The code is available today
from <a href="http://github.com/Microsoft/referencesource">http://github.com/Microsoft/referencesource</a>.
Mono will be able to use as much a it wants from this
project.
<p>We have a project underway that already does this. We are
replacing chunks of Mono code that was either incomplete,
buggy, or not as fully featured as it should be with
Microsoft's code.
<p>We will be checking the code into github.com/mono by the
end of the week (I am currently in NY celebrating :-)
<p>Microsoft has stated that they do not currently plan on
taking patches back or engaging into a full open source
community style development of this code base, as the
requirements for backwards compatibility on Windows are very
high.
<h3>.NET Core</h3>
<p>The <b>.NET Core</b> is a redesigned version of .NET
that is based on the simplified version of the class libraries
as well as a design that allows for .NET to be incorporated
into applications.
<p>Those of you familiar with the PCL 2.0 contract assemblies
have a good idea of what these assemblies will look like.
<p>This effort is being hosted at <a href="https://github.com/dotnet/corefx">https://github.com/dotnet/corefx</a> and is an
effort where Microsoft will fully engage with the community to
evolve, develop and improve the class libraries.
<p>Today, they released the first few components to github;
the plan is for the rest of the redesigned frameworks to be
checked in here in the next few months.
<p>Xamarin and the Mono project will be contributing to the
efforts to bring .NET to Mac, Unix, Linux and other
platforms. We will do this as Microsoft open sources more
pieces of .NET Core, including RyuJIT.
<h2>Next Steps</h2>
<p>Like we did in the past with .NET code that Microsoft open
sourced, and like we did with Roslyn, we are going to be
integrating this code into Mono and Xamarin's products.
<p>Later this week, expect updated versions of the Mono
project roadmap and a list of tasks that need to be completed
to integrate the Microsoft .NET Framework code into Mono.
<p>Longer term, we will make the Mono virtual machine support
the new .NET Core deployment model as well as the new VM/class
library interface
<p>We are going to be moving the .NET Core discussions over to
the .NET Foundation Forums.
<p>With the Mono project, we have spent 14 years working on
open source .NET. Having Microsoft release .NET and issue a
patent covenant will ensure that we can all cooperate and
build a more vibrant, richer, and larger .NET community.
http://tirania.org/blog/archive/2014/Nov-12.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Nov-12.htmlWed, 12 Nov 2014 15:44:00 -0500Mono for Unreal Engine
<p><img src="http://tirania.org/pictures/mono-unreal.png"
align="right" style="width:240px;">Earlier this year, both
Epic Games and CryTech
made
their <em><a href="http://gamasutra.com/view/news/213647/Epics_Tim_Sweeney_lays_out_the_case_for_Unreal_Engine_4.php">Unreal
Engine</a></em>
and <em><a href="http://www.crytek.com/news/crytek-announces-its-cryengine-as-a-service-program-for-990-usd-per-month">CryEngine</a></em>
available under an affordable subscription model. These are
both very sophisticated game engines that power some high end
and popular games.
<p>We had previously helped Unity bring Mono as the scripting
language used in their engine and we now had a chance to do
this over again.
<p>Today I am happy to
introduce <a href="http://mono-ue.github.io">Mono for
Unreal Engine</a>.
<p>This is a project that allows Unreal Engine users to build
their game code in C# or F#.
<p>Take a look at this video for a quick overview of what we
did:
<p>
<iframe width="720" height="405"
src="//www.youtube.com/embed/5hAahXahUVU" frameborder="0"
allowfullscreen></iframe>
<p>This is a taste of what you get out of the box:
<ul>
<li>Create game projects purely in C#
<li>Add C# to an existing project that uses C++ or
Blueprints.
<li>Access any API surfaced by Blueprint to C++, and
easily surface C# classes to Blueprint.
<li>Quick iteration: we fully support UnrealEngine's
hot reloading, with the added twist that we support it
from C#. This means that you hit "Build" in your IDE
and the code is automatically reloaded into the editor
(with live updates!)
<li>Complete support for the .NET 4.5/Mobile Profile API.
This means, all the APIs you love are available for
you to use.
<li>Async-based programming: we have added special
game schedulers that allow you to use C# async
naturally in any of your game logic. Beautiful and
transparent.
<li>Comprehensive API coverage of the Unreal Engine
Blueprint API.
</ul>
<p>This is not a supported product by Xamarin. It is
currently delivered as a source code package with patches that
must be applied to a precise version of Unreal Engine before
you can use it. If you want to use higher versions, or lower
versions, you will likely need to adjust the patches on your own.
<p>We have set up
a <a href="http://lists.ximian.com/mailman/listinfo/mono-ue">mailing
list</a> that you can use to join the conversation about this
project.
<p>Visit the site
for <a href="http://mono-ue.github.io">Mono for Unreal
Engine</a> to learn more.
<p>(I no longer have time to manage comments on the blog,
please use the mailing list to discuss).
http://tirania.org/blog/archive/2014/Oct-23.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Oct-23.htmlThu, 23 Oct 2014 21:18:00 -0500.NET Foundation: Forums and Advisory Council
<p>Today, I want to share some news from the .NET Foundation.
<p><b>Forums:</b> We are launching the official .NET
Foundation forums to engage with the larger .NET community and
to start the flow of ideas on the future of .NET, the
community of users of .NET, and the community of contributors
to the .NET ecosystem.
<p>Please join us
at <a href="http://forums.dotnetfoundation.org/">forums.dotnetfoundation.org</a>.
We are using the powerful Discourse platform. Come join us!
<p><b>Advisory Council:</b> We want to make the .NET
Foundation open and transparent. To achieve that goal, we
decided to create an advisory council. But we need your help
in shaping the advisory council: its role, its reach, its
obligations and its influence on the foundation itself.
<p>To bootstrap the discussion, we have a baseline proposal
that was contributed by Shaun Walker. We want to invite the
larger .NET community to a conversation about this proposal
and help us shape the advisory council.
<p>Check out
the <a href="http://www.dotnetfoundation.org/call-for-public-comment.aspx">Call
for Public Comments</a> which has a link to
the <a href="http://www.dotnetfoundation.org/media/1010/net-foundation-advisory-council-proposal.pdf">baseline
proposal</a> and
come <a href="http://forums.dotnetfoundation.org/t/advisory-council-proposal/63">join
the discussion</a> at the .NET Forums.
http://tirania.org/blog/archive/2014/Oct-14.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Oct-14.htmlTue, 14 Oct 2014 15:20:00 -0500Markdown Style Guide
<p><a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a>
is as a file format for easily producing text that can be
pleasantly read both on the web and while using command line
tools, or plain text editors.
<p>Recently, a crop of tools have emerged that deliver some
form of WYSIWYG or side-by-side authoring tools to assist
writers to visualize the final output as they work.
<p>Authors are turning to these tools to produce documentation
that looks good when authoring the document, yet the tools are
not true to the spirit and goals of markdown. And in some
cases, authors are not familiar with the essence of what makes
markdown great, nor the philosophy behind it:
<blockquote>
Readability, however, is emphasized above all else. A
Markdown-formatted document should be publishable as-is, as
plain text, without looking like it’s been marked up with tags
or formatting instructions.
</blockquote>
<p>Using these editors is the modern equivalent of using
Microsoft Word to produce HTML documentation.
<p>The generated markdown files very easy to produce, but are
not suitable for human consumption. They likely violate a
number of international treaties and probably will be banned
by the EU.
<p>This short post is a set of simple rules to improve your
markdown.
<p>They will help you deliver delight to all of your users,
not just those using a web browser, but also those casually
reading your documentation with a file manager, their console,
and most importantly, potential contributors and copy editors
that have to interact with your text.
<h2>Wrap Your Text</h2>
<p>The ideal reading length for reading prose with a
monospaced font is somewhere between 72 and 78 characters.
<p>This is text snippet is from Mark Twain's Adventures of Tom
Sawyer, with text wrapped around column 72, when reading in an
80x25 console:
<center>
<p><a href="http://tirania.org/pictures/markdown-sample-4.png">
<img src="http://tirania.org/pictures/markdown-sample-4.png"
width="50%"></a>
</center>
<p>It wont matter if you are using a larger console, the text
will still be pleasant to read.
<p>But if you use some of these markdown editors that do not
bother wrapping your text, this is what the user would get:
<center>
<p><a href="http://tirania.org/pictures/markdown-sample-1.png">
<img src="http://tirania.org/pictures/markdown-sample-1.png"
width="50%"></a>
</center>
<p>And this is what is more likely to happen, with big
consoles on big displays:
<p>
<a href="http://tirania.org/pictures/markdown-sample-2.png">
<img src="http://tirania.org/pictures/markdown-sample-2.png"
width="100%"></a>
<p>There is a reason why most web sites set a maximum width
for the places where text will be displayed. It is just too
obnoxious to read otherwise.
<p>Many text editors have the ability of reformatting text
your text when you make changes.
<p>This is how you can fill your text in some common editors:
<ul>
<li>Emacs: Alt-Q will reformat your paragraph.
<li>Vim: "V" (to start selection) then "gq" will
reformat your selection.
<li>TextMate: Control-Q.
</ul>
<h2>Considering Using Two Spaces After a Period</h2>
<p>When reading text on the console, using two spaces after a
period makes it easier to see where phrases end and start.
<p>While there is some debate as to the righteouness of one vs
two spaces in the word of advanced typography these do not
apply to markdown text. When markdown is rendered into HTML,
the browser will ignore the two spaces and turn it into one,
but you will give your users the extra visual cues that they
need when reading text.
<p>If you are interested in the topic,
check these posts by <a href="http://www.heracliteanriver.com/?p=324">Heraclitean
River</a>
and <a href="http://www.ditchwalk.com/2011/01/19/two-spaces-after-a-period/">DitchWalk</a>.
<h2>Sample Code</h2>
<p>For small code snippets, it is best if you just indent your
code with spaces, as this will make your console experience
more pleasant to use.
<p>Recently many tools started delimiting code with the "```".
While this has its place in large chunks of text, for small
snippets, it is the visual equivalent of being punched in the
face.
<p>Try to punch your readers in the face only when absolutely
necessary.
<h2>Headers</h2>
<p>Unless you have plans to use multiple-nested level of
headers, use the underline syntax for your headers, as this is
visually very easy to scan when reading on a console.
<p>That is, use:
<pre>
Chapter Four: Which iPhone 6 is Right For You.
==============================================
In the previous chapter we established the requirement to buy iPhones
in packs of six. Now you must choose just whether you are going to go
for an apologetically aluminum case, or an unapologetically plastic
iPhone.
</pre>
<p>Instead of the Atx-style headers:
<pre>
# Chapter Four: Which iPhone 6 is Right For You.
</pre>
<p>The second style can easily drown in a body of text, and
can not help as a visual aid to see where new sections start.
<h2>Blockquotes</h2>
<p>While markdown allows you to only set the first character
for a blockquote, like this:
<pre>
> his is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
</pre>
<p>Editors like Emacs, can reformat that text just fine, all
you have to do is set the "Fill Prefix", by positioning your
cursor after the "> " and use Control-x ., then you can use
the regular fill command: Alt-Q, and this will produce:
<pre>
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere
> lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet
> vitae, risus.
</pre>
<h2>Lists</h2>
<p>Again, while Markdown will happily allow you to write
things like:
<pre>
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
</pre>
<p>You should love your reader, and once again, if you are
using something like Emacs, use the fill prefix to render the
list like this instead:
<pre>
* Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi,
viverra nec, fringilla in, laoreet vitae, risus.
* Donec sit amet nisl. Aliquam semper ipsum sit amet velit.
Suspendisse id sem consectetuer libero luctus adipiscing.
</pre>
http://tirania.org/blog/archive/2014/Sep-30.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Sep-30.htmlWed, 01 Oct 2014 01:53:00 -0500Three Tricks in Xamarin Studio
<p>I wanted to share three tricks that I use a lot in Xamarin
Studio/MonoDevelop.
<h2>Trick 1: Navigate APIs</h2>
<p>Xamarin Studio's code completion for members of an object
defaults to showing all the members sorted by name.
<p>But if you press Control-space, it toggles the rendering
and organizes the results. For example, for this object of
type UIWindow, it first lists the methods available for
<a href="http://iosapi.xamarin.com/?link=T%3aMonoTouch.UIKit.UIWindow">UIWindow</a>
sorted by name, and then the cluster for its base class
UIView:
<img src="http://tirania.org/images/xs-complete-1.png">
<p>This is what happens if you scroll to the end of the
UIWindow members:
<img src="http://tirania.org/images/xs-complete-2.png">
<h2>Trick 2: Universal Search</h2>
<p>Use the Command-. shortcut to activate the universal
search, once you do this and start typing it will find matches
for both members and types in your solution, as well as IDE
commands and the option to perform a full text search:
<img src="http://tirania.org/images/xs-find-1.png">
<h2>Trick 3: Dynamic Abbreviation Completion</h2>
<p>This is a feature that we took from Emacs's Dynamic
Abbrevs.
<p>If you type Control-/ when you type some text, the editor
will try to complete the text you are typing based on strings
found in your project that start with the same prefix.
<p>Hit control-/ repeatedly to cycle over possible
completions.
<img src="http://tirania.org/images/xs-dabbrev.gif">
http://tirania.org/blog/archive/2014/Aug-20-1.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Aug-20-1.htmlWed, 20 Aug 2014 16:26:00 -0500Five Cross Platform Pillars
<p>The last couple of years have been good to C# and .NET, in
particular in the mobile space.
<p>While we started just with a runtime and some basic
bindings to Android and iOS back in 2009, we have now grown to
provide a comprehensive development stack: from the runtime,
to complete access to native APIs, to designers and IDEs and
to a process to continuously deliver polish to our users.
<p>Our solution is based on a blend of C# and .NET as well as
bindings to the native platform, giving users a spectrum of
tools they can use to easily target multiple platforms without
sacrificing quality or performance.
<p>As the industry matured, our users found themselves solving
the same kinds of problems over and over. In particular,
many problems related to targeting multiple platforms at once
(Android, iOS, Mac, WinPhone, WinRT and Windows).
<p>By the end of last year we had identified five areas where
we could provide solutions for our users. We could deliver a
common framework for developers, and our users could focus on
the problem they are trying to solve.
<p>These are the five themes that we identified.
<ul>
<li>Cross-platform UI programming.
<li>2D gaming/retained graphics.
<li>2D direct rendering graphics.
<li>Offline storage, ideally using SQLite.
<li>Data synchronization.
</ul>
<p>Almost a year later, we have now delivered four out of the
five pillars.
<p>Each one of those pillars is delivered as a NuGet package
for all of the target platforms. Additionally, they are
Portable Class Libraries, which allows developers to create
their
own <a href="http://developer.xamarin.com/guides/cross-platform/application_fundamentals/pcl/">Portable
Class Libraries</a> on top of these frameworks.
<h1>Cross Platform UI programming</h1>
<p>With Xamarin 3.0 we
introduced <a href="http://xamarin.com/forms">Xamarin.Forms</a>,
which is a cross-platform UI toolkit that allows developers to
use a single API to target Android, iOS and WinPhone.
<p>Added bonus: you can host Xamarin.Forms inside an existing
native Android, iOS or WinPhone app, or you can extend a
Xamarin.Forms app with native Android, iOS or WinPhone APIs.
<p>So you do not have to take sides on the debate over 100%
native vs 100% cross-platform.
<p>Many developers also want to use HTML and Javascript for
parts of their application, but they do not want to do
everything manually. So we also launched support for the
<a href="http://developer.xamarin.com/guides/cross-platform/advanced/razor_html_templates/">Razor
view engine</a> in our products.
<h1>2D Gaming/Retained Graphics</h1>
<p>Gaming and 2D visualizations are an important part of
applications that are being built on mobile platforms.
<p>We productized the Cocos2D API for C#. While it is a great
library for building 2D games -and many developers build their
entire experiences entirely with this API- we have also
<a href="https://github.com/mono/CocosSharp/wiki/Key-Differences">extended
it</a> to allow developers to spice up an existing native
application.
<p>We launched it this
month: <a href="https://github.com/mono/CocosSharp">CocosSharp</a>.
<h1>Offline Storage</h1>
<p>While originally our goal was to bring Mono's System.Data
across multiple platforms (and we might still bring this as
well), Microsoft released a cross-platform SQLite binding with
the same requirements that we
had: <a href="http://log.paulbetts.org/the-bait-and-switch-pcl-trick/">NuGet
and PCL</a>.
<p>While Microsoft was focused on the Windows platforms, they
<a href="https://sqlitepcl.codeplex.com/">open sourced the
effort</a>, and we contributed the Android and iOS ports.
<p>This is what powers Azure's offline/sync APIs for C#.
<p>In the meantime, there are a couple of other efforts that
have also gained traction: Eric
Sink's <a href="https://github.com/ericsink/SQLitePCL.raw">SQLite.Raw</a>
and Frank
Krueger's <a href="https://github.com/praeclarum/sqlite-net">sqlite-net</a>
which provides a higher-level ORM interface.
<p>All three SQLite libraries provide NuGet/PCL interfaces.
<h1>Data Synchronization</h1>
<p>There is no question that developers love Couchbase. A
lightweight NoSQL database that supports data synchronization
via Sync gateways and Couchbase servers.
<p>While Couchbase used to offer native Android and iOS APIs
and you could use those, the APIs were different, since each
API was modeled/designed for each platform.
<p>Instead of writing an abstraction to isolate those APIs
(which would have been just too hard), we decided to port the
Java implementation entirely to C#.
<p>The result
is <a href="https://github.com/couchbaselabs/couchbase-lite-net">Couchbase
Lite for .NET</a>.
We <a href="http://www.couchbase.com/press-releases/couchbase-announces-beta-version-couchbase-lite-net">co-announced
this development</a> with Couchbase back in May.
<p>Since we did the initial work to bootstrap the effort,
Couchbase has taken over the maintenance and future
development duties of the library and they are now keeping it
<a href="http://components.xamarin.com/view/couchbase-lite-net">up-to-date</a>.
<p>While this is not yet a PCL/NuGet, work is in progress to
make this happen.
<h1>Work in Progress: 2D Direct Rendering</h1>
<p>Developers want to have access to a rich API to draw.
Sometimes used to build custom controls, sometimes used to
draw charts or to build entire applications based on 2D
rendered API.
<p>We are working on bringing the System.Drawing API to all of
the mobile platforms. We have completed an implementation of
System.Drawing for iOS using CoreGraphics, and we are now
working on both an Android and WinPhone implementations.
<p>Once we complete this work, you can expect System.Drawing
to be available across the board as a NuGet/PCL library.
<p>If you can not wait, you can get your hands today on the
Mac/iOS version
from <a href="https://github.com/mono/sysdrawing-coregraphics">Mono's
repository</a>.
<h1>Next Steps</h1>
<p>We are now working with our users to improve these APIs.
But we wont stop at the API work, we are also adding IDE
support to both Xamarin Studio and Visual Studio.
http://tirania.org/blog/archive/2014/Aug-20.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Aug-20.htmlWed, 20 Aug 2014 14:47:00 -0500Mono Performance Team
<p>For many years a major focus of Mono has been to be
compatible-enough with .NET and to support the popular
features that developers use.
<p>We have always believed that it is better to be slow and
correct than to be fast and wrong.
<p>That said, over the years we have embarked on some
multi-year projects to address some of the major performance
bottlenecks: from implementing a precise GC and fine tuning it
for a number of different workloads to having implemented now
four versions of the code generator as well as
the <a href="http://www.mono-project.com/Mono_LLVM">LLVM
backend</a> for additional speed and things
like <a href="http://tirania.org/blog/archive/2008/Nov-03.html">Mono.SIMD</a>.
<p>But these optimizations have been mostly reactive: we wait
for someone to identify or spot a problem, and then we start
working on a solution.
<p>We are now taking a proactive approach.
<p>A few months
ago, <a href="http://schani.wordpress.com/">Mark Probst</a>
started the new Mono performance team. The goal of the team
is to improve the performance of the Mono runtime and treat
performance improvements as a feature that is continously
being developed, fine-tuned and monitored.
<p>The team is working both on ways to track performance of
Mono over time, implemented support for getting better
insights into what happens inside the runtime and has
implemented several optimizations that have been landing into
Mono for the last few months.
<p>We are <a href="http://xamarin.com/jobs/ok7DYfwM">actively
hiring</a> for developers to join the Mono performance team
(ideally in San Francisco, where Mark is based).
<p>Most recently, the team added a new and sophisticated new
stack for performance counters which allows us to monitor what
is happening on the runtime, and we are now able to export to
our profiler (a joint effort between our performance team and
our feature team and implemented by Ludovic). We also
unified both the runtime and user-defined performance counters
and will soon be sharing a new profiler UI.
http://tirania.org/blog/archive/2014/Jul-23.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Jul-23.htmlWed, 23 Jul 2014 14:28:00 -0500Better Crypto: Did Snowden Succeed?
<p>Snowden is quoted on Greenwald's new book "No Place to
Hide" as wanting to both spark a debate over the use of
surveillance and to get software developers to adopt and
create better encryption:
<blockquote>
While I pray that public awareness and debate will lead to
reform, bear in mind that the policies of men change in time,
and even the Constitution is subverted when the appetites of
power demand it. In words from history: Let us speak no more
of faith in man, but bind him down from mischief by the chains
of cryptography.
<p>[...]
<p>The shock of this initial period [after the first revelations]
will provide the support needed to build a more equal
internet, but this will not work to the advantage of the
average person unless science outpaces law. By understanding
the mechanisms through which our privacy is violated, we can
win here. We can guarantee for all people equal protection
against unreasonable search through universal laws, but only
if the technical community is willing to face the threat and
commit to implementing over-engineered solutions.
</blockquote>
<p>Last week Matthew Green asked:
<blockquote class="twitter-tweet" lang="en"><p>So has Snowden succeeded? Have developers &#39;created better encryption&#39; since his leaks?</p>&mdash; Matthew Green (@matthew_d_green) <a href="https://twitter.com/matthew_d_green/statuses/466567760504705024">May 14, 2014</a></blockquote>
<script async src="//platform.twitter.com/widgets.js"
charset="utf-8"></script>
<p>Only time will be able to answer whether as a community the
tech world can devise better and simpler tools for normal
users to have their privacy protected by default.
<p>Snowden has succeeded in starting an important discussion
and having software developers and their patrons react to the
news.
<p>At <a href="http://xamarin.com">Xamarin</a> we build
developer tools for Android and iOS developers. It is our
job to provide tools that developers use on a day to day basis
to build their applications, and we help them build these
mobile applications.
<p>In the last year, we have noticed several changes in our
developer userbase. Our customers are requesting both
features and guidance on a number of areas.
<p>Developers are reaching to us both because there is a new
understanding about what is happening to our electronic
communications and also response to rapidly changing
requirements from the public and private sectors.
<p>Among the things we have noticed:
<ul>
<li><b>Using Trusted Roots Respectfully:</b> For
years, we tried
to <a href="http://www.mono-project.com/UsingTrustedRootsRespectfully">educate
our users</a> on what they should do when dealing with
X509 certificates. Two years ago, most users would
just pick the first option "Ignore the problem".
<br>Today this is no longer what developers do by
default.
<li><b>Certificate Pinning:</b> more than ever,
developers are using certificate pinning to ensure
that their mobile applications are only talking to the
exact party they want to.
<li><b>Ciphersuite Selection:</b> We recently had to
<a href="http://iosapi.xamarin.com/?link=P%3aSystem.Net.ServicePointManager.ClientCipherSuitesCallback">
extend the .NET API</a> to allow developers to force
our networking stack to control which cipher suites
the underlying SSL/TLS stack uses. This is used to
prevent weak or suspected ciphersuites to be used for
the communications.
<li><b>Request for more CipherSuites:</b> Our Mono
runtime implements its own SSL/TLS and crypto stacks
entirely in C#. Our customers have asked us to
support new cipher suites on newer versions of the
standards.
</ul>
<p>Sometimes developers can use the native APIs we provide to
achieve the above goals, but sometimes the native APIs on
Android and iOS make this very hard or do not expose the new
desired functionality, so we need to step in.
http://tirania.org/blog/archive/2014/May-21.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/May-21.htmlWed, 21 May 2014 19:03:00 -0500News from the .NET World
<p>Some great announcements today from the Microsoft world.
<h2>#1 Open Source ASP.NET stack</h1>
<p>The first one is that
Microsoft's <a href="http://blogs.msdn.com/b/dotnet/archive/2014/05/12/the-next-generation-of-net-asp-net-vnext.aspx#_ASP.NET_vNext">next
generation web stack</a> (ASP.NET vNext) is open source from
the ground up, and runs on Mono on both Linux and Mac.
<p>There are plenty of other design principles in this new
version of ASP.NET. I provide a translation from Microsoft
speak into Unix speak in parenthesis:
<ul>
<li>Cloud-ready out of the box (this is code name for
"can run with different versions of .NET side by side").
<li>A single programming model for Web sites and services
<li>Low-latency developer experience (Refresh on
browser recompiles)
<li>Make high-performance and high-productivity APIs
and patterns available - enable them both to be used
and compose together within a single app.
<li>Fine-grained control available via command-line
tools and standard file formats.
<li>Delivered via NuGet (package manager, similar to
Node's NPM or Ruby Gems).
<li>Release as open source via the .NET Foundation.
<li>Can run on Mono, on Mac and Linux.
</ul>
<p><b>Update:</b> And the software is live at http://github.com/aspnet
<h2>Client Libraries to Microsoft Services</h2>
<p>They are shipping a number of new components to talk to
their online services, and they all have a license suitable
for being used from platforms other than Windows.
http://tirania.org/blog/archive/2014/May-12.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/May-12.htmlMon, 12 May 2014 21:48:00 -0500Roslyn Update
<p>As promised, we are now tracking the Unix-friendly Roslyn
port on <a href="https://github.com/mono/roslyn">Mono's GitHub
Organization</a>.
<p>We implemented a few C# 6.0 features in Mono's C# compiler
to simplify the set of patches required to compile Roslyn.
<p>So you will need a fresh Mono (from git).
http://tirania.org/blog/archive/2014/Apr-28.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Apr-28.htmlMon, 28 Apr 2014 21:41:00 -0500Documentation for our new iOS Designer
<p>The team has put together
some <a href="http://docs.xamarin.com/guides/ios/user_interface/designer/">beautiful
getting started documentation</a> for our iOS User Interface
Designer.
<center>
<img src="http://tirania.org/images/designer_new.png">
</center>
<p>In particular, check a couple of hot features on it:
<ul>
<li><a href="http://docs.xamarin.com/guides/ios/user_interface/designer/ios_designable_controls_walkthrough/">Using
Custom Controls</a> with the designer. Shows how you
can render your C# code live in the designer.
<li><a href="http://docs.xamarin.com/guides/ios/user_interface/designer/designer_auto_layout/">Using
AutoLayout</a> with the iOS Designer.
</li>
</ul>
http://tirania.org/blog/archive/2014/Apr-14-1.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Apr-14-1.htmlMon, 14 Apr 2014 14:53:00 -0500Mono on PS4
<p>We have been working with a few PlayStation 4 C# lovers for
the last few months. The first PS4 powered by Mono and
MonoGame
was <a href="http://blog.us.playstation.com/2014/03/14/towerfall-ascension-on-ps4-behind-the-arena/">TowerFall</a>:
<center>
<img src="http://tirania.org/images/sA8kT2q.gif">
</center>
<p>We are very excited about the upcoming Transistor, by the
makers of Bastion, coming out on May 20th:
<center>
<img src="http://tirania.org/images/Transistor_10-apr-2014_02-small.jpg">
</center>
<p>Mono on the PS4 is based on a special branch of Mono that
was originally designed to support static compilation for
Windows's WinStore applications [1].
<p>[1] Kind of not very useful anymore, since Microsoft just
shipped <a href="http://blogs.msdn.com/b/dotnet/archive/2014/04/02/announcing-net-native-preview.aspx">static
compilation of .NET</a> at BUILD. Still, there is no wasted
effort in Mono land!
http://tirania.org/blog/archive/2014/Apr-14.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Apr-14.htmlMon, 14 Apr 2014 14:50:00 -0500Mono and Roslyn
<p>Last week, Microsoft open sourced Roslyn, the <a
href="http://roslyn.codeplex.com/">.NET Compiler Platform</a>
for C# and VB.
<p>Roslyn is an effort to create a new generation of compilers
written in managed code. In addition to the standard batch
compiler, it contains a compiler API that can be used by all
kinds of tools that want to understand and manipulate C#
source code.
<p>Roslyn is the foundation that powers the new smarts in
Visual Studio and can also be used for static analysis, code
refactoring or even to smartly <a
href="http://source.roslyn.codeplex.com/">navigate your source
code</a>. It is a great foundation that tool developers will
be able to build on.
<p>I had the honor of sharing the stage with Anders Hejlsberg
when he published the source code, and showed both Roslyn
working on a Mac with Mono, as well as showing the very same
patch that he demoed on stage running on Mono.
<center>
<img src="http://tirania.org/s/102b3dc9.png">
</center>
<h2>Roslyn on Mono</h2>
<p>At
BUILD, <a href="http://channel9.msdn.com/Events/Build/2014/KEY02">we
showed Roslyn running on Mono</a>. If you want to run your
own copy of Roslyn today, you need to use both a fresh version
of Mono, and apply
a <a href="http://tirania.org/roslyn-patches">handful of
patches</a> to Roslyn [2].
<center>
<img src="http://tirania.org/s/3b8cf812.png">
</center>
<p>The source code as released contains some C# 6.0 features
so the patches add a bootstrapping phase, allowing Roslyn to
be built with a C# 5.0 compiler from sources. There are also
a couple of patches to deal with paths (Windows vs Unix paths)
as well as a Unix Makefile to build the result.
<p>Sadly, Roslyn's build script depends on a number of
features of MSBuild that neither Mono or
MonoDevelop/XamarinStudio support currently [3], but we hope
we can address in the future. For now, we will have to
maintain a Makefile-based system to use Roslyn.
<p>Our patches no longer apply to the tip of Roslyn master, as
Roslyn is under very active development. We will be updating the
patches and track Roslyn master on <a
href="http://github.com/mono/roslyn">our fork</a> moving
forward.
<p>Currently Roslyn generates debug information using a Visual
Studio native library. So the /debug switch does not work.
We will be providing an alternative implementation that uses
Mono's symbol writer.
<h2>Adopting Roslyn: Mono SDK</h2>
<p>Our goal is to keep track of Roslyn as it is being
developed, and when it is officially released, to bundle
Roslyn's compilers with Mono [6].
<p>But in addition, this will provide an up-to-date and
compliant Visual Basic.NET compiler to Unix platforms.
<p>Our plans currently are to keep both compilers around, and
we will implement the various C# 6.0 features into Mono's C#
compiler.
<p>There are a couple of reasons for this. Our batch compiler
has been fine tuned over the years, and for day-to-day
compilation it is currently faster than the Roslyn compiler.
<p>The second one is that our compiler powers our <a href="http://tirania.org/blog/archive/2008/Sep-08.html">Interactive
C# Shell</a> and we are about to launch something very
interesting with it. This functionality is not currently
available on the open sourced Roslyn stack.
<p>In addition, we plan on distributing the various Roslyn
assemblies to Mono users, so they can build their own tools on
top of Roslyn out of the box.
<h2>Adopting Roslyn: MonoDevelop/Xamarin Studio</h2>
<p>Roslyn really shines for use in IDEs.
<p>We have started an effort to adopt Roslyn in
MonoDevelop/Xamarin Studio. This means that the underlying
NRefactory engine will also adopt Roslyn.
<p>This is going to be a gradual process, and during the
migration the goal is to keep using both Mono's C# compiler as
a service engine and bit by bit, replace with the Roslyn
components.
<p>We are evaluating various areas where Roslyn will have a
positive impact. The plan is to start with code completion
[4] and later on, support the full spectrum of features that
NRefactory provides (from refactoring to code generation).
<h2>C# Standard</h2>
<p>While not related to Roslyn, I figured it was time to share
this.
<p>For the last couple of months, the ECMA C# committee has been
working on updating the spec to reflect C# 5. And this time
around, the spec benefits from having two independent compiler
implementations.
<h2>Mono Project and Roslyn</h2>
<p>Our goal is to contribute fixes to the Roslyn team to make
sure that Roslyn works great on Unix systems, and hopefully to
provide bug reports and bug fixes as time goes by.
<p>We are very excited about the release of Roslyn, it is an
amazing piece of technology and one of the most sophisticated
compiler designs available. A great place to learn great C#
idioms and best practices [5], and a great foundation for
great tooling for C# and VB.
<p>Thanks to everyone at Microsoft that made this possible,
and thanks to everyone on the Roslyn team for starting,
contributing and delivering such an ambitious project.
<h2>Notes</h2>
<p>[1] Roslyn uses a few tracing APIs that were not available
on Mono, so you must use a newer version of Mono to build
Roslyn.
<p>[2] We even include the patch to add french quotes that
Anders demoed. Make sure to skip that patch if you don't
want it :-)
<p>[3] From Michael Hutchinson:
<ul>
<li>There are references of the form: <code>&lt;Reference Include="Microsoft.Build, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"&gt;</code>
<br>
This is a problem because our project system tries to load project
references verbatim from the project file, instead of evaluating them
from the MSBuild engine. This would be fixed by one of the MSBuild
integration improvements I've proposed.
<li>There's an InvalidProjectFileException error from the xbuild engine
when loading one of the targets files that's imported by several of
the code analysis projects, VSL.Settings.targets. I'm pretty sure this
is because it uses MSBuild property functions, an MSBuild 4.0 feature
that xbuild does not support.
<li>They use the <code>AllowNonModulatedReference</code> metadata on some references
and it's completely undocumented, so I have no idea what it does and
what problems might be caused by not handling it in xbuild.
<li>One project can't be opened because it's a VS Extension project.
I've added the GUID and name to our list of known project types so we
show a more useful error message.
<li>A few of the projects depend on
Microsoft.Build.dll, and Mono does not have a working
implementation of it yet. They also reference other
MSBuild assemblies which I know we have not
finished.
</ul>
<p>[4] Since Roslyn is much better at error recovery and has a
much more comprehensive support for code completion than
Mono's C# compiler does. It also has much better support for
dealing with incremental changes than we do.
<p>[5] Modulo <code>private</code>. They use
<code>private</code> everywhere, and that is just plain ugly.
<p>[6] We will find out a way of selecting which compiler to use,
either <code>mcs</code> (Mono's C# Compiler) or Roslyn.
http://tirania.org/blog/archive/2014/Apr-09.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Apr-09.htmlWed, 09 Apr 2014 17:03:00 -0500ISO C++ 2D API
<p>Herb Sutter from the ISO C++
group, <a href="http://lists.cairographics.org/archives/cairo/2013-December/024858.html">reached
out to the Cairo folks</a>:
<blockquote>
We are actively looking at the potential standardization of a basic 2D
drawing library for ISO C++, and would like to base it on (or outright
adopt, possibly as a binding) solid prior art in the form of an existing
library.
</blockquote>
<p>And also:
<blockquote>
we are focused on current Cairo as a starting point, even though it's
not C++ -- we believe Cairo itself it is very well written C (already
in an OO style, already const-correct, etc.).
</blockquote>
<p>Congratulations to the Cairo guys for designing such a
pleasant to use 2D API.
<p>But this would not be a Saturday blog post without pointing
out that Cairo's C-based API is easier and simpler to use than
many of those C++ libraries out there. The more sophisticated
the use of the C++ language to get some performance benefit,
the more unpleasant the API is to use.
<p>The incredibly
powerful <a href="http://www.antigrain.com/">Antigrain</a>
sports an insanely fast software renderer and also a quite
hostile template-based API.
<p>We got to compare Antigrain and Cairo back when we worked
on Moonlight. Cairo was the clear winner.
<p>We built Moonlight in C++ for all the wrong reasons
("better performance", "memory usage") and was a decision we
came to regret. Not only were the reasons wrong, it is not
clear we got any performance benefit and it is clear that we
did worse with memory usage.
<p>But that is a story for another time.
http://tirania.org/blog/archive/2014/Jan-04.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2014/Jan-04.htmlSat, 04 Jan 2014 11:52:00 -0500Debugging Remote Mono Targets
<p>Few guys have approached us recently about doing remote
debugging of a Mono process. Typically this involves an
underpowered system, or some kind of embedded system running
Mono, and a fancy Mac or PC on the other end.
<p>These are the instructions that Michael Hutchinson kindly
provided on how to remotely debug your process using either
Xamarin Studio or MonoDevelop:
<blockquote>
Remote debugging is actually really easy with the Mono soft debugger.
The IDE sends commands over TCP/IP to the Mono Soft Debugger agent
inside the runtime. Depending how you launch the debuggee, you can
either have it connect to the IDE over TCP, or have it open a port and
wait for the IDE to connect to it.
<p>For simple prototyping purposes, you can just set the
<code>MONODEVELOP_SDB_TEST</code> env var, and a new "Run->Run
With->Custom Soft Debugger" command will show up in Xamarin
Studio / MonoDevelop, and you can specify an arbitrary IP and
port or connect or or listen on, and optionally a command to
run. Then you just have to start the debuggee with the
correct <code>--debugger-agent</code> arguments (see the Mono
manpage for details), start the connection, and start
debugging.
<p>For a production workflow, you'd typically create a
MonoDevelop addin with a debugger engine and session
subclassing the soft debugger classes, and overriding how to
launch the app and set up the connection parameters. You'd
typically have a custom project type too subclassing the
DotNetProject, so you could override how the project was built
and executed, and so that the new debugger engine could be the
primary debugger for projects of that type. You'd get all the
default .NET/Mono project and debugger functionality "for
free".
</blockquote>
<p>You can get some inspiration on how to build your own
add-in from the <a href="https://github.com/mono/monodevelop/tree/master/extras/MonoDevelop.MeeGo">old MeeGo add-in</a>. It has bitrotted, since
MeeGo is no more, but it is good enough as a starting point.
http://tirania.org/blog/archive/2013/Oct-29.html
miguel@xamarin.com (Miguel de Icaza)http://tirania.org/blog/archive/2013/Oct-29.htmlTue, 29 Oct 2013 19:35:00 -0500