Friday, 31 October 2008

PDC Day 4: XAML, .Net 4.0, MGrammer, and F#

Has anybody got a handkerchief? sniff, snuffle, wipes away tears. PDC is over. They’ve turned off the wireless. We’ve been kicked out of the conference centre. All my new geek friends are heading home. Will I ever find people that understand me so well ever again? Never mind. It was good well it lasted, and I’ve collected a good bunch of business cards. Perhaps geek friendships work best by email and twitter anyway.

And get this: I’ve got Raymond Chen’s autograph. On his own business card. He even promised to stop by my blog. Better make sure it looks tidy; quick check for inanities: geek royalty might be here any minute. Raymond, if you’re reading this: I’ll stop gushing now! Promise!

XAML

No keynote today, but that meant more time for a whole load of interesting sessions. The first one I attended was on XAML. That’s right: a whole session on eXtensible Application Markup Language. They announced a new version of it, with a raft of new language features, and new XAML Readers and Writers.

The new language features include:

  • The ability to reference other elements by name – independently of anything that the target framework (like WPF) provides
  • Full support for Generic types, everywhere in the language – this is done by using {x:TypeArguments} when defining instances for example
  • Better support for events – including a markup extension that can return a delegate
  • The ability to define new properties of a class within XAML
  • Use of Factory methods to create instances

They’re also introducing a new library, System.Xaml.dll is its name, I believe. In this library will be classes for working with XAML in a much more fine-grained way than the current XamlReader and XamlWriter give us, and with much better performance. Basically they work with a new intermediate format of XamlNodes: kind of like an Object Model for XAML. For example, XmlXamlReader will take an xml file, and return some XamlNodes representing the xaml at a higher level of abstraction than xml. Then an ObjectWriter is used to take those XamlNodes and turn them bit by bit into objects. The cool thing is that you can do the reverse: there’s an ObjectReader that will take an object and return the XamlNodes that represent it, and a XmlXamlWriter  that push those XamlNodes to xml. They’re also making public the BamlReader and BamlWriter classes.

As a demo of all the new stuff, they showed a demo of a whole client-server app written entirely in XAML: WPF UI, Windows Workflow handling the button clicks calling to a WCF service defined in XAML with a Windows Workflow again doing the work. Impressive!

.Net 4.0

After that I went to a session on CLR Futures: basically the foundations of .Net 4.0. The nice feature here, as I already mentioned is the ability to load .Net 4.0 into the same process as .Net 2.0. Now I actually can’t see myself using this feature directly, but I’m sure it will open up a lot of opportunities in other areas, mainly around application addin models; no longer it will it cause a problem if an application loads an addin bound to one version of the .net Framework, and then a second addin needing a newer version; both can happily co-exist.

There are going to be a number of refinements throughout the CLR:

  • Improvements Garbage Collector to reduce the number of times it has to pause the application to do garbage collection
  • Improved Thread Pool to support the new Parallel Extensions framework
  • A new feature that will prevent certain critical exceptions being caught – the ones that indicate a corrupt application that should bomb out as quickly as possible: things like AccessViolation and others.
  • New Profiling APIs that will allow Profilers to attach to running applications – a featured focused on Server scenarios.
  • Managed Crash dumps can be opened in Visual Studio

Two announcements that I found most interesting: they’re going to add tuples to the BCL – we have the F# and Dynamic languages teams to thank for this, and also for the BigInteger class that they’ve finally got right, with the optimisation expertise of the Microsoft Solver Foundation team.

The second one: a new Contract class, and associated features. This is like Assert on steroids. It allows code contracts to be specified within methods. For example, there are the Contract.Requires methods that set up pre-conditions, and the Contract.Ensures method that set up post-conditions. All these conditions are established at the beginning of the method, then as a post-processing step, somebody (not quite clear whether it’s the compiler or the JIT) rearranges the post-conditions to make sure they’re checked at the end of the method. There are also going to be tools that will check a code-base for situations where these conditions might be broken – I’m guessing that Pex is the place to look for this.

MGrammar

After a hastily consumed lunch-in-a-box, I headed for Chris Andersons talk on the new MGrammar language and tooling for building Domain Specific Languages. This was exactly what I was hoping for, and Chris did a brilliant job of showing it off. The topic deserves a blog post of its own, but suffice it to say for now that the Intellipad text editor provides a great environment for developing and testing the DSL, and even provides syntax highlighting for your new language once you’ve defined it. There are also APIs that can be used in your own applications that accept a grammar and a string and will parse it, and provide back a data representation of it. Exciting stuff.

F#

