Bill Blogs in C# -- Metro

Bill Blogs in C# -- Metro

Created: 9/16/2011 5:24:18 PM

Let’s preface by correcting a couple tweets from yesterday.

  • First, the next version of C# will be C# 5.0, not C# 4.5 as I heard earlier. The next version of the framework will be .NET 4.5.  However, you should expect the language versions to be whole numbers.
  • Second, I was misleading on the pattern based comment on C# async.  The await keyword is pattern based. As long as the object being awaited has the right methods to represent a future, it can be awaited.  However, async methods must return either void, or Task<T>. This is different than the current CTP version, but the official release will enforce this.

Onward.

Anyone that still feels managed code, C# and VB.NET are no longer first class citizens in Windows 8 must watch Anders’ talk about the future directions of C# and VB.NET.

The first part of the talk was discussing the async programming metaphor for Windows 8, and how the managed languages support those concepts.

One goal of the Windows 8 runtime and the Windows 8 libraries is to avoid the infamous spinning toilet bowls in your UI. Any operation that could reasonably expect to take more than 200 ms should be an asynchronous operation. The new WinRT APIs take that into account.  Roughly 10% to 15% of the WinRT APIs are async methods. That makes it very important to support async programming in the languages.  Otherwise, your app would block the UI thread unnecessarily  and your UI would frost over.

Most of my audience has seen the async features before, so I won’t dwell on the features of async. Let’s just focus on how these upcoming async features interact with the WinRT libraries.  The move to WinRT shows the benefits of the pattern based await specification. The WinRT methods support the awaitable pattern, even though they don’t return Task<T>. You can await them directly.

One other important point Anders went over in some detail:  async methods do not necessarily mean creating more threads.  However, work delegated to a background thread can be asynchronous. Network APIs and File APIs are async, but do not create new threads. They will use IO Completion ports, or other noification means.

Roslyn gets the big stage

I can’t do Anders’ demo justice in a blog post. Even if you’ve seen earlier Roslyn demos Anders’ has done, watch this.  I’m amazed at how far along the Roslyn team is. I think Anders is thrilled as well.  He was clearly very happy to announce that the team is releasing a CTP for the Roslyn compiler in roughly a month. It will install on top of Visual Studio 2010.

As for the features, I’m really amazed to see the refactoring work in the C# immediate window.  That must have been quite a bit of work. The compiler has also seen significant progress, if the team is far enough to release a CTP.

It’s also clear to me that the Roslyn work would not have been progressing at this kind of a pace if Microsoft is not committed to making continued investment in these languages and the .NET managed environment. Equally important, .NET 4.5 and C# 5 can leverage the already announced async features in the WinRT runtime. It’s just one of many examples that show how much the .NET runtime and BCL design idioms have had an affect on the WinRT API design. Anders also showed some of this interop by creating a C# class library and consuming it in a Javascript Metro application.  It’s amazingly easy.

Starting to grow some Metro skills

I spent the rest of the day learning about the Metro programming model. My initial impression is positive.  The APIs seem very natural from both C# and Javascript.  There has been some very interesting work in the Projection layer to the WinRT APIs in a natural way to any of the supported environments (Javascript, C++, and Managed code).

There are some very strong recommendations and guidelines regarding a well-behaved Metro application. They cover areas like suspending your app when necessary, use of the screen real estate, tiles and other notifications.  As I build some samples, I’ll cover those in more detail.  There are a few key messages I got on Metro applications:

  • The guidelines provide consistency for the user. Following them will almost certainly give your application a better chance at gaining acceptance.
  • There are a lot of ways for your app to interact with the user. They include tiles, toast, and badges.  Think carefully about what you want to tell the user, and how you want the user to react to that information. It will help you build a better app

Overall, I like the Metro experience, and the programming model. I do have quite a bit to learn before I feel like I can give guidance on creating those applications yet.

Created: 9/13/2011 8:22:10 PM

Steven Sinofsky discusses the changing world of computing. Form factors and user interaction models change how programs should work. I’m gad that’s at the core of Windows 8 design. In addition, Mobility now means devices that you use while carrying, not just devices you carry and then use. They have clearly been spending a lot of time determining what’s important to users now.

“Touch first, but still comfortable with a mouse and keyboard” is a great way to describe this important design considerations.  Historically, Windows had always been Mouse + Keyboard, and maybe touch. That message changes the design goals, and should provide better end user experience.

Observations on Julie Larson Green’s demo

That customized password design is great for new form factors. Good idea. It’s also going to be a great way to provide security.

The start page is a great idea, However, I’m concerned that what they’ve done is optimize for a very cluttered start screen. My opinion is that a better UX would be to optimize for a smaller number of tiles, and encourage users to have fewer tiles.

The IE demo shows some of the system level features to leverage for applications: the semantic clipboard sharing, the smart sharing. and the system-wide spell checking.  

The best design change for Windows 8 is that the focus is on the application, not on the system (or the system chrome). That really catches the changing face of computing. The second big change is that the system should be an ecosystem (web) of apps connected to each other, and the cloud.

And on to Building applications. The big picture seems to say this to me:

  • All the managed languages are in.
  • XAML based UIs are in.
  • So is HTML5 / Javascript.
  • The CLR/BCL seems to move into something now called ‘WinRT’.
  • The runtime is surfaced to all clients, including Java script in the browser (at least IE).

There are open questions:

  • Does WinRT contain the superset of the BCL APIs and the native C++ library? Or what?
  • How many APIs are moving forward? And in what timeframe?
  • What will the performance implications be for the managed languages with respect to C++?

The tools are moving forward in quite a few ways.  VS11 will have support for the HTML/JS development.  Expression Blend gains support for laying out HTML layout by introspection on the DOM.

Great discussion of the different hardware that Windows 8 runs on.  The key take away for the non-hardware nerd:  The OS is optimized for the hardware its running on. It will expose everything in place.

And of course, every Build attendee gets the developer preview tablet.

Sinofsky shows great demos of setup/refresh/and other system tools.  Once again, some really good design into making this a professional system that is somewhat accessible to the average use.

Next, he’s showing a lot of the multi-monitor support and power user synchronization.  There’s a lot for serious power users and developers.  Also, luckily, it doesn’t surface unless you want it.

Windows live synchronization. The big picture here is that it really does show the “Three screens and a cloud” message at its fruition.

There’s a lot of questions.  I am hoping to get some information on these areas over the rest of the week:

  • How much control does an app have over sharing? This could be a security risk.
  • How easy is it to create an app that runs well in both Metro style and desktop style?
  • How much of the existing APIs are going to be surfaced in the Windows Runtime (WinRT)?
  • F# wasn’t mentioned on the developer tools slide.  Is that an oversight? (I think so.  Don Syme is speaking at Build)
  • How do my apps participate in the Sync PC Settings?

For more of my immediate thoughts, check out my twitter stream from today.

Final Thoughts

Overall, I’m very impressed. Windows 8 clearly is an ambitious redesign of the Windows system. It’s as big a change as the change from Windows 3.1 to Windows 95. It clearly reflects a lot of thought on how people do use computers today, and how they want to use computers.

Current Projects

I create content for .NET Core. My work appears in the .NET Core documentation site. I'm primarily responsible for the section that will help you learn C#.

All of these projects are Open Source (using the Creative Commons license for content, and the MIT license for code). If you would like to contribute, visit our GitHub Repository. Or, if you have questions, comments, or ideas for improvement, please create an issue for us.

I'm also the president of Humanitarian Toolbox. We build Open Source software that supports Humanitarian Disaster Relief efforts. We'd appreciate any help you can give to our projects. Look at our GitHub home page to see a list of our current projects. See what interests you, and dive in.

Or, if you have a group of volunteers, talk to us about hosting a codeathon event.