Friday, December 5, 2008

Job done

My presentation at DevTeach went very well. As a matter of fact I was impressed to see so many people even though I was in competition with Carl Franklin and Rod Paddock.

 

I want to thanks everyone who was there.

 

Friday, September 12, 2008

Presenting @ DevTeach

If you needed one more reason to register for DevTeach here it is. I'm giving a talk about parallel extensions. Here is the teaser:
A glimpse into the parallel universe
There is no more free lunch! The Moore's law is over. If we want more power we need to cross the processor barrier and do work in parallel. In June 2008, Microsoft released its second CTP of Parallel Extensions library. Come with me to see how easy it will be to make that leap of faith into the world of parallel processing. We will see how Task, concurrent collections, lazy initialization, parallel Linq and other tools can help us in this endeavour.

Wednesday, July 9, 2008

New SQL to XML in SQL Server 2005, no more FOR XML EXPLICIT

Did you ever try to spit out XML data from a SQL database? Of course you can use the “FOR XML AUTO” clause but it will throw you something like this:

SELECT TOP 6 ProductID, ProductName, UnitPrice
FROM Products 
FOR XML EXPLICIT
<root>
	<Products ProductID="1" ProductName="Chai" UnitPrice="18.0000" />
	<Products ProductID="2" ProductName="Chang" UnitPrice="19.0000" />
	<Products ProductID="3" ProductName="Aniseed Syrup" UnitPrice="10.0000" />
	<Products ProductID="4" ProductName="Chef Anton's Cajun Seasoning" UnitPrice="22.0000" />
	<Products ProductID="5" ProductName="Chef Anton's Gumbo Mix" UnitPrice="21.3500" />
	<Products ProductID="6" ProductName="Grandma's Boysenberry Spread" UnitPrice="25.0000" />
</root>

With “FOR XML EXPLICIT” you can have a little more control:

SELECT TOP 6 
	1 AS Tag, 
	NULL AS parent, 
	ProductID AS [Product!1!ID], 
	ProductName AS [Product!1!Name!element], 
	UnitPrice AS [Product!1!Price!element]
FROM Products 
FOR XML EXPLICIT

<root>
  <Product ID="1">
    <Name>Chai</Name>
    <Price>18.0000</Price>
  </Product>
  <Product ID="2">
    <Name>Chang</Name>
    <Price>19.0000</Price>
  </Product>
  <Product ID="3">
    <Name>Aniseed Syrup</Name>
    <Price>10.0000</Price>
  </Product>
  <Product ID="4">
    <Name>Chef Anton&apos;s Cajun Seasoning</Name>
    <Price>22.0000</Price>
  </Product>
  <Product ID="5">
    <Name>Chef Anton&apos;s Gumbo Mix</Name>
    <Price>21.3500</Price>
  </Product>
  <Product ID="6">
    <Name>Grandma&apos;s Boysenberry Spread</Name>
    <Price>25.0000</Price>
  </Product>
</root>

But this SQL syntax is a bit odd. It gets worst when you try to add multiple level in your XML output. SQL Server 2005 provides another constrct: “FOR XML PATH”. Here is the same sample:

SELECT TOP 6 
	ProductID AS [@ID], 
	ProductName AS [Name], 
	UnitPrice AS [Price]
FROM Products 
FOR XML PATH('Product')

This will produce the same output as the previous EXPLICIT sample but the syntax is much more understandable.

Monday, January 7, 2008

Volta: Redefining Web Development

Volta: Redefining Web Development

via Yet Another Language Geek by wesdyer on 12/5/07

Anyone who writes web applications knows that web development is not easy. Developers wrangle with a soup of technologies distributed across multiple tiers. We live in a world where programmers accept the fact that they need to know four or five different languages, tools, and environments just to get a site up and running. In ancient times, the Egyptians built marvelous structures despite the primitive tools that the workmen used. Building a pyramid took most of the national resources of wealth and labor. Today, we build structures which are vastly more complicated and yet require only a tiny fraction of the resources. The difference is in the tools and the infrastructure.

In a similar way, Volta significantly improves web development. Programmers write web applications using familiar .NET languages, libraries, and tools. Volta splits the application into multiple parts potentially running on different tiers, say, client and server. Client code needs only a minimal, JavaScript-enabled browser, though Volta will take advantage of additional runtimes that may be present.

Programmers simply refactor classes that need to run on tiers other than the client and Volta injects the boilerplate code for communication, serialization, synchronization -- all the remoting code. The developer enjoys all of the benefits of .NET: a great debugger, test tools, profiling, intellisense, refactorings, etc.

Just how simple is Volta? Let's write an application that uses a button to query the server for a string and displays that string to the client: the hello world web application.

image

Now, let's write the code for the web page. We need a Div for the output and an Input for the interaction. Of course, we could have constructed the page elements with HTML/CSS instead.

using System;
using Microsoft.LiveLabs.Volta.Html;
using Microsoft.LiveLabs.Volta.Xml;

namespace HelloWorld
{
    public partial class VoltaPage1 : Page
    {
        public VoltaPage1()
        {
            var output = new Div();
            var b = new Input();
            b.Type = "button";
            b.Value = "Get Message";
            b.Click += () => output.InnerHtml = C.GetMessage();
            Document.Body.AppendChild(output);
            Document.Body.AppendChild(b);
        }
    }

    internal class C
    {
        public static string GetMessage()
        {
            return "Hello, World";
        }
    }
}

But we want to produce the message on the server. Time to refactor.

image

Browser clients call the server, the "Origin", because this ensures the message will come from the same server that supplied the HTML.

[RunAtOrigin]
internal class C
{
    public static string GetMessage()
    {
        return "Hello, World";
    }
}

That is it. Try it out.

image

Now, click "Get Message".

image

Great. But is it cross-browser compatible?

image

Yes. And you can debug it.

image

You can even debug across tiers.

image

There is a lot more to Volta in the first technology preview which was made publicly available at 11 am PST today and there will be a lot more to come.

Still skeptical? Try it out for yourself.

http://labs.live.com/volta

image