Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Roslyn CTP is available

In case you have missed the late yesterday news from Redmond: Roslyn CTP is now available! See soma, ericli, vsteam, vbteam, c#faq blog posts. But to concretely get started, see the official msdn page: msdn.microsoft.com/roslyn This page points to 7 walk through typical Roslyn API usages + a white book.

But wait a minute, what is Roslyn?

  • Roslyn is the result of the last 4 or 5 years effort from the C# and VB.NET team now unified around the Roslyn project.
  • Roslyn will be a replacement for the actual C# and VB.NET compilers, when exactly? after dev11 goes live, dixit Soma : the Roslyn work is focused towards a post-Visual Studio 11 release. So it sounds like we can’t expect a RTM version before at best, a year.
  • Roslyn is entirely written in managed code and, opposed to current C# and VB.NET compilers, Roslyn is open, it is not a black box: Roslyn proposes a .NET API to let developers write meta-programsMetaprogramming is the writing of computer programs that write or manipulate other programs (or themselves) as their data. Meta-programming represents concretely many sort of cool things such as: syntax analysis, semantic analysis, refactoring, Aspect Oriented Programming engines, interactive C# and VB.NET editors…
  • But also, Roslyn will be used  to add tremendous flexibility to your application by letting the user expresses what he wants to achieve through portions of C# or VB.NET code. For example, I can thing of financial traders (you know the guys that rule the world) writing complex financial data treatments through a C# interactive Window. I already saw them writing VBA code to achieve what they wanted!
  • Finally, Roslyn is the implementation of the Compiler as Services paradigm introduced by Anders Helsberg last year.

Some facts about Roslyn

As usual, when putting my hands dirty in a new .NET API, I do a quick check with NDepend to get some sort quantitative ideas. And actually Roslyn exposes a big, very big API, bigger than anything you’ve seen except the whole .NET Framework itself.

  • 939 publicly visible types (and a total of 5 811 types).
  • 6.105 publicly visible methods (and a total of 51 843 method).
  • Just a bit more than 1 M IL instructions which means around 150K lines of code.

Keep in mind that Roslyn is still in an early alpha stage, and these numbers will certainly increase. The purpose of this CTP is, for the Roslyn team, to get as much relevant feedbacks, to make sure they go in the right direction. This CTP version is far from being feature complete (more details in ericli post).

Here is a treemap representation of the Roslyn implementation, the blue squares being the public types, the elementary rectangles being methods with a surface proportional to the implementation size (in terms of IL instructions).

This treemap view is especially suited to locate where the public surface of the Roslyn API is. While such a project potentially comes with plenty of potential extension points, not everything will be publicly available and the Roslyn team are serious about keeping the public API compact.

You must also keep in mind that the Roslyn API is built upon one tenet: Immutability. Objects grapes returned by Roslyn API, (like Abstract Syntax Trees) will be seen as immutable , which not necessarily mean they are internally immutable, but one behavior you’ll observe and can rely on will be immutability.

Here is also the number of publicly available types and methods exposed by Roslyn assemblies and namespaces:

For those interested, here are Roslyn assemblies dependencies displayed through a dependency matrix (it is too complex to be shown through a comprehensive dependency graph): a blue square means that the column assembly is using the row assembly, the number in a blue square is the number of types consumed.

The C# Interactive Windows

Roslyn proposes an interactive C# editor windows view available in VS2010 Menu View> Others Windows > C# Interactive Windows:

I wanted to see exactly which Roslyn API was consumed by this C# Interactive Windows  but to my surprise, this assembly seems to consume only oldish Microsoft.VisualStudio API assemblies? Any feedback on that?

Update: Answer from a Roslyn Team member: The InteractiveWindow assembly is the language agnostic VS host for the window.  The “smarts” are in Roslyn.VisualStudio.CSharp.Repl.dll.

I don’t think I have the right to decompile this Roslyn.VisualStudio.CSharp.Repl.dll assembly, but it is still interesting to have a look at which Roslyn API types it is using. The number in blue square represents the number of members used. A zero means that the type is an interface implemented, or an enumeration used. (btw, a Mono C# Repl is available since more than a year ago).

To be continued…

Without any doubt Roslyn is a major initiative. Roslyn will revolutionize the .NET development tooling sphere. Since VS inception, many have bashed the lake of refactoring facilities in VS, but available in Eclipse or through third-party addin like Resharper or CodeRush. But with Roslyn, instead of giving fishes, MS is building a multi-purposes fishing rod: developing features such as complex and customized search, semantic analysis or refactoring goodies, is what Roslyn will excel at.

During internal pre-discussions with the Roslyn team I noted that Roslyn will be delivered with the .NET Fx bits, so no need to have VisualStudio installed to consume the Roslyn API from your widely delivered code. Hence what we don’t clearly see yet, is that Roslyn might well change the face of  typical application, by letting introducing features based on Compiler as Services and Meta-Programming paradigms.

This entry was posted in Uncategorized. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://www.papercupsmachines.com/ Paper cups machines

    Nice post..

  • http://www.nonwovenbagsmakingmachine.in/ Non woven bag making machine

    Beautiful and amazing before and after. The articles are different & nice!

  • Ghost

    Possibly one of the best details about the Roslyn. 
    Good work and many thanks.

  • Bjerre

    Thanks for the info! Saw some of it at a presentation by Brian Rasmussen some weeks ago :)

  • RichB

    That assumes Roslyn is built with the C#5 compiler. If I was on that team, I’d have built a custom C#5 compiler with extra features to help me.

    I’d wager they have done that.

  • Anonymous

    Around 10% of types are generated by compiler (652 on 5811).

    More language features will certainly be the next step and my little finger tells me that  better support for concurrency (including immutability) should be the flagship feature of C#6 or 7. For now, C#5 ”only” comes with the new async stuff, certainly driven by the WinRT team that makes a point in building responsive UIs.

    But all this is my own opinion and guess, I am not a MSFT.

  • Anonymous

    As said, it’ll be mainly useful for development tooling purposes to develop your own refactoring or analysis tool. But, as said, you can imagine, for example, a financial trader using a C# interactive Windows to write instruction to treat financial data live.

  • Anonymous

    Yes it is!

  • RichB

    What proportion of the classes/methods are auto-generated by the compiler? ie – it’s not really worth counting iterator state machine classes.

    And as they are the C# compiler team, I would expect them to have added language features to the existing C# compiler to make their job writing a compiler easier. For example – better language support for immutability? 

    Any clues to whether that happened?

  • Henning

    Is this the compilers as a service Anders Hejlsberg mentioned in one of his talks at PDC (or similar)?

  • http://www.facebook.com/aidnanddo Fernando Urkijo Cereceda

    Hi! Nice article, but i don’t get some ideas, it’s pretty cool to script c# with roslyn CTP, and to inject code directly into the compiler like an sripting language, but i cannot imagine what else can this CTP make… can you put some examples that will beneffit from Roslyn CTP? thanks!