Tim Sneath

Musings of a Client Platform Guy

  • Tim Sneath

    A Modern Browser

    • 100 Comments

    This morning, Mozilla shared their feelings on IE9 with a post that claims to answer the question, “Is IE9 a modern browser?” While they grudgingly concede that IE9 is “a step in the right direction”, they seem to be operating under a very narrow definition of what “modern” means, that I don’t think matches the dreams that web developers and end-users actually have.

    Let me help them with a definition for what we believe users and developers should expect from a “modern browser”:

    • Modern browsers are fast. They take full advantage of the underlying platform to render graphics with the GPU, compile and execute JavaScript across multiple CPU cores and ensure that web applications run as close as possible to the same speed as native applications.
    • Modern browsers enable rich, immersive experiences that could hitherto only be delivered through a plug-in or native application. They can blend video, vector and raster graphics, audio and text seamlessly without sacrificing performance.
    • Modern browsers implement features when they are ready, providing predictable patterns that developers can rely on rather than suddenly breaking or removing specifications. They don’t check off support based on a half-completed implementation written to pass a synthetic test, but validate against a test suite that confirms interoperability.
    • Modern browsers do adopt standards at an early stage of readiness so developers can experiment and validate the specification, but clearly delineate unstable prototypes as such.

    It seems that others share this view. The discussion on YCombinator starts with this comment:

    Maybe I'm just weird, but I consider issues like performance, reliability, and having a stable foundation to build on to be far more important than supporting your own browser's take on some hypothetical future "standard", which is just IE vs. Netscape all over again. On that basis, IE is currently the only one of the big three that is actually going in the right direction.

    And Download Squad concludes its analysis of the Mozilla article with the following:

    Don't get us wrong, [Firefox] is an excellent browser -- but more stuff doesn't necessarily equate to better stuff.

    To our friends at Mozilla, we admire your passion for the open web, and we look forward to continued competition.

  • Tim Sneath

    An Open Letter from the President of the United States of Google

    • 224 Comments

    esperandmThe world’s ability to communicate with one another is a key factor in its rapid evolution and economic growth. The Esperanto language was invented last century as a politically neutral language that would foster peace and international understanding. Since the launch, we’ve seen first-hand the benefits of a constructed language:

    • A pure form of communication that is unsullied by cultural context;
    • Broad adoption by as many as 10,000 speakers
    • Independent (yet mostly compatible) dialects that not only bring additional choice for speakers also foster healthy competition and innovation

    We expect even more communication between people in the coming year and are therefore focusing our investments in languages that are created based on constructed language principles. To that end, we are changing the spoken and written language of this nation to make it consistent with the form of speech already supported by the Language Creation Society. Specifically, we are supporting the Esperanto and Klingon languages, and will consider adding support for other high-quality constructed languages in the future. Though English plays an important role in speech today, as our goal is to enable open innovation, its further use as a form of communication in this country will be prohibited and our resources directed towards languages that are untainted by real-world usage.

    These changes will occur in the next couple months but we are announcing them now to give citizens using other languages an opportunity to translate the libraries of the world into Esperanto.

    Dankon, nedankinde!

  • Tim Sneath

    Top 10 Tips for the Effective Use of Social Media

    • 3 Comments

    While my job here at Microsoft consumes much of my waking life, I spend a little of my spare time volunteering with a small charitable organization called HEAL Africa. They do work in the Democratic Republic of Congo healing victims of sexual violence from the ongoing civil war there. It’s a compelling story of how an organization is changing lives in an appalling situation, but I digress from the purpose of this entry.

    One area they asked me to think about is how they can use social media effectively – a question that many charities and non-profit organizations wrestle with. And of course, it’s an area of great interest to evangelists like myself: an area that is a daily focus as we attempt to change perceptions of emerging technologies like IE9 and Silverlight.

    So I thought I’d share a few thoughts here, both as a forcing function for me to distil a few ideas and hopefully as something that might be of interest to others.

    1. Know what you’re trying to achieve. Too few organizations have a clear sense of the outcomes they hope to realize from engaging in social networks. What are your goals? Many organizations spend a lot of time encouraging supporters to ‘follow’ them on networks like Twitter and Facebook without much sense of why this is important or what they’ll do with these people once mobilized. This has a negative, rather than a positive effect – it diverts attention away from a core mission, and it leaves supporters with a premature feeling that they’ve ‘done their part’. Remember your core mission and be cautious about using followers as a proxy metric of success.
    2. Know your audience. Assuming some measure of success, it’s important to have a clear sense of who you’re communicating with. In a non-profit setting, those who follow you on a social network are likely already your supporters. A familiar trap is organizations who fail to recognize the difference between converting and energizing. In this setting, converting is the act of trying to persuade new people to side with your cause or invest in some way; energizing is the act of deepening an existing relationship or motivating someone to act in some way. The way you engage online should vary depending on whether your audience primarily consists of dedicated volunteers or those who have no prior knowledge of your organization. Fortunately, online channels tend to self-segment – a Facebook page is likely to be dominated with those who need energizing. A blog will often reach a far more diverse audience who aren’t already invested.
    3. Use social and online media to humanize your organization. It’s tempting to take press releases or other news items and blast them out on all available channels. But that’s not the best use of social media – it disconnects you from your audience rather than creating a closer connection. This is your opportunity to put a more human face to your organization: telling the inside story, being open and transparent about how you think through issues and challenges, and providing a perspective that others can relate to. Ensure that you don’t edit out the personality. Tell people about the things you’ve done right, and the things you can learn from.
    4. Be timely. Social media is about a flow of discourse and a conversation, rather than about blasting your message out to an audience. Use channels like Twitter and blogs to provide an up-to-the-minute view of the work you’re doing, offering fresh, first-hand updates on the situation that respond to current trends or news. You can only set the news agenda when you’re part of this flow.
    5. Don’t moderate views that you dislike. To some people this is obvious, to others it’s counter-intuitive. If you are changing perceptions, you’re necessarily going to be bumping into those who don’t share your views. On a blog, it’s tempting to moderate or delete comments that provide an opposing view: it feels like a guest has come into your home and is insulting your choice of décor. Yet for the most part, these are the comments to relish: they demonstrate that you are engaged in an authentic conversation that is generating a reaction. There’s a lot more to say on this topic that I’ll perhaps address in a future post.
    6. Build a public record. Particularly with blogs, podcasts and similar channels, consistency is key. Unless you establish a regular cadence of content, you’ll never establish a regular cadence of visitors. That doesn’t mean you have to post at a certain time each day: you don’t have to be rigid about it, but don’t go dark for weeks on end either. Remember that everything you post has a lifetime that extends for years beyond the original week of posting. Looking at the traffic to my blog, maybe as much as two-thirds of it goes to content I wrote in the preceding months rather than what is on the current home page.
    7. Be a recommendation engine. In social media, the currency traded isn’t the dollar: it’s influence, reputation and audience. Use your own influence and reputation to give other interesting organizations or individuals their own spotlight. Follow and link to those around you who are doing interesting things. Unlike real money, trading online currency is that it isn’t a zero-sum game – in fact, the more you give, the more you earn. Even your competitors can be your allies in this regard. But whatever you do, be authentic – don’t fall into the trap of trading links for cynical gain. Make your recommendations count.
    8. Strike up a conversation. The single most valuable outcome of social media is to strike up a conversation with your supporters or customers, giving you a much more accurate ability to channel their needs and wants. Don’t just pontificate: ask questions. The goal isn’t to preach, it’s to collaborate. You need to listen more than you talk. Give air for others to contribute – don’t leap in immediately with a reply to any comment that’s made because that stifles a broader discussion. Show you’re listening by responding, but don’t necessarily feel the need to offer a blow-by-blow response to every point that’s made.
    9. Understand the volume level. Once in a while you have an earth-shattering announcement that blows out the barn doors. But not everything “goes to 11”. It’s important to understand the volume level you want to apply to what you share, otherwise it’ll be hard for others to spot when you’re telling them something big. My team often talks about new things we’re doing in terms of the impact it’s going to make – to use another analogy, how much it “moves the needle”. You have to have dynamic range in your communications – if everything is shouted from the rooftops, people will stop listening.
    10. To build traffic, go where your audience is. Don’t spam or steal someone else’s platform to push your cause. But spend time growing your profile and influence through others’ sites. Get involved and comment – become known for insightful responses that add value to the debates folks are having in other forums. When posting comments on another blog, use your real email and web address, but don’t be nakedly self-promoting.

    What do you think? What would you add? What are your most effective strategies? Have you seen good counter-examples where the “accepted wisdom” is in fact the wrong way to engage?

  • Tim Sneath

    PDC10: The Future of C# and Visual Basic

    • 0 Comments

    At PDC 2000, we rolled out the .NET platform, including a new language called C#. A lot has happened since then! Each release has had a theme – in C# 2 we added generics; in C# 3 it was LINQ. Most recently in C#  4 with VS2010 we introduced deeper dynamic language support and expressed a commitment to feature parity across VB and C#.

    Language designers need to observe and integrate major trends into their work. Over the last few years, we’ve seen several major trends: (i) declarative styles – where you say more about the ‘what’ and less about the ‘how’, e.g. DSLs, functional programming; (ii) the resurgence of dynamic languages like Ruby and JavaScript, and how that affects static typed languages; (iii) concurrency.

    In the last major editions of the language, there has been significant investment in declarative styles and dynamic programming. But there isn’t heavy language support for concurrency today, even though there is good support in the framework through the likes of the Task Parallel Library.

    One reason for the rise in concurrency is the rise in connected applications: it’s almost impossible today to build an application that doesn’t talk to a service, or indeed to build a service that doesn’t talk to another service. This increases latency – for example, it is just not acceptable for a UI to freeze while it waits for a service to return. As a result, we all practice the art of asynchronous programming. It is starting to become the norm, and we’re even starting to see the rise of async-only APIs in languages like JavaScript and Silverlight.

    As a result, we’re looking at making concurrency the theme of the next release of our C# and Visual Basic languages.

    The Challenges of Asynchronous Programming

    In a synchronous call, the act of invoking a method and waiting for the result are fused: you can’t separate the two. With asynchronous programming, that changes. You can call the method and it will return immediately; later, it will deliver the result, so the two operations are separable.

    There are a few problems with today’s model: (i) that the function can’t return the result, since the code is asynchronously executing, so it has to use a callback instead; (ii) it can be complex to update the UI without marshaling data back from a background thread; (iii) in a server setting, you don’t really want unconstrained thread creation because of the increased competition to the thread pool.

    Anders demonstrated a simple example that shows how complex the asynchronous model quickly becomes. The code fragment below downloads and display movies based on a query of the NetFlix OData feed:

    Movie[] QueryMovies(int year, int first, int count) {
      var client = new WebClient();
      var url = String.Format(query, year, first, count);
      var data = client.DownloadString(new Uri(url));
      var movies = 
        from entry in XDocument.Parse(data).Descendants(xa + "entry")
        let properties = entry.Element(xm + "properties")
        select new Movie {
          Title = (string)entry.Element(xa + "title"),
          Url = (string)properties.Element(xd + "Url"),
          BoxArtUrl = (string)properties.Element(xd + "BoxArt").Element(xd + "LargeUrl")
        };
        return movies.ToArray();
    }

    But this code is synchronous – the UI will hang while waiting for the call to return. Let’s follow through the steps needed to fix this:

    • We can replace the DownloadString() method with DownloadStringAsync();
    • Then we need to separate out the remaining code in the method to a handler for the DownloadStringCompleted event;
    • But how do we then return the result to the calling method? The QueryMovies method will already completed by this point. We can’t – instead, we need to make this method async as well, adding an Action<> delegate as a parameter.
    • Now we have to go back to the method that called QueryMovies and retrieve the result asynchronously . And this is where it really starts to get unpleasant, because QueryMovies is being called in a while loop, as follows:
      void LoadMovies(int year) {
        resultsPanel.Children.Clear();
        statusText.Text = "";
        var pageSize = 10;
        var imageCount = 0;
        while (true) {
          var movies = QueryMovies(year, imageCount, pageSize);
          if (movies.Length == 0) break;
          DisplayMovies(movies);
          imageCount += movies.Length;
        }
        statusText.Text = string.Format("{0} Titles", imageCount);
      }
    • How do we pass a delegate to a while loop? It’s delegates all the way down. Instead we have to replace the while loop and reorder the code, as shown below: 
        ...
        action = movies => {
          if (movies.Length > 0) {
            DisplayMovies(movies);
            imageCount += movies.Length;
            QueryMovies(year, imageCount, pageSize, action);
        }
        else { 
          statusText.Text = string.Format("{0} Titles", imageCount);
        }
        ...

    As shown in the code above, you can do it – but it’s unwieldy, and the flow of the code gets lost. And this is before we’ve dealt with error handling! Clearly we can do better.

    New Async Features

    The Visual Studio Async CTP, announced at PDC, introduces some new extensions to VB and C# to support a simpler, more declarative approach to asynchronous development.

    The Task Parallel Library introduced a Task<T> type, which is used to represent an ongoing operation: a value that is currently being computed and will be delivered at some time in the future. We can use this as the return type along with a new async keyword to let the compiler know how it will be used, as follows:

    async Task<Movie[]> QueryMoviesAsync(int year, int first, int count) {  

    We now can add some asynchronous work to the class. The CTP introduces a number of Task<T>-centric extension methods that will eventually be added into the core framework, which enable us to compose and call other asynchronous methods seamlessly. For example, the call to DownloadString() in our original method can be replaced by a call to DownloadStringTaskAsync(), which returns Task<string> instead of just string. (This is something you can offer for your APIs too, of course.)

    And we can now use the await operator, as follows:

      var data = await client.DownloadStringTaskAsync(new Uri(url));

    The compiler rewrites your code (as it does for iterators), to use a continuation and then return, executing the rest of the code when the result becomes available.

    Now the LoadMovies() method is really simple. Starting with the original code above, we can again mark the header with the async keyword and then we can call the new async version of QueryMovies using the same await operator:

      var movies = await QueryMoviesAsync(year, imageCount, pageSize);

    That’s all you have to do! As you can see, the new syntax preserves the logical syntax of the code. Exception handling requires no additional work: we don’t need to worry about callbacks, for instance.

    It’s relatively easy to cancel an asynchronously executing task: you use the .NET 4 cancellation types, specifically CancellationToken and CancellationTokenSource, to indicate a request to cancel the task. The token can be passed into the DownloadStringTaskAsync() method. Everything here is just as before.

    Background and Foreground Threads

    It’s important to note that the example shown above does not use a background thread – the async calls are happening on the UI thread. They aren’t computationally expensive; they are just blocking on a network call.

    What if there is something that is computationally expensive that you do want to run on a background thread? You can simply use a lambda within an await context, for example:

    async void ComputeStuffAsync() {
      double result = 0;
      await TaskEx.Run(() => {
        for (int i=1; i < 500000000; i++) {
          result += Math.Sqrt(i);
        }
      });
      MessageBox.Show("The result is " + result, "Background Task",
        MessageBoxButton.OK, MessageBoxImage.Information);
    }
    In summary, what the new asynchronous support offers is an abstraction layer that unifies computational, network and I/O asynchrony. For more information on the features, you can read a whitepaper on the MSDN site. There are also a number of good samples in the CTP, including the example demonstrated above.
  • Tim Sneath

    PDC10: Introducing HTML5 Vector Graphics

    • 4 Comments

    The HTML5 family of specifications provide two different models for vector graphics: canvas and SVG. Why have both? What is the difference between them, and how do you use them?

    It’s important to start by understanding the difference between retained mode and an immediate mode graphics models:

    • In a retained mode API, the structure of a graphical scene or object is stored in memory as a graph. The runtime itself is responsible for drawing the scene or elements of the scene as appropriate.
    • In an immediate mode API, it is the application that is responsible for drawing the scene and you can’t manipulate an object in the scene once it has been drawn. Each has their benefits, depending on the style of application being created, as we’ll see.

    More information on retained and immediate mode models can be found on MSDN.

    SVG is a retained-mode graphics model. To build a scene graph in SVG, you write declarative markup to create an in-memory tree structure that lives in the HTML DOM. You can manipulate the scene graph through code or through CSS. SVG markup can be generated from a variety of tools, including Adobe Illustrator and Microsoft Visio.

    Canvas is the immediate-mode graphics model. Because it doesn’t store the graph in memory, it takes less memory overhead to use, and can be faster for intensive use. Unlike SVG, it is programmatic in nature – there is only one parent <canvas> element, and code is used to populate it. While you draw primitive objects on a canvas, the only thing that is stored is the generated bitmap surface. In general, canvas is a lower-level API than SVG because of these constraints.

    A quick tabular comparison of the two technologies:

    Canvas SVG
    Pixel-based (almost like a “dynamic PNG”) Shape-based (no concept of a pixel)
    Single HTML element Multiple graphical elements which become part of the HTML DOM
    Modified through script only Modified through script and CSS
    Event model / user interaction is simplified (x,y) Event model / user interaction is abstracted (rect, path)
    Performance is better with smaller surface and/or larger number of objects Performance is better with a larger surface and/or smaller number of objects

    Given these characteristics, what is the best technology to use for a specific scenario? SVG is perfect for high-fidelity documents and graphics for viewing and printing, and for interactive charts and maps. On the other hand, canvas is perfect for mathematically-intensive operations and complex scenes. However, there are a lot of cross-over scenarios where there’s no clear winner at this point in time, and as browsers evolve and improve, it seems that the performance characteristics of both technologies are starting to converge. Both technologies are clearly valuable!

    [Session CD53 | presented by Patrick Dengler]

Page 1 of 105 (525 items) 12345»