The last presentation of the conference was Luca Bolognase’s Introduction to F#. Luca did a great job of showing the strong points of F#: the succinctness of the syntax and its integration with other .Net languages. The last point he showed really wowed the audience: he had written a real world application that pulled stock prices off the Yahoo finance website and did some calculations with them. The punch-line was when he add one “async” keyword and sprinkled a few “!” symbols, and the whole function became parallelized.

The remains of the day

And that was the end of the conference. But the day held one last surprise for me. On the bus back, I found myself sat next to two guys from the Walt Disney World Company. We got talking about the conference (I doubt anybody on the bus was discussing much else), and when we got back to the hotel they mentioned how they were going to meet up with some colleagues at Downtown Disney, and they invited me to go along with them. We had a great dinner down there, munching over M and F# as well as pizza. So Dave and Kevin: thanks a bunch. It was awesome!

PDC is at an end. Tomorrow I fly home. Then the real fun begins: making sense of everything I’ve heard, and putting it to work.

Thursday, 30 October 2008

PDC Day 3: Microsoft Research

I’ve not given Google Reader much attention over the last few days – I’ve been a bit busy with other stuff – so tonight when I finished up I thought I better pay down some of my aggregator debt: I had something like 450 posts to look through, and my aged laptop stuttered through them rather slowly. Thus I don’t have a great deal of time to give you today’s news before I fall asleepppppppppppppppppppppppppp – oops - at the keyboard: a guy sat in the armchair next to me in the keynote did just that, and his whole screen filled up with zs!

The Keynote

P1020974 They Key note this morning was given by Rick Rashid, Head (or Director, or Vice President or whatever top-flight title they’ve given him) of Microsoft Research. He’s clearly a distinguished guy, even if he did say so himself. He’s been in the same job for 17 years. Before that he worked on various groundbreaking projects, like NeXT OS, which later became MacOS X, and one of the very first networking games, AltoTrek. Since joining Microsoft Research, Rick has led the team that delivered the first version of DirectX,  and other tools that became shipping products.

After its 17 years of growth, Microsoft Research now has more than 800 researchers: that was equivalent to creating a new computer science faculty every year. They have Turing and Field medal winners in their ranks, and more members of the National Academy of Engineering than IBM.

Rick mentioned a couple of interesting areas of research. One was Theorem Proving software. For example, they have developed Terminator: software that is able to prove termination for a very large class of programs. In connection with this, one Microsoft Researcher proved Church’s Thesis, which was an open problem for 50 years.

P1020983Changing up a gear (for energy efficiency), Rick introduced a colleague who talked about the work they were doing with sensor networks. As a demo, they had rigged up the PDC hall with a network of 90 environmental sensors. Live on stage they showed the temperature readings that the sensors were giving, superimposed on a view of the hall from Virtual Earth. The presenter showed fast forwarded through the data, showing the hall cooling at night, then warming up again as the lights were turned on, then even more so in the regions around the doors as attendees streamed in. This kind of information can be used to optimise the use of Air Conditioning in a building, for example. Microsoft themselves are using this to make their new Data Centers more energy efficient. An extension of this is SensorWeb, a web-based Sensor sharing project (all hosted in the Cloud of course) that allows many researchers from all over the world to contribute their own sensor data to a big pot for interesting analysis.

Rick then flicked through some other demos from the Computational Biology arena (Human Genome decoding, HIV research) – there’s even code for this stuff that you can get from CodePlex.

They finished with two cool demos. One was of Boku, a game for Children to teach them how to program. They’ll release a version of it for the XBox later next year. Children can create their own games by putting objects and characters in a world, then visually assigning rules to the things to tell them how to behave. For example, you can drop a couple of apples in the world, then configure a little creature to move towards an apple when sighting it. It looked great.

The other demo was of a future version of the Microsoft Surface device called SecondLight. This one uses some clever materials to allow secondary displays in the space above the surface. They showed Virtual Earth in satellite view display on the surface, then they held a piece of tracing paper above the device, and the street view was projected onto the tracing paper. Cool stuff. It works by using a voltage to control toggle the surface material very quickly between opaque and transparent. While it is opaque the surface display is project; when it is transparent, the image for the secondary display is shown.

The Sessions

On that high note the keynote ended, and I arose from my comfy chair for the last time. I attended Daniel Moth’s excellently presented session on the Parallel Task library, and the features they are adding to Visual Studio 2010 to support it. They announced that the library (which includes PLINQ) will be shipping with .Net 4.0. In Visual Studio there will be two new features to debug Tasks (which are like light-weight threads): the Parallel Tasks window which is a bit like the Thread window, but shows running and scheduled Tasks; then there’s the parallel Stacks window which shows a tree view of all Tasks and their relationships, and the stack for each Task. There’s a good MSDN article on these features.

I spent most of the rest of the day in Oslo sessions. I think the picture is becoming a bit clearer now; I’m going to one last session tomorrow from Chris Anderson to learn about the language for building DSLs (In other news, I added his autograph to my Oslo Modelling book today). After that I hope to blog my impressions of it. In the meantime, you’ll have to content yourselves with Martin Fowler’s analysis!

One last piece of excitement. I filled in my session evaluation forms today, being the good boy that I am. After completing one of them an announcement came up on screen that I’d won a prize. Since it didn’t invite me to Click Here!, but rather to go to the main information desk, I took it seriously, but didn’t hope for more than a tee-shirt. I was actually handed a copy of Windows Vista Ultimate. Now since I already have a spare copy of Vista, I’m inclined to find an innovative way of giving it away. Watch this space!

Wednesday, 29 October 2008

PDC Day 2: Windows 7, VS2010, Office 14 and Oslo

I’m dedicated. While all the other PDCers are still out partying at Universal Studios, I came back to my hotel room in order to bring you the news from the PDC. Or to put it another way, I wasn’t really taken with the chainsaw-wielding zombies lunging at the legs of passing guests, or the ghouls that lurked behind pillars and leaped out to induce a scream. I picked up a free meal at Pizza Hut, including the biggest Funnel Cake I’ve ever seen, and then snuck my way back to the bus, making sure to keep well away from the scaries.

But lets go back to the start. For me, Day 2 of PDC tops Day 1 by some margin. Yesterday’s Keynote by Ray Ozzie on Azure was heavy on marketing but light on the interesting stuff. Today’s all-morning-long keynote was packed with geekness.

Windows 7

The first new thing to be demoed was Windows 7 (that’s not a codename by the way. They’re actually calling it that). Although they’re positioning it as “Windows Vista done right” there’s actually some cool new stuff here – features that should be really useful. New Window Management features for a start. How much time do you waste positioning your windows so that you can see them side by side? Now you can drag them towards the top or sides of the screen, and they will dock – rather like in Visual Studio. “Jumpers” on menu bars is another. These are little application specific tasks that an app can display hanging off its icon in the start menu even before it’s launched.

All the utilities, like Paint and Wordpad, get an overhaul (“we’ve decided we’ll do it once every fifteen years, whether they need it or not”, said Steven Sinofsky). They are all Ribbonified, and Wordpad gains Open XML and ODF support. For developers, there’s the nice feature of being able to mount Virtual Hard Disks (VHDs) from within Windows, and even boot from them. And then there’s finally proper multi-monitor support for Remote Desktopping.

And Microsoft would not like me to forget multi-touch. If you have a touch enabled screen you’ll be able to use multiple fingers to manipulate things. They demoed all the cool zooming and scrolling and gestures stuff that we’ve envied on the iPhone.

Lastly, but not leastly, one that the UK government will surely appreciate: BitLocker encryption for USB memory sticks. I need say no more.

.Net and Visual Studio

Scott Guthrie came on to the stage next, to much cheering and clapping, and it was well-deserved. He brought news of a new set of controls for WPF being released to web today. Amongst those going live are the DataGrid, a new DatePicker, a Calender control, and the Visual State Manager that has been ported from Silverlight. All these can be found on Codeplex. They’ve also released a CTP of an Office 2007-style Ribbon Control and RibbonWindow that they’ve been promising for a little while; this is apparently to be found on the Office UI site, but I couldn’t see it!

On the .Net 4.0 front, the Gu-ru announced that CLR 2.0 and 4.0 will run side by side in process. This is good news for Addin developers, and may also hold promise for those that want to develop shell extensions in .Net. There will also be improvements for WPF such as DeepZoom integration (bringing parity with Silverlight) and improved Text rendering. Other than that, they’re being rather vague. I went to a whole presentation on WPF Futures later in the afternoon, only to discover that they didn’t really have any firm plans they wanted to talk about beyond the controls they’ve already announced.

The most exciting news in this area is that Visual Studio 2010 is going to be rewritten to use WPF and managed code. They’ll be making use of the Managed Extensibility Framework (MEF) to allow anybody to create extensions to it. As an example, Mr Guthrie created a new ScottGu mode for code comments. He used managed code to write an extension to the text editor that displayed the xml comments above a method in a rich WPF view – including Bug numbers formatted as hyperlinks that could be clicked to see full details.

Office 14

The big news for Office is that there will be new web based versions of Word, Excel and One Note, written in Silverlight. These will allow collaborative editing of documents, with automatic synchronisation of changes when multiple users are editing a document. They demoed a spreadsheet being edited in the browser, complete with charting and formulae support. The UI looks much the same as in the Desktop, because they’ve created a Ribbon control for Silverlight.

Oslo

Oslo, for me, was the wildcard of the PDC. It sounded exciting, but would it be useful? I was expecting that this would feature in a keynote, especially when I saw that Chris and Don were scheduled for a slot in Hall A. But they spent that time doing a live coding exercise in Azure which was interesting, but not what I hoped for. Instead we had to wait till the afternoon to discover what it is all about. And I’m still not quite sure!

What I saw this afternoon was a new language called “M”. This M allows data to be defined and stored in a database (a repository, as they call it), and allows queries to be written on top of this data in a strongly typed fashion. Don Box used the analogy that M is to T-SQL what C is to assembler. The idea, it seems, is to make it very easy to write applications that are configured, and even driven by data. One example might be a business rules application, where the rules are written in M and pushed into the repository. The application can then query the repository, and determine how it is supposed to behave.

Another component to Oslo is another language galled MGrammer. MGrammer is a language for defining Domain Specific languages: in fact, the M language itself is defined using MGrammer. MGrammer allows the syntax of a language to be defined (in a way similar to ANTLR, if you’ve ever used that) along with projections that map from the DSL to M so that your DSL can then be interpreted by querying the repository.

There’s a nice text editing tool for this (IntelliPad), and a graphical tool (Quadrant) as well, though I’ve not seen that yet. Everything, including the compiler, is in managed code, and it is all highly extensible.

I will freely admit that, at the moment I only have the edge pieces of the jigsaw, and a few loose floaters in the middle. I’ll let you know when I’ve slotted everything into place. Fortunately they were handing out free copies of a new book, The “OSLO” Modelling Language. I got Don Box to sign my copy, so that must surely help me understand it!

Tuesday, 28 October 2008

The dynamic Future of C# 4.0

P1020889The session I’d been most looking forward to was Anders Hejlsberg’s presentation on the Future of C#. It was clear that many  others were to, because the session room, the second biggest in the convention centre, holding around 2500 people was packed. Anders stood, regarding us all with a Fatherly smile as we filled in. A few dared to approach him. One came forward to get an autograph, and was clearly so overwhelmed that, when the great man asked him for a pen, he forgot that he had one attached to his conference pass, and went back to fetch one from his seat. Others, more brazen, even asked to be photographed with him.

Then the session began. Anders kicked off by outlining the history of C#. You wouldn’t believe it, but it will be Ten years old in December, counting from conception, rather then from birth. C# 1.0 was about managed code; 2.0 was about generics; 3.0 introduced Functional Programming and LINQ. And now 4.0 introduces dynamic programming.

Anders introduced us to the dynamic keyword, which is used when declaring a variable, function return type, or parameter. As Anders said, it is used to declare that the static type of the thing is dynamic. When an variable is marked as being dynamic, C# won’t bother to resolve calls made on that object at compile-time: instead it will delay all method resolution to run time, but will use exactly the same algorithm as it would have used, so that overload resolution works correctly.

The basis of the dynamic resolution is the IDynamicObject interface, shared with the Dynamic Language Runtime. This has on it methods like Invoke which the compiler will call to allow the object itself to participate in method resolution. As well as allowing easy interaction with other dynamic languages such as IronPython and IronRuby this also has the benefit of making COM Interop much more natural. Rather than having to resort to Reflection when encountering “Peter-out typing” (Ander’s term for the phenomenon where COM object models become more loosely typed the further out along a property path you go), using dynamic typing will allow natural-looking code all the way.

Another big help when talking to COM is support for optional and named parameters. Anders made his mea culpa on this one. You can now write code in C# talking to COM the way you could ten years ago in VBA, he said; no longer do we need to call upon Type.Missing to flesh out the method calls to COM objects.

The final thing he announced was support for co-variance and contra-variance of generic interfaces and delegates. No big surprise there: Eric Lippert has been trailing this for a while (hypothetically, of course!). The syntax they’ve decided upon is that type parameters that are only going to be used to return values can be marked with out in the type declaration, whereas parameters that are used for receiving values will be marked with in. For example, IEnumerable<out T>, or IComparable<in T>. I think this is sufficiently complicated to warrant me writing another blog post on it, so that I can understand it better myself.

All in all, no huge surprises, but very useful none-the less. Anders conclusion was that C#4.0 allows you to do things in your code that you were always surprised you couldn’t do before.

But that wasn’t the end. The maestro had one last treat in store for us: a sneak preview of something coming after C# 4.0. Anders explained that for historical reasons not hard to determine, the C# compiler, being the very first C# compiler ever written, is not actually written in C#. This is a big millstone round their collective necks, he admits. So they have already started work on rewriting the compiler in C#, and when it’s done, they will release it for use by the world in its own applications.

It will include the ability to get at a language object model version of code, enabling easy refactoring or meta programming. It could be included in applications to enable runtime evaluation of expressions. To much applause, Anders concluded his session with a demonstration of how easy it is to create a REPL (Run Evaluate Print Loop) using the new C# compiler component